[Orxonox-commit 2134] r6850 - in code/branches/ai: data/levels/templates src/orxonox/controllers src/orxonox/worldentities
solex at orxonox.net
solex at orxonox.net
Mon May 3 18:41:43 CEST 2010
Author: solex
Date: 2010-05-03 18:41:43 +0200 (Mon, 03 May 2010)
New Revision: 6850
Modified:
code/branches/ai/data/levels/templates/spaceship_pirate.oxt
code/branches/ai/src/orxonox/controllers/AIController.cc
code/branches/ai/src/orxonox/controllers/ArtificialController.cc
code/branches/ai/src/orxonox/controllers/ArtificialController.h
code/branches/ai/src/orxonox/controllers/CMakeLists.txt
code/branches/ai/src/orxonox/worldentities/CMakeLists.txt
Log:
master/slave interaction of bots now correct - getting closer to formation flight
Modified: code/branches/ai/data/levels/templates/spaceship_pirate.oxt
===================================================================
--- code/branches/ai/data/levels/templates/spaceship_pirate.oxt 2010-05-03 15:03:05 UTC (rev 6849)
+++ code/branches/ai/data/levels/templates/spaceship_pirate.oxt 2010-05-03 16:41:43 UTC (rev 6850)
@@ -68,21 +68,21 @@
accelerationleftright = 125
accelerationupdown = 125
>
- <active>
+ <EffectContainer condition="not idle">
<FadingBillboard mainstate=activity active=false scale=0.02 position=" 1.3, -4, -15" colour="1.0, 0.65, 0.2, 1.0" material="Examples/FlareZwei" turnontime=0.5 turnofftime=0.5 />
<FadingBillboard mainstate=activity active=false scale=0.02 position=" 0, -4, -15" colour="1.0, 0.65, 0.2, 1.0" material="Examples/FlareZwei" turnontime=0.5 turnofftime=0.5 />
<FadingBillboard mainstate=activity active=false scale=0.02 position="-1.3, -4, -15" colour="1.0, 0.65, 0.2, 1.0" material="Examples/FlareZwei" turnontime=0.5 turnofftime=0.5 />
- </active>
- <forward>
+ </EffectContainer>
+ <EffectContainer condition="normal or boost">
<Backlight mainstate=activity active=false scale=0.4 name=bltest position=" 13, -4, 9.5" colour="1.0, 0.65, 0.2, 1.0" width=8 length=800 lifetime=1 elements=50 trailmaterial="Trail/backlighttrail" turnontime=1 turnofftime=1 material="Flares/ThrusterFlare1" />
<Backlight mainstate=activity active=false scale=0.4 name=bltest position="-13, -4, 9.5" colour="1.0, 0.65, 0.2, 1.0" width=8 length=800 lifetime=1 elements=50 trailmaterial="Trail/backlighttrail" turnontime=1 turnofftime=1 material="Flares/ThrusterFlare1" />
- </forward>
- <boost>
+ </EffectContainer>
+ <EffectContainer condition="boost">
<Backlight mainstate=activity active=false scale=0.4 name=bltest position=" 0, 5, 15.5" colour="1.0, 0.65, 0.2, 1.0" width=16 length=1600 lifetime=2 elements=50 trailmaterial="Trail/backlighttrail" turnontime=1 turnofftime=1 material="Flares/ThrusterFlare1" />
- </boost>
- <brake>
+ </EffectContainer>
+ <EffectContainer condition="brake">
<FadingBillboard mainstate=activity active=false scale=0.1 position=" 4.4, -5.5, 5" colour="0.8, 0.0, 0.0, 0.3" material="Examples/Flare" turnontime=0.5 turnofftime=0.5 />
<FadingBillboard mainstate=activity active=false scale=0.1 position="-4.4, -5.5, 5" colour="0.8, 0.0, 0.0, 0.3" material="Examples/Flare" turnontime=0.5 turnofftime=0.5 />
- </brake>
+ </EffectContainer>
</MultiStateEngine>
</Template>
Modified: code/branches/ai/src/orxonox/controllers/AIController.cc
===================================================================
--- code/branches/ai/src/orxonox/controllers/AIController.cc 2010-05-03 15:03:05 UTC (rev 6849)
+++ code/branches/ai/src/orxonox/controllers/AIController.cc 2010-05-03 16:41:43 UTC (rev 6850)
@@ -48,13 +48,6 @@
AIController::~AIController()
{
-COUT(0) << "~AIController 1" << std::endl;
- if (this->state_ == MASTER) setNewMasterWithinFormation();
-COUT(0) << "~AIController 2" << std::endl;
- if (this->state_ == SLAVE) unregisterSlave();
-COUT(0) << "~AIController 3" << std::endl;
- this->slaves_.clear();
-COUT(0) << "~AIController 4" << std::endl;
}
void AIController::action()
@@ -62,18 +55,65 @@
float random;
float maxrand = 100.0f / ACTION_INTERVAL;
- if (this->state_ == FREE)//FREE
+ if (this->state_ == FREE)
{
- //this->state_ = MASTER;
- // search master
- //random = rnd(maxrand);
- //if (random < 101 && (!this->target_))
+
+ // return to Master after being forced free
+ if (this->freedomCount_ == 1)
+ {
+ this->state_ = SLAVE;
+ this->freedomCount_ = 0;
+ }
+
+ random = rnd(maxrand);
+ if (random < 90 && (((!this->target_) || (random < 50 && this->target_)) && !this->forcedFree()))
this->searchNewMaster();
+
+ // search enemy
+ random = rnd(maxrand);
+ if (random < 15 && (!this->target_))
+ this->searchNewTarget();
+
+ // forget enemy
+ random = rnd(maxrand);
+ if (random < 5 && (this->target_))
+ this->forgetTarget();
+
+ // next enemy
+ random = rnd(maxrand);
+ if (random < 10 && (this->target_))
+ this->searchNewTarget();
+
+ // fly somewhere
+ random = rnd(maxrand);
+ if (random < 50 && (!this->bHasTargetPosition_ && !this->target_))
+ this->searchRandomTargetPosition();
+
+ // stop flying
+ random = rnd(maxrand);
+ if (random < 10 && (this->bHasTargetPosition_ && !this->target_))
+ this->bHasTargetPosition_ = false;
+
+ // fly somewhere else
+ random = rnd(maxrand);
+ if (random < 30 && (this->bHasTargetPosition_ && !this->target_))
+ this->searchRandomTargetPosition();
+
+
+ random = rnd(maxrand);
+ if (random < 75 && (this->target_ && !this->bShooting_))
+ this->bShooting_ = true;
+
+ // stop shooting
+ random = rnd(maxrand);
+ if (random < 25 && (this->bShooting_))
+ this->bShooting_ = false;
+
}
- if (this->state_ == SLAVE)//SLAVE
+ if (this->state_ == SLAVE)
{
// this->bShooting_ = true;
}
@@ -81,17 +121,18 @@
if (this->state_ == MASTER)//MASTER
{
- // command slaves
+
this->commandSlaves();
// 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 < 15/(this->slaves_.size()+1) && this->slaves_.size() < 5 )
this->loseMasterState();
// look out for outher masters if formation is small
- if(this->slaves_.size() < 3)
+ random = rnd(maxrand);
+ if(this->slaves_.size() < 3 && random < 20)
this->searchNewMaster();
// search enemy
@@ -114,10 +155,6 @@
if (random < 50 && (!this->bHasTargetPosition_ && !this->target_))
this->searchRandomTargetPosition();
- // stop flying
- random = rnd(maxrand);
- if (random < 10 && (this->bHasTargetPosition_ && !this->target_))
- this->bHasTargetPosition_ = false;
// fly somewhere else
random = rnd(maxrand);
@@ -125,15 +162,18 @@
this->searchRandomTargetPosition();
// shoot
- /*random = rnd(maxrand);
- if (random < 75 && (this->target_ && !this->bShooting_))
+ random = rnd(maxrand);
+ if (random < 5 && (this->target_ && !this->bShooting_))
+ {
this->bShooting_ = true;
-*/
+ this->forceFreeSlaves();
+ }
// stop shooting
random = rnd(maxrand);
if (random < 25 && (this->bShooting_))
this->bShooting_ = false;
}
+
}
void AIController::tick(float dt)
@@ -159,8 +199,18 @@
if (this->bHasTargetPosition_)
this->moveToTargetPosition();
- //this->getControllableEntity()->fire(0);
+ }
+ if (this->state_ == FREE)
+ {
+ if (this->target_)
+ this->aimAtTarget();
+
+ if (this->bHasTargetPosition_)
+ this->moveToTargetPosition();
+
+ if (this->getControllableEntity() && this->bShooting_ && this->isCloseAtTarget(1000) && this->isLookingAtTarget(Ogre::Math::PI / 20.0f))
+ 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-05-03 15:03:05 UTC (rev 6849)
+++ code/branches/ai/src/orxonox/controllers/ArtificialController.cc 2010-05-03 16:41:43 UTC (rev 6850)
@@ -44,13 +44,12 @@
this->target_ = 0;
this->myMaster_ = 0;
- //this->slaveNumber_ = -1;
- this->team_ = -1;//new
- this->state_ = FREE;//new
+ this->freedomCount_ = 0;
+ this->team_ = -1;
+ this->state_ = FREE;
this->bShooting_ = false;
this->bHasTargetPosition_ = false;
this->targetPosition_ = Vector3::ZERO;
- //this->slaves_ = new std::list<ArtificialController*>;
this->target_.setCallback(createFunctor(&ArtificialController::targetDied, this));
}
@@ -66,6 +65,24 @@
XMLPortParam(ArtificialController, "team", setTeam, getTeam, xmlelement, mode).defaultValues(0);
}
+// gets called when Bot dies
+ void ArtificialController::changedControllableEntity()
+ {
+COUT(0) << "~changedControllableEntity 0" << std::endl;
+ if(!getControllableEntity())
+ {
+COUT(0) << "~changedControllableEntity 1" << std::endl;
+ if (this->state_ == SLAVE) unregisterSlave();
+COUT(0) << "~changedControllableEntity 2" << std::endl;
+ if (this->state_ == MASTER) setNewMasterWithinFormation();
+COUT(0) << "~changedControllableEntity 3" << std::endl;
+ this->slaves_.clear();
+COUT(0) << "~changedControllableEntity 4" << std::endl;
+ this->state_ = FREE;
+COUT(0) << "~changedControllableEntity 5" << std::endl;
+ }
+ }
+
void ArtificialController::moveToPosition(const Vector3& target)
{
if (!this->getControllableEntity())
@@ -76,15 +93,28 @@
if (this->target_ || distance > 10)
{
- // Multiply with 0.8 to make them a bit slower
- this->getControllableEntity()->rotateYaw(-0.8f * sgn(coord.x) * coord.x*coord.x);
- this->getControllableEntity()->rotatePitch(0.8f * sgn(coord.y) * coord.y*coord.y);
+ // Multiply with rotateFactor to make them a bit slower
+ float rotateFactor;
+ if(this->state_ == SLAVE) rotateFactor = 1.0f;
+ if(this->state_ == MASTER) rotateFactor = 0.4f;
+ else rotateFactor = 0.8f;
+
+ this->getControllableEntity()->rotateYaw(-1.0f * rotateFactor * sgn(coord.x) * coord.x*coord.x);
+ this->getControllableEntity()->rotatePitch(rotateFactor * sgn(coord.y) * coord.y*coord.y);
+
+
+
}
if (this->target_ && distance < 200 && this->getControllableEntity()->getVelocity().squaredLength() > this->target_->getVelocity().squaredLength())
- this->getControllableEntity()->moveFrontBack(-0.5f); // They don't brake with full power to give the player a chance
- else
- this->getControllableEntity()->moveFrontBack(0.8f);
+ {
+ if(this->state_ == SLAVE) this->getControllableEntity()->moveFrontBack(-0.8f);
+ else this->getControllableEntity()->moveFrontBack(-0.05f); // They don't brake with full power to give the player a chance
+ } else {
+ if(this->state_ == SLAVE) this->getControllableEntity()->moveFrontBack(2.5f);
+ if(this->state_ == MASTER) this->getControllableEntity()->moveFrontBack(0.4f);
+ else this->getControllableEntity()->moveFrontBack(0.8f);
+ }
}
void ArtificialController::moveToTargetPosition()
@@ -101,6 +131,7 @@
if(myMaster_)
{
myMaster_->slaves_.remove(this);
+COUT(0) << "~unregister slave" << std::endl;
}
}
@@ -125,21 +156,28 @@
if (!it->getController())
continue;
- ArtificialController *controller = static_cast<ArtificialController*>(it->getController());
- if (!controller || controller->getState() != MASTER)
+ ArtificialController *newMaster = static_cast<ArtificialController*>(it->getController());
+
+ if (!newMaster || newMaster->getState() != MASTER)
continue;
//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(newMaster->slaves_.size() > 6) continue;
- this->freeAllSlaves();
+ //this->freeSlaves();
+
+ for(std::list<ArtificialController*>::iterator itSlave = this->slaves_.begin(); itSlave != this->slaves_.end(); itSlave++)
+ {
+ (*itSlave)->myMaster_ = newMaster;
+ newMaster->slaves_.push_back(*itSlave);
+ }
this->slaves_.clear();
this->state_ = SLAVE;
- this->myMaster_ = controller;
- controller->slaves_.push_back(this);
+ this->myMaster_ = newMaster;
+ newMaster->slaves_.push_back(this);
break;
}
@@ -147,7 +185,7 @@
//hasn't encountered any masters in range? -> become a master
if (state_!=SLAVE) state_ = MASTER; // keep in mind: what happens when two masters encounter eache other? -> has to be evaluated in the for loop within master mode in AIcontroller...
-
+COUT(0) << "~searcheNewMaster" << std::endl;
}
void ArtificialController::commandSlaves() {
@@ -156,21 +194,6 @@
{
(*it)->setTargetPosition(this->getControllableEntity()->getPosition());
}
-/*
- for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it; ++it)
- {
-
- if (!it->getController())
- continue;
-
- ArtificialController *controller = static_cast<ArtificialController*>(it->getController());
- if (!controller || controller->getState() != SLAVE)
- continue;
- //controller->setTargetPosition(this->getControllableEntity()->getPosition());
- controller->targetPosition_ = this->getControllableEntity()->getPosition();
- controller->bHasTargetPosition_ = true;
- }
-*/
}
// binds slaves to new Master within formation
@@ -189,7 +212,7 @@
COUT(0) << "~setNewMasterWithinFormation 4" << std::endl;
newMaster->state_ = MASTER;
newMaster->slaves_ = this->slaves_;
- //this->slaves_.clear();
+ this->slaves_.clear();
this->state_ = SLAVE;
this->myMaster_ = newMaster;
@@ -204,32 +227,47 @@
}
- void ArtificialController::freeAllSlaves()
+ void ArtificialController::freeSlaves()
{
-
-
for(std::list<ArtificialController*>::iterator it = slaves_.begin(); it != slaves_.end(); it++)
{
(*it)->state_ = FREE;
}
-/*
- for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it; ++it)
+ this->slaves_.clear();
+ }
+
+ void ArtificialController::forceFreeSlaves()
+ {
+ for(std::list<ArtificialController*>::iterator it = slaves_.begin(); it != slaves_.end(); it++)
{
- ArtificialController *controller = static_cast<ArtificialController*>(it->getController());
- if (controller && controller->getState() != SLAVE)
- continue;
-
- controller->state_ = FREE;
+ (*it)->state_ = FREE;
+ (*it)->forceFreedom();
+ (*it)->targetPosition_ = this->targetPosition_;
+ (*it)->bShooting_ = true;
+ (*it)->getControllableEntity()->fire(0);
}
-*/
}
void ArtificialController::loseMasterState()
{
- this->freeAllSlaves();
+ this->freeSlaves();
this->state_ = FREE;
}
+ void ArtificialController::forceFreedom()
+ {
+ this->freedomCount_ = 5;
+ }
+
+ bool ArtificialController::forcedFree()
+ {
+ if(this->freedomCount_ > 0)
+ {
+ this->freedomCount_--;
+ return true;
+ } else return false;
+ }
+
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-05-03 15:03:05 UTC (rev 6849)
+++ code/branches/ai/src/orxonox/controllers/ArtificialController.h 2010-05-03 16:41:43 UTC (rev 6850)
@@ -50,24 +50,34 @@
{ this->team_ = team; }
inline int getTeam() const
{ return this->team_; }
- //virtual void changedControllableEntity();
+ virtual void changedControllableEntity();
protected:
+
+ int team_;
+ int freedomCount_;
+ enum State {SLAVE, MASTER, FREE};
+ State state_;
+ std::list<ArtificialController*> slaves_;
+
void targetDied();
void moveToPosition(const Vector3& target);
+ //void speedToTargetPosition(const Vector3& target);
void moveToTargetPosition();
- enum State {SLAVE, MASTER, FREE};
int getState();
- std::list<ArtificialController*> slaves_;
+
void unregisterSlave();
void searchNewMaster();
void commandSlaves();
void setNewMasterWithinFormation();
- void freeAllSlaves();
+ void freeSlaves();
+ void forceFreeSlaves();
void loseMasterState();
+ void forceFreedom();
+ bool forcedFree();
ArtificialController *myMaster_;
@@ -89,10 +99,6 @@
WeakPtr<Pawn> target_;
bool bShooting_;
-
- State state_;
- int team_;
-
private:
};
}
Modified: code/branches/ai/src/orxonox/controllers/CMakeLists.txt
===================================================================
--- code/branches/ai/src/orxonox/controllers/CMakeLists.txt 2010-05-03 15:03:05 UTC (rev 6849)
+++ code/branches/ai/src/orxonox/controllers/CMakeLists.txt 2010-05-03 16:41:43 UTC (rev 6850)
@@ -7,5 +7,5 @@
ScriptController.cc
WaypointController.cc
WaypointPatrolController.cc
- DroneController.cc
+
)
Modified: code/branches/ai/src/orxonox/worldentities/CMakeLists.txt
===================================================================
--- code/branches/ai/src/orxonox/worldentities/CMakeLists.txt 2010-05-03 15:03:05 UTC (rev 6849)
+++ code/branches/ai/src/orxonox/worldentities/CMakeLists.txt 2010-05-03 16:41:43 UTC (rev 6850)
@@ -4,7 +4,6 @@
MovableEntity.cc
MobileEntity.cc
ControllableEntity.cc
- Drone.cc
BigExplosion.cc
EffectContainer.cc
ExplosionChunk.cc
More information about the Orxonox-commit
mailing list