Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

first bot master/slave behavior

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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
Note: See TracChangeset for help on using the changeset viewer.