[Orxonox-commit 4320] r8991 - code/branches/formation/src/orxonox/controllers
jo at orxonox.net
jo at orxonox.net
Fri Dec 16 16:56:15 CET 2011
Author: jo
Date: 2011-12-16 16:56:15 +0100 (Fri, 16 Dec 2011)
New Revision: 8991
Modified:
code/branches/formation/src/orxonox/controllers/AIController.cc
code/branches/formation/src/orxonox/controllers/ArtificialController.cc
code/branches/formation/src/orxonox/controllers/ArtificialController.h
code/branches/formation/src/orxonox/controllers/FormationController.cc
code/branches/formation/src/orxonox/controllers/FormationController.h
code/branches/formation/src/orxonox/controllers/HumanController.cc
Log:
Works. (Seperate/independent states are used to manage the behaviour).
Modified: code/branches/formation/src/orxonox/controllers/AIController.cc
===================================================================
--- code/branches/formation/src/orxonox/controllers/AIController.cc 2011-12-16 15:25:28 UTC (rev 8990)
+++ code/branches/formation/src/orxonox/controllers/AIController.cc 2011-12-16 15:56:15 UTC (rev 8991)
@@ -77,7 +77,7 @@
}
- if (this->state_ == SLAVE && this->mode_ == ATTACK) //TODO: add botlevel parameter
+ if (this->state_ == SLAVE && this->formationMode_ == ATTACK) //TODO: add botlevel parameter
{
// search enemy
random = rnd(maxrand);
@@ -150,8 +150,8 @@
float random;
float maxrand = 100.0f / ACTION_INTERVAL;
ControllableEntity* controllable = this->getControllableEntity();
-
- if (controllable && this->mode_ == NORMAL)// bot is ready to move to a target // mode was DEFAULT in original implementation!
+ //DOES: Either move to the waypoint or search for a Point of interest
+ if (controllable && this->mode_ == DEFAULT)// bot is ready to move to a target
{
if (this->waypoints_.size() > 0 ) //Waypoint functionality.
{
@@ -173,7 +173,7 @@
}
}
- if (this->mode_ != ROCKET)
+ if (this->mode_ == DEFAULT)
{
if (this->state_ == MASTER)
{
@@ -206,13 +206,13 @@
this->follow();
}
- if (this->state_ == SLAVE && this->mode_!=ATTACK)
+ if (this->state_ == SLAVE && this->formationMode_ != ATTACK)
{
if (this->bHasTargetPosition_)
this->moveToTargetPosition();
}
- if (this->state_ == FREE || (this->state_==SLAVE && this->mode_==ATTACK) )
+ if (this->state_ == FREE || (this->state_==SLAVE && this->formationMode_ == ATTACK) )
{
if (this->target_)
{
Modified: code/branches/formation/src/orxonox/controllers/ArtificialController.cc
===================================================================
--- code/branches/formation/src/orxonox/controllers/ArtificialController.cc 2011-12-16 15:25:28 UTC (rev 8990)
+++ code/branches/formation/src/orxonox/controllers/ArtificialController.cc 2011-12-16 15:56:15 UTC (rev 8991)
@@ -49,6 +49,7 @@
this->currentWaypoint_ = 0;
this->setAccuracy(5);
this->defaultWaypoint_ = NULL;
+ this->mode_ = DEFAULT;//Vector-implementation: mode_.push_back(DEFAULT);
}
ArtificialController::~ArtificialController()
@@ -196,7 +197,7 @@
void ArtificialController::setPreviousMode()
{
- this->mode_ = NORMAL; //Vector-implementation: mode_.pop_back();
+ this->mode_ = DEFAULT; //Vector-implementation: mode_.pop_back();
}
/**
Modified: code/branches/formation/src/orxonox/controllers/ArtificialController.h
===================================================================
--- code/branches/formation/src/orxonox/controllers/ArtificialController.h 2011-12-16 15:25:28 UTC (rev 8990)
+++ code/branches/formation/src/orxonox/controllers/ArtificialController.h 2011-12-16 15:56:15 UTC (rev 8991)
@@ -70,6 +70,8 @@
bool isLookingAtTarget(float angle) const;
//************************************************************************* NEW
float botlevel_; //<! Makes the level of a bot configurable.
+ enum Mode {DEFAULT, ROCKET, DEFENCE, MOVING};//TODO; implement DEFENCE, MOVING modes
+ Mode mode_; //TODO: replace single value with stack-like implementation: std::vector<Mode> mode_;
void setPreviousMode();
Modified: code/branches/formation/src/orxonox/controllers/FormationController.cc
===================================================================
--- code/branches/formation/src/orxonox/controllers/FormationController.cc 2011-12-16 15:25:28 UTC (rev 8990)
+++ code/branches/formation/src/orxonox/controllers/FormationController.cc 2011-12-16 15:56:15 UTC (rev 8991)
@@ -80,7 +80,7 @@
this->freedomCount_ = 0;
this->state_ = FREE;
- this->mode_ = NORMAL;
+ this->formationMode_ = NORMAL;
this->specificMasterAction_ = NONE;
this->specificMasterActionHoldCount_ = 0;
this->bShooting_ = false;
@@ -651,15 +651,15 @@
/**
@brief Sets the new mode. If master, set it for all slaves.
*/
- void FormationController::setMode(Mode val)
+ void FormationController::setFormationMode(FormationMode val)
{
- this->mode_=val;
- if (this->state_==MASTER)
+ this->formationMode_ = val;
+ if (this->state_ == MASTER)
{
for(std::vector<FormationController*>::iterator it = slaves_.begin(); it != slaves_.end(); it++)
{
- (*it)->mode_=val;
- if (val==ATTACK)
+ (*it)->formationMode_ = val;
+ if (val == ATTACK)
(*it)->forgetTarget();
}
}
Modified: code/branches/formation/src/orxonox/controllers/FormationController.h
===================================================================
--- code/branches/formation/src/orxonox/controllers/FormationController.h 2011-12-16 15:25:28 UTC (rev 8990)
+++ code/branches/formation/src/orxonox/controllers/FormationController.h 2011-12-16 15:56:15 UTC (rev 8991)
@@ -87,14 +87,14 @@
Defend-just defend the master
Attack-leave formation, attack every target
*/
- enum Mode {NORMAL,DEFEND,ATTACK,ROCKET};
+ enum FormationMode {NORMAL,DEFEND,ATTACK};
/**
@brief Sets the new mode. If master, set it for all slaves.
*/
- void setMode(Mode val);
- inline Mode getMode() const
- { return this->mode_; }
+ void setFormationMode(FormationMode val);
+ inline FormationMode getFormationMode() const
+ { return this->formationMode_; }
protected:
bool formationFlight_;
@@ -108,7 +108,7 @@
std::vector<FormationController*> slaves_;
FormationController* myMaster_;
- Mode mode_;
+ FormationMode formationMode_;
enum SpecificMasterAction {NONE, HOLD, SPIN, TURN180, FOLLOW};
SpecificMasterAction specificMasterAction_;
Modified: code/branches/formation/src/orxonox/controllers/HumanController.cc
===================================================================
--- code/branches/formation/src/orxonox/controllers/HumanController.cc 2011-12-16 15:25:28 UTC (rev 8990)
+++ code/branches/formation/src/orxonox/controllers/HumanController.cc 2011-12-16 15:56:15 UTC (rev 8991)
@@ -105,7 +105,7 @@
// commandslaves when Master of a formation
if (HumanController::localController_s && HumanController::localController_s->state_==MASTER)
{
- if (HumanController::localController_s->mode_!=ATTACK)
+ if (HumanController::localController_s->formationMode_ != ATTACK)
HumanController::localController_s->commandSlaves();
}
}
@@ -176,7 +176,7 @@
{
HumanController::localController_s->controllableEntity_->fire(firemode);
//if human fires, set slaves free. See FormationController::forceFreeSlaves()
- if (HumanController::localController_s->state_==MASTER && HumanController::localController_s->mode_==NORMAL)
+ if (HumanController::localController_s->state_==MASTER && HumanController::localController_s->formationMode_ == NORMAL)
{
HumanController::localController_s->forceFreeSlaves();
}
@@ -316,21 +316,19 @@
{
if (HumanController::localController_s && HumanController::localController_s->state_==MASTER)
{
- switch (HumanController::localController_s->getMode()) {
+ switch (HumanController::localController_s->getFormationMode()) {
case NORMAL:
- HumanController::localController_s->setMode(DEFEND);
+ HumanController::localController_s->setFormationMode(DEFEND);
orxout(message) <<"Mode: DEFEND "<< endl;
break;
case DEFEND:
- HumanController::localController_s->setMode(ATTACK);
+ HumanController::localController_s->setFormationMode(ATTACK);
orxout(message) <<"Mode: ATTACK "<< endl;
break;
case ATTACK:
- HumanController::localController_s->setMode(NORMAL);
+ HumanController::localController_s->setFormationMode(NORMAL);
orxout(message) <<"Mode: NORMAL "<< endl;
break;
- default: //catch all non-formation related states
- break;
}
}
}
@@ -339,7 +337,7 @@
//used, when slaves are in DEFEND mode.
void HumanController::hit(Pawn* originator, btManifoldPoint& contactpoint, float damage)
{
- if (!this->formationFlight_ || this->state_!=MASTER || this->mode_!=DEFEND) return;
+ if (!this->formationFlight_ || this->state_!=MASTER || this->formationMode_!=DEFEND) return;
this->masterAttacked(originator);
}
More information about the Orxonox-commit
mailing list