Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 8990


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)

Location:
code/branches/formation/src/orxonox/controllers
Files:
7 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}
  • code/branches/formation/src/orxonox/controllers/AIController.h

    r8729 r8990  
    4444            virtual ~AIController();
    4545
    46             virtual void tick(float dt);
     46            virtual void tick(float dt); //<! Carrying out the targets set in action().
    4747
    4848        protected:
    49             virtual void action();
     49            virtual void action(); //<! action() is called in regular intervals managing the bot's behaviour ~ setting targets.
     50            void defaultBehaviour(float maxrand); //<! Helper function for code reusage. Some concrete commands for a bot.
    5051
    5152        private:
    5253            static const float ACTION_INTERVAL;
    5354
    54             Timer actionTimer_;
     55            Timer actionTimer_; //<! Regularly calls action().
    5556    };
    5657}
  • code/branches/formation/src/orxonox/controllers/ArtificialController.cc

    r8989 r8990  
    3030#include "core/CoreIncludes.h"
    3131#include "worldentities/pawns/Pawn.h"
     32#include "worldentities/pawns/SpaceShip.h"
     33
     34#include "weaponsystem/WeaponMode.h"
     35#include "weaponsystem/WeaponPack.h"
     36#include "weaponsystem/Weapon.h"
     37#include "weaponsystem/WeaponSlot.h"
     38#include "weaponsystem/WeaponSlot.h"
    3239
    3340
     
    3744    ArtificialController::ArtificialController(BaseObject* creator) : FormationController(creator)
    3845    {
    39          
     46        this->bSetupWorked = false;
     47        this->botlevel_ = 0.5f;
     48        this->timeout_ = 0;
     49        this->currentWaypoint_ = 0;
     50        this->setAccuracy(5);
     51        this->defaultWaypoint_ = NULL;
    4052    }
    4153
    4254    ArtificialController::~ArtificialController()
    4355    {
    44        
     56        if (this->isInitialized())
     57        {//Vector-implementation: mode_.erase(mode_.begin(),mode_.end());
     58            this->waypoints_.clear();
     59            this->weaponModes_.clear();
     60        }
    4561    }
    4662
     
    181197    void ArtificialController::setPreviousMode()
    182198    {
    183         this->mode_ = DEFAULT; //Vector-implementation: mode_.pop_back();
     199        this->mode_ = NORMAL; //Vector-implementation: mode_.pop_back();
    184200    }
    185201
     
    249265
    250266    /**
    251         @brief Adds point of interest depending on context. Further Possibilites: "ForceField", "PortalEndPoint", "MovableEntity", "Dock"
     267        @brief Adds point of interest depending on context.  TODO: Further Possibilites: "ForceField", "PortalEndPoint", "MovableEntity", "Dock"
    252268    */
    253269    void ArtificialController::manageWaypoints()
  • code/branches/formation/src/orxonox/controllers/FormationController.cc

    r8989 r8990  
    4040#include "gametypes/TeamDeathmatch.h"
    4141#include "gametypes/Dynamicmatch.h"
     42//#include "gametypes/Mission.h" TODO: include mission after merging
    4243#include "gametypes/Gametype.h"
    4344#include "controllers/WaypointPatrolController.h"
     
    961962        }
    962963
    963         Mission* miss = orxonox_cast<Mission*>(gametype); //NEW
     964        /*Mission* miss = orxonox_cast<Mission*>(gametype); //NEW
    964965        if (miss)
    965966        {
     
    969970            if (entity2->getPlayer())
    970971                team2 = miss->getTeam(entity2->getPlayer());
    971         }
     972        }*/
    972973
    973974        TeamBaseMatchBase* base = 0;
  • code/branches/formation/src/orxonox/controllers/FormationController.h

    r8978 r8990  
    8888               Attack-leave formation, attack every target
    8989      */
    90       enum Mode {NORMAL,DEFEND,ATTACK};
     90      enum Mode {NORMAL,DEFEND,ATTACK,ROCKET};
    9191     
    9292      /**
  • code/branches/formation/src/orxonox/controllers/HumanController.cc

    r8978 r8990  
    318318        {
    319319            switch (HumanController::localController_s->getMode()) {
    320               case NORMAL:
    321                 HumanController::localController_s->setMode(DEFEND);
    322                 orxout(message) <<"Mode: DEFEND "<< endl;
    323                 break;
    324               case DEFEND:
    325                 HumanController::localController_s->setMode(ATTACK);
    326                 orxout(message) <<"Mode: ATTACK "<< endl;
    327                 break;
    328               case ATTACK:
    329                 HumanController::localController_s->setMode(NORMAL);
    330                 orxout(message) <<"Mode: NORMAL "<< endl;
    331                 break;
     320                case NORMAL:
     321                    HumanController::localController_s->setMode(DEFEND);
     322                    orxout(message) <<"Mode: DEFEND "<< endl;
     323                    break;
     324                case DEFEND:
     325                    HumanController::localController_s->setMode(ATTACK);
     326                    orxout(message) <<"Mode: ATTACK "<< endl;
     327                    break;
     328                case ATTACK:
     329                    HumanController::localController_s->setMode(NORMAL);
     330                    orxout(message) <<"Mode: NORMAL "<< endl;
     331                    break;
     332                default: //catch all non-formation related states
     333                    break;
    332334            }
    333335        }
  • code/branches/formation/src/orxonox/controllers/NewHumanController.cc

    r8965 r8990  
    277277    }
    278278
    279     void NewHumanController::doFire(unsigned int firemode)
     279    void NewHumanController::doFire(unsigned int firemode)//TODO??
    280280    {
    281281        if (!this->controllableEntity_)
Note: See TracChangeset for help on using the changeset viewer.