Changeset 8891 for code/trunk/src/orxonox/controllers/AIController.cc
- Timestamp:
- Oct 12, 2011, 7:50:43 PM (13 years ago)
- Location:
- code/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk
-
code/trunk/src/orxonox/controllers/AIController.cc
r8729 r8891 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 … … 76 76 // search enemy 77 77 random = rnd(maxrand); 78 if (random < 15&& (!this->target_))78 if (random < (15 + botlevel_* 20) && (!this->target_)) 79 79 this->searchNewTarget(); 80 80 81 81 // forget enemy 82 82 random = rnd(maxrand); 83 if (random < 5&& (this->target_))83 if (random < ((1-botlevel_)*6) && (this->target_)) 84 84 this->forgetTarget(); 85 85 86 86 // next enemy 87 87 random = rnd(maxrand); 88 if (random < 10&& (this->target_))88 if (random < (botlevel_*20) && (this->target_)) 89 89 this->searchNewTarget(); 90 90 … … 106 106 // shoot 107 107 random = rnd(maxrand); 108 if (!(this->passive_) && random < 75&& (this->target_ && !this->bShooting_))108 if (!(this->passive_) && random < (75 + botlevel_*25) && (this->target_ && !this->bShooting_)) 109 109 this->bShooting_ = true; 110 110 111 111 // stop shooting 112 112 random = rnd(maxrand); 113 if (random < 25&& (this->bShooting_))113 if (random < ((1 - botlevel_)*25) && (this->bShooting_)) 114 114 this->bShooting_ = false; 115 116 // boost 117 random = rnd(maxrand); 118 if (random < botlevel_*100 ) 119 this->boostControl(); 120 121 // update Checkpoints 122 /*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(); 115 128 116 129 } … … 159 172 // search enemy 160 173 random = rnd(maxrand); 161 if (random < 15 && (!this->target_))174 if (random < (botlevel_)*25 && (!this->target_)) 162 175 this->searchNewTarget(); 163 176 164 177 // forget enemy 165 178 random = rnd(maxrand); 166 if (random < 5&& (this->target_))179 if (random < (1-botlevel_)*6 && (this->target_)) 167 180 this->forgetTarget(); 168 181 … … 185 198 // shoot 186 199 random = rnd(maxrand); 187 if (!(this->passive_) && random < 9&& (this->target_ && !this->bShooting_))188 { 189 this->bShooting_ = true;190 this->forceFreeSlaves();200 if (!(this->passive_) && random < 25*(botlevel_)+1 && (this->target_ && !this->bShooting_)) 201 { 202 this->bShooting_ = true; 203 this->forceFreeSlaves(); 191 204 } 192 205 193 206 // stop shooting 194 207 random = rnd(maxrand); 195 if (random < 25&& (this->bShooting_))208 if (random < ( (1- botlevel_)*25 ) && (this->bShooting_)) 196 209 this->bShooting_ = false; 197 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(); 198 223 } 199 224 } … … 206 231 return; 207 232 208 if (this->state_ == MASTER) 233 float random; 234 float maxrand = 100.0f / ACTION_INTERVAL; 235 ControllableEntity* controllable = this->getControllableEntity(); 236 237 if (controllable && this->mode_ == DEFAULT)// bot is ready to move to a target 209 238 { 210 if (this->specificMasterAction_ == NONE) 239 if (this->waypoints_.size() > 0 ) //Waypoint functionality. 240 { 241 WorldEntity* wPoint = this->waypoints_[this->waypoints_.size()-1]; 242 if(wPoint) 243 { 244 this->moveToPosition(wPoint->getWorldPosition()); //BUG ?? sometime wPoint->getWorldPosition() causes crash 245 if (wPoint->getWorldPosition().squaredDistance(controllable->getPosition()) <= this->squaredaccuracy_) 246 this->waypoints_.pop_back(); // if goal is reached, remove it from the list 247 } 248 else 249 this->waypoints_.pop_back(); // remove invalid waypoints 250 251 } 252 else if(this->defaultWaypoint_ && ((this->defaultWaypoint_->getPosition()-controllable->getPosition()).length() > 200.0f)) 253 { 254 this->moveToPosition(this->defaultWaypoint_->getPosition()); // stay within a certain range of the defaultWaypoint_ 255 random = rnd(maxrand); 256 } 257 } 258 if(this->mode_ == DEFAULT) 259 { 260 if (this->state_ == MASTER) 261 { 262 if (this->specificMasterAction_ == NONE) 263 { 264 if (this->target_) 265 { 266 if (!this->target_->getRadarVisibility()) /* So AI won't shoot invisible Spaceships */ 267 this->forgetTarget(); 268 else 269 { 270 this->aimAtTarget(); 271 random = rnd(maxrand); 272 if(this->botlevel_*100 > random && !this->isCloseAtTarget(20)) 273 this->follow(); //If a bot is shooting a player, it shouldn't let him go away easily. 274 } 275 } 276 277 if (this->bHasTargetPosition_) 278 this->moveToTargetPosition(); 279 280 this->doFire(); 281 } 282 283 if (this->specificMasterAction_ == TURN180) 284 this->turn180(); 285 286 if (this->specificMasterAction_ == SPIN) 287 this->spin(); 288 if (this->specificMasterAction_ == FOLLOW) 289 this->follow(); 290 } 291 292 if (this->state_ == SLAVE) 293 { 294 if (this->bHasTargetPosition_) 295 this->moveToTargetPosition(); 296 } 297 298 if (this->state_ == FREE) 211 299 { 212 300 if (this->target_) … … 214 302 if (!this->target_->getRadarVisibility()) /* So AI won't shoot invisible Spaceships */ 215 303 this->forgetTarget(); 216 else this->aimAtTarget(); 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 } 217 312 } 218 313 … … 220 315 this->moveToTargetPosition(); 221 316 222 if (this->getControllableEntity() && this->bShooting_ && this->isCloseAtTarget(1000) && this->isLookingAtTarget(math::pi / 20.0f)) 223 this->getControllableEntity()->fire(0); 224 } 225 226 if (this->specificMasterAction_ == TURN180) 227 this->turn180(); 228 229 if (this->specificMasterAction_ == SPIN) 230 this->spin(); 231 if (this->specificMasterAction_ == FOLLOW) 317 this->doFire(); 318 } 319 }//END_OF DEFAULT MODE 320 else if (this->mode_ == ROCKET)//Rockets do not belong to a group of bots -> bot states are not relevant. 321 { //Vector-implementation: mode_.back() == ROCKET; 322 if(controllable) 323 { 324 if(controllable->getRocket())//Check wether the bot is controlling the rocket and if the timeout is over. 325 { 232 326 this->follow(); 233 } 234 235 if (this->state_ == SLAVE) 236 { 237 238 if (this->bHasTargetPosition_) 239 this->moveToTargetPosition(); 240 241 } 242 243 if (this->state_ == FREE) 244 { 245 if (this->target_) 246 { 247 if (!this->target_->getRadarVisibility()) /* So AI won't shoot invisible Spaceships */ 248 this->forgetTarget(); 249 else this->aimAtTarget(); 250 } 251 252 if (this->bHasTargetPosition_) 253 this->moveToTargetPosition(); 254 255 if (this->getControllableEntity() && this->bShooting_ && this->isCloseAtTarget(1000) && this->isLookingAtTarget(math::pi / 20.0f)) 256 this->getControllableEntity()->fire(0); 257 } 327 this->timeout_ -= dt; 328 if((timeout_< 0)||(!target_))//Check if the timeout is over or target died. 329 { 330 controllable->fire(0);//kill the rocket 331 this->setPreviousMode();//get out of rocket mode 332 } 333 } 334 else 335 this->setPreviousMode();//no rocket entity -> get out of rocket mode 336 } 337 else 338 this->setPreviousMode();//If bot dies -> getControllableEntity == NULL -> get out of ROCKET mode 339 }//END_OF ROCKET MODE 258 340 259 341 SUPER(AIController, tick, dt);
Note: See TracChangeset
for help on using the changeset viewer.