[Orxonox-commit 5995] r10654 - code/branches/AI_HS15/src/orxonox/controllers
gania at orxonox.net
gania at orxonox.net
Sun Oct 18 20:53:38 CEST 2015
Author: gania
Date: 2015-10-18 20:53:37 +0200 (Sun, 18 Oct 2015)
New Revision: 10654
Modified:
code/branches/AI_HS15/src/orxonox/controllers/AIController.cc
code/branches/AI_HS15/src/orxonox/controllers/AIController.h
Log:
changed AIController -> collecting data about spaceships with each action()
Modified: code/branches/AI_HS15/src/orxonox/controllers/AIController.cc
===================================================================
--- code/branches/AI_HS15/src/orxonox/controllers/AIController.cc 2015-10-18 12:35:35 UTC (rev 10653)
+++ code/branches/AI_HS15/src/orxonox/controllers/AIController.cc 2015-10-18 18:53:37 UTC (rev 10654)
@@ -104,7 +104,43 @@
if (this->state_ == MASTER)
{
+
+ //-------------------------------------------------------
+ //collect data for AI behaviour
+ Vector3 meanOfEnemies;
+ Vector3 meanOfAllies;
+ for (ObjectList<AIController>::iterator it = ObjectList<AIController>::begin(); it; ++it)
+ {
+
+ Gametype* gt=this->getGametype();
+ if (!gt)
+ {
+ gt=it->getGametype();
+ }
+ if (!FormationController::sameTeam(this->getControllableEntity(), it->getControllableEntity(),gt))
+ {
+ enemies.push_back(*it);
+ }
+ else {
+ allies.push_back(*it);
+ }
+ }
+ if (enemies.size() != 0 && allies.size() != 0){
+ for (std::vector<AIController*>::iterator it = enemies.begin() ; it != enemies.end(); ++it)
+ meanOfEnemies += (*it)->getControllableEntity()->getPosition();
+ meanOfEnemies /= enemies.size();
+ for (std::vector<AIController*>::iterator it = allies.begin() ; it != allies.end(); ++it)
+ meanOfAllies += (*it)->getControllableEntity()->getPosition();
+ meanOfAllies /= allies.size();
+ //orxout(internal_error) << "There are " << enemiesCounter << " enemies, mean position is " << meanOfEnemies << endl;
+ orxout(internal_error) << "Distance is " << (meanOfEnemies-meanOfAllies).length() << endl;
+ orxout(internal_error) << "mean of Allies is " << meanOfAllies << ", with a size " << allies.size() << endl;
+ orxout(internal_error) << "mean of Enemies is " << meanOfEnemies << ", with a size " << enemies.size() << endl;
+ }
+ //-------------------------------------------------------
+
+
this->setFormationMode(ATTACK);
this->commandSlaves();
@@ -115,6 +151,7 @@
else {
// make 180 degree turn - a specific Master Action
+ /*
random = rnd(1000.0f);
if (random < 5)
this->turn180Init();
@@ -124,6 +161,7 @@
if (random < 5)
this->spinInit();
+ */
/*// follow a randomly chosen human - a specific Master Action
random = rnd(1000.0f);
if (random < 1)
@@ -145,7 +183,8 @@
}
}
-
+ allies.clear();
+ enemies.clear();
}
void AIController::tick(float dt)
Modified: code/branches/AI_HS15/src/orxonox/controllers/AIController.h
===================================================================
--- code/branches/AI_HS15/src/orxonox/controllers/AIController.h 2015-10-18 12:35:35 UTC (rev 10653)
+++ code/branches/AI_HS15/src/orxonox/controllers/AIController.h 2015-10-18 18:53:37 UTC (rev 10654)
@@ -53,6 +53,7 @@
static const float ACTION_INTERVAL;
Timer actionTimer_; //<! Regularly calls action().
+ std::vector<AIController*> enemies, allies;
};
}
More information about the Orxonox-commit
mailing list