Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 6640


Ignore:
Timestamp:
Mar 29, 2010, 4:23:08 PM (14 years ago)
Author:
solex
Message:

first bot master/slave behavior

Location:
code/branches/ai/src/orxonox
Files:
4 edited

Legend:

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

    r5929 r6640  
    5656        float maxrand = 100.0f / ACTION_INTERVAL;
    5757
    58         // search enemy
    59         random = rnd(maxrand);
    60         if (random < 15 && (!this->target_))
    61             this->searchNewTarget();
     58        if (this->state_==0)
     59        {
    6260
    63         // forget enemy
    64         random = rnd(maxrand);
    65         if (random < 5 && (this->target_))
    66             this->forgetTarget();
     61            // search master
     62            random = rnd(maxrand);
     63            if (random < 50 && (!this->target_))
     64                this->searchNewMaster();
    6765
    68         // next enemy
    69         random = rnd(maxrand);
    70         if (random < 10 && (this->target_))
    71             this->searchNewTarget();
     66            //this->state_=1;
    7267
    73         // fly somewhere
    74         random = rnd(maxrand);
    75         if (random < 50 && (!this->bHasTargetPosition_ && !this->target_))
    76             this->searchRandomTargetPosition();
     68        }
    7769
    78         // stop flying
    79         random = rnd(maxrand);
    80         if (random < 10 && (this->bHasTargetPosition_ && !this->target_))
    81             this->bHasTargetPosition_ = false;
     70        if (this->state_==-1)
     71        {
     72           
     73        }
    8274
    83         // fly somewhere else
    84         random = rnd(maxrand);
    85         if (random < 30 && (this->bHasTargetPosition_ && !this->target_))
    86             this->searchRandomTargetPosition();
     75        if (this->state_==1)
     76        {
     77            // search enemy
     78            random = rnd(maxrand);
     79            if (random < 15 && (!this->target_))
     80                this->searchNewTarget();
    8781
    88         // shoot
    89         random = rnd(maxrand);
    90         if (random < 75 && (this->target_ && !this->bShooting_))
    91             this->bShooting_ = true;
     82            // forget enemy
     83            random = rnd(maxrand);
     84            if (random < 5 && (this->target_))
     85                this->forgetTarget();
    9286
    93         // stop shooting
    94         random = rnd(maxrand);
    95         if (random < 25 && (this->bShooting_))
    96             this->bShooting_ = false;
     87            // next enemy
     88            random = rnd(maxrand);
     89            if (random < 10 && (this->target_))
     90                this->searchNewTarget();
     91
     92            // fly somewhere
     93            random = rnd(maxrand);
     94            if (random < 50 && (!this->bHasTargetPosition_ && !this->target_))
     95                this->searchRandomTargetPosition();
     96
     97            // stop flying
     98            random = rnd(maxrand);
     99            if (random < 10 && (this->bHasTargetPosition_ && !this->target_))
     100                this->bHasTargetPosition_ = false;
     101
     102            // fly somewhere else
     103            random = rnd(maxrand);
     104            if (random < 30 && (this->bHasTargetPosition_ && !this->target_))
     105                this->searchRandomTargetPosition();
     106
     107            // shoot
     108            random = rnd(maxrand);
     109            if (random < 75 && (this->target_ && !this->bShooting_))
     110                this->bShooting_ = true;
     111
     112            // stop shooting
     113            random = rnd(maxrand);
     114            if (random < 25 && (this->bShooting_))
     115                this->bShooting_ = false;
     116        }
    97117    }
    98118
     
    102122            return;
    103123
    104         if (this->target_)
    105             this->aimAtTarget();
     124        if (this->state_==1)
     125        {
     126            if (this->target_)
     127                this->aimAtTarget();
    106128
    107         if (this->bHasTargetPosition_)
    108             this->moveToTargetPosition();
     129            if (this->bHasTargetPosition_)
     130                this->moveToTargetPosition();
    109131
    110         if (this->getControllableEntity() && this->bShooting_ && this->isCloseAtTarget(1000) && this->isLookingAtTarget(Ogre::Math::PI / 20.0f))
    111             this->getControllableEntity()->fire(0);
     132            if (this->getControllableEntity() && this->bShooting_ && this->isCloseAtTarget(1000) && this->isLookingAtTarget(Ogre::Math::PI / 20.0f))
     133                this->getControllableEntity()->fire(0);
     134        }
     135
     136        if (this->state_==-1)
     137        {
     138            //this->state_=1;
     139
     140
     141        }
    112142
    113143        SUPER(AIController, tick, dt);
  • code/branches/ai/src/orxonox/controllers/ArtificialController.cc

    r6601 r6640  
    4444
    4545        this->target_ = 0;
    46         this->team_ = 0;//new
    47         this->isMaster_ = false;//new
     46        this->team_ = -1;//new
     47        this->state_ = 0;//new
    4848        this->bShooting_ = false;
    4949        this->bHasTargetPosition_ = false;
     
    8888    {
    8989        this->moveToPosition(this->targetPosition_);
     90    }
     91
     92    int ArtificialController::getState()
     93    {
     94        return this->state_;
     95    }
     96
     97    void ArtificialController::searchNewMaster()
     98    {
     99        if (!this->getControllableEntity())
     100            return;
     101
     102        this->targetPosition_ = this->getControllableEntity()->getPosition();
     103        this->forgetTarget();
     104
     105        //go through all pawns
     106        for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it; ++it)
     107        {
     108            //same team? no: continue
     109            if (!ArtificialController::sameTeam(this->getControllableEntity(), static_cast<ControllableEntity*>(*it), this->getGametype()))
     110                continue;
     111
     112            //has it an ArtificialController and is it a master? no: continue
     113
     114            ArtificialController *controller = static_cast<ArtificialController*>(it->getController());
     115            if (controller && controller->getState()!=1)
     116                continue;
     117
     118            //is pawn oneself? && is pawn in range?
     119            if (static_cast<ControllableEntity*>(*it) != this->getControllableEntity() /*&& it->getPosition().squaredDistance(this->getControllableEntity()->getPosition()) < 1000 */)
     120            {
     121                //this->target_ = (*it);
     122                //this->targetPosition_ = it->getPosition();
     123                this->state_ = -1;
     124
     125            }
     126        }//for
     127
     128        //hasn't encountered any masters in range? -> become a master
     129        if (state_!=-1) state_=1; // keep in mind: what happens when two masters encounter eache other? -> has to be evaluated in the for loop of within master mode in AIcontroller...
    90130    }
    91131
  • code/branches/ai/src/orxonox/controllers/ArtificialController.h

    r6601 r6640  
    5959            void moveToTargetPosition();
    6060
     61            int getState();
     62            void searchNewMaster();
     63
    6164            void setTargetPosition(const Vector3& target);
    6265            void searchRandomTargetPosition();
     
    7780            bool bShooting_;
    7881
    79             bool isMaster_;//new
     82            int state_;//new master: 1 slave: -1  free: 0
    8083            int team_;//new
    8184
  • code/branches/ai/src/orxonox/worldentities/pawns/Pawn.h

    r6540 r6640  
    115115            Vector3 getAimPosition()
    116116                { return this->aimPosition_; }
    117                
     117
    118118            virtual const Vector3& getCarrierPosition(void)
    119119                { return this->getWorldPosition(); };
Note: See TracChangeset for help on using the changeset viewer.