Changeset 9016 for code/trunk/src/orxonox/controllers/AIController.cc
- Timestamp:
- Feb 15, 2012, 11:51:58 PM (12 years ago)
- Location:
- code/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk
- Property svn:mergeinfo changed
-
code/trunk/src/orxonox/controllers/AIController.cc
r8891 r9016 59 59 if (this->state_ == FREE) 60 60 { 61 61 62 62 if (this->formationFlight_) 63 63 { 64 65 //changed order -> searchNewMaster MUSTN'T be called in SLAVE-state (bugfix for internal-error messages at quit) 66 random = rnd(maxrand); 67 if (random < 90 && (((!this->target_) || (random < 50 && this->target_)) && !this->forcedFree())) 68 this->searchNewMaster(); 69 64 70 // return to Master after being forced free 65 71 if (this->freedomCount_ == 1) … … 68 74 this->freedomCount_ = 0; 69 75 } 70 71 random = rnd(maxrand); 72 if (random < 90 && (((!this->target_) || (random < 50 && this->target_)) && !this->forcedFree())) 73 this->searchNewMaster(); 74 } 75 76 } 77 78 this->defaultBehaviour(maxrand); 79 80 } 81 82 if (this->state_ == SLAVE && this->formationMode_ == ATTACK) 83 { 76 84 // search enemy 77 85 random = rnd(maxrand); 78 if (random < ( 15 + botlevel_* 20) && (!this->target_))86 if (random < (botlevel_*100) && (!this->target_)) 79 87 this->searchNewTarget(); 80 88 81 // forget enemy82 random = rnd(maxrand);83 if (random < ((1-botlevel_)*6) && (this->target_))84 this->forgetTarget();85 86 89 // next enemy 87 90 random = rnd(maxrand); 88 if (random < (botlevel_* 20) && (this->target_))91 if (random < (botlevel_*30) && (this->target_)) 89 92 this->searchNewTarget(); 90 93 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 94 // shoot 107 95 random = rnd(maxrand); 108 if (!(this->passive_) && random < ( 75 + botlevel_*25) && (this->target_ && !this->bShooting_))96 if (!(this->passive_) && random < (botlevel_*100) && (this->target_ && !this->bShooting_)) 109 97 this->bShooting_ = true; 110 98 111 99 // stop shooting 112 100 random = rnd(maxrand); 113 if (random < ( (1 - botlevel_)*25)&& (this->bShooting_))101 if (random < (1-botlevel_)*50 && (this->bShooting_)) 114 102 this->bShooting_ = false; 115 103 116 // boost117 random = rnd(maxrand);118 if (random < botlevel_*100 )119 this->boostControl();120 121 // update Checkpoints122 /*random = rnd(maxrand);123 if (this->defaultWaypoint_ && random > (maxrand-10))124 this->manageWaypoints();125 else //if(random > maxrand-10) //CHECK USABILITY!!*/126 if (this->waypoints_.size() == 0 )127 this->manageWaypoints();128 129 }130 131 if (this->state_ == SLAVE)132 {133 134 104 } 135 105 136 106 if (this->state_ == MASTER) 137 107 { 138 139 140 108 this->commandSlaves(); 141 109 … … 155 123 this->spinInit(); 156 124 157 / / follow a randomly chosen human - a specific Master Action125 /*// follow a randomly chosen human - a specific Master Action 158 126 random = rnd(1000.0f); 159 127 if (random < 1) 160 128 this->followRandomHumanInit(); 161 129 */ 162 130 // lose master status (only if less than 4 slaves in formation) 163 131 random = rnd(maxrand); … … 170 138 this->searchNewMaster(); 171 139 172 // search enemy 173 random = rnd(maxrand); 174 if (random < (botlevel_)*25 && (!this->target_)) 175 this->searchNewTarget(); 176 177 // forget enemy 178 random = rnd(maxrand); 179 if (random < (1-botlevel_)*6 && (this->target_)) 180 this->forgetTarget(); 181 182 // next enemy 183 random = rnd(maxrand); 184 if (random < 10 && (this->target_)) 185 this->searchNewTarget(); 186 187 // fly somewhere 188 random = rnd(maxrand); 189 if (random < 50 && (!this->bHasTargetPosition_ && !this->target_)) 190 this->searchRandomTargetPosition(); 191 192 193 // fly somewhere else 194 random = rnd(maxrand); 195 if (random < 30 && (this->bHasTargetPosition_ && !this->target_)) 196 this->searchRandomTargetPosition(); 197 198 // shoot 199 random = rnd(maxrand); 200 if (!(this->passive_) && random < 25*(botlevel_)+1 && (this->target_ && !this->bShooting_)) 201 { 202 this->bShooting_ = true; 203 this->forceFreeSlaves(); 204 } 205 206 // stop shooting 207 random = rnd(maxrand); 208 if (random < ( (1- botlevel_)*25 ) && (this->bShooting_)) 209 this->bShooting_ = false; 210 211 // boost 212 random = rnd(maxrand); 213 if (random < botlevel_*100 ) 214 this->boostControl(); 215 216 // update Checkpoints 217 /*random = rnd(maxrand); 218 if (this->defaultWaypoint_ && random > (maxrand-10)) 219 this->manageWaypoints(); 220 else //if(random > maxrand-10) //CHECK USABILITY!!*/ 221 if (this->waypoints_.size() == 0 ) 222 this->manageWaypoints(); 140 this->defaultBehaviour(maxrand); 141 223 142 } 224 143 } … … 234 153 float maxrand = 100.0f / ACTION_INTERVAL; 235 154 ControllableEntity* controllable = this->getControllableEntity(); 236 155 //DOES: Either move to the waypoint or search for a Point of interest 237 156 if (controllable && this->mode_ == DEFAULT)// bot is ready to move to a target 238 157 { … … 256 175 } 257 176 } 258 if(this->mode_ == DEFAULT) 259 { 177 178 if (this->mode_ == DEFAULT) 179 { 260 180 if (this->state_ == MASTER) 261 181 { … … 270 190 this->aimAtTarget(); 271 191 random = rnd(maxrand); 272 if(this->botlevel_* 100 > random && !this->isCloseAtTarget(20))192 if(this->botlevel_*70 > random && !this->isCloseAtTarget(100)) 273 193 this->follow(); //If a bot is shooting a player, it shouldn't let him go away easily. 274 194 } … … 277 197 if (this->bHasTargetPosition_) 278 198 this->moveToTargetPosition(); 279 280 199 this->doFire(); 281 200 } … … 290 209 } 291 210 292 if (this->state_ == SLAVE )211 if (this->state_ == SLAVE && this->formationMode_ != ATTACK) 293 212 { 294 213 if (this->bHasTargetPosition_) … … 296 215 } 297 216 298 if (this->state_ == FREE )217 if (this->state_ == FREE || (this->state_==SLAVE && this->formationMode_ == ATTACK) ) 299 218 { 300 219 if (this->target_) … … 302 221 if (!this->target_->getRadarVisibility()) /* So AI won't shoot invisible Spaceships */ 303 222 this->forgetTarget(); 304 else 305 { 306 this->aimAtTarget(); 307 random = rnd(maxrand); 308 309 if(this->botlevel_*100 > random && !this->isCloseAtTarget(20)) 310 this->follow();//If a bot is shooting a player, it shouldn't let him go away easily. 311 } 223 else this->aimAtTarget(); 312 224 } 313 225 … … 315 227 this->moveToTargetPosition(); 316 228 317 this->doFire();318 } 319 } //END_OF DEFAULT MODE229 this->doFire(); 230 } 231 } 320 232 else if (this->mode_ == ROCKET)//Rockets do not belong to a group of bots -> bot states are not relevant. 321 233 { //Vector-implementation: mode_.back() == ROCKET; 322 234 if(controllable) 323 { 324 if(controllable->getRocket())//Check wether the bot is controlling the rocket and if the timeout is over. 235 {//Check wether the bot is controlling the rocket and if the timeout is over. 236 if(controllable->getIdentifier() == ClassByString("Rocket")) 237 325 238 { 326 239 this->follow(); … … 341 254 SUPER(AIController, tick, dt); 342 255 } 256 //**********************************************NEW 257 void AIController::defaultBehaviour(float maxrand) 258 { float random; 259 // search enemy 260 random = rnd(maxrand); 261 if (random < (botlevel_* 100) && (!this->target_)) 262 this->searchNewTarget(); 263 264 // forget enemy 265 random = rnd(maxrand); 266 if (random < ((1-botlevel_)*20) && (this->target_)) 267 this->forgetTarget(); 268 269 // next enemy 270 random = rnd(maxrand); 271 if (random < (botlevel_*30) && (this->target_)) 272 this->searchNewTarget(); 273 274 // fly somewhere 275 random = rnd(maxrand); 276 if (random < 50 && (!this->bHasTargetPosition_ && !this->target_)) 277 this->searchRandomTargetPosition(); 278 279 // stop flying 280 random = rnd(maxrand); 281 if (random < 10 && (this->bHasTargetPosition_ && !this->target_)) 282 this->bHasTargetPosition_ = false; 283 284 // fly somewhere else 285 random = rnd(maxrand); 286 if (random < 30 && (this->bHasTargetPosition_ && !this->target_)) 287 this->searchRandomTargetPosition(); 288 289 if (this->state_ == MASTER) // master: shoot 290 { 291 random = rnd(maxrand); 292 if (!(this->passive_) && random < (100*botlevel_) && (this->target_ && !this->bShooting_)) 293 { 294 this->bShooting_ = true; 295 this->forceFreeSlaves(); 296 } 297 } 298 else 299 { 300 // shoot 301 random = rnd(maxrand); 302 if (!(this->passive_) && random < (botlevel_*100) && (this->target_ && !this->bShooting_)) 303 this->bShooting_ = true; 304 } 305 306 // stop shooting 307 random = rnd(maxrand); 308 if (random < ((1 - botlevel_)*50) && (this->bShooting_)) 309 this->bShooting_ = false; 310 311 // boost 312 random = rnd(maxrand); 313 if (random < botlevel_*50 ) 314 this->boostControl(); 315 316 // update Checkpoints 317 /*random = rnd(maxrand); 318 if (this->defaultWaypoint_ && random > (maxrand-10)) 319 this->manageWaypoints(); 320 else //if(random > maxrand-10) //CHECK USABILITY!!*/ 321 if (this->waypoints_.size() == 0 ) 322 this->manageWaypoints(); 323 } 343 324 344 325 }
Note: See TracChangeset
for help on using the changeset viewer.