Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Oct 12, 2011, 7:50:43 PM (13 years ago)
Author:
jo
Message:

Ai and tutorial improvements merged back to the trunk. AI features: all weapons are used, the ai-firestrength is configurable, bots are able to collect pickups . I've set the tutorial level as default level.

Location:
code/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/trunk

  • code/trunk/src/orxonox/controllers/AIController.cc

    r8729 r8891  
    6565                if (this->freedomCount_ == 1)
    6666                {
    67                 this->state_ = SLAVE;
    68                 this->freedomCount_ = 0;
     67                    this->state_ = SLAVE;
     68                    this->freedomCount_ = 0;
    6969                }
    7070
     
    7676            // search enemy
    7777            random = rnd(maxrand);
    78             if (random < 15 && (!this->target_))
     78            if (random < (15 + botlevel_* 20) && (!this->target_))
    7979                this->searchNewTarget();
    8080
    8181            // forget enemy
    8282            random = rnd(maxrand);
    83             if (random < 5 && (this->target_))
     83            if (random < ((1-botlevel_)*6) && (this->target_))
    8484                this->forgetTarget();
    8585
    8686            // next enemy
    8787            random = rnd(maxrand);
    88             if (random < 10 && (this->target_))
     88            if (random < (botlevel_*20) && (this->target_))
    8989                this->searchNewTarget();
    9090
     
    106106            // shoot
    107107            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_))
    109109                this->bShooting_ = true;
    110110
    111111            // stop shooting
    112112            random = rnd(maxrand);
    113             if (random < 25 && (this->bShooting_))
     113            if (random < ((1 - botlevel_)*25) && (this->bShooting_))
    114114                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();
    115128
    116129        }
     
    159172                // search enemy
    160173                random = rnd(maxrand);
    161                 if (random < 15 && (!this->target_))
     174                if (random < (botlevel_)*25 && (!this->target_))
    162175                    this->searchNewTarget();
    163176
    164177                // forget enemy
    165178                random = rnd(maxrand);
    166                 if (random < 5 && (this->target_))
     179                if (random < (1-botlevel_)*6 && (this->target_))
    167180                    this->forgetTarget();
    168181
     
    185198                // shoot
    186199                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();
    191204                }
    192205
    193206                // stop shooting
    194207                random = rnd(maxrand);
    195                 if (random < 25 && (this->bShooting_))
     208                if (random < ( (1- botlevel_)*25 ) && (this->bShooting_))
    196209                    this->bShooting_ = false;
    197210
     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();
    198223            }
    199224        }
     
    206231            return;
    207232
    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
    209238        {
    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)
    211299            {
    212300                if (this->target_)
     
    214302                    if (!this->target_->getRadarVisibility()) /* So AI won't shoot invisible Spaceships */
    215303                        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                     }
    217312                }
    218313
     
    220315                    this->moveToTargetPosition();
    221316
    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                {
    232326                    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
    258340
    259341        SUPER(AIController, tick, dt);
Note: See TracChangeset for help on using the changeset viewer.