Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
May 17, 2010, 4:45:50 PM (14 years ago)
Author:
solex
Message:

finally some decent formation flying!

File:
1 edited

Legend:

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

    r6891 r6919  
    5959        {
    6060
    61 
     61            if (this->formationFlight_)
     62            {
    6263            // return to Master after being forced free
    63             if (this->freedomCount_ == 1)   
    64             {
     64                if (this->freedomCount_ == 1)
     65                {
    6566                this->state_ = SLAVE;
    6667                this->freedomCount_ = 0;
    67             }
    68 
    69             random = rnd(maxrand);
    70             if (random < 90 && (((!this->target_) || (random < 50 && this->target_)) && !this->forcedFree()))
    71                 this->searchNewMaster();
    72 
     68                }
     69
     70                random = rnd(maxrand);
     71                if (random < 90 && (((!this->target_) || (random < 50 && this->target_)) && !this->forcedFree()))
     72                    this->searchNewMaster();
     73            }
    7374
    7475            // search enemy
     
    116117        if (this->state_ == SLAVE)
    117118        {
    118                // this->bShooting_ = true;
     119
    119120        }
    120121
     
    125126            this->commandSlaves();
    126127
    127 
    128             // lose master status (only if less than 4 slaves in formation)
    129 //             random = rnd(maxrand);
    130 //             if(random < 15/(this->slaves_.size()+1) && this->slaves_.size() < 4 )
    131 //                 this->loseMasterState();
    132 
    133             // look out for outher masters if formation is small
    134             random = rnd(maxrand);
    135             if(this->slaves_.size() < 3 && random < 20)
    136                 this->searchNewMaster();
    137 
    138             // search enemy
    139             random = rnd(maxrand);
    140             if (random < 15 && (!this->target_))
    141                 this->searchNewTarget();
    142 
    143             // forget enemy
    144             random = rnd(maxrand);
    145             if (random < 5 && (this->target_))
    146                 this->forgetTarget();
    147 
    148             // next enemy
    149             random = rnd(maxrand);
    150             if (random < 10 && (this->target_))
    151                 this->searchNewTarget();
    152 
    153             // fly somewhere
    154             random = rnd(maxrand);
    155             if (random < 50 && (!this->bHasTargetPosition_ && !this->target_))
    156                 this->searchRandomTargetPosition();
    157 
    158 
    159             // fly somewhere else
    160             random = rnd(maxrand);
    161             if (random < 30 && (this->bHasTargetPosition_ && !this->target_))
    162                 this->searchRandomTargetPosition();
    163 
    164             // shoot
    165             random = rnd(maxrand);
    166             if (random < 5 && (this->target_ && !this->bShooting_))
     128            if  (this->specificMasterAction_ != NONE)
    167129            {
     130                if (this->specificMasterAction_  == HOLD)
     131                    this->specificMasterActionHold();
     132
     133                if (this->specificMasterAction_  == TURN180)
     134                    this->turn180();
     135
     136                if (this->specificMasterAction_ == SPIN)
     137                    this->spin();
     138            }
     139
     140            else {
     141
     142                 // make 180 degree turn - a specific Master Action
     143                random = rnd(maxrand);
     144                if (random < 5)
     145                   this->specificMasterAction_ = TURN180;
     146
     147                // spin around - a specific Master Action
     148                random = rnd(maxrand);
     149                if (random < 5)
     150                   this->specificMasterAction_ = SPIN;
     151
     152                 // lose master status (only if less than 4 slaves in formation)
     153                random = rnd(maxrand);
     154                if(random < 15/(this->slaves_.size()+1) && this->slaves_.size() < 4 )
     155                   this->loseMasterState();
     156
     157                // look out for outher masters if formation is small
     158                random = rnd(maxrand);
     159                if(this->slaves_.size() < 3 && random < 20)
     160                    this->searchNewMaster();
     161
     162                // search enemy
     163                random = rnd(maxrand);
     164                if (random < 15 && (!this->target_))
     165                    this->searchNewTarget();
     166
     167                // forget enemy
     168                random = rnd(maxrand);
     169                if (random < 5 && (this->target_))
     170                    this->forgetTarget();
     171
     172                // next enemy
     173                random = rnd(maxrand);
     174                if (random < 10 && (this->target_))
     175                    this->searchNewTarget();
     176
     177                // fly somewhere
     178                random = rnd(maxrand);
     179                if (random < 50 && (!this->bHasTargetPosition_ && !this->target_))
     180                    this->searchRandomTargetPosition();
     181
     182
     183                // fly somewhere else
     184                random = rnd(maxrand);
     185                if (random < 30 && (this->bHasTargetPosition_ && !this->target_))
     186                    this->searchRandomTargetPosition();
     187
     188                // shoot
     189                random = rnd(maxrand);
     190                if (random < 5 && (this->target_ && !this->bShooting_))
     191                {
    168192                this->bShooting_ = true;
    169 //                 this->forceFreeSlaves();
    170             }
    171             // stop shooting
    172             random = rnd(maxrand);
    173             if (random < 25 && (this->bShooting_))
    174                 this->bShooting_ = false;
     193                this->forceFreeSlaves();
     194                }
     195
     196                // stop shooting
     197                random = rnd(maxrand);
     198                if (random < 25 && (this->bShooting_))
     199                    this->bShooting_ = false;
     200
     201            }
    175202        }
    176203
     
    189216            if (this->bHasTargetPosition_)
    190217                this->moveToTargetPosition();
     218            if (this->specificMasterAction_ ==  NONE)
     219            {
     220                if (this->getControllableEntity() && this->bShooting_ && this->isCloseAtTarget(1000) && this->isLookingAtTarget(Ogre::Math::PI / 20.0f))
     221                    this->getControllableEntity()->fire(0);
     222            }
     223        }
     224
     225        if (this->state_ == SLAVE)
     226        {
     227
     228            if (this->bHasTargetPosition_)
     229                this->moveToTargetPosition();
     230
     231        }
     232
     233         if (this->state_ == FREE)
     234        {
     235            if (this->target_)
     236                this->aimAtTarget();
     237
     238            if (this->bHasTargetPosition_)
     239                this->moveToTargetPosition();
    191240
    192241            if (this->getControllableEntity() && this->bShooting_ && this->isCloseAtTarget(1000) && this->isLookingAtTarget(Ogre::Math::PI / 20.0f))
     
    194243        }
    195244
    196         if (this->state_ == SLAVE)
    197         {
    198 
    199             if (this->bHasTargetPosition_)
    200                 this->moveToTargetPosition();
    201 
    202         }
    203 
    204          if (this->state_ == FREE)
    205         {
    206             if (this->target_)
    207                 this->aimAtTarget();
    208 
    209             if (this->bHasTargetPosition_)
    210                 this->moveToTargetPosition();
    211 
    212             if (this->getControllableEntity() && this->bShooting_ && this->isCloseAtTarget(1000) && this->isLookingAtTarget(Ogre::Math::PI / 20.0f))
    213                 this->getControllableEntity()->fire(0);
    214         }
    215 
    216245        SUPER(AIController, tick, dt);
    217246    }
Note: See TracChangeset for help on using the changeset viewer.