Changeset 8990 for code/branches/formation/src
- Timestamp:
- Dec 16, 2011, 4:25:28 PM (13 years ago)
- Location:
- code/branches/formation/src/orxonox/controllers
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/formation/src/orxonox/controllers/AIController.cc
r8978 r8990 65 65 if (this->freedomCount_ == 1) 66 66 { 67 this->state_ = SLAVE;68 this->freedomCount_ = 0;67 this->state_ = SLAVE; 68 this->freedomCount_ = 0; 69 69 } 70 70 … … 74 74 } 75 75 76 this->defaultBehaviour(maxrand); 77 78 } 79 80 if (this->state_ == SLAVE && this->mode_ == ATTACK) //TODO: add botlevel parameter 81 { 76 82 // search enemy 77 83 random = rnd(maxrand); 78 if (random < 15 && (!this->target_))84 if (random < 75 && (!this->target_)) 79 85 this->searchNewTarget(); 80 81 // forget enemy82 random = rnd(maxrand);83 if (random < 5 && (this->target_))84 this->forgetTarget();85 86 86 87 // next enemy … … 89 90 this->searchNewTarget(); 90 91 91 // fly somewhere92 random = rnd(maxrand);93 if (random < 50 && (!this->bHasTargetPosition_ && !this->target_))94 this->searchRandomTargetPosition();95 96 // stop flying97 random = rnd(maxrand);98 if (random < 10 && (this->bHasTargetPosition_ && !this->target_))99 this->bHasTargetPosition_ = false;100 101 // fly somewhere else102 random = rnd(maxrand);103 if (random < 30 && (this->bHasTargetPosition_ && !this->target_))104 this->searchRandomTargetPosition();105 106 92 // shoot 107 93 random = rnd(maxrand); … … 116 102 } 117 103 118 if (this->state_ == SLAVE && this->mode_==ATTACK)119 {120 // search enemy121 random = rnd(maxrand);122 if (random < 75 && (!this->target_))123 this->searchNewTarget();124 125 // next enemy126 random = rnd(maxrand);127 if (random < 10 && (this->target_))128 this->searchNewTarget();129 130 // shoot131 random = rnd(maxrand);132 if (!(this->passive_) && random < 75 && (this->target_ && !this->bShooting_))133 this->bShooting_ = true;134 135 // stop shooting136 random = rnd(maxrand);137 if (random < 25 && (this->bShooting_))138 this->bShooting_ = false;139 140 }141 142 104 if (this->state_ == MASTER) 143 105 { 144 145 146 106 this->commandSlaves(); 147 107 … … 176 136 this->searchNewMaster(); 177 137 178 // search enemy 179 random = rnd(maxrand); 180 if (random < 15 && (!this->target_)) 181 this->searchNewTarget(); 182 183 // forget enemy 184 random = rnd(maxrand); 185 if (random < 5 && (this->target_)) 186 this->forgetTarget(); 187 188 // next enemy 189 random = rnd(maxrand); 190 if (random < 10 && (this->target_)) 191 this->searchNewTarget(); 192 193 // fly somewhere 194 random = rnd(maxrand); 195 if (random < 50 && (!this->bHasTargetPosition_ && !this->target_)) 196 this->searchRandomTargetPosition(); 197 198 199 // fly somewhere else 200 random = rnd(maxrand); 201 if (random < 30 && (this->bHasTargetPosition_ && !this->target_)) 202 this->searchRandomTargetPosition(); 203 204 // shoot 205 random = rnd(maxrand); 206 if (!(this->passive_) && random < 9 && (this->target_ && !this->bShooting_)) 207 { 208 this->bShooting_ = true; 209 this->forceFreeSlaves(); 210 } 211 212 // stop shooting 213 random = rnd(maxrand); 214 if (random < 25 && (this->bShooting_)) 215 this->bShooting_ = false; 138 this->defaultBehaviour(maxrand); 216 139 217 140 } … … 225 148 return; 226 149 227 if (this->state_ == MASTER) 228 { 229 if (this->specificMasterAction_ == NONE) 150 float random; 151 float maxrand = 100.0f / ACTION_INTERVAL; 152 ControllableEntity* controllable = this->getControllableEntity(); 153 154 if (controllable && this->mode_ == NORMAL)// bot is ready to move to a target // mode was DEFAULT in original implementation! 155 { 156 if (this->waypoints_.size() > 0 ) //Waypoint functionality. 157 { 158 WorldEntity* wPoint = this->waypoints_[this->waypoints_.size()-1]; 159 if(wPoint) 160 { 161 this->moveToPosition(wPoint->getWorldPosition()); //BUG ?? sometime wPoint->getWorldPosition() causes crash 162 if (wPoint->getWorldPosition().squaredDistance(controllable->getPosition()) <= this->squaredaccuracy_) 163 this->waypoints_.pop_back(); // if goal is reached, remove it from the list 164 } 165 else 166 this->waypoints_.pop_back(); // remove invalid waypoints 167 168 } 169 else if(this->defaultWaypoint_ && ((this->defaultWaypoint_->getPosition()-controllable->getPosition()).length() > 200.0f)) 170 { 171 this->moveToPosition(this->defaultWaypoint_->getPosition()); // stay within a certain range of the defaultWaypoint_ 172 random = rnd(maxrand); 173 } 174 } 175 176 if (this->mode_ != ROCKET) 177 { 178 if (this->state_ == MASTER) 179 { 180 if (this->specificMasterAction_ == NONE) 181 { 182 if (this->target_) 183 { 184 if (!this->target_->getRadarVisibility()) /* So AI won't shoot invisible Spaceships */ 185 this->forgetTarget(); 186 else 187 { 188 this->aimAtTarget(); 189 random = rnd(maxrand); 190 if(this->botlevel_*70 > random && !this->isCloseAtTarget(100)) 191 this->follow(); //If a bot is shooting a player, it shouldn't let him go away easily. 192 } 193 } 194 195 if (this->bHasTargetPosition_) 196 this->moveToTargetPosition(); 197 this->doFire(); 198 } 199 200 if (this->specificMasterAction_ == TURN180) 201 this->turn180(); 202 203 if (this->specificMasterAction_ == SPIN) 204 this->spin(); 205 if (this->specificMasterAction_ == FOLLOW) 206 this->follow(); 207 } 208 209 if (this->state_ == SLAVE && this->mode_!=ATTACK) 210 { 211 if (this->bHasTargetPosition_) 212 this->moveToTargetPosition(); 213 } 214 215 if (this->state_ == FREE || (this->state_==SLAVE && this->mode_==ATTACK) ) 230 216 { 231 217 if (this->target_) … … 239 225 this->moveToTargetPosition(); 240 226 241 if (this->getControllableEntity() && this->bShooting_ && this->isCloseAtTarget(1000) && this->isLookingAtTarget(math::pi / 20.0f))242 this->getControllableEntity()->fire(0);243 244 245 if (this->specificMasterAction_ == TURN180)246 this->turn180();247 248 if (this->specificMasterAction_ == SPIN)249 this->spin(); 250 if (this->specificMasterAction_ == FOLLOW)227 this->doFire(); 228 } 229 } 230 else if (this->mode_ == ROCKET)//Rockets do not belong to a group of bots -> bot states are not relevant. 231 { //Vector-implementation: mode_.back() == ROCKET; 232 if(controllable) 233 {//Check wether the bot is controlling the rocket and if the timeout is over. 234 if(controllable->getIdentifier() == ClassByString("Rocket")) 235 236 { 251 237 this->follow(); 252 } 253 254 if (this->state_ == SLAVE && this->mode_!=ATTACK) 255 { 256 257 if (this->bHasTargetPosition_) 258 this->moveToTargetPosition(); 259 260 } 261 262 if (this->state_ == FREE || (this->state_==SLAVE && this->mode_==ATTACK) ) 263 { 264 if (this->target_) 265 { 266 if (!this->target_->getRadarVisibility()) /* So AI won't shoot invisible Spaceships */ 267 this->forgetTarget(); 268 else this->aimAtTarget(); 269 } 270 271 if (this->bHasTargetPosition_) 272 this->moveToTargetPosition(); 273 274 if (this->getControllableEntity() && this->bShooting_ && this->isCloseAtTarget(1000) && this->isLookingAtTarget(math::pi / 20.0f)) 275 this->getControllableEntity()->fire(0); 276 } 238 this->timeout_ -= dt; 239 if((timeout_< 0)||(!target_))//Check if the timeout is over or target died. 240 { 241 controllable->fire(0);//kill the rocket 242 this->setPreviousMode();//get out of rocket mode 243 } 244 } 245 else 246 this->setPreviousMode();//no rocket entity -> get out of rocket mode 247 } 248 else 249 this->setPreviousMode();//If bot dies -> getControllableEntity == NULL -> get out of ROCKET mode 250 }//END_OF ROCKET MODE 277 251 278 252 SUPER(AIController, tick, dt); 279 253 } 254 //**********************************************NEW 255 void AIController::defaultBehaviour(float maxrand) 256 { float random; 257 // search enemy 258 random = rnd(maxrand); 259 if (random < (botlevel_* 100) && (!this->target_)) 260 this->searchNewTarget(); 261 262 // forget enemy 263 random = rnd(maxrand); 264 if (random < ((1-botlevel_)*20) && (this->target_)) 265 this->forgetTarget(); 266 267 // next enemy 268 random = rnd(maxrand); 269 if (random < (botlevel_*30) && (this->target_)) 270 this->searchNewTarget(); 271 272 // fly somewhere 273 random = rnd(maxrand); 274 if (random < 50 && (!this->bHasTargetPosition_ && !this->target_)) 275 this->searchRandomTargetPosition(); 276 277 // stop flying 278 random = rnd(maxrand); 279 if (random < 10 && (this->bHasTargetPosition_ && !this->target_)) 280 this->bHasTargetPosition_ = false; 281 282 // fly somewhere else 283 random = rnd(maxrand); 284 if (random < 30 && (this->bHasTargetPosition_ && !this->target_)) 285 this->searchRandomTargetPosition(); 286 287 if (this->state_ == MASTER) // master: shoot 288 { 289 random = rnd(maxrand); 290 if (!(this->passive_) && random < (100*botlevel_) && (this->target_ && !this->bShooting_)) 291 { 292 this->bShooting_ = true; 293 this->forceFreeSlaves(); 294 } 295 } 296 else 297 { 298 // shoot 299 random = rnd(maxrand); 300 if (!(this->passive_) && random < (botlevel_*100) && (this->target_ && !this->bShooting_)) 301 this->bShooting_ = true; 302 } 303 304 // stop shooting 305 random = rnd(maxrand); 306 if (random < ((1 - botlevel_)*50) && (this->bShooting_)) 307 this->bShooting_ = false; 308 309 // boost 310 random = rnd(maxrand); 311 if (random < botlevel_*50 ) 312 this->boostControl(); 313 314 // update Checkpoints 315 /*random = rnd(maxrand); 316 if (this->defaultWaypoint_ && random > (maxrand-10)) 317 this->manageWaypoints(); 318 else //if(random > maxrand-10) //CHECK USABILITY!!*/ 319 if (this->waypoints_.size() == 0 ) 320 this->manageWaypoints(); 321 } 280 322 281 323 } -
code/branches/formation/src/orxonox/controllers/AIController.h
r8729 r8990 44 44 virtual ~AIController(); 45 45 46 virtual void tick(float dt); 46 virtual void tick(float dt); //<! Carrying out the targets set in action(). 47 47 48 48 protected: 49 virtual void action(); 49 virtual void action(); //<! action() is called in regular intervals managing the bot's behaviour ~ setting targets. 50 void defaultBehaviour(float maxrand); //<! Helper function for code reusage. Some concrete commands for a bot. 50 51 51 52 private: 52 53 static const float ACTION_INTERVAL; 53 54 54 Timer actionTimer_; 55 Timer actionTimer_; //<! Regularly calls action(). 55 56 }; 56 57 } -
code/branches/formation/src/orxonox/controllers/ArtificialController.cc
r8989 r8990 30 30 #include "core/CoreIncludes.h" 31 31 #include "worldentities/pawns/Pawn.h" 32 #include "worldentities/pawns/SpaceShip.h" 33 34 #include "weaponsystem/WeaponMode.h" 35 #include "weaponsystem/WeaponPack.h" 36 #include "weaponsystem/Weapon.h" 37 #include "weaponsystem/WeaponSlot.h" 38 #include "weaponsystem/WeaponSlot.h" 32 39 33 40 … … 37 44 ArtificialController::ArtificialController(BaseObject* creator) : FormationController(creator) 38 45 { 39 46 this->bSetupWorked = false; 47 this->botlevel_ = 0.5f; 48 this->timeout_ = 0; 49 this->currentWaypoint_ = 0; 50 this->setAccuracy(5); 51 this->defaultWaypoint_ = NULL; 40 52 } 41 53 42 54 ArtificialController::~ArtificialController() 43 55 { 44 56 if (this->isInitialized()) 57 {//Vector-implementation: mode_.erase(mode_.begin(),mode_.end()); 58 this->waypoints_.clear(); 59 this->weaponModes_.clear(); 60 } 45 61 } 46 62 … … 181 197 void ArtificialController::setPreviousMode() 182 198 { 183 this->mode_ = DEFAULT; //Vector-implementation: mode_.pop_back();199 this->mode_ = NORMAL; //Vector-implementation: mode_.pop_back(); 184 200 } 185 201 … … 249 265 250 266 /** 251 @brief Adds point of interest depending on context. Further Possibilites: "ForceField", "PortalEndPoint", "MovableEntity", "Dock"267 @brief Adds point of interest depending on context. TODO: Further Possibilites: "ForceField", "PortalEndPoint", "MovableEntity", "Dock" 252 268 */ 253 269 void ArtificialController::manageWaypoints() -
code/branches/formation/src/orxonox/controllers/FormationController.cc
r8989 r8990 40 40 #include "gametypes/TeamDeathmatch.h" 41 41 #include "gametypes/Dynamicmatch.h" 42 //#include "gametypes/Mission.h" TODO: include mission after merging 42 43 #include "gametypes/Gametype.h" 43 44 #include "controllers/WaypointPatrolController.h" … … 961 962 } 962 963 963 Mission* miss = orxonox_cast<Mission*>(gametype); //NEW964 /*Mission* miss = orxonox_cast<Mission*>(gametype); //NEW 964 965 if (miss) 965 966 { … … 969 970 if (entity2->getPlayer()) 970 971 team2 = miss->getTeam(entity2->getPlayer()); 971 } 972 }*/ 972 973 973 974 TeamBaseMatchBase* base = 0; -
code/branches/formation/src/orxonox/controllers/FormationController.h
r8978 r8990 88 88 Attack-leave formation, attack every target 89 89 */ 90 enum Mode {NORMAL,DEFEND,ATTACK };90 enum Mode {NORMAL,DEFEND,ATTACK,ROCKET}; 91 91 92 92 /** -
code/branches/formation/src/orxonox/controllers/HumanController.cc
r8978 r8990 318 318 { 319 319 switch (HumanController::localController_s->getMode()) { 320 case NORMAL: 321 HumanController::localController_s->setMode(DEFEND); 322 orxout(message) <<"Mode: DEFEND "<< endl; 323 break; 324 case DEFEND: 325 HumanController::localController_s->setMode(ATTACK); 326 orxout(message) <<"Mode: ATTACK "<< endl; 327 break; 328 case ATTACK: 329 HumanController::localController_s->setMode(NORMAL); 330 orxout(message) <<"Mode: NORMAL "<< endl; 331 break; 320 case NORMAL: 321 HumanController::localController_s->setMode(DEFEND); 322 orxout(message) <<"Mode: DEFEND "<< endl; 323 break; 324 case DEFEND: 325 HumanController::localController_s->setMode(ATTACK); 326 orxout(message) <<"Mode: ATTACK "<< endl; 327 break; 328 case ATTACK: 329 HumanController::localController_s->setMode(NORMAL); 330 orxout(message) <<"Mode: NORMAL "<< endl; 331 break; 332 default: //catch all non-formation related states 333 break; 332 334 } 333 335 } -
code/branches/formation/src/orxonox/controllers/NewHumanController.cc
r8965 r8990 277 277 } 278 278 279 void NewHumanController::doFire(unsigned int firemode) 279 void NewHumanController::doFire(unsigned int firemode)//TODO?? 280 280 { 281 281 if (!this->controllableEntity_)
Note: See TracChangeset
for help on using the changeset viewer.