Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 6683


Ignore:
Timestamp:
Apr 12, 2010, 1:24:24 PM (14 years ago)
Author:
solex
Message:

master/slave behavior enhancments

Location:
code/branches/ai/src/orxonox/controllers
Files:
3 edited

Legend:

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

    r6640 r6683  
    4949    AIController::~AIController()
    5050    {
     51        if (this->state_ == MASTER) freeAllSlaves();
    5152    }
    5253
     
    5657        float maxrand = 100.0f / ACTION_INTERVAL;
    5758
    58         if (this->state_==0)
     59        if (this->state_ == FREE)//FREE
    5960        {
    6061
     
    6465                this->searchNewMaster();
    6566
    66             //this->state_=1;
     67
    6768
    6869        }
    6970
    70         if (this->state_==-1)
     71        if (this->state_ == SLAVE)//SLAVE
    7172        {
    72            
     73               // this->bShooting_ = true;
    7374        }
    7475
    75         if (this->state_==1)
     76        if (this->state_ == MASTER)//MASTER
    7677        {
     78            // command slaves
     79            this->commandSlaves();
    7780            // search enemy
    7881            random = rnd(maxrand);
     
    106109
    107110            // shoot
    108             random = rnd(maxrand);
     111            /*random = rnd(maxrand);
    109112            if (random < 75 && (this->target_ && !this->bShooting_))
    110113                this->bShooting_ = true;
    111 
     114*/
    112115            // stop shooting
    113116            random = rnd(maxrand);
     
    122125            return;
    123126
    124         if (this->state_==1)
     127        if (this->state_ == MASTER)
    125128        {
    126129            if (this->target_)
    127130                this->aimAtTarget();
    128131
    129             if (this->bHasTargetPosition_)
     132            /*if (this->bHasTargetPosition_)
    130133                this->moveToTargetPosition();
    131 
     134*/
    132135            if (this->getControllableEntity() && this->bShooting_ && this->isCloseAtTarget(1000) && this->isLookingAtTarget(Ogre::Math::PI / 20.0f))
    133136                this->getControllableEntity()->fire(0);
    134137        }
    135138
    136         if (this->state_==-1)
     139        if (this->state_==SLAVE)
    137140        {
    138             //this->state_=1;
    139141
     142            if (this->bHasTargetPosition_)
     143                this->moveToTargetPosition();
     144
     145        //this->getControllableEntity()->fire(0);
    140146
    141147        }
  • code/branches/ai/src/orxonox/controllers/ArtificialController.cc

    r6640 r6683  
    4545        this->target_ = 0;
    4646        this->team_ = -1;//new
    47         this->state_ = 0;//new
     47        this->state_ = FREE;//new
    4848        this->bShooting_ = false;
    4949        this->bHasTargetPosition_ = false;
     
    113113
    114114            ArtificialController *controller = static_cast<ArtificialController*>(it->getController());
    115             if (controller && controller->getState()!=1)
     115            if (controller && controller->getState() != MASTER)
    116116                continue;
    117117
     
    121121                //this->target_ = (*it);
    122122                //this->targetPosition_ = it->getPosition();
    123                 this->state_ = -1;
     123                this->state_ = SLAVE;
    124124
    125125            }
     
    127127
    128128        //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...
    130     }
     129        if (state_!=SLAVE) state_=MASTER; // 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...
     130    }
     131
     132    void ArtificialController::commandSlaves() {
     133
     134        for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it; ++it)
     135        {
     136            ArtificialController *controller = static_cast<ArtificialController*>(it->getController());
     137            if (controller && controller->getState() != MASTER)
     138                continue;
     139
     140            controller->targetPosition_ = this->getControllableEntity()->getPosition();
     141        }
     142
     143    }
     144
     145    void ArtificialController::freeAllSlaves()
     146    {
     147        for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it; ++it)
     148        {
     149            ArtificialController *controller = static_cast<ArtificialController*>(it->getController());
     150            if (controller && controller->getState() != MASTER)
     151                continue;
     152
     153            controller->state_ = FREE;
     154        }
     155
     156    }
     157
    131158
    132159    void ArtificialController::setTargetPosition(const Vector3& target)
  • code/branches/ai/src/orxonox/controllers/ArtificialController.h

    r6640 r6683  
    5959            void moveToTargetPosition();
    6060
     61            enum State {SLAVE, MASTER, FREE};
    6162            int getState();
    6263            void searchNewMaster();
     64            void commandSlaves();
     65            void freeAllSlaves();
    6366
    6467            void setTargetPosition(const Vector3& target);
     
    8083            bool bShooting_;
    8184
    82             int state_;//new master: 1 slave: -1  free: 0
     85
     86            State state_;//new master: 1 slave: -1  free: 0
    8387            int team_;//new
    8488
Note: See TracChangeset for help on using the changeset viewer.