Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jun 22, 2011, 6:57:16 PM (14 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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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}
Note: See TracChangeset for help on using the changeset viewer.