Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jun 22, 2011, 6:57:16 PM (13 years ago)
Author:
jo
Message:

Bots are ready for rocket usage. (The hit rate for rockets is just about 60% though.). Note that this is just a proof of concept implementation. The next goal is a more generic implementation that adjusts the AI to any spaceship, not only the assff and similar ones.

Location:
code/branches/ai/src/orxonox/controllers
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • code/branches/ai/src/orxonox/controllers/AIController.cc

    r8701 r8711  
    270270            }
    271271        }//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.
    273273        {   
    274274            ControllableEntity *controllable = this->getControllableEntity();
    275275            if(controllable)
    276276            {
    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
    283289            }
    284290            else
    285                 this->mode_ = DEFAULT;//If bot dies -> getControllableEntity == NULL -> get out of ROCKET mode
     291                this->setPreviousMode();//If bot dies -> getControllableEntity == NULL -> get out of ROCKET mode
    286292        }//END_OF ROCKET MODE
    287293        SUPER(AIController, tick, dt);
  • code/branches/ai/src/orxonox/controllers/ArtificialController.cc

    r8701 r8711  
    8989        this->botlevel_ = 1.0f;
    9090        this->mode_ = DEFAULT;
     91        this->timeout_=0;
    9192    }
    9293
     
    10351036        else if(this->getControllableEntity()&&(numberOfWeapons>0)&&this->bShooting_ && this->isCloseAtTarget((1 + 2*botlevel_)*1000) && this->isLookingAtTarget(math::pi / 20.0f))
    10361037        {
    1037             /*if (this->isCloseAtTarget(130) && this->isLookingAtTarget(math::pi / 20.0f)&&(weapons[1]==1) )
     1038            if (this->isCloseAtTarget(130) &&(weapons[1]==1) )
    10381039            {//LENSFLARE: short range weapon     
    10391040                this->getControllableEntity()->fire(1); //ai uses lens flare if they're close enough to the target
    10401041            }
    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]*/ )
    10421043            {//ROCKET: mid range weapon
    10431044                //TODO: Which weapon is the rocket? How many rockets are available?
    10441045                this->mode_ = ROCKET;
    1045                 //TODO: this->rockettimer->start()
    10461046                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               
    10471057                this->projectiles[3]-=1;//decrease ammo !!
    10481058            }
    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);
    10521061        }
    10531062    }
     
    10941103            it->setBotLevel(level);
    10951104    }
     1105
     1106    void ArtificialController::setPreviousMode()
     1107    {
     1108        this->mode_ = DEFAULT;
     1109    }
    10961110   
    10971111}
  • code/branches/ai/src/orxonox/controllers/ArtificialController.h

    r8701 r8711  
    149149            int weapons[WeaponSystem::MAX_WEAPON_MODES];
    150150            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.)
    152153
    153154            enum Mode {DEFAULT, ROCKET, DEFENCE, MOVING};//TODO; implement DEFENCE, MOVING modes
    154155            Mode mode_;
     156            void setPreviousMode();
    155157
    156158        private:
Note: See TracChangeset for help on using the changeset viewer.