Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Dec 16, 2011, 4:25:28 PM (12 years ago)
Author:
jo
Message:

Rough adding of both concepts. Further work on the states is needed. (single player bots are inactive at the moment)

File:
1 edited

Legend:

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

    r8978 r8990  
    6565                if (this->freedomCount_ == 1)
    6666                {
    67                 this->state_ = SLAVE;
    68                 this->freedomCount_ = 0;
     67                    this->state_ = SLAVE;
     68                    this->freedomCount_ = 0;
    6969                }
    7070
     
    7474            }
    7575
     76            this->defaultBehaviour(maxrand);
     77
     78        }
     79
     80        if (this->state_ == SLAVE && this->mode_ == ATTACK) //TODO: add botlevel parameter
     81        {
    7682            // search enemy
    7783            random = rnd(maxrand);
    78             if (random < 15 && (!this->target_))
     84            if (random < 75 && (!this->target_))
    7985                this->searchNewTarget();
    80 
    81             // forget enemy
    82             random = rnd(maxrand);
    83             if (random < 5 && (this->target_))
    84                 this->forgetTarget();
    8586
    8687            // next enemy
     
    8990                this->searchNewTarget();
    9091
    91             // fly somewhere
    92             random = rnd(maxrand);
    93             if (random < 50 && (!this->bHasTargetPosition_ && !this->target_))
    94                 this->searchRandomTargetPosition();
    95 
    96             // stop flying
    97             random = rnd(maxrand);
    98             if (random < 10 && (this->bHasTargetPosition_ && !this->target_))
    99                 this->bHasTargetPosition_ = false;
    100 
    101             // fly somewhere else
    102             random = rnd(maxrand);
    103             if (random < 30 && (this->bHasTargetPosition_ && !this->target_))
    104                 this->searchRandomTargetPosition();
    105 
    10692            // shoot
    10793            random = rnd(maxrand);
     
    116102        }
    117103
    118         if (this->state_ == SLAVE && this->mode_==ATTACK)
    119         {
    120             // search enemy
    121             random = rnd(maxrand);
    122             if (random < 75 && (!this->target_))
    123                 this->searchNewTarget();
    124 
    125             // next enemy
    126             random = rnd(maxrand);
    127             if (random < 10 && (this->target_))
    128                 this->searchNewTarget();
    129 
    130             // shoot
    131             random = rnd(maxrand);
    132             if (!(this->passive_) && random < 75 && (this->target_ && !this->bShooting_))
    133                 this->bShooting_ = true;
    134 
    135             // stop shooting
    136             random = rnd(maxrand);
    137             if (random < 25 && (this->bShooting_))
    138                 this->bShooting_ = false;
    139 
    140         }
    141 
    142104        if (this->state_ == MASTER)
    143105        {
    144 
    145 
    146106            this->commandSlaves();
    147107
     
    176136                    this->searchNewMaster();
    177137
    178                 // search enemy
    179                 random = rnd(maxrand);
    180                 if (random < 15 && (!this->target_))
    181                     this->searchNewTarget();
    182 
    183                 // forget enemy
    184                 random = rnd(maxrand);
    185                 if (random < 5 && (this->target_))
    186                     this->forgetTarget();
    187 
    188                 // next enemy
    189                 random = rnd(maxrand);
    190                 if (random < 10 && (this->target_))
    191                     this->searchNewTarget();
    192 
    193                 // fly somewhere
    194                 random = rnd(maxrand);
    195                 if (random < 50 && (!this->bHasTargetPosition_ && !this->target_))
    196                     this->searchRandomTargetPosition();
    197 
    198 
    199                 // fly somewhere else
    200                 random = rnd(maxrand);
    201                 if (random < 30 && (this->bHasTargetPosition_ && !this->target_))
    202                     this->searchRandomTargetPosition();
    203 
    204                 // shoot
    205                 random = rnd(maxrand);
    206                 if (!(this->passive_) && random < 9 && (this->target_ && !this->bShooting_))
    207                 {
    208                 this->bShooting_ = true;
    209                 this->forceFreeSlaves();
    210                 }
    211 
    212                 // stop shooting
    213                 random = rnd(maxrand);
    214                 if (random < 25 && (this->bShooting_))
    215                     this->bShooting_ = false;
     138                this->defaultBehaviour(maxrand);
    216139
    217140            }
     
    225148            return;
    226149
    227         if (this->state_ == MASTER)
    228         {
    229             if (this->specificMasterAction_ ==  NONE)
     150        float random;
     151        float maxrand = 100.0f / ACTION_INTERVAL;
     152        ControllableEntity* controllable = this->getControllableEntity();
     153
     154        if (controllable && this->mode_ == NORMAL)// bot is ready to move to a target // mode was DEFAULT in original implementation!
     155        {
     156            if (this->waypoints_.size() > 0 ) //Waypoint functionality.
     157            {
     158                WorldEntity* wPoint = this->waypoints_[this->waypoints_.size()-1];
     159                if(wPoint)
     160                {
     161                    this->moveToPosition(wPoint->getWorldPosition()); //BUG ?? sometime wPoint->getWorldPosition() causes crash
     162                    if (wPoint->getWorldPosition().squaredDistance(controllable->getPosition()) <= this->squaredaccuracy_)
     163                        this->waypoints_.pop_back(); // if goal is reached, remove it from the list
     164                }
     165                else
     166                    this->waypoints_.pop_back(); // remove invalid waypoints
     167
     168            }
     169            else if(this->defaultWaypoint_ && ((this->defaultWaypoint_->getPosition()-controllable->getPosition()).length()  > 200.0f))
     170            {
     171                this->moveToPosition(this->defaultWaypoint_->getPosition()); // stay within a certain range of the defaultWaypoint_
     172                random = rnd(maxrand);
     173            }
     174        }
     175
     176        if (this->mode_ != ROCKET)
     177        {
     178            if (this->state_ == MASTER)
     179            {
     180                if (this->specificMasterAction_ ==  NONE)
     181                {
     182                    if (this->target_)
     183                    {
     184                        if (!this->target_->getRadarVisibility()) /* So AI won't shoot invisible Spaceships */
     185                            this->forgetTarget();
     186                        else
     187                        {
     188                            this->aimAtTarget();
     189                            random = rnd(maxrand);
     190                            if(this->botlevel_*70 > random && !this->isCloseAtTarget(100))
     191                                this->follow();  //If a bot is shooting a player, it shouldn't let him go away easily.
     192                        }
     193                    }
     194
     195                    if (this->bHasTargetPosition_)
     196                        this->moveToTargetPosition();
     197                    this->doFire();
     198                }
     199
     200                if (this->specificMasterAction_  == TURN180)
     201                    this->turn180();
     202
     203                if (this->specificMasterAction_ == SPIN)
     204                    this->spin();
     205                if (this->specificMasterAction_ == FOLLOW)
     206                    this->follow();
     207            }
     208
     209            if (this->state_ == SLAVE && this->mode_!=ATTACK)
     210            {
     211                if (this->bHasTargetPosition_)
     212                    this->moveToTargetPosition();
     213            }
     214
     215            if (this->state_ == FREE || (this->state_==SLAVE && this->mode_==ATTACK) )
    230216            {
    231217                if (this->target_)
     
    239225                    this->moveToTargetPosition();
    240226
    241                 if (this->getControllableEntity() && this->bShooting_ && this->isCloseAtTarget(1000) && this->isLookingAtTarget(math::pi / 20.0f))
    242                     this->getControllableEntity()->fire(0);
    243             }
    244 
    245             if (this->specificMasterAction_  == TURN180)
    246                     this->turn180();
    247 
    248             if (this->specificMasterAction_ == SPIN)
    249                     this->spin();
    250             if (this->specificMasterAction_ == FOLLOW)
     227                    this->doFire();
     228            }
     229        }
     230        else if (this->mode_ == ROCKET)//Rockets do not belong to a group of bots -> bot states are not relevant.
     231        {   //Vector-implementation: mode_.back() == ROCKET;
     232            if(controllable)
     233            {//Check wether the bot is controlling the rocket and if the timeout is over.
     234                if(controllable->getIdentifier() == ClassByString("Rocket"))
     235
     236                {
    251237                    this->follow();
    252         }
    253 
    254         if (this->state_ == SLAVE && this->mode_!=ATTACK)
    255         {
    256 
    257             if (this->bHasTargetPosition_)
    258                 this->moveToTargetPosition();
    259 
    260         }
    261 
    262          if (this->state_ == FREE || (this->state_==SLAVE && this->mode_==ATTACK) )
    263         {
    264             if (this->target_)
    265             {
    266                 if (!this->target_->getRadarVisibility()) /* So AI won't shoot invisible Spaceships */
    267                     this->forgetTarget();
    268                 else this->aimAtTarget();
    269             }
    270 
    271             if (this->bHasTargetPosition_)
    272                 this->moveToTargetPosition();
    273 
    274             if (this->getControllableEntity() && this->bShooting_ && this->isCloseAtTarget(1000) && this->isLookingAtTarget(math::pi / 20.0f))
    275                 this->getControllableEntity()->fire(0);
    276         }
     238                    this->timeout_ -= dt;
     239                    if((timeout_< 0)||(!target_))//Check if the timeout is over or target died.
     240                    {
     241                       controllable->fire(0);//kill the rocket
     242                       this->setPreviousMode();//get out of rocket mode
     243                    }
     244                }
     245                else
     246                    this->setPreviousMode();//no rocket entity -> get out of rocket mode
     247            }
     248            else
     249                this->setPreviousMode();//If bot dies -> getControllableEntity == NULL -> get out of ROCKET mode
     250        }//END_OF ROCKET MODE
    277251
    278252        SUPER(AIController, tick, dt);
    279253    }
     254//**********************************************NEW
     255    void AIController::defaultBehaviour(float maxrand)
     256    {       float random;
     257            // search enemy
     258            random = rnd(maxrand);
     259            if (random < (botlevel_* 100) && (!this->target_))
     260                this->searchNewTarget();
     261
     262            // forget enemy
     263            random = rnd(maxrand);
     264            if (random < ((1-botlevel_)*20) && (this->target_))
     265                this->forgetTarget();
     266
     267            // next enemy
     268            random = rnd(maxrand);
     269            if (random < (botlevel_*30) && (this->target_))
     270                this->searchNewTarget();
     271
     272            // fly somewhere
     273            random = rnd(maxrand);
     274            if (random < 50 && (!this->bHasTargetPosition_ && !this->target_))
     275                this->searchRandomTargetPosition();
     276
     277            // stop flying
     278            random = rnd(maxrand);
     279            if (random < 10 && (this->bHasTargetPosition_ && !this->target_))
     280                this->bHasTargetPosition_ = false;
     281
     282            // fly somewhere else
     283            random = rnd(maxrand);
     284            if (random < 30 && (this->bHasTargetPosition_ && !this->target_))
     285                this->searchRandomTargetPosition();
     286
     287            if (this->state_ == MASTER) // master: shoot
     288            {
     289                random = rnd(maxrand);
     290                if (!(this->passive_) && random < (100*botlevel_) && (this->target_ && !this->bShooting_))
     291                {
     292                    this->bShooting_ = true;
     293                    this->forceFreeSlaves();
     294                }
     295            }
     296            else
     297            {
     298                // shoot
     299                random = rnd(maxrand);
     300                if (!(this->passive_) && random < (botlevel_*100) && (this->target_ && !this->bShooting_))
     301                    this->bShooting_ = true;
     302            }
     303
     304            // stop shooting
     305            random = rnd(maxrand);
     306            if (random < ((1 - botlevel_)*50) && (this->bShooting_))
     307                this->bShooting_ = false;
     308
     309            // boost
     310            random = rnd(maxrand);
     311            if (random < botlevel_*50 )
     312                this->boostControl();
     313
     314            // update Checkpoints
     315            /*random = rnd(maxrand);
     316            if (this->defaultWaypoint_ && random > (maxrand-10))
     317                this->manageWaypoints();
     318            else //if(random > maxrand-10) //CHECK USABILITY!!*/
     319            if (this->waypoints_.size() == 0 )
     320                this->manageWaypoints();
     321    }
    280322
    281323}
Note: See TracChangeset for help on using the changeset viewer.