Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Aug 11, 2010, 8:55:13 AM (14 years ago)
Author:
dafrick
Message:

Merged presentation3 branch into trunk.

Location:
code/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/trunk

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

    r5929 r7163  
    2323 *      Fabian 'x3n' Landau
    2424 *   Co-authors:
    25  *      ...
     25 *      Dominik Solenicki
    2626 *
    2727 */
     
    3333#include "core/Executor.h"
    3434#include "worldentities/ControllableEntity.h"
     35#include "worldentities/pawns/Pawn.h"
    3536
    3637namespace orxonox
     
    5657        float maxrand = 100.0f / ACTION_INTERVAL;
    5758
    58         // search enemy
    59         random = rnd(maxrand);
    60         if (random < 15 && (!this->target_))
    61             this->searchNewTarget();
    62 
    63         // forget enemy
    64         random = rnd(maxrand);
    65         if (random < 5 && (this->target_))
    66             this->forgetTarget();
    67 
    68         // next enemy
    69         random = rnd(maxrand);
    70         if (random < 10 && (this->target_))
    71             this->searchNewTarget();
    72 
    73         // fly somewhere
    74         random = rnd(maxrand);
    75         if (random < 50 && (!this->bHasTargetPosition_ && !this->target_))
    76             this->searchRandomTargetPosition();
    77 
    78         // stop flying
    79         random = rnd(maxrand);
    80         if (random < 10 && (this->bHasTargetPosition_ && !this->target_))
    81             this->bHasTargetPosition_ = false;
    82 
    83         // fly somewhere else
    84         random = rnd(maxrand);
    85         if (random < 30 && (this->bHasTargetPosition_ && !this->target_))
    86             this->searchRandomTargetPosition();
    87 
    88         // shoot
    89         random = rnd(maxrand);
    90         if (random < 75 && (this->target_ && !this->bShooting_))
    91             this->bShooting_ = true;
    92 
    93         // stop shooting
    94         random = rnd(maxrand);
    95         if (random < 25 && (this->bShooting_))
    96             this->bShooting_ = false;
     59        if (this->state_ == FREE)
     60        {
     61
     62            if (this->formationFlight_)
     63            {
     64                // return to Master after being forced free
     65                if (this->freedomCount_ == 1)
     66                {
     67                this->state_ = SLAVE;
     68                this->freedomCount_ = 0;
     69                }
     70
     71                random = rnd(maxrand);
     72                if (random < 90 && (((!this->target_) || (random < 50 && this->target_)) && !this->forcedFree()))
     73                    this->searchNewMaster();
     74            }
     75
     76            // search enemy
     77            random = rnd(maxrand);
     78            if (random < 15 && (!this->target_))
     79                this->searchNewTarget();
     80
     81            // forget enemy
     82            random = rnd(maxrand);
     83            if (random < 5 && (this->target_))
     84                this->forgetTarget();
     85
     86            // next enemy
     87            random = rnd(maxrand);
     88            if (random < 10 && (this->target_))
     89                this->searchNewTarget();
     90
     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
     106            // shoot
     107            random = rnd(maxrand);
     108            if (!(this->passive_) && random < 75 && (this->target_ && !this->bShooting_))
     109                this->bShooting_ = true;
     110
     111            // stop shooting
     112            random = rnd(maxrand);
     113            if (random < 25 && (this->bShooting_))
     114                this->bShooting_ = false;
     115
     116        }
     117
     118        if (this->state_ == SLAVE)
     119        {
     120
     121        }
     122
     123        if (this->state_ == MASTER)
     124        {
     125
     126
     127            this->commandSlaves();
     128
     129            if  (this->specificMasterAction_ != NONE)
     130                    this->specificMasterActionHold();
     131
     132            else {
     133
     134                 // make 180 degree turn - a specific Master Action
     135                random = rnd(1000.0f);
     136                if (random < 5)
     137                   this->turn180Init();
     138
     139                // spin around - a specific Master Action
     140                random = rnd(1000.0f);
     141                if (random < 5)
     142                   this->spinInit();
     143
     144                // follow a randomly chosen human - a specific Master Action
     145                random = rnd(1000.0f);
     146                if (random < 1)
     147                   this->followRandomHumanInit();
     148
     149                 // lose master status (only if less than 4 slaves in formation)
     150                random = rnd(maxrand);
     151                if(random < 15/(this->slaves_.size()+1) && this->slaves_.size() < 4 )
     152                   this->loseMasterState();
     153
     154                // look out for outher masters if formation is small
     155                random = rnd(maxrand);
     156                if(this->slaves_.size() < 3 && random < 20)
     157                    this->searchNewMaster();
     158
     159                // search enemy
     160                random = rnd(maxrand);
     161                if (random < 15 && (!this->target_))
     162                    this->searchNewTarget();
     163
     164                // forget enemy
     165                random = rnd(maxrand);
     166                if (random < 5 && (this->target_))
     167                    this->forgetTarget();
     168
     169                // next enemy
     170                random = rnd(maxrand);
     171                if (random < 10 && (this->target_))
     172                    this->searchNewTarget();
     173
     174                // fly somewhere
     175                random = rnd(maxrand);
     176                if (random < 50 && (!this->bHasTargetPosition_ && !this->target_))
     177                    this->searchRandomTargetPosition();
     178
     179
     180                // fly somewhere else
     181                random = rnd(maxrand);
     182                if (random < 30 && (this->bHasTargetPosition_ && !this->target_))
     183                    this->searchRandomTargetPosition();
     184
     185                // shoot
     186                random = rnd(maxrand);
     187                if (!(this->passive_) && random < 9 && (this->target_ && !this->bShooting_))
     188                {
     189                this->bShooting_ = true;
     190                this->forceFreeSlaves();
     191                }
     192
     193                // stop shooting
     194                random = rnd(maxrand);
     195                if (random < 25 && (this->bShooting_))
     196                    this->bShooting_ = false;
     197
     198            }
     199        }
     200
    97201    }
    98202
     
    102206            return;
    103207
    104         if (this->target_)
    105             this->aimAtTarget();
    106 
    107         if (this->bHasTargetPosition_)
    108             this->moveToTargetPosition();
    109 
    110         if (this->getControllableEntity() && this->bShooting_ && this->isCloseAtTarget(1000) && this->isLookingAtTarget(Ogre::Math::PI / 20.0f))
    111             this->getControllableEntity()->fire(0);
     208        if (this->state_ == MASTER)
     209        {
     210            if (this->specificMasterAction_ ==  NONE)
     211            {
     212                if (this->target_)
     213                {
     214                                if (!this->target_->getRadarVisibility()) /* So AI won't shoot invisible Spaceships */
     215                        this->forgetTarget();
     216                else this->aimAtTarget();
     217            }
     218
     219                if (this->bHasTargetPosition_)
     220                    this->moveToTargetPosition();
     221
     222                if (this->getControllableEntity() && this->bShooting_ && this->isCloseAtTarget(1000) && this->isLookingAtTarget(Ogre::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)
     232                    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(Ogre::Math::PI / 20.0f))
     256                this->getControllableEntity()->fire(0);
     257        }
    112258
    113259        SUPER(AIController, tick, dt);
Note: See TracChangeset for help on using the changeset viewer.