Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

master/slave behavior enhancments

File:
1 edited

Legend:

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