[Orxonox-commit 4115] r8786 - in code/branches/ai2: data/levels src/orxonox/controllers
jo at orxonox.net
jo at orxonox.net
Mon Jul 25 23:18:20 CEST 2011
Author: jo
Date: 2011-07-25 23:18:20 +0200 (Mon, 25 Jul 2011)
New Revision: 8786
Modified:
code/branches/ai2/data/levels/missionOne.oxw
code/branches/ai2/src/orxonox/controllers/AIController.cc
code/branches/ai2/src/orxonox/controllers/ArtificialController.cc
code/branches/ai2/src/orxonox/controllers/ArtificialController.h
code/branches/ai2/src/orxonox/controllers/WaypointController.cc
Log:
Bots can fetch pickups. Waypointmanagement is unstable yet.
Modified: code/branches/ai2/data/levels/missionOne.oxw
===================================================================
--- code/branches/ai2/data/levels/missionOne.oxw 2011-07-25 21:07:51 UTC (rev 8785)
+++ code/branches/ai2/data/levels/missionOne.oxw 2011-07-25 21:18:20 UTC (rev 8786)
@@ -55,7 +55,7 @@
<BoxCollisionShape position="0,0,0" halfExtents="15,15,15" />
</collisionShapes>
</Pawn>
- <Pawn health=30 position="20,0,0" direction="0,-1,0" collisionType=dynamic mass=100000>
+ <Pawn health=30 position="70,0,0" direction="0,-1,0" collisionType=dynamic mass=100000>
<attached>
<Model position="0,0,0" mesh="crate.mesh" scale3D="3,3,3" />
</attached>
@@ -63,7 +63,7 @@
<BoxCollisionShape position="0,0,0" halfExtents="15,15,15" />
</collisionShapes>
</Pawn>
- <Pawn health=30 position="40,0,0" direction="0,-1,0" collisionType=dynamic mass=100000>
+ <Pawn health=30 position="140,0,0" direction="0,-1,0" collisionType=dynamic mass=100000>
<attached>
<Model position="0,0,0" mesh="crate.mesh" scale3D="5,5,5" />
</attached>
@@ -71,7 +71,7 @@
<BoxCollisionShape position="0,0,0" halfExtents="25,25,25" />
</collisionShapes>
</Pawn>
- <Pawn health=30 position="60,0,0" direction="0,-1,0" collisionType=dynamic mass=100000>
+ <Pawn health=30 position="210,0,0" direction="0,-1,0" collisionType=dynamic mass=100000>
<attached>
<Model position="0,0,0" mesh="crate.mesh" scale3D="5,5,5" />
</attached>
Modified: code/branches/ai2/src/orxonox/controllers/AIController.cc
===================================================================
--- code/branches/ai2/src/orxonox/controllers/AIController.cc 2011-07-25 21:07:51 UTC (rev 8785)
+++ code/branches/ai2/src/orxonox/controllers/AIController.cc 2011-07-25 21:18:20 UTC (rev 8786)
@@ -113,6 +113,18 @@
if (random < ((1 - botlevel_)*25) && (this->bShooting_))
this->bShooting_ = false;
+ // boost
+ random = rnd(maxrand);
+ if (random < botlevel_*100 )
+ this->boostControl();
+
+ // update Checkpoints
+ random = rnd(maxrand);
+ if (this->defaultWaypoint_ && random > (maxrand-10))
+ this->manageWaypoints();
+ else //if(random > maxrand-10) //CHECK USABILITY!!
+ this->manageWaypoints();
+
}
if (this->state_ == SLAVE)
@@ -195,10 +207,17 @@
if (random < ( (1- botlevel_)*25 ) && (this->bShooting_))
this->bShooting_ = false;
- //boost
+ // boost
random = rnd(maxrand);
if (random < botlevel_*100 )
- this->boostControl(); //TEST
+ this->boostControl();
+
+ // update Checkpoints
+ random = rnd(maxrand);
+ if (this->defaultWaypoint_ && random > (maxrand-10))
+ this->manageWaypoints();
+ else //if(random > maxrand-10) //CHECK USABILITY!!
+ this->manageWaypoints();
}
}
@@ -211,12 +230,22 @@
float random;
float maxrand = 100.0f / ACTION_INTERVAL;
- if (this->waypoints_.size() > 0 && this->getControllableEntity() && this->mode_ == DEFAULT) //Waypoint functionality.
+ ControllableEntity* controllable = this->getControllableEntity();
+
+ if (controllable && this->mode_ == DEFAULT)// bot is ready to move to a target
{
- if (this->waypoints_[this->currentWaypoint_]->getWorldPosition().squaredDistance(this->getControllableEntity()->getPosition()) <= this->squaredaccuracy_)
- this->currentWaypoint_ = (this->currentWaypoint_ + 1) % this->waypoints_.size();
-
- this->moveToPosition(this->waypoints_[this->currentWaypoint_]->getWorldPosition());
+ if (this->waypoints_.size() > 0 ) //Waypoint functionality.
+ {
+ if (this->waypoints_[this->waypoints_.size()-1]->getWorldPosition().squaredDistance(controllable->getPosition()) <= this->squaredaccuracy_)
+ this->waypoints_.pop_back(); // if goal is reached, remove it from the list
+ if(this->waypoints_.size() > 0 )
+ this->moveToPosition(this->waypoints_[this->waypoints_.size()-1]->getWorldPosition());
+ }
+ else if(this->defaultWaypoint_ && ((this->defaultWaypoint_->getPosition()-controllable->getPosition()).length() > 200.0f))
+ {
+ this->moveToPosition(this->defaultWaypoint_->getPosition()); // stay within a certain range of the defaultWaypoint_
+ random = rnd(maxrand);
+ }
}
if(this->mode_ == DEFAULT)
{
@@ -282,7 +311,6 @@
}//END_OF DEFAULT MODE
else if (this->mode_ == ROCKET)//Rockets do not belong to a group of bots -> bot states are not relevant.
{ //Vector-implementation: mode_.back() == ROCKET;
- ControllableEntity *controllable = this->getControllableEntity();
if(controllable)
{
if(controllable->getRocket())//Check wether the bot is controlling the rocket and if the timeout is over.
Modified: code/branches/ai2/src/orxonox/controllers/ArtificialController.cc
===================================================================
--- code/branches/ai2/src/orxonox/controllers/ArtificialController.cc 2011-07-25 21:07:51 UTC (rev 8785)
+++ code/branches/ai2/src/orxonox/controllers/ArtificialController.cc 2011-07-25 21:18:20 UTC (rev 8786)
@@ -95,7 +95,8 @@
this->mode_ = DEFAULT;////Vector-implementation: mode_.push_back(DEFAULT);
this->timeout_ = 0;
this->currentWaypoint_ = 0;
- this->setAccuracy(100);
+ this->setAccuracy(9);
+ this->defaultWaypoint_ = NULL;
}
ArtificialController::~ArtificialController()
@@ -1124,6 +1125,9 @@
this->mode_ = DEFAULT; //Vector-implementation: mode_.pop_back();
}
+ /**
+ @brief Manages boost. Switches between boost usage and boost safe mode.
+ */
void ArtificialController::boostControl()
{
SpaceShip* ship = orxonox_cast<SpaceShip*>(this->getControllableEntity());
@@ -1157,49 +1161,43 @@
return 0;
}
- void ArtificialController::updatePointsOfInterest(std::string name, float distance)
+ /**
+ @brief Adds first waypoint of type name to the waypoint stack, which is within the searchDistance
+ @param name object-name of a point of interest (e.g. "PickupSpawner", "ForceField")
+ */
+ void ArtificialController::updatePointsOfInterest(std::string name, float searchDistance)
{
WorldEntity* waypoint = NULL;
- if(name == "Pickup")
+ for (ObjectList<WorldEntity>::iterator it = ObjectList<WorldEntity>::begin(); it != ObjectList<WorldEntity>::end(); ++it)
{
- for (ObjectList<WorldEntity>::iterator it = ObjectList<WorldEntity>::begin(); it != ObjectList<WorldEntity>::end(); ++it)
+ if((*it)->getIdentifier() == ClassByString(name))
{
- //get POI by string: Possible POIs are PICKUPSPAWNER, FORCEFIELDS (!analyse!), ...
- //distance to POI decides wether it is added (neither too close nor too far away)
- //How should POI's be managed? (e.g. Look for POIs if there are no real targets to move to or if they can be taken "en passant".)
- waypoint = *it;
- if(waypoint->getIdentifier() == ClassByString(name))
- {
- ControllableEntity* controllable = this->getControllableEntity();
- if(!controllable) continue;
- float distance = ( waypoint->getPosition() - controllable->getPosition() ).length();
- if(distance > 50.0f || distance < 5.0f) continue;
- if(name == "PickupSpawner") // PickupSpawner: adjust waypoint accuracy to PickupSpawner's triggerdistance
- {
- squaredaccuracy_ = waypoint->getTriggerDistance() * waypoint->getTriggerDistance();
- }
- else if(name == "ForceField") // ForceField: analyze is angle between forcefield boost and own flying direction is acceptable
- {
-
- }
-
-
- break;
- }
-
- /*const Vector3 realDistance = it->getPosition() - this->getControllableEntity()->getPosition();
- if( realDistance.length() < distance)
+ ControllableEntity* controllable = this->getControllableEntity();
+ if(!controllable) continue;
+ float actualDistance = ( (*it)->getPosition() - controllable->getPosition() ).length();
+ if(actualDistance > searchDistance || actualDistance < 5.0f) continue;
+ // TODO: PickupSpawner: adjust waypoint accuracy to PickupSpawner's triggerdistance
+ // TODO: ForceField: analyze is angle between forcefield boost and own flying direction is acceptable
+ else
{
- float minDistance = it->getTriggerDistance().length()*it->getTriggerDistance().length();
- if(this->squaredaccuracy_ > minDistance)
- this->squaredaccuracy_ = minDistance;
- //waypoint = static_cast<WorldEntity*>(it);
+ waypoint = *it;
break;
- // }*/
+ }
}
}
if(waypoint)
this->waypoints_.push_back(waypoint);
}
+ /**
+ @brief Adds point of interest depending on context
+ */
+ void ArtificialController::manageWaypoints()
+ {
+ if(!defaultWaypoint_)
+ this->updatePointsOfInterest("PickupSpawner", 60.0f); // long search radius if there is no default goal
+ else
+ this->updatePointsOfInterest("PickupSpawner", 20.0f); // take pickup en passant if there is a default waypoint
+ }
+
}
Modified: code/branches/ai2/src/orxonox/controllers/ArtificialController.h
===================================================================
--- code/branches/ai2/src/orxonox/controllers/ArtificialController.h 2011-07-25 21:07:51 UTC (rev 8785)
+++ code/branches/ai2/src/orxonox/controllers/ArtificialController.h 2011-07-25 21:18:20 UTC (rev 8786)
@@ -92,6 +92,7 @@
inline float getAccuracy() const
{ return sqrt(this->squaredaccuracy_); }
void updatePointsOfInterest(std::string name, float distance);
+ void manageWaypoints();
protected:
@@ -174,6 +175,7 @@
std::vector<WorldEntity*> waypoints_;
size_t currentWaypoint_;
float squaredaccuracy_;
+ WorldEntity* defaultWaypoint_;
};
}
Modified: code/branches/ai2/src/orxonox/controllers/WaypointController.cc
===================================================================
--- code/branches/ai2/src/orxonox/controllers/WaypointController.cc 2011-07-25 21:07:51 UTC (rev 8785)
+++ code/branches/ai2/src/orxonox/controllers/WaypointController.cc 2011-07-25 21:18:20 UTC (rev 8786)
@@ -39,6 +39,7 @@
WaypointController::WaypointController(BaseObject* creator) : ArtificialController(creator)
{
RegisterObject(WaypointController);
+ this->setAccuracy(100);
}
WaypointController::~WaypointController()
More information about the Orxonox-commit
mailing list