[Orxonox-commit 1966] r6683 - code/branches/ai/src/orxonox/controllers
solex at orxonox.net
solex at orxonox.net
Mon Apr 12 13:24:25 CEST 2010
Author: solex
Date: 2010-04-12 13:24:24 +0200 (Mon, 12 Apr 2010)
New Revision: 6683
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:
master/slave behavior enhancments
Modified: code/branches/ai/src/orxonox/controllers/AIController.cc
===================================================================
--- code/branches/ai/src/orxonox/controllers/AIController.cc 2010-04-12 11:11:26 UTC (rev 6682)
+++ code/branches/ai/src/orxonox/controllers/AIController.cc 2010-04-12 11:24:24 UTC (rev 6683)
@@ -48,6 +48,7 @@
AIController::~AIController()
{
+ if (this->state_ == MASTER) freeAllSlaves();
}
void AIController::action()
@@ -55,7 +56,7 @@
float random;
float maxrand = 100.0f / ACTION_INTERVAL;
- if (this->state_==0)
+ if (this->state_ == FREE)//FREE
{
// search master
@@ -63,17 +64,19 @@
if (random < 50 && (!this->target_))
this->searchNewMaster();
- //this->state_=1;
+
}
- if (this->state_==-1)
+ if (this->state_ == SLAVE)//SLAVE
{
-
+ // this->bShooting_ = true;
}
- if (this->state_==1)
+ if (this->state_ == MASTER)//MASTER
{
+ // command slaves
+ this->commandSlaves();
// search enemy
random = rnd(maxrand);
if (random < 15 && (!this->target_))
@@ -105,10 +108,10 @@
this->searchRandomTargetPosition();
// shoot
- random = rnd(maxrand);
+ /*random = rnd(maxrand);
if (random < 75 && (this->target_ && !this->bShooting_))
this->bShooting_ = true;
-
+*/
// stop shooting
random = rnd(maxrand);
if (random < 25 && (this->bShooting_))
@@ -121,23 +124,26 @@
if (!this->isActive())
return;
- if (this->state_==1)
+ if (this->state_ == MASTER)
{
if (this->target_)
this->aimAtTarget();
- if (this->bHasTargetPosition_)
+ /*if (this->bHasTargetPosition_)
this->moveToTargetPosition();
-
+*/
if (this->getControllableEntity() && this->bShooting_ && this->isCloseAtTarget(1000) && this->isLookingAtTarget(Ogre::Math::PI / 20.0f))
this->getControllableEntity()->fire(0);
}
- if (this->state_==-1)
+ if (this->state_==SLAVE)
{
- //this->state_=1;
+ if (this->bHasTargetPosition_)
+ this->moveToTargetPosition();
+ //this->getControllableEntity()->fire(0);
+
}
SUPER(AIController, tick, dt);
Modified: code/branches/ai/src/orxonox/controllers/ArtificialController.cc
===================================================================
--- code/branches/ai/src/orxonox/controllers/ArtificialController.cc 2010-04-12 11:11:26 UTC (rev 6682)
+++ code/branches/ai/src/orxonox/controllers/ArtificialController.cc 2010-04-12 11:24:24 UTC (rev 6683)
@@ -44,7 +44,7 @@
this->target_ = 0;
this->team_ = -1;//new
- this->state_ = 0;//new
+ this->state_ = FREE;//new
this->bShooting_ = false;
this->bHasTargetPosition_ = false;
this->targetPosition_ = Vector3::ZERO;
@@ -112,7 +112,7 @@
//has it an ArtificialController and is it a master? no: continue
ArtificialController *controller = static_cast<ArtificialController*>(it->getController());
- if (controller && controller->getState()!=1)
+ if (controller && controller->getState() != MASTER)
continue;
//is pawn oneself? && is pawn in range?
@@ -120,15 +120,42 @@
{
//this->target_ = (*it);
//this->targetPosition_ = it->getPosition();
- this->state_ = -1;
+ this->state_ = SLAVE;
}
}//for
//hasn't encountered any masters in range? -> become a master
- if (state_!=-1) state_=1; // keep in mind: what happens when two masters encounter eache other? -> has to be evaluated in the for loop of within master mode in AIcontroller...
+ if (state_!=SLAVE) state_=MASTER; // keep in mind: what happens when two masters encounter eache other? -> has to be evaluated in the for loop of within master mode in AIcontroller...
}
+ void ArtificialController::commandSlaves() {
+
+ for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it; ++it)
+ {
+ ArtificialController *controller = static_cast<ArtificialController*>(it->getController());
+ if (controller && controller->getState() != MASTER)
+ continue;
+
+ controller->targetPosition_ = this->getControllableEntity()->getPosition();
+ }
+
+ }
+
+ void ArtificialController::freeAllSlaves()
+ {
+ for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it; ++it)
+ {
+ ArtificialController *controller = static_cast<ArtificialController*>(it->getController());
+ if (controller && controller->getState() != MASTER)
+ continue;
+
+ controller->state_ = FREE;
+ }
+
+ }
+
+
void ArtificialController::setTargetPosition(const Vector3& target)
{
this->targetPosition_ = target;
Modified: code/branches/ai/src/orxonox/controllers/ArtificialController.h
===================================================================
--- code/branches/ai/src/orxonox/controllers/ArtificialController.h 2010-04-12 11:11:26 UTC (rev 6682)
+++ code/branches/ai/src/orxonox/controllers/ArtificialController.h 2010-04-12 11:24:24 UTC (rev 6683)
@@ -58,8 +58,11 @@
void moveToPosition(const Vector3& target);
void moveToTargetPosition();
+ enum State {SLAVE, MASTER, FREE};
int getState();
void searchNewMaster();
+ void commandSlaves();
+ void freeAllSlaves();
void setTargetPosition(const Vector3& target);
void searchRandomTargetPosition();
@@ -79,7 +82,8 @@
WeakPtr<Pawn> target_;
bool bShooting_;
- int state_;//new master: 1 slave: -1 free: 0
+
+ State state_;//new master: 1 slave: -1 free: 0
int team_;//new
private:
More information about the Orxonox-commit
mailing list