[Orxonox-commit 6066] r10725 - in code/branches/AI_HS15: data/levels src/orxonox/controllers src/orxonox/worldentities/pawns
gania at orxonox.net
gania at orxonox.net
Fri Oct 30 23:07:34 CET 2015
Author: gania
Date: 2015-10-30 23:07:34 +0100 (Fri, 30 Oct 2015)
New Revision: 10725
Modified:
code/branches/AI_HS15/data/levels/AITest.oxw
code/branches/AI_HS15/src/orxonox/controllers/CommonController.cc
code/branches/AI_HS15/src/orxonox/controllers/CommonController.h
code/branches/AI_HS15/src/orxonox/controllers/DivisionController.cc
code/branches/AI_HS15/src/orxonox/controllers/DivisionController.h
code/branches/AI_HS15/src/orxonox/controllers/LeaderController.h
code/branches/AI_HS15/src/orxonox/controllers/SectionController.cc
code/branches/AI_HS15/src/orxonox/controllers/SectionController.h
code/branches/AI_HS15/src/orxonox/controllers/WingmanController.cc
code/branches/AI_HS15/src/orxonox/controllers/WingmanController.h
code/branches/AI_HS15/src/orxonox/worldentities/pawns/Pawn.cc
Log:
fixed pointers
Modified: code/branches/AI_HS15/data/levels/AITest.oxw
===================================================================
--- code/branches/AI_HS15/data/levels/AITest.oxw 2015-10-30 18:51:49 UTC (rev 10724)
+++ code/branches/AI_HS15/data/levels/AITest.oxw 2015-10-30 22:07:34 UTC (rev 10725)
@@ -70,17 +70,16 @@
</controller>
</StaticEntity>
-
<SpaceShip position="1000, 1000, -1300 ?>" lookat="0,0,0">
<templates>
<Template link=spaceshipassff />
</templates>
<controller>
- <SectionController team=1>
- </SectionController>
+ <DivisionController team=1>
+ </DivisionController>
</controller>
</SpaceShip>
- <SpaceShip position="1000, 1000, -1600 ?>" lookat="0,0,0">
+ <SpaceShip position="1000, 1000, -1300 ?>" lookat="0,0,0">
<templates>
<Template link=spaceshipassff />
</templates>
@@ -89,6 +88,15 @@
</WingmanController>
</controller>
</SpaceShip>
+ <SpaceShip position="1000, 1000, -1700 ?>" lookat="0,0,0">
+ <templates>
+ <Template link=spaceshipassff />
+ </templates>
+ <controller>
+ <WingmanController team=1>
+ </WingmanController>
+ </controller>
+ </SpaceShip>
<SpaceShip position="1000, 1000, -1900 ?>" lookat="0,0,0">
<templates>
<Template link=spaceshipassff />
Modified: code/branches/AI_HS15/src/orxonox/controllers/CommonController.cc
===================================================================
--- code/branches/AI_HS15/src/orxonox/controllers/CommonController.cc 2015-10-30 18:51:49 UTC (rev 10724)
+++ code/branches/AI_HS15/src/orxonox/controllers/CommonController.cc 2015-10-30 22:07:34 UTC (rev 10725)
@@ -50,7 +50,6 @@
{
RegisterObject(CommonController);
-
//this->actionTimer_.setTimer(ACTION_INTERVAL, true, createExecutor(createFunctor(&LeaderController::action, this)));
}
@@ -59,6 +58,38 @@
{
}
+ void CommonController::moveToPosition(const Vector3& target)
+ {
+ if (!this->getControllableEntity())
+ return;
+
+ Vector2 coord = get2DViewCoordinates(this->getControllableEntity()->getPosition(), this->getControllableEntity()->getOrientation() * WorldEntity::FRONT, this->getControllableEntity()->getOrientation() * WorldEntity::UP, target);
+ float distance = (target - this->getControllableEntity()->getPosition()).length();
+ float rotateX = clamp(coord.x * 10, -1.0f, 1.0f);
+ float rotateY = clamp(coord.y * 10, -1.0f, 1.0f);
+
+
+ if (this->target_ || distance > 10)
+ {
+ this->getControllableEntity()->rotateYaw(-1.0f * 0.8f * rotateX);
+ this->getControllableEntity()->rotatePitch(0.8f * rotateY);
+ }
+
+ if (this->target_ && distance < 200 && this->getControllableEntity()->getVelocity().squaredLength() > this->target_->getVelocity().squaredLength())
+ {
+ this->getControllableEntity()->moveFrontBack(-0.05f); // They don't brake with full power to give the player a chance
+ }
+ else if (distance > 100)
+ this->getControllableEntity()->moveFrontBack(0.8f);
+
+
+
+ if (distance < 100)
+ {
+ this->positionReached();
+ bHasTargetOrientation_=false;
+ }
+ }
}
Modified: code/branches/AI_HS15/src/orxonox/controllers/CommonController.h
===================================================================
--- code/branches/AI_HS15/src/orxonox/controllers/CommonController.h 2015-10-30 18:51:49 UTC (rev 10724)
+++ code/branches/AI_HS15/src/orxonox/controllers/CommonController.h 2015-10-30 22:07:34 UTC (rev 10725)
@@ -38,18 +38,58 @@
class _OrxonoxExport CommonController : public Controller
{
public:
-
+ enum FormationMode {VEE,FINGER4,DIAMOND, WALL};
+ virtual void setFormationMode(FormationMode val)
+ { this->formationMode_ = val; }
+ inline FormationMode getFormationMode() const
+ { return this->formationMode_; }
+
CommonController(Context* context);
virtual ~CommonController();
virtual bool isLeader();
virtual bool setWingman(CommonController* wingman);
virtual bool hasWingman();
- CommonController* myWingman_;
+ Vector3* desiredRelativePosition_;
- CommonController* myLeader_;
protected:
+ void moveToPosition(const Vector3& target);
+ virtual void positionReached() {}
+ /* void moveToTargetPosition();
+ void absoluteMoveToPosition(const Vector3& target);
+ void copyOrientation(const Quaternion& orient);
+ void copyTargetOrientation();
+
+ void spin();
+ void turn180();
+ void follow();
+ void setTargetPosition(const Vector3& target);
+
+ void setTargetOrientation(const Quaternion& orient);
+ void setTargetOrientation(Pawn* target);
+
+
+
+ void setTarget(Pawn* target);
+
+ void searchNewTarget();
+ void forgetTarget();
+
+ void targetDied();
+*/
+ bool bHasTargetPosition_;
+ Vector3 targetPosition_;
+ bool bHasTargetOrientation_;
+ Quaternion targetOrientation_;
+
+ WeakPtr<ControllableEntity> target_;
+ bool bShooting_;
+
+ FormationMode formationMode_;
+
+
+
//void defaultBehaviour(float maxrand); //<! Helper function for code reusage. Some concrete commands for a bot.
private:
Modified: code/branches/AI_HS15/src/orxonox/controllers/DivisionController.cc
===================================================================
--- code/branches/AI_HS15/src/orxonox/controllers/DivisionController.cc 2015-10-30 18:51:49 UTC (rev 10724)
+++ code/branches/AI_HS15/src/orxonox/controllers/DivisionController.cc 2015-10-30 22:07:34 UTC (rev 10725)
@@ -33,27 +33,35 @@
{
RegisterClass(DivisionController);
+ static const float ACTION_INTERVAL = 1.0f;
DivisionController::DivisionController(Context* context) : LeaderController(context)
{
RegisterObject(DivisionController);
+ this->setFormationMode(WALL);
+
bIsDivisionLeader_ = true;
+ this->myFollower_ = 0;
+ this->myWingman_ = 0;
+ this->actionTimer_.setTimer(ACTION_INTERVAL, true, createExecutor(createFunctor(&DivisionController::action, this)));
+
}
DivisionController::~DivisionController()
{
- if (this->isInitialized())
- {
- if (this->myFollower_)
- this->myFollower_->myDivisionLeader_ = 0;
- if (this->myWingman_)
- this->myWingman_->myLeader_ = 0;
- }
- } void DivisionController::tick(float dt)
+
+ }
+ void DivisionController::tick(float dt)
{
SUPER(DivisionController, tick, dt);
}
+ void DivisionController::action()
+ {
+/* setDesiredPositionOfFollower();
+ setDesiredPositionOfWingman();*/
+ }
+
bool DivisionController::setFollower(LeaderController* myFollower)
{
if (!this->myFollower_)
@@ -66,6 +74,59 @@
return false;
}
}
+
+ /* void DivisionController::setDesiredPositionOfWingman()
+ {
+ if (!this->myWingman_)
+ return;
+
+ switch (this->formationMode_){
+ case WALL:
+ {
+ myWingman_->desiredRelativePosition_ = new Vector3 (200, 0, 0);
+ break;
+ }
+ case FINGER4:
+ {
+ break;
+ }
+ case VEE:
+ {
+ break;
+ }
+ case DIAMOND:
+ {
+ break;
+ }
+ }
+
+ }
+ void DivisionController::setDesiredPositionOfFollower()
+ {
+ if (!this->myFollower_)
+ return;
+
+ switch (this->formationMode_){
+ case WALL:
+ {
+ myWingman_->desiredRelativePosition_ = new Vector3 (-200, 0, 0);
+ break;
+ }
+ case FINGER4:
+ {
+ break;
+ }
+ case VEE:
+ {
+ break;
+ }
+ case DIAMOND:
+ {
+ break;
+ }
+ }
+
+ }*/
void DivisionController::XMLPort(Element& xmlelement, XMLPort::Mode mode)
{
SUPER(DivisionController, XMLPort, xmlelement, mode);
Modified: code/branches/AI_HS15/src/orxonox/controllers/DivisionController.h
===================================================================
--- code/branches/AI_HS15/src/orxonox/controllers/DivisionController.h 2015-10-30 18:51:49 UTC (rev 10724)
+++ code/branches/AI_HS15/src/orxonox/controllers/DivisionController.h 2015-10-30 22:07:34 UTC (rev 10725)
@@ -47,10 +47,8 @@
virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
//Using british military aircraft formations
- enum FormationMode {VEE,FINGER4,DIAMOND, WALL};
- void setFormationMode(FormationMode val);
- inline FormationMode getFormationMode() const
- { return this->formationMode_; }
+
+
virtual bool setFollower(LeaderController* myFollower);
virtual bool setWingman(CommonController* wingman)
{
@@ -84,20 +82,20 @@
protected:
+ void setDesiredPositionOfWingman();
+ void setDesiredPositionOfFollower();
+ virtual void action(); //<! action() is called in regular intervals managing the bot's behaviour ~ setting targets.
//Target enemy, set by fleet controller.
- WeakPtr<Pawn> target_;
- bool bHasTargetPosition_;
- Vector3 targetPosition_;
- bool bHasTargetOrientation_;
- Quaternion targetOrientation_;
- FormationMode formationMode_;
+
private:
+ Timer actionTimer_; //<! Regularly calls action().
+
};
}
Modified: code/branches/AI_HS15/src/orxonox/controllers/LeaderController.h
===================================================================
--- code/branches/AI_HS15/src/orxonox/controllers/LeaderController.h 2015-10-30 18:51:49 UTC (rev 10724)
+++ code/branches/AI_HS15/src/orxonox/controllers/LeaderController.h 2015-10-30 22:07:34 UTC (rev 10725)
@@ -62,10 +62,12 @@
{
return true;
};
- LeaderController* myFollower_;
- LeaderController* myDivisionLeader_;
+ WeakPtr<CommonController> myWingman_;
+ WeakPtr<LeaderController> myFollower_;
+ WeakPtr<LeaderController> myDivisionLeader_;
+
protected:
@@ -74,7 +76,6 @@
private:
- WeakPtr<Pawn> target_;
//Timer actionTimer_; //<! Regularly calls action().
Modified: code/branches/AI_HS15/src/orxonox/controllers/SectionController.cc
===================================================================
--- code/branches/AI_HS15/src/orxonox/controllers/SectionController.cc 2015-10-30 18:51:49 UTC (rev 10724)
+++ code/branches/AI_HS15/src/orxonox/controllers/SectionController.cc 2015-10-30 22:07:34 UTC (rev 10725)
@@ -37,23 +37,49 @@
SectionController::SectionController(Context* context) : LeaderController(context)
{
RegisterObject(SectionController);
+ this->setFormationMode(WALL);
+
bIsDivisionLeader_ = false;
this->actionTimer_.setTimer(ACTION_INTERVAL, true, createExecutor(createFunctor(&SectionController::action, this)));
+ this->myWingman_ = 0;
+ this->myDivisionLeader_ = 0;
+ this->desiredRelativePosition_ = 0;
+ orxout(internal_error) << this << "Was created" << endl;
}
SectionController::~SectionController()
{
- if (this->isInitialized())
- {
- if (this->myDivisionLeader_)
- this->myDivisionLeader_->myFollower_ = 0;
- if(this->myWingman_)
- this->myWingman_->myLeader_ = 0;
+
+ }
+ /*void SectionController::setDesiredPositionOfWingman()
+ {
+ if (!this->myWingman_)
+ return;
+
+ switch (this->formationMode_){
+ case WALL:
+ {
+ myWingman_->desiredRelativePosition_ = new Vector3 (-200, 0, 0);
+ break;
+ }
+ case FINGER4:
+ {
+ break;
+ }
+ case VEE:
+ {
+ break;
+ }
+ case DIAMOND:
+ {
+ break;
+ }
}
+
}
-
+*/
LeaderController* SectionController::findNewDivisionLeader()
{
@@ -111,12 +137,12 @@
{
LeaderController* newDivisionLeader = findNewDivisionLeader();
this->myDivisionLeader_ = newDivisionLeader;
- /*if (newDivisionLeader)
+ if (newDivisionLeader)
orxout(internal_error) << "new DivisionLeader set" << endl;
- else
- orxout(internal_error) << "0 division leader" << endl;*/
+
}
- }
+/* setDesiredPositionOfWingman();
+*/ }
/*
Wingmen and Leaders attack target_, which is a member variable of their classes.
Wingmen's target_ is set to sectionTarget_, which is a member variable of SectionController class, unless
@@ -131,34 +157,35 @@
but the other section, that is not a leading section, can attack any target that is near divisonTarget_
*/
+ /* void SectionController::keepDivisionTick()
+ {
+
+
+ if (this->myDivisionLeader_ && this->myDivisionLeader_->getControllableEntity() && desiredRelativePosition_)
+ {
+
+ Vector3 desiredAbsolutePosition = ((this->myDivisionLeader_->getControllableEntity()->getWorldPosition()) +
+ (this->myDivisionLeader_->getControllableEntity()->getWorldOrientation()* (*desiredRelativePosition_)));
+ this->moveToPosition (desiredAbsolutePosition);
+ }
+ }*/
void SectionController::tick(float dt)
- {/*
+ {
+
+
+ /*
if (!this->isActive())
return;
//--------------------------Stay in division--------------------------
- this->keepDivisionTick();*/
- /*keepDivisionTick(){
- if (this->divisionLeader_ && this->divisionLeader_->getControllableEntity() && desiredRelativePosition_){
- Vector3 desiredAbsolutePosition = ((this->divisionLeader_->getControllableEntity()->getWorldPosition()) +
- (this->divisionLeader_->getControllableEntity()->getWorldOrientation()* (*desiredRelativePosition_)));
- this->moveToPosition (desiredAbsolutePosition);
- }
- }
+ this->keepDivisionTick();
*/
- /*//If ordered to attack -> follow target and shoot
- if (this->bAttackOrder_)
- {
-
- }
//If ordered to move -> move to a target Point
//No orders -> Don't move, but shoot at whatever is close, unless Boss is shooting at it.
//(Section shoots same target, Boss's section shoots another target)
- {
+
- }*/
-
//orxout(internal_error) << "my Wingman is " << this->myWingman_ << endl;
SUPER(SectionController, tick, dt);
Modified: code/branches/AI_HS15/src/orxonox/controllers/SectionController.h
===================================================================
--- code/branches/AI_HS15/src/orxonox/controllers/SectionController.h 2015-10-30 18:51:49 UTC (rev 10724)
+++ code/branches/AI_HS15/src/orxonox/controllers/SectionController.h 2015-10-30 22:07:34 UTC (rev 10725)
@@ -52,7 +52,8 @@
{
return false;
}
- };
+ }
+
virtual bool hasWingman()
{
if (this->myWingman_)
@@ -67,7 +68,8 @@
LeaderController* findNewDivisionLeader();
protected:
-
+ void setDesiredPositionOfWingman();
+ void keepDivisionTick();
//A division is the biggest block of spaceships.
//In division one section is leading, the other one always stays on the same position
//relative to the Leader of the leading section.
@@ -82,7 +84,6 @@
private:
Timer actionTimer_; //<! Regularly calls action().
- Vector3* desiredRelativePosition_;
};
}
Modified: code/branches/AI_HS15/src/orxonox/controllers/WingmanController.cc
===================================================================
--- code/branches/AI_HS15/src/orxonox/controllers/WingmanController.cc 2015-10-30 18:51:49 UTC (rev 10724)
+++ code/branches/AI_HS15/src/orxonox/controllers/WingmanController.cc 2015-10-30 22:07:34 UTC (rev 10725)
@@ -39,12 +39,13 @@
{
RegisterObject(WingmanController);
this->actionTimer_.setTimer(ACTION_INTERVAL, true, createExecutor(createFunctor(&WingmanController::action, this)));
+ this->myLeader_ = 0;
+ this->desiredRelativePosition_ = 0;
}
WingmanController::~WingmanController()
{
- if (this->myLeader_)
- this->myLeader_->myWingman_ = 0;
+
}
CommonController* WingmanController::findNewLeader()
@@ -68,23 +69,13 @@
if (it->getControllableEntity() == this->getControllableEntity())
continue;
-
-
-
-
float distance = (it->getControllableEntity()->getPosition() - this->getControllableEntity()->getPosition()).length();
if (distance < minDistance && !(it->hasWingman()))
{
closestLeader = *it;
minDistance = distance;
}
- /*// is pawn in range?
- if (distance < RADIUS_TO_SEARCH_FOR_LEADER)
- {
-
- if (it->setWingman(this))
- return *it;
- }*/
+
}
if (closestLeader)
{
@@ -110,8 +101,6 @@
else
{
- //orxout(internal_error) << "already have a Leader" << endl;
-
}
}
/*//collect data for AI behaviour
@@ -154,63 +143,40 @@
orxout(internal_error) << "mean of enemies_ is " << meanOfEnemies << ", with a size " << enemies_.size() << endl;
}*/
- /* void FormationController::setDesiredPositionOfSlaves()
+
+ /*void WingmanController::keepSectionTick()
{
- if (this->state_ != MASTER)
- return;
- switch (this->formationMode_){
- case ATTACK:
- {
- float i = 0;
- for(std::vector<FormationController*>::iterator it = slaves_.begin(); it != slaves_.end(); it++)
- {
- (*it)->desiredRelativePosition_ = new Vector3 ((i-slaves_.size()/2)*200, 0, 0);
- i++;
- }
- break;
- }
- case NORMAL:
- {
- break;
- }
- case DEFEND:
- {
- break;
- }
+ if (this->myLeader_ && this->myLeader_->getControllableEntity())
+ //orxout(internal_error) << "MOVING" << endl;
+
+ if (this->myLeader_ && this->myLeader_->getControllableEntity() && desiredRelativePosition_)
+ {
+ Vector3 desiredAbsolutePosition = ((this->myLeader_->getControllableEntity()->getWorldPosition()) +
+ (this->myLeader_->getControllableEntity()->getWorldOrientation()* (*desiredRelativePosition_)));
+ this->moveToPosition (desiredAbsolutePosition);
}
-
}*/
void WingmanController::tick(float dt)
{
- //-------------------------------------------------------
+ /* //-------------------------------------------------------
- /*
+
if (!this->isActive())
return;
//--------------------------Stay in formation--------------------------
- if (bFollowLeader_)
- {
- this->keepSectionTick();
+ this->keepSectionTick();*/
- keepSectionTick(){
- if (this->sectionLeader_ && this->sectionLeader_->getControllableEntity() && desiredRelativePosition_){
- Vector3 desiredAbsolutePosition = ((this->sectionLeader_->getControllableEntity()->getWorldPosition()) +
- (this->sectionLeader_->getControllableEntity()->getWorldOrientation()* (*desiredRelativePosition_)));
- this->moveToPosition (desiredAbsolutePosition);
- }
- }
-
-
- //--------------------------Attack same target as the Leader--------------------------
+
+ //--------------------------Attack same target as the Leader--------------------------
- if (this->target_)
- {
- this->aimAtTarget();
- this->doFire();
- }
+ /*if (this->target_)
+ {
+ this->aimAtTarget();
+ this->doFire();
}
- */
- //orxout(internal_error) << "I am " << this << endl;
+*/
+
+ //orxout(internal_error) << "I am " << this << endl;
SUPER(WingmanController, tick, dt);
Modified: code/branches/AI_HS15/src/orxonox/controllers/WingmanController.h
===================================================================
--- code/branches/AI_HS15/src/orxonox/controllers/WingmanController.h 2015-10-30 18:51:49 UTC (rev 10724)
+++ code/branches/AI_HS15/src/orxonox/controllers/WingmanController.h 2015-10-30 22:07:34 UTC (rev 10725)
@@ -56,6 +56,7 @@
CommonController* findNewLeader();
protected:
+ WeakPtr<CommonController> myLeader_;
virtual void action(); //<! action() is called in regular intervals managing the bot's behaviour ~ setting targets.
//void defaultBehaviour(float maxrand); //<! Helper function for code reusage. Some concrete commands for a bot.
@@ -64,8 +65,8 @@
private:
//const float ACTION_INTERVAL;
-
- WeakPtr<Pawn> target_;
+ void keepSectionTick();
+
//LeaderController* leader_;
Timer actionTimer_; //<! Regularly calls action().
Modified: code/branches/AI_HS15/src/orxonox/worldentities/pawns/Pawn.cc
===================================================================
--- code/branches/AI_HS15/src/orxonox/worldentities/pawns/Pawn.cc 2015-10-30 18:51:49 UTC (rev 10724)
+++ code/branches/AI_HS15/src/orxonox/worldentities/pawns/Pawn.cc 2015-10-30 22:07:34 UTC (rev 10725)
@@ -319,7 +319,6 @@
}
}
-
void Pawn::death()
{
this->setHealth(1);
More information about the Orxonox-commit
mailing list