[Orxonox-commit 2079] r6795 - code/branches/ai/src/orxonox/controllers
solex at orxonox.net
solex at orxonox.net
Mon Apr 26 17:02:50 CEST 2010
Author: solex
Date: 2010-04-26 17:02:49 +0200 (Mon, 26 Apr 2010)
New Revision: 6795
Modified:
code/branches/ai/src/orxonox/controllers/AIController.cc
code/branches/ai/src/orxonox/controllers/ArtificialController.cc
code/branches/ai/src/orxonox/controllers/ArtificialController.h
Log:
death of master results in forming a new formation. Correct response to master death still to solve.
Modified: code/branches/ai/src/orxonox/controllers/AIController.cc
===================================================================
--- code/branches/ai/src/orxonox/controllers/AIController.cc 2010-04-26 15:01:07 UTC (rev 6794)
+++ code/branches/ai/src/orxonox/controllers/AIController.cc 2010-04-26 15:02:49 UTC (rev 6795)
@@ -48,9 +48,13 @@
AIController::~AIController()
{
- if (this->state_ == MASTER) freeAllSlaves();
+COUT(0) << "~AIController 1" << std::endl;
+ if (this->state_ == MASTER) setNewMasterWithinFormation();
+COUT(0) << "~AIController 2" << std::endl;
if (this->state_ == SLAVE) unregisterSlave();
- this->slaves.clear();
+COUT(0) << "~AIController 3" << std::endl;
+ this->slaves_.clear();
+COUT(0) << "~AIController 4" << std::endl;
}
void AIController::action()
@@ -83,11 +87,11 @@
// lose master status (only if less than 4 slaves in formation)
random = rnd(maxrand);
- if(random < 5/(this->slaves.size()+1) && this->slaves.size() < 5 )
+ if(random < 5/(this->slaves_.size()+1) && this->slaves_.size() < 5 )
this->loseMasterState();
// look out for outher masters if formation is small
- if(this->slaves.size() < 3)
+ if(this->slaves_.size() < 3)
this->searchNewMaster();
// search enemy
Modified: code/branches/ai/src/orxonox/controllers/ArtificialController.cc
===================================================================
--- code/branches/ai/src/orxonox/controllers/ArtificialController.cc 2010-04-26 15:01:07 UTC (rev 6794)
+++ code/branches/ai/src/orxonox/controllers/ArtificialController.cc 2010-04-26 15:02:49 UTC (rev 6795)
@@ -50,6 +50,7 @@
this->bShooting_ = false;
this->bHasTargetPosition_ = false;
this->targetPosition_ = Vector3::ZERO;
+ //this->slaves_ = new std::list<ArtificialController*>;
this->target_.setCallback(createFunctor(&ArtificialController::targetDied, this));
}
@@ -99,7 +100,7 @@
void ArtificialController::unregisterSlave() {
if(myMaster_)
{
- myMaster_->slaves.remove(this);
+ myMaster_->slaves_.remove(this);
}
}
@@ -131,14 +132,14 @@
//is pawn oneself? && is pawn in range?
if (static_cast<ControllableEntity*>(*it) != this->getControllableEntity()) //&& it->getPosition().squaredDistance(this->getControllableEntity()->getPosition()) < 1000
{
- if(controller->slaves.size() > 9) continue;
+ if(controller->slaves_.size() > 9) continue;
this->freeAllSlaves();
- this->slaves.clear();
+ this->slaves_.clear();
this->state_ = SLAVE;
this->myMaster_ = controller;
- controller->slaves.push_back(this);
+ controller->slaves_.push_back(this);
break;
}
@@ -151,7 +152,7 @@
void ArtificialController::commandSlaves() {
- for(std::list<ArtificialController*>::iterator it = slaves.begin(); it != slaves.end(); it++)
+ for(std::list<ArtificialController*>::iterator it = slaves_.begin(); it != slaves_.end(); it++)
{
(*it)->setTargetPosition(this->getControllableEntity()->getPosition());
}
@@ -172,11 +173,42 @@
*/
}
+ // binds slaves to new Master within formation
+ void ArtificialController::setNewMasterWithinFormation()
+ {
+COUT(0) << "~setNewMasterWithinFormation 1" << std::endl;
+ if (this->slaves_.empty())
+ return;
+COUT(0) << "~setNewMasterWithinFormation 1b" << std::endl;
+
+ ArtificialController *newMaster = this->slaves_.back();
+COUT(0) << "~setNewMasterWithinFormation 2" << std::endl;
+ this->slaves_.pop_back();
+COUT(0) << "~setNewMasterWithinFormation 3" << std::endl;
+ if(!newMaster) return;
+COUT(0) << "~setNewMasterWithinFormation 4" << std::endl;
+ newMaster->state_ = MASTER;
+ newMaster->slaves_ = this->slaves_;
+ //this->slaves_.clear();
+
+ this->state_ = SLAVE;
+ this->myMaster_ = newMaster;
+
+COUT(0) << "~setNewMasterWithinFormation 5" << std::endl;
+ for(std::list<ArtificialController*>::iterator it = newMaster->slaves_.begin(); it != newMaster->slaves_.end(); it++)
+ {
+COUT(0) << "~setNewMasterWithinFormation 6" << std::endl;
+ (*it)->myMaster_ = newMaster;
+ }
+COUT(0) << "~setNewMasterWithinFormation 7" << std::endl;
+
+ }
+
void ArtificialController::freeAllSlaves()
{
- for(std::list<ArtificialController*>::iterator it = slaves.begin(); it != slaves.end(); it++)
+ for(std::list<ArtificialController*>::iterator it = slaves_.begin(); it != slaves_.end(); it++)
{
(*it)->state_ = FREE;
}
Modified: code/branches/ai/src/orxonox/controllers/ArtificialController.h
===================================================================
--- code/branches/ai/src/orxonox/controllers/ArtificialController.h 2010-04-26 15:01:07 UTC (rev 6794)
+++ code/branches/ai/src/orxonox/controllers/ArtificialController.h 2010-04-26 15:02:49 UTC (rev 6795)
@@ -46,10 +46,11 @@
void abandonTarget(Pawn* target);
- inline void setTeam(int team)//new
+ inline void setTeam(int team)
{ this->team_ = team; }
inline int getTeam() const
{ return this->team_; }
+ virtual void changedControllableEntity();
protected:
@@ -60,10 +61,11 @@
enum State {SLAVE, MASTER, FREE};
int getState();
- std::list<ArtificialController*> slaves;
+ std::list<ArtificialController*> slaves_;
void unregisterSlave();
void searchNewMaster();
void commandSlaves();
+ void setNewMasterWithinFormation();
void freeAllSlaves();
void loseMasterState();
@@ -88,8 +90,8 @@
bool bShooting_;
- State state_;//new master: 1 slave: -1 free: 0
- int team_;//new
+ State state_;
+ int team_;
private:
};
More information about the Orxonox-commit
mailing list