Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Feb 15, 2012, 11:51:58 PM (12 years ago)
Author:
jo
Message:

Merging presentation2011 branch to trunk. Please check for possible bugs.

Location:
code/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/trunk

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

    r8891 r9016  
    5959        if (this->state_ == FREE)
    6060        {
    61 
     61           
    6262            if (this->formationFlight_)
    6363            {
     64
     65                //changed order -> searchNewMaster MUSTN'T be called in SLAVE-state (bugfix for internal-error messages at quit)
     66                random = rnd(maxrand);
     67                if (random < 90 && (((!this->target_) || (random < 50 && this->target_)) && !this->forcedFree()))
     68                       this->searchNewMaster();
     69
    6470                // return to Master after being forced free
    6571                if (this->freedomCount_ == 1)
     
    6874                    this->freedomCount_ = 0;
    6975                }
    70 
    71                 random = rnd(maxrand);
    72                 if (random < 90 && (((!this->target_) || (random < 50 && this->target_)) && !this->forcedFree()))
    73                     this->searchNewMaster();
    74             }
    75 
     76            }
     77
     78            this->defaultBehaviour(maxrand);
     79
     80        }
     81
     82        if (this->state_ == SLAVE && this->formationMode_ == ATTACK)
     83        {
    7684            // search enemy
    7785            random = rnd(maxrand);
    78             if (random < (15 + botlevel_* 20) && (!this->target_))
     86            if (random < (botlevel_*100) && (!this->target_))
    7987                this->searchNewTarget();
    8088
    81             // forget enemy
    82             random = rnd(maxrand);
    83             if (random < ((1-botlevel_)*6) && (this->target_))
    84                 this->forgetTarget();
    85 
    8689            // next enemy
    8790            random = rnd(maxrand);
    88             if (random < (botlevel_*20) && (this->target_))
     91            if (random < (botlevel_*30) && (this->target_))
    8992                this->searchNewTarget();
    9093
    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 
    10694            // shoot
    10795            random = rnd(maxrand);
    108             if (!(this->passive_) && random < (75 + botlevel_*25) && (this->target_ && !this->bShooting_))
     96            if (!(this->passive_) && random < (botlevel_*100) && (this->target_ && !this->bShooting_))
    10997                this->bShooting_ = true;
    11098
    11199            // stop shooting
    112100            random = rnd(maxrand);
    113             if (random < ((1 - botlevel_)*25) && (this->bShooting_))
     101            if (random < (1-botlevel_)*50 && (this->bShooting_))
    114102                this->bShooting_ = false;
    115103
    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();
    128 
    129         }
    130 
    131         if (this->state_ == SLAVE)
    132         {
    133 
    134104        }
    135105
    136106        if (this->state_ == MASTER)
    137107        {
    138 
    139 
    140108            this->commandSlaves();
    141109
     
    155123                   this->spinInit();
    156124
    157                 // follow a randomly chosen human - a specific Master Action
     125                /*// follow a randomly chosen human - a specific Master Action
    158126                random = rnd(1000.0f);
    159127                if (random < 1)
    160128                   this->followRandomHumanInit();
    161 
     129*/
    162130                 // lose master status (only if less than 4 slaves in formation)
    163131                random = rnd(maxrand);
     
    170138                    this->searchNewMaster();
    171139
    172                 // search enemy
    173                 random = rnd(maxrand);
    174                 if (random < (botlevel_)*25 && (!this->target_))
    175                     this->searchNewTarget();
    176 
    177                 // forget enemy
    178                 random = rnd(maxrand);
    179                 if (random < (1-botlevel_)*6 && (this->target_))
    180                     this->forgetTarget();
    181 
    182                 // next enemy
    183                 random = rnd(maxrand);
    184                 if (random < 10 && (this->target_))
    185                     this->searchNewTarget();
    186 
    187                 // fly somewhere
    188                 random = rnd(maxrand);
    189                 if (random < 50 && (!this->bHasTargetPosition_ && !this->target_))
    190                     this->searchRandomTargetPosition();
    191 
    192 
    193                 // fly somewhere else
    194                 random = rnd(maxrand);
    195                 if (random < 30 && (this->bHasTargetPosition_ && !this->target_))
    196                     this->searchRandomTargetPosition();
    197 
    198                 // shoot
    199                 random = rnd(maxrand);
    200                 if (!(this->passive_) && random < 25*(botlevel_)+1 && (this->target_ && !this->bShooting_))
    201                 {
    202                     this->bShooting_ = true;
    203                     this->forceFreeSlaves();
    204                 }
    205 
    206                 // stop shooting
    207                 random = rnd(maxrand);
    208                 if (random < ( (1- botlevel_)*25 ) && (this->bShooting_))
    209                     this->bShooting_ = false;
    210 
    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();
     140                this->defaultBehaviour(maxrand);
     141
    223142            }
    224143        }
     
    234153        float maxrand = 100.0f / ACTION_INTERVAL;
    235154        ControllableEntity* controllable = this->getControllableEntity();
    236 
     155        //DOES: Either move to the waypoint or search for a Point of interest
    237156        if (controllable && this->mode_ == DEFAULT)// bot is ready to move to a target
    238157        {
     
    256175            }
    257176        }
    258         if(this->mode_ == DEFAULT)
    259             {
     177
     178        if (this->mode_ == DEFAULT)
     179        {
    260180            if (this->state_ == MASTER)
    261181            {
     
    270190                            this->aimAtTarget();
    271191                            random = rnd(maxrand);
    272                             if(this->botlevel_*100 > random && !this->isCloseAtTarget(20))
     192                            if(this->botlevel_*70 > random && !this->isCloseAtTarget(100))
    273193                                this->follow();  //If a bot is shooting a player, it shouldn't let him go away easily.
    274194                        }
     
    277197                    if (this->bHasTargetPosition_)
    278198                        this->moveToTargetPosition();
    279 
    280199                    this->doFire();
    281200                }
     
    290209            }
    291210
    292             if (this->state_ == SLAVE)
     211            if (this->state_ == SLAVE && this->formationMode_ != ATTACK)
    293212            {
    294213                if (this->bHasTargetPosition_)
     
    296215            }
    297216
    298             if (this->state_ == FREE)
     217            if (this->state_ == FREE || (this->state_==SLAVE && this->formationMode_ == ATTACK) )
    299218            {
    300219                if (this->target_)
     
    302221                    if (!this->target_->getRadarVisibility()) /* So AI won't shoot invisible Spaceships */
    303222                        this->forgetTarget();
    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                      }
     223                    else this->aimAtTarget();
    312224                }
    313225
     
    315227                    this->moveToTargetPosition();
    316228
    317                 this->doFire();
    318             }
    319         }//END_OF DEFAULT MODE
     229                    this->doFire();
     230            }
     231        }
    320232        else if (this->mode_ == ROCKET)//Rockets do not belong to a group of bots -> bot states are not relevant.
    321233        {   //Vector-implementation: mode_.back() == ROCKET;
    322234            if(controllable)
    323             {
    324                 if(controllable->getRocket())//Check wether the bot is controlling the rocket and if the timeout is over.
     235            {//Check wether the bot is controlling the rocket and if the timeout is over.
     236                if(controllable->getIdentifier() == ClassByString("Rocket"))
     237
    325238                {
    326239                    this->follow();
     
    341254        SUPER(AIController, tick, dt);
    342255    }
     256//**********************************************NEW
     257    void AIController::defaultBehaviour(float maxrand)
     258    {       float random;
     259            // search enemy
     260            random = rnd(maxrand);
     261            if (random < (botlevel_* 100) && (!this->target_))
     262                this->searchNewTarget();
     263
     264            // forget enemy
     265            random = rnd(maxrand);
     266            if (random < ((1-botlevel_)*20) && (this->target_))
     267                this->forgetTarget();
     268
     269            // next enemy
     270            random = rnd(maxrand);
     271            if (random < (botlevel_*30) && (this->target_))
     272                this->searchNewTarget();
     273
     274            // fly somewhere
     275            random = rnd(maxrand);
     276            if (random < 50 && (!this->bHasTargetPosition_ && !this->target_))
     277                this->searchRandomTargetPosition();
     278
     279            // stop flying
     280            random = rnd(maxrand);
     281            if (random < 10 && (this->bHasTargetPosition_ && !this->target_))
     282                this->bHasTargetPosition_ = false;
     283
     284            // fly somewhere else
     285            random = rnd(maxrand);
     286            if (random < 30 && (this->bHasTargetPosition_ && !this->target_))
     287                this->searchRandomTargetPosition();
     288
     289            if (this->state_ == MASTER) // master: shoot
     290            {
     291                random = rnd(maxrand);
     292                if (!(this->passive_) && random < (100*botlevel_) && (this->target_ && !this->bShooting_))
     293                {
     294                    this->bShooting_ = true;
     295                    this->forceFreeSlaves();
     296                }
     297            }
     298            else
     299            {
     300                // shoot
     301                random = rnd(maxrand);
     302                if (!(this->passive_) && random < (botlevel_*100) && (this->target_ && !this->bShooting_))
     303                    this->bShooting_ = true;
     304            }
     305
     306            // stop shooting
     307            random = rnd(maxrand);
     308            if (random < ((1 - botlevel_)*50) && (this->bShooting_))
     309                this->bShooting_ = false;
     310
     311            // boost
     312            random = rnd(maxrand);
     313            if (random < botlevel_*50 )
     314                this->boostControl();
     315
     316            // update Checkpoints
     317            /*random = rnd(maxrand);
     318            if (this->defaultWaypoint_ && random > (maxrand-10))
     319                this->manageWaypoints();
     320            else //if(random > maxrand-10) //CHECK USABILITY!!*/
     321            if (this->waypoints_.size() == 0 )
     322                this->manageWaypoints();
     323    }
    343324
    344325}
Note: See TracChangeset for help on using the changeset viewer.