[Orxonox-commit 6196] r10854 - in code/branches/campaignHS15: data/levels src/orxonox/controllers
gania at orxonox.net
gania at orxonox.net
Wed Nov 25 12:07:22 CET 2015
Author: gania
Date: 2015-11-25 12:07:22 +0100 (Wed, 25 Nov 2015)
New Revision: 10854
Modified:
code/branches/campaignHS15/data/levels/AITest.oxw
code/branches/campaignHS15/src/orxonox/controllers/CommonController.cc
code/branches/campaignHS15/src/orxonox/controllers/CommonController.h
code/branches/campaignHS15/src/orxonox/controllers/DivisionController.cc
code/branches/campaignHS15/src/orxonox/controllers/DivisionController.h
code/branches/campaignHS15/src/orxonox/controllers/LeaderController.cc
code/branches/campaignHS15/src/orxonox/controllers/LeaderController.h
code/branches/campaignHS15/src/orxonox/controllers/SectionController.cc
code/branches/campaignHS15/src/orxonox/controllers/SectionController.h
code/branches/campaignHS15/src/orxonox/controllers/WingmanController.cc
Log:
Fixed some bugs, only DivisionController works for now
Modified: code/branches/campaignHS15/data/levels/AITest.oxw
===================================================================
--- code/branches/campaignHS15/data/levels/AITest.oxw 2015-11-24 21:47:44 UTC (rev 10853)
+++ code/branches/campaignHS15/data/levels/AITest.oxw 2015-11-25 11:07:22 UTC (rev 10854)
@@ -66,38 +66,20 @@
<Template link=spaceshipassff />
</templates>
<controller>
- <DivisionController team=0>
+ <DivisionController team=0 formationMode="finger4">
<actionpoints>
- <Actionpoint position="-1000,750,-500" action="FLY" />
+ <Actionpoint position="0,0,0" action="FLY" />
<Actionpoint position="-1000,750,-500" action="ATTACK" enemy="ss3" />
<Actionpoint position="-1000,750,-500" action="PROTECt" protect="fuck" />
</actionpoints>
</DivisionController>
</controller>
</SpaceShip>
- <SpaceShip position="-2000, 1800, -1000" lookat="0,0,0" team=0>
+ <SpaceShip position="-2000, 1900, -1000" lookat="0,0,0" team=0>
<templates>
<Template link=spaceshipassff />
</templates>
<controller>
- <WingmanController team=0>
- </WingmanController>
- </controller>
- </SpaceShip>
- <SpaceShip position="-2000, 2100, -1000" lookat="0,0,0" team=0>
- <templates>
- <Template link=spaceshipassff />
- </templates>
- <controller>
- <WingmanController team=0>
- </WingmanController>
- </controller>
- </SpaceShip>
- <SpaceShip position="-2000, 2400, -1000" lookat="0,0,0" team=0>
- <templates>
- <Template link=spaceshipassff />
- </templates>
- <controller>
<SectionController team=0>
</SectionController>
</controller>
Modified: code/branches/campaignHS15/src/orxonox/controllers/CommonController.cc
===================================================================
--- code/branches/campaignHS15/src/orxonox/controllers/CommonController.cc 2015-11-24 21:47:44 UTC (rev 10853)
+++ code/branches/campaignHS15/src/orxonox/controllers/CommonController.cc 2015-11-25 11:07:22 UTC (rev 10854)
@@ -64,7 +64,7 @@
{
this->squaredaccuracy_ = 10000;
this->bFirstTick_ = true;
- this->tolerance_ = 65;
+ this->tolerance_ = 50;
this->action_ = Action::NONE;
this->stopLookingAtTarget();
this->attackRange_ = 2500;
@@ -72,13 +72,7 @@
}
CommonController::~CommonController()
{
- for (size_t i = 0; i < this->actionpoints_.size(); ++i)
- {
- if(this->actionpoints_[i])
- this->actionpoints_[i]->destroy();
- }
- this->parsedActionpoints_.clear();
- this->actionpoints_.clear();
+
}
void CommonController::tick(float dt)
{
@@ -491,7 +485,7 @@
copyTargetOrientation( dt );
}
}
- if (distance > 200 || (rotateX > -0.1 && rotateX < 0.1 && rotateY > -0.1 && rotateY < 0.1))
+ if (distance > this->tolerance_*1.5f || (rotateX > -0.01 && rotateX < 0.01 && rotateY > -0.01 && rotateY < 0.01))
this->getControllableEntity() ->moveFrontBack( SPEED * dt );
}
else
@@ -745,7 +739,7 @@
}
return 0;
}
- bool CommonController::startAttackingEnemiesThatAreClose()
+ void CommonController::startAttackingEnemiesThatAreClose()
{
if (this->action_ != Action::FIGHT && this->action_ != Action::FIGHTALL)
{
@@ -760,11 +754,9 @@
Point p = { Action::FIGHT, this->getName(newTarget), Vector3::ZERO };
this->parsedActionpoints_.push_back(p);
this->executeActionpoint();
- return true;
}
}
}
- return false;
}
//------------------------------------------------------------------------------
@@ -782,7 +774,19 @@
switch ( this->action_ )
{
case Action::FIGHT:
- {
+ {
+ std::string targetName = this->parsedActionpoints_.back().name;
+ if (targetName == "")
+ {
+ break;
+ }
+ for (ObjectList<Pawn>::iterator itP = ObjectList<Pawn>::begin(); itP; ++itP)
+ {
+ if (CommonController::getName(*itP) == targetName)
+ {
+ this->setTarget (static_cast<ControllableEntity*>(*itP));
+ }
+ }
break;
}
case Action::FLY:
@@ -850,6 +854,14 @@
this->action_ = Action::NONE;
}
}
+ void CommonController::stayNearProtect()
+ {
+ Vector3* targetRelativePosition;
+ targetRelativePosition = new Vector3 (0, 300, 300);
+ Vector3 targetAbsolutePosition = ((this->getProtect()->getWorldPosition()) +
+ (this->getProtect()->getWorldOrientation()* (*targetRelativePosition)));
+ this->setTargetPosition(targetAbsolutePosition);
+ }
void CommonController::nextActionpoint()
{
if (!this->parsedActionpoints_.empty())
@@ -858,4 +870,107 @@
}
this->setAction(Action::NONE);
}
+ void CommonController::action()
+ {
+ this->startAttackingEnemiesThatAreClose();
+ //No action -> pop one from stack
+ if (this->action_ == Action::NONE)
+ {
+ this->executeActionpoint();
+ }
+ //Action fightall -> fight till nobody alive
+ if (this->action_ == Action::FIGHTALL)
+ {
+ if (!this->hasTarget())
+ {
+ //----find a target----
+ ControllableEntity* newTarget = this->closestTarget();
+ if (newTarget)
+ {
+ this->setAction (Action::FIGHTALL, newTarget);
+ }
+ else
+ {
+ this->nextActionpoint();
+ return;
+ }
+ }
+ else if (this->hasTarget())
+ {
+
+ }
+ }
+ //Action fight -> fight as long as enemies in range
+ else if (this->action_ == Action::FIGHT)
+ {
+ if (!this->hasTarget())
+ {
+ //----find a target----
+ ControllableEntity* newTarget = this->closestTarget();
+ if (newTarget &&
+ CommonController::distance (this->getControllableEntity(), newTarget) < this->attackRange_)
+ {
+ this->setAction (Action::FIGHT, newTarget);
+ }
+ else
+ {
+ this->nextActionpoint();
+ return;
+ }
+ }
+ else if (this->hasTarget())
+ {
+ //----fly in formation if far enough----
+ Vector3 diffVector = this->positionOfTarget_ - this->getControllableEntity()->getWorldPosition();
+
+ if (diffVector.length() > this->attackRange_)
+ {
+ ControllableEntity* newTarget = this->closestTarget();
+
+ if (newTarget &&
+ CommonController::distance (this->getControllableEntity(), newTarget) < this->attackRange_)
+ {
+ this->setAction (Action::FIGHT, newTarget);
+ }
+ else
+ {
+ this->nextActionpoint();
+ return;
+ }
+ }
+ }
+ }
+ else if (this->action_ == Action::FLY)
+ {
+ if (this->squaredDistanceToTarget() <= this->squaredaccuracy_)
+ {
+ this->nextActionpoint();
+ return;
+ }
+ }
+ else if (this->action_ == Action::PROTECT)
+ {
+ if (!this->getProtect())
+ {
+ this->nextActionpoint();
+ return;
+ }
+ this->stayNearProtect();
+ }
+ else if (this->action_ == Action::ATTACK)
+ {
+ if (!this->hasTarget())
+ {
+ this->nextActionpoint();
+ return;
+ }
+ }
+ if (this->hasTarget())
+ {
+ //----choose where to go----
+ this->maneuver();
+ //----fire if you can----
+ this->bShooting_ = this->canFire();
+ }
+ }
}
Modified: code/branches/campaignHS15/src/orxonox/controllers/CommonController.h
===================================================================
--- code/branches/campaignHS15/src/orxonox/controllers/CommonController.h 2015-11-24 21:47:44 UTC (rev 10853)
+++ code/branches/campaignHS15/src/orxonox/controllers/CommonController.h 2015-11-25 11:07:22 UTC (rev 10854)
@@ -40,6 +40,7 @@
#include <limits>
#include <algorithm>
#include "worldentities/Actionpoint.h"
+#include "worldentities/pawns/SpaceShip.h"
namespace orxonox
{
@@ -132,17 +133,10 @@
bool isLookingAtTarget(float angle);
//----[/Helper methods]----
- //----[Actionpoint information]----
-
- std::vector<WeakPtr<WorldEntity> > actionpoints_;
- float squaredaccuracy_;
- std::vector<Point > parsedActionpoints_;
-
- //----[/Actionpoint information]----
- //----[Actionpoint methods]----
- void executeActionpoint();
- void nextActionpoint();
- //----[Actionpoint methods]----
+
+ virtual void stayNearProtect();
+ virtual void action(); //<! action() is called in regular intervals managing the bot's behaviour.
+
protected:
//----[Flying methods]----
void stopMoving();
@@ -179,7 +173,7 @@
void doFire();
void setClosestTarget();
Pawn* closestTarget();
- bool startAttackingEnemiesThatAreClose();
+ void startAttackingEnemiesThatAreClose();
//----[/Fighting methods]----
//----[where-to-fly information]----
@@ -202,7 +196,17 @@
Quaternion orientationOfTarget_;
//----[/who-to-kill information]----
-
+ //----[Actionpoint information]----
+
+ std::vector<WeakPtr<WorldEntity> > actionpoints_;
+ float squaredaccuracy_;
+ std::vector<Point > parsedActionpoints_;
+
+ //----[/Actionpoint information]----
+ //----[Actionpoint methods]----
+ void executeActionpoint();
+ void nextActionpoint();
+ //----[Actionpoint methods]----
//----["Private" variables]----
FormationMode::Value formationMode_;
Rank::Value rank_;
Modified: code/branches/campaignHS15/src/orxonox/controllers/DivisionController.cc
===================================================================
--- code/branches/campaignHS15/src/orxonox/controllers/DivisionController.cc 2015-11-24 21:47:44 UTC (rev 10853)
+++ code/branches/campaignHS15/src/orxonox/controllers/DivisionController.cc 2015-11-25 11:07:22 UTC (rev 10854)
@@ -49,6 +49,17 @@
DivisionController::~DivisionController()
{
+ if (this->myFollower_)
+ {
+ this->myFollower_->takeActionpoints(this->parsedActionpoints_);
+ }
+ for (size_t i = 0; i < this->actionpoints_.size(); ++i)
+ {
+ if(this->actionpoints_[i])
+ this->actionpoints_[i]->destroy();
+ }
+ this->parsedActionpoints_.clear();
+ this->actionpoints_.clear();
}
void DivisionController::XMLPort(Element& xmlelement, XMLPort::Mode mode)
@@ -64,204 +75,14 @@
SUPER(DivisionController, tick, dt);
}
void DivisionController::action()
- {
- if (this->startAttackingEnemiesThatAreClose())
- {
- Point p = { Action::FIGHT, "", Vector3::ZERO };
-
- if (this->myWingman_)
- {
- this->myWingman_->parsedActionpoints_.push_back(p);
- }
- if (this->myFollower_)
- {
- this->myFollower_->parsedActionpoints_.push_back(p);
- }
- }
-
- if (this->action_ == Action::NONE)
- {
- this->executeActionpoint();
- }
- if (this->action_ == Action::FIGHT || this->action_ == Action::FIGHTALL)
- {
- if (!this->hasTarget())
- {
- //----find a target----
- ControllableEntity* newTarget = this->closestTarget();
- if (this->action_ == Action::FIGHT)
- {
- if (newTarget &&
- CommonController::distance (this->getControllableEntity(), newTarget) < this->attackRange_)
- {
- this->setAction (Action::FIGHT, newTarget);
- }
- else
- {
- this->nextActionpoint();
- if (this->myWingman_)
- {
- this->myWingman_->nextActionpoint();
- }
- if (this->myFollower_)
- {
- this->myFollower_->nextActionpoint();
- }
- return;
- }
- }
- else if (this->action_ == Action::FIGHTALL)
- {
- if (newTarget && newTarget->getController())
- {
- this->setAction (Action::FIGHTALL, newTarget);
- }
- else
- {
- this->nextActionpoint();
- if (this->myWingman_)
- {
- this->myWingman_->nextActionpoint();
- }
- if (this->myFollower_)
- {
- this->myFollower_->nextActionpoint();
- }
- return;
- }
- }
-
- }
- else if (this->hasTarget())
- {
- //----fly in formation if far enough----
- Vector3 diffVector = this->positionOfTarget_ - this->getControllableEntity()->getWorldPosition();
-
- if (diffVector.length() > this->attackRange_)
- {
- if (this->action_ == Action::FIGHT)
- {
- this->nextActionpoint();
- if (this->myWingman_)
- {
- this->myWingman_->nextActionpoint();
- }
- if (this->myFollower_)
- {
- this->myFollower_->nextActionpoint();
- }
- return;
- }
- else
- {
- this->setTargetPositionOfWingman();
- this->setTargetPositionOfFollower();
- }
- }
- else
- {
- //----wingmans shall support the fire of their leaders----
- if (this->myWingman_)
- {
- this->myWingman_->setAction (Action::FIGHT, this->target_);
- }
- if (this->myFollower_)
- {
- this->myFollower_->setAction (Action::FIGHT);
- }
- }
- }
- }
- else if (this->action_ == Action::FLY)
- {
- if (this->squaredDistanceToTarget() <= this->squaredaccuracy_)
- {
- this->nextActionpoint();
- if (this->myWingman_)
- {
- this->myWingman_->nextActionpoint();
- }
- if (this->myFollower_)
- {
- this->myFollower_->nextActionpoint();
- }
- return;
- }
- this->setTargetPositionOfWingman();
- this->setTargetPositionOfFollower();
- }
- else if (this->action_ == Action::PROTECT)
- {
- if (!this->getProtect())
- {
- this->nextActionpoint();
- if (this->myWingman_)
- {
- this->myWingman_->nextActionpoint();
- }
- if (this->myFollower_)
- {
- this->myFollower_->nextActionpoint();
- }
- return;
- }
-
- Vector3* targetRelativePosition;
-
- targetRelativePosition = new Vector3 (0, 300, 300);
-
- Vector3 targetAbsolutePosition = ((this->getProtect()->getWorldPosition()) +
- (this->getProtect()->getWorldOrientation()* (*targetRelativePosition)));
- this->setTargetPosition(targetAbsolutePosition);
-
- this->setTargetPositionOfWingman();
- this->setTargetPositionOfFollower();
-
- }
- else if (this->action_ == Action::ATTACK)
- {
- if (!this->hasTarget())
- {
- this->nextActionpoint();
- if (this->myWingman_)
- {
- this->myWingman_->nextActionpoint();
- }
- if (this->myFollower_)
- {
- this->myFollower_->nextActionpoint();
- }
- return;
- }
- //----fly in formation if far enough----
- Vector3 diffVector = this->positionOfTarget_ - this->getControllableEntity()->getWorldPosition();
- if (diffVector.length() > this->attackRange_)
- {
- this->setTargetPositionOfWingman();
- this->setTargetPositionOfFollower();
- }
- else
- {
- //----wingmans shall support the fire of their leaders----
- if (this->myWingman_)
- {
- this->myWingman_->setAction (Action::FIGHT, this->target_);
- }
- if (this->myFollower_)
- {
- this->myFollower_->setAction (Action::FIGHT);
- }
- }
- }
- if (this->hasTarget())
- {
- //----choose where to go----
- this->maneuver();
- //----fire if you can----
- this->bShooting_ = this->canFire();
- }
+ {
+ CommonController::action();
+
}
-
+ void DivisionController::stayNearProtect()
+ {
+ CommonController::stayNearProtect();
+ }
void DivisionController::setTargetPositionOfWingman()
{
if (!this->myWingman_)
@@ -293,38 +114,7 @@
myWingman_->setAction( Action::FLY, targetAbsolutePositionOfWingman, orient);
}
- void DivisionController::setTargetPositionOfFollower()
- {
- if (!this->myFollower_)
- return;
- this->myFollower_->setFormationMode(this->formationMode_);
-
- Vector3* targetRelativePositionOfFollower;
- switch (this->formationMode_){
- case FormationMode::WALL:
- {
- targetRelativePositionOfFollower = new Vector3 (-400, 0, 0);
- break;
- }
- case FormationMode::FINGER4:
- {
- targetRelativePositionOfFollower = new Vector3 (-400, 0, 200);
- break;
- }
-
- case FormationMode::DIAMOND:
- {
- targetRelativePositionOfFollower = new Vector3 (-400, 0, 200);
- break;
- }
- }
- Quaternion orient = this->getControllableEntity()->getWorldOrientation();
-
- Vector3 targetAbsolutePositionOfFollower = ((this->getControllableEntity()->getWorldPosition()) +
- (this->getControllableEntity()->getWorldOrientation()* (*targetRelativePositionOfFollower)));
-
- myFollower_->setAction ( Action::FLY, targetAbsolutePositionOfFollower, orient );
- }
+
bool DivisionController::setWingman(CommonController* cwingman)
{
Modified: code/branches/campaignHS15/src/orxonox/controllers/DivisionController.h
===================================================================
--- code/branches/campaignHS15/src/orxonox/controllers/DivisionController.h 2015-11-24 21:47:44 UTC (rev 10853)
+++ code/branches/campaignHS15/src/orxonox/controllers/DivisionController.h 2015-11-25 11:07:22 UTC (rev 10854)
@@ -57,13 +57,14 @@
virtual bool hasFollower();
void setTargetPositionOfWingman();
- void setTargetPositionOfFollower();
+
//----[/own functions]----
+ virtual void stayNearProtect();
protected:
//----action must only be managed by this----
virtual void action(); //<! action() is called in regular intervals managing the bot's behaviour.
-
+
private:
//----private variables-----
Timer actionTimer_; //<! Regularly calls action().
Modified: code/branches/campaignHS15/src/orxonox/controllers/LeaderController.cc
===================================================================
--- code/branches/campaignHS15/src/orxonox/controllers/LeaderController.cc 2015-11-24 21:47:44 UTC (rev 10853)
+++ code/branches/campaignHS15/src/orxonox/controllers/LeaderController.cc 2015-11-25 11:07:22 UTC (rev 10854)
@@ -50,6 +50,14 @@
LeaderController::~LeaderController()
{
}
+ void LeaderController::takeActionpoints (std::vector<Point > vector)
+ {
+ this->parsedActionpoints_ = vector;
+ this->setAction (Action::NONE);
+ this->setTarget(0);
+ this->setTargetPosition (this->getControllableEntity()->getWorldPosition());
+ orxout(internal_error) << "Top action is " << this->parsedActionpoints_.back().action << endl;
+ }
}
Modified: code/branches/campaignHS15/src/orxonox/controllers/LeaderController.h
===================================================================
--- code/branches/campaignHS15/src/orxonox/controllers/LeaderController.h 2015-11-24 21:47:44 UTC (rev 10853)
+++ code/branches/campaignHS15/src/orxonox/controllers/LeaderController.h 2015-11-25 11:07:22 UTC (rev 10854)
@@ -52,9 +52,9 @@
virtual bool hasFollower()
{ return true; }
//----[/pseudo virtual methods]----
+ virtual void takeActionpoints (std::vector<Point > vector);
-
protected:
//----private variables-----
WeakPtr<WingmanController> myWingman_;
Modified: code/branches/campaignHS15/src/orxonox/controllers/SectionController.cc
===================================================================
--- code/branches/campaignHS15/src/orxonox/controllers/SectionController.cc 2015-11-24 21:47:44 UTC (rev 10853)
+++ code/branches/campaignHS15/src/orxonox/controllers/SectionController.cc 2015-11-25 11:07:22 UTC (rev 10854)
@@ -50,7 +50,13 @@
SectionController::~SectionController()
{
-
+ for (size_t i = 0; i < this->actionpoints_.size(); ++i)
+ {
+ if(this->actionpoints_[i])
+ this->actionpoints_[i]->destroy();
+ }
+ this->parsedActionpoints_.clear();
+ this->actionpoints_.clear();
}
void SectionController::XMLPort(Element& xmlelement, XMLPort::Mode mode)
{
@@ -85,216 +91,77 @@
}
if (!myDivisionLeader_)
{
- if (this->startAttackingEnemiesThatAreClose())
+ CommonController::action();
+ }
+ else if (myDivisionLeader_)
+ {
+ switch (myDivisionLeader_->getAction())
{
- Point p = { Action::FIGHT, "", Vector3::ZERO };
-
- if (this->myWingman_)
+ // case Action::FLY:
+ // {
+ // // Vector3 targetRelativePosition = getFormationPosition();
+ // // Quaternion orient =
+ // // this->myDivisionLeader_->getControllableEntity()->getWorldOrientation();
+ // // Vector3 targetAbsolutePosition =
+ // // ((this->myDivisionLeader_->getControllableEntity()->getWorldPosition()) +
+ // // (orient* (targetRelativePosition)));
+ // // this->setAction (Action::FLY, targetAbsolutePosition, orient);
+ // break;
+ // }
+ // case Action::FIGHT:
+ // {
+
+ // // this->setAction (Action::FLY, targetAbsolutePosition, orient);
+ // break;
+ // }
+ default:
{
- this->myWingman_->parsedActionpoints_.push_back(p);
- }
- }
- if (this->action_ == Action::NONE)
- {
- this->executeActionpoint();
- }
- if (this->action_ == Action::FIGHT || this->action_ == Action::FIGHTALL)
- {
- if (!this->hasTarget())
- {
- //----find a target----
- ControllableEntity* newTarget = this->closestTarget();
- if (this->action_ == Action::FIGHT)
+ ControllableEntity* myEntity = this->getControllableEntity();
+ Vector3 myPosition = myEntity->getWorldPosition();
+ if (!this->myDivisionLeader_)
{
- if (newTarget &&
- CommonController::distance (this->getControllableEntity(), newTarget) < this->attackRange_)
- {
- this->setAction (Action::FIGHT, newTarget);
- }
- else
- {
- this->nextActionpoint();
- if (this->myWingman_)
- {
- this->myWingman_->nextActionpoint();
- }
-
- return;
- }
+ return;
}
- else if (this->action_ == Action::FIGHTALL)
+ ControllableEntity* leaderEntity = this->myDivisionLeader_->getControllableEntity();
+ Quaternion orient = leaderEntity->getWorldOrientation();
+ Vector3 leaderPosition = leaderEntity->getWorldPosition();
+
+ Vector3 targetRelativePosition = getFormationPosition();
+ if (!this->myDivisionLeader_)
{
- if (newTarget && newTarget->getController())
- {
- this->setAction (Action::FIGHTALL, newTarget);
- }
- else
- {
- this->nextActionpoint();
- if (this->myWingman_)
- {
- this->myWingman_->nextActionpoint();
- }
- return;
- }
+ return;
}
-
- }
- else if (this->hasTarget())
- {
- //----fly in formation if far enough----
- Vector3 diffVector = this->positionOfTarget_ - this->getControllableEntity()->getWorldPosition();
-
- if (diffVector.length() > this->attackRange_)
+ Vector3 targetAbsolutePosition =
+ (leaderPosition + (orient*WorldEntity::FRONT) * (leaderEntity->getVelocity().length()/5)
+ + (orient* (targetRelativePosition)));
+
+ this->setAction (Action::FLY, targetAbsolutePosition, orient);
+ if ((targetAbsolutePosition - myPosition).length() > this->tolerance_ * 1.5f)
{
- if (this->action_ == Action::FIGHT)
- {
- this->nextActionpoint();
- if (this->myWingman_)
- {
- this->myWingman_->nextActionpoint();
- }
- return;
- }
- else
- {
- this->setTargetPositionOfWingman();
- }
+ this->boostControl();
}
else
{
- //----wingmans shall support the fire of their leaders----
- if (this->myWingman_)
- {
- this->myWingman_->setAction (Action::FIGHT, this->target_);
- }
-
+ this->getControllableEntity()->boost(false);
}
}
}
- else if (this->action_ == Action::FLY)
- {
- if (this->squaredDistanceToTarget() <= this->squaredaccuracy_)
- {
- this->nextActionpoint();
- if (this->myWingman_)
- {
- this->myWingman_->nextActionpoint();
- }
- return;
- }
- this->setTargetPositionOfWingman();
- }
- else if (this->action_ == Action::PROTECT)
- {
- if (!this->getProtect())
- {
- this->nextActionpoint();
- if (this->myWingman_)
- {
- this->myWingman_->nextActionpoint();
- }
- return;
- }
-
- Vector3* targetRelativePosition;
-
- targetRelativePosition = new Vector3 (0, 300, 300);
+ }
- Vector3 targetAbsolutePosition = ((this->getProtect()->getWorldPosition()) +
- (this->getProtect()->getWorldOrientation()* (*targetRelativePosition)));
- this->setTargetPosition(targetAbsolutePosition);
-
- this->setTargetPositionOfWingman();
+ }
- }
- else if (this->action_ == Action::ATTACK)
- {
- if (!this->hasTarget())
- {
- this->nextActionpoint();
- if (this->myWingman_)
- {
- this->myWingman_->nextActionpoint();
- }
- return;
- }
- //----fly in formation if far enough----
- Vector3 diffVector = this->positionOfTarget_ - this->getControllableEntity()->getWorldPosition();
- if (diffVector.length() > this->attackRange_)
- {
- this->setTargetPositionOfWingman();
- }
- else
- {
- //----wingmans shall support the fire of their leaders----
- if (this->myWingman_)
- {
- this->myWingman_->setAction (Action::FIGHT, this->target_);
- }
-
- }
- }
- if (this->hasTarget())
- {
- //----choose where to go----
- this->maneuver();
- //----fire if you can----
- this->bShooting_ = this->canFire();
- }
- }
- //----If have leader----
- else
+ void SectionController::boostControl()
+ {
+ SpaceShip* ship = orxonox_cast<SpaceShip*>(this->getControllableEntity());
+ if(ship == NULL) return;
+ if(ship->getBoostPower()*1.5f > ship->getInitialBoostPower() ) //upper limit ->boost
{
- //----action was set to fight----
- if (this->action_ == Action::FIGHT)
- {
- if (!this->hasTarget())
- {
- this->chooseTarget();
- }
- else
- {
- //----fly in formation if far enough----
- Vector3 diffVector = this->positionOfTarget_ - this->getControllableEntity()->getWorldPosition();
- if (diffVector.length() > this->attackRange_)
- {
- this->setTargetPositionOfWingman();
- }
- else
- {
- //----wingmans shall support the fire of their leaders----
- if (this->myWingman_)
- {
- this->myWingman_->setAction (Action::FIGHT, this->target_);
- }
- }
- }
- if (this->hasTarget())
- {
- //----choose where to go----
- this->maneuver();
- //----fire if you can----
- this->bShooting_ = this->canFire();
- }
- }
- //----action was set to fly----
- else if (this->action_ == Action::FLY)
- {
- this->setTargetPositionOfWingman();
- Pawn* newTarget = this->closestTarget();
- if ( newTarget && this->distance (this->getControllableEntity(),
- static_cast<ControllableEntity*>(newTarget)) <= this->attackRange_ )
- {
- this->setAction (Action::FIGHT, static_cast<ControllableEntity*>(newTarget));
- }
- }
+ this->getControllableEntity()->boost(true);
}
- if (this->bFirstAction_ && this->myDivisionLeader_)
+ else if(ship->getBoostPower()*4.0f < ship->getInitialBoostPower()) //lower limit ->do not boost
{
- this->parsedActionpoints_ = this->myDivisionLeader_->parsedActionpoints_;
- this->bFirstAction_ = false;
+ this->getControllableEntity()->boost(false);
}
}
//PRE: myDivisionLeader_ != 0 && myDivisionLeader_->action_ == Action::FIGHT
@@ -302,7 +169,10 @@
void SectionController::chooseTarget()
{
//----If division leader fights, cover him by fighting emenies close to his target----
- if (this->myDivisionLeader_->getAction() == Action::FIGHT)
+ Action::Value action = this->myDivisionLeader_->getAction();
+
+ Pawn* target;
+ if (action == Action::FIGHT || action == Action::FIGHTALL || action == Action::ATTACK)
{
//----if he has a target----
if (this->myDivisionLeader_->hasTarget())
@@ -326,7 +196,7 @@
(*itP) != this->myDivisionLeader_->getTarget())
{
foundTarget = true;
- this->setAction(Action::FIGHT, (*itP));
+ target = (*itP);
//orxout(internal_error) << "Found target" << endl;
break;
}
@@ -334,13 +204,13 @@
//----no target? then attack same target as division leader----
if (!foundTarget)
{
- this->setAction(Action::FIGHT, this->myDivisionLeader_->getTarget());
+ target = orxonox_cast<Pawn*>(this->myDivisionLeader_->getTarget());
}
}
//----if division leader doesn't have a wingman, support his fire----
else
{
- this->setAction(Action::FIGHT, this->myDivisionLeader_->getTarget());
+ target = orxonox_cast<Pawn*>(this->myDivisionLeader_->getTarget());
}
}
//----If he fights but doesn't have a target, wait for him to get one----
@@ -348,8 +218,36 @@
{
}
+ this->setAction (Action::FIGHT, orxonox_cast<ControllableEntity*>(target));
+ }
+ else
+ {
}
}
+ Vector3 SectionController::getFormationPosition ()
+ {
+ this->setFormationMode( this->myDivisionLeader_->getFormationMode() );
+ Vector3* targetRelativePosition;
+ switch (this->formationMode_){
+ case FormationMode::WALL:
+ {
+ targetRelativePosition = new Vector3 (-400, 0, 0);
+ break;
+ }
+ case FormationMode::FINGER4:
+ {
+ targetRelativePosition = new Vector3 (-400, 0, 200);
+ break;
+ }
+
+ case FormationMode::DIAMOND:
+ {
+ targetRelativePosition = new Vector3 (-400, 0, 200);
+ break;
+ }
+ }
+ return *targetRelativePosition;
+ }
//----stay in formation----
//gani-TODO: sum targetAbso... and this->predicted position
Modified: code/branches/campaignHS15/src/orxonox/controllers/SectionController.h
===================================================================
--- code/branches/campaignHS15/src/orxonox/controllers/SectionController.h 2015-11-24 21:47:44 UTC (rev 10853)
+++ code/branches/campaignHS15/src/orxonox/controllers/SectionController.h 2015-11-25 11:07:22 UTC (rev 10854)
@@ -62,13 +62,14 @@
protected:
//----action must only be managed by this----
virtual void action(); //<! action() is called in regular intervals managing the bot's behaviour.
-
+ Vector3 getFormationPosition ();
+ void boostControl();
private:
//----private variables-----
Timer actionTimer_; //<! Regularly calls action().
bool bFirstAction_;
-
+
};
}
Modified: code/branches/campaignHS15/src/orxonox/controllers/WingmanController.cc
===================================================================
--- code/branches/campaignHS15/src/orxonox/controllers/WingmanController.cc 2015-11-24 21:47:44 UTC (rev 10853)
+++ code/branches/campaignHS15/src/orxonox/controllers/WingmanController.cc 2015-11-25 11:07:22 UTC (rev 10854)
@@ -47,7 +47,13 @@
WingmanController::~WingmanController()
{
-
+ for (size_t i = 0; i < this->actionpoints_.size(); ++i)
+ {
+ if(this->actionpoints_[i])
+ this->actionpoints_[i]->destroy();
+ }
+ this->parsedActionpoints_.clear();
+ this->actionpoints_.clear();
}
void WingmanController::XMLPort(Element& xmlelement, XMLPort::Mode mode)
@@ -85,132 +91,13 @@
}
if (!this->myLeader_)
{
- bool b = this->startAttackingEnemiesThatAreClose();
-
- if (this->action_ == Action::NONE)
- {
- this->executeActionpoint();
- }
- if (this->action_ == Action::FIGHT || this->action_ == Action::FIGHTALL)
- {
- if (!this->hasTarget())
- {
- //----find a target----
- ControllableEntity* newTarget = this->closestTarget();
- if (this->action_ == Action::FIGHT)
- {
- if (newTarget &&
- CommonController::distance (this->getControllableEntity(), newTarget) < this->attackRange_)
- {
- this->setAction (Action::FIGHT, newTarget);
- }
- else
- {
- this->nextActionpoint();
- return;
- }
- }
- else if (this->action_ == Action::FIGHTALL)
- {
- if (newTarget && newTarget->getController())
- {
- this->setAction (Action::FIGHTALL, newTarget);
- }
- else
- {
- this->nextActionpoint();
- return;
- }
- }
-
- }
- else if (this->hasTarget())
- {
- //----fly in formation if far enough----
- Vector3 diffVector = this->positionOfTarget_ - this->getControllableEntity()->getWorldPosition();
-
- if (diffVector.length() > this->attackRange_)
- {
- if (this->action_ == Action::FIGHT)
- {
- this->nextActionpoint();
- return;
- }
- }
- }
- }
- else if (this->action_ == Action::FLY)
- {
- if (this->squaredDistanceToTarget() <= this->squaredaccuracy_)
- {
- this->nextActionpoint();
- return;
- }
- }
- else if (this->action_ == Action::PROTECT)
- {
- if (!this->getProtect())
- {
- this->nextActionpoint();
- return;
- }
-
- Vector3* targetRelativePosition;
-
- targetRelativePosition = new Vector3 (0, 300, 300);
-
- Vector3 targetAbsolutePosition = ((this->getProtect()->getWorldPosition()) +
- (this->getProtect()->getWorldOrientation()* (*targetRelativePosition)));
- this->setTargetPosition(targetAbsolutePosition);
-
-
- }
- else if (this->action_ == Action::ATTACK)
- {
- if (!this->hasTarget())
- {
- this->nextActionpoint();
- return;
- }
-
- }
- if (this->hasTarget())
- {
- //----choose where to go----
- this->maneuver();
- //----fire if you can----
- this->bShooting_ = this->canFire();
- }
+ CommonController::action();
}
- else
+ else if (this->myLeader_)
{
- //----action was set to fight----
- if (this->action_ == Action::FIGHT)
- {
- //----If no leader found, attack someone----
- if (!this->hasTarget())
- {
- this->setClosestTarget();
- }
- if (this->hasTarget())
- {
- //----choose where to go----
- this->maneuver();
- //----fire if you can----
- this->bShooting_ = this->canFire();
- }
- }
- //----action was set to fly, leader handles the logic----
- else if (this->action_ == Action::FLY)
- {
- }
- }
- if (this->bFirstAction_ && this->myLeader_)
- {
- this->parsedActionpoints_ = this->myLeader_->parsedActionpoints_;
- this->bFirstAction_ = false;
}
+
}
More information about the Orxonox-commit
mailing list