Changeset 8711 for code/branches/ai/src/orxonox
- Timestamp:
- Jun 22, 2011, 6:57:16 PM (13 years ago)
- Location:
- code/branches/ai/src/orxonox/controllers
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/ai/src/orxonox/controllers/AIController.cc
r8701 r8711 270 270 } 271 271 }//END_OF DEFAULT MODE 272 else if (this->mode_ == ROCKET) 272 else if (this->mode_ == ROCKET)//Rockets do not belong to a group of bots -> bot states are not relevant. 273 273 { 274 274 ControllableEntity *controllable = this->getControllableEntity(); 275 275 if(controllable) 276 276 { 277 if(controllable->getRocket())//Check wether the bot is controlling the rocket. 278 { 279 this->follow(); //TODO: CHECK: does follow make the bot crash into the target_ ? 280 } 281 else 282 this->mode_ = DEFAULT;//no rocket -> get out of rocket mode 277 if(controllable->getRocket())//Check wether the bot is controlling the rocket and if the timeout is over. 278 { 279 this->follow(); //TODO: CHECK: does follow make the bot crash into the target_ ? 280 this->timeout_ -= dt; 281 if((timeout_< 0)||(!target_))//Check if the timeout is over or target died. 282 { 283 controllable->fire(0);//kill the rocket 284 this->setPreviousMode();//get out of rocket mode 285 } 286 } 287 else 288 this->setPreviousMode();//no rocket entity -> get out of rocket mode 283 289 } 284 290 else 285 this-> mode_ = DEFAULT;//If bot dies -> getControllableEntity == NULL -> get out of ROCKET mode291 this->setPreviousMode();//If bot dies -> getControllableEntity == NULL -> get out of ROCKET mode 286 292 }//END_OF ROCKET MODE 287 293 SUPER(AIController, tick, dt); -
code/branches/ai/src/orxonox/controllers/ArtificialController.cc
r8701 r8711 89 89 this->botlevel_ = 1.0f; 90 90 this->mode_ = DEFAULT; 91 this->timeout_=0; 91 92 } 92 93 … … 1035 1036 else if(this->getControllableEntity()&&(numberOfWeapons>0)&&this->bShooting_ && this->isCloseAtTarget((1 + 2*botlevel_)*1000) && this->isLookingAtTarget(math::pi / 20.0f)) 1036 1037 { 1037 /*if (this->isCloseAtTarget(130) && this->isLookingAtTarget(math::pi / 20.0f)&&(weapons[1]==1) )1038 if (this->isCloseAtTarget(130) &&(weapons[1]==1) ) 1038 1039 {//LENSFLARE: short range weapon 1039 1040 this->getControllableEntity()->fire(1); //ai uses lens flare if they're close enough to the target 1040 1041 } 1041 else if( this->isLookingAtTarget(math::pi / 20.0f)&&(weapons[3]==3)&& this->isCloseAtTarget(260) &&projectiles[3] )*/1042 else if((weapons[3]==3)&& this->isCloseAtTarget(400) /*&&projectiles[3]*/ ) 1042 1043 {//ROCKET: mid range weapon 1043 1044 //TODO: Which weapon is the rocket? How many rockets are available? 1044 1045 this->mode_ = ROCKET; 1045 //TODO: this->rockettimer->start()1046 1046 this->getControllableEntity()->fire(3);//launch rocket 1047 if(this->getControllableEntity()&&this->target_)//after fire(3) getControllableEntity() refers to the rocket! 1048 { 1049 float speed = this->getControllableEntity()->getVelocity().length() - target_->getVelocity().length(); 1050 if(!speed) speed = 0.1f; 1051 float distance = target_->getPosition().length() - this->getControllableEntity()->getPosition().length(); 1052 this->timeout_= distance/speed*sgn(speed*distance) + 1.8f;//predicted time of target hit (+ tolerance) 1053 } 1054 else 1055 this->timeout_ = 4.0f;//TODO: find better default value 1056 1047 1057 this->projectiles[3]-=1;//decrease ammo !! 1048 1058 } 1049 1050 /*else if ((weapons[0]==0))//LASER: default weapon 1051 this->getControllableEntity()->fire(0);*/ 1059 else if ((weapons[0]==0))//LASER: default weapon 1060 this->getControllableEntity()->fire(0); 1052 1061 } 1053 1062 } … … 1094 1103 it->setBotLevel(level); 1095 1104 } 1105 1106 void ArtificialController::setPreviousMode() 1107 { 1108 this->mode_ = DEFAULT; 1109 } 1096 1110 1097 1111 } -
code/branches/ai/src/orxonox/controllers/ArtificialController.h
r8701 r8711 149 149 int weapons[WeaponSystem::MAX_WEAPON_MODES]; 150 150 int projectiles[WeaponSystem::MAX_WEAPON_MODES]; 151 float botlevel_; //< Makes the level of a bot configurable. 151 float botlevel_; //< Makes the level of a bot configurable. 152 float timeout_; //< Timeout for rocket usage. (If a rocket misses, a bot should stop using it.) 152 153 153 154 enum Mode {DEFAULT, ROCKET, DEFENCE, MOVING};//TODO; implement DEFENCE, MOVING modes 154 155 Mode mode_; 156 void setPreviousMode(); 155 157 156 158 private:
Note: See TracChangeset
for help on using the changeset viewer.