Changeset 8769 for code/branches/ai2/src
- Timestamp:
- Jul 21, 2011, 5:36:37 PM (13 years ago)
- Location:
- code/branches/ai2/src/orxonox/controllers
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/ai2/src/orxonox/controllers/AIController.cc
r8766 r8769 212 212 float random; 213 213 float maxrand = 100.0f / ACTION_INTERVAL; 214 if (this->waypoints_.size() > 0 && this->getControllableEntity() && this->mode_ == DEFAULT) //Waypoint functionality. 215 { 216 if (this->waypoints_[this->currentWaypoint_]->getWorldPosition().squaredDistance(this->getControllableEntity()->getPosition()) <= this->squaredaccuracy_) 217 this->currentWaypoint_ = (this->currentWaypoint_ + 1) % this->waypoints_.size(); 218 219 this->moveToPosition(this->waypoints_[this->currentWaypoint_]->getWorldPosition()); 220 } 214 221 if(this->mode_ == DEFAULT) 215 222 { -
code/branches/ai2/src/orxonox/controllers/ArtificialController.cc
r8764 r8769 49 49 #include "weaponsystem/Weapon.h" 50 50 #include "weaponsystem/WeaponSlot.h" 51 #include "weaponsystem/WeaponSlot.h" 51 52 52 53 namespace orxonox … … 93 94 this->botlevel_ = 0.5f; 94 95 this->mode_ = DEFAULT;////Vector-implementation: mode_.push_back(DEFAULT); 95 this->timeout_=0; 96 this->timeout_ = 0; 97 this->currentWaypoint_ = 0; 98 this->setAccuracy(100); 96 99 } 97 100 … … 100 103 if (this->isInitialized()) 101 104 {//Vector-implementation: mode_.erase(mode_.begin(),mode_.end()); 105 for (size_t i = 0; i < this->waypoints_.size(); ++i) 106 this->waypoints_[i]->destroy(); 102 107 this->removeFromFormation(); 103 108 this->weaponModes_.clear(); … … 1140 1145 } 1141 1146 1147 void ArtificialController::addWaypoint(WorldEntity* waypoint) 1148 { 1149 this->waypoints_.push_back(waypoint); 1150 } 1151 1152 WorldEntity* ArtificialController::getWaypoint(unsigned int index) const 1153 { 1154 if (index < this->waypoints_.size()) 1155 return this->waypoints_[index]; 1156 else 1157 return 0; 1158 } 1159 1160 void ArtificialController::updatePointsOfInterest(std::string name, float distance) 1161 { 1162 WorldEntity* waypoint = NULL; 1163 if(name == "Pickup") 1164 { 1165 for (ObjectList<WorldEntity>::iterator it = ObjectList<WorldEntity>::begin(); it != ObjectList<WorldEntity>::end(); ++it) 1166 { 1167 //get POI by string: Possible POIs are PICKUPSPAWNER, FORCEFIELDS (!analyse!), ... 1168 //if(it->isA(Pickupable)) //distance to POI decides wether it is added (neither too close nor too far away) 1169 //To Think: how should POI's be managed? (e.g. if there are no real moving target or if the can be taken "en passant".) 1170 waypoint = *it; 1171 /*const Vector3 realDistance = it->getPosition() - this->getControllableEntity()->getPosition(); 1172 if( realDistance.length() < distance) 1173 { 1174 float minDistance = it->getTriggerDistance().length()*it->getTriggerDistance().length(); 1175 if(this->squaredaccuracy_ > minDistance) 1176 this->squaredaccuracy_ = minDistance; 1177 //waypoint = static_cast<WorldEntity*>(it); 1178 break; 1179 // }*/ 1180 } 1181 } 1182 if(waypoint) 1183 this->waypoints_.push_back(waypoint); 1184 } 1185 1142 1186 } -
code/branches/ai2/src/orxonox/controllers/ArtificialController.h
r8763 r8769 84 84 { return this->botlevel_; } 85 85 static void setAllBotLevel(float level); 86 //WAYPOINT FUNCTIONS 87 void addWaypoint(WorldEntity* waypoint); 88 WorldEntity* getWaypoint(unsigned int index) const; 89 90 inline void setAccuracy(float accuracy) 91 { this->squaredaccuracy_ = accuracy*accuracy; } 92 inline float getAccuracy() const 93 { return sqrt(this->squaredaccuracy_); } 94 void updatePointsOfInterest(std::string name, float distance); 86 95 87 96 protected: … … 149 158 bool bShooting_; 150 159 151 std::map<std::string, int> weaponModes_; //<! Links each "weapon" to it's weaponmode- managed by setupWeapons()152 //std::vector<int> projectiles_; //<! Displays amount of projectiles of each weapon. - managed by setupWeapons()153 160 float botlevel_; //<! Makes the level of a bot configurable. 154 float timeout_; //<! Timeout for rocket usage. (If a rocket misses, a bot should stop using it.)155 156 161 enum Mode {DEFAULT, ROCKET, DEFENCE, MOVING};//TODO; implement DEFENCE, MOVING modes 157 162 Mode mode_; //TODO: replace single value with stack-like implementation: std::vector<Mode> mode_; 158 163 void setPreviousMode(); 164 165 //WEAPONSYSTEM DATA 166 std::map<std::string, int> weaponModes_; //<! Links each "weapon" to it's weaponmode- managed by setupWeapons() 167 //std::vector<int> projectiles_; //<! Displays amount of projectiles of each weapon. - managed by setupWeapons() 168 float timeout_; //<! Timeout for rocket usage. (If a rocket misses, a bot should stop using it.) 159 169 void setupWeapons(); //<! Defines which weapons are available for a bot. Is recalled whenever a bot was killed. 160 170 bool bSetupWorked; //<! If false, setupWeapons() is called. 161 171 int getFiremode(std::string name); 172 173 //WAYPOINT DATA 174 std::vector<WorldEntity*> waypoints_; 175 size_t currentWaypoint_; 176 float squaredaccuracy_; 162 177 }; 163 178 } -
code/branches/ai2/src/orxonox/controllers/WaypointController.cc
r5929 r8769 40 40 { 41 41 RegisterObject(WaypointController); 42 43 this->currentWaypoint_ = 0;44 this->setAccuracy(100);45 42 } 46 43 47 44 WaypointController::~WaypointController() 48 45 { 49 if (this->isInitialized())50 {51 for (size_t i = 0; i < this->waypoints_.size(); ++i)52 this->waypoints_[i]->destroy();53 }54 46 } 55 47 … … 58 50 SUPER(WaypointController, XMLPort, xmlelement, mode); 59 51 60 XMLPortParam( WaypointController, "accuracy", setAccuracy, getAccuracy, xmlelement, mode).defaultValues(100.0f);61 XMLPortObject( WaypointController, WorldEntity, "waypoints", addWaypoint, getWaypoint, xmlelement, mode);52 XMLPortParam(ArtificialController, "accuracy", setAccuracy, getAccuracy, xmlelement, mode).defaultValues(100.0f); 53 XMLPortObject(ArtificialController, WorldEntity, "waypoints", addWaypoint, getWaypoint, xmlelement, mode); 62 54 } 63 55 … … 76 68 } 77 69 78 void WaypointController::addWaypoint(WorldEntity* waypoint)79 {80 this->waypoints_.push_back(waypoint);81 }82 83 WorldEntity* WaypointController::getWaypoint(unsigned int index) const84 {85 if (index < this->waypoints_.size())86 return this->waypoints_[index];87 else88 return 0;89 }90 70 } -
code/branches/ai2/src/orxonox/controllers/WaypointController.h
r5781 r8769 47 47 virtual void tick(float dt); 48 48 49 void addWaypoint(WorldEntity* waypoint); 50 WorldEntity* getWaypoint(unsigned int index) const; 49 protected: 51 50 52 inline void setAccuracy(float accuracy)53 { this->squaredaccuracy_ = accuracy*accuracy; }54 inline float getAccuracy() const55 { return sqrt(this->squaredaccuracy_); }56 57 protected:58 std::vector<WorldEntity*> waypoints_;59 size_t currentWaypoint_;60 float squaredaccuracy_;61 51 }; 62 52 }
Note: See TracChangeset
for help on using the changeset viewer.