Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

master now lists slaves

File:
1 edited

Legend:

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

    r6683 r6695  
    4444
    4545        this->target_ = 0;
     46        this->myMaster_ = 0;
     47        //this->slaveNumber_ = -1;
    4648        this->team_ = -1;//new
    4749        this->state_ = FREE;//new
     
    9597    }
    9698
     99    void ArtificialController::unregisterSlave() {
     100        if(myMaster_)
     101        {
     102            myMaster_->slaves.remove(this);
     103        }
     104    }
     105
    97106    void ArtificialController::searchNewMaster()
    98107    {
     108
    99109        if (!this->getControllableEntity())
    100110            return;
     
    106116        for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it; ++it)
    107117        {
    108             //same team? no: continue
     118
     119            //same team?
    109120            if (!ArtificialController::sameTeam(this->getControllableEntity(), static_cast<ControllableEntity*>(*it), this->getGametype()))
    110121                continue;
    111122
    112             //has it an ArtificialController and is it a master? no: continue
     123            //has it an ArtificialController and is it a master?
     124            if (!it->getController())
     125                continue;
    113126
    114127            ArtificialController *controller = static_cast<ArtificialController*>(it->getController());
    115             if (controller && controller->getState() != MASTER)
     128            if (!controller || controller->getState() != MASTER)
    116129                continue;
    117130
    118131            //is pawn oneself? && is pawn in range?
    119             if (static_cast<ControllableEntity*>(*it) != this->getControllableEntity() /*&& it->getPosition().squaredDistance(this->getControllableEntity()->getPosition()) < 1000 */)
     132            if (static_cast<ControllableEntity*>(*it) != this->getControllableEntity()) //&& it->getPosition().squaredDistance(this->getControllableEntity()->getPosition()) < 1000
    120133            {
    121                 //this->target_ = (*it);
    122                 //this->targetPosition_ = it->getPosition();
    123134                this->state_ = SLAVE;
    124 
     135                this->myMaster_ = controller;
     136                controller->slaves.push_back(this);
     137                break;
    125138            }
    126139        }//for
    127140
    128141        //hasn't encountered any masters in range? -> become a master
    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...
     142        if (state_!=SLAVE) state_ = MASTER; // keep in mind: what happens when two masters encounter eache other? -> has to be evaluated in the for loop within master mode in AIcontroller...
     143
    130144    }
    131145
    132146    void ArtificialController::commandSlaves() {
    133147
     148        for(std::list<ArtificialController*>::iterator it = slaves.begin(); it != slaves.end(); it++)
     149        {
     150            (*it)->setTargetPosition(this->getControllableEntity()->getPosition());
     151        }
     152/*
    134153        for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it; ++it)
    135154        {
     155
     156            if (!it->getController())
     157                continue;
     158
    136159            ArtificialController *controller = static_cast<ArtificialController*>(it->getController());
    137             if (controller && controller->getState() != MASTER)
    138                 continue;
    139 
     160            if (!controller || controller->getState() != SLAVE)
     161                continue;
     162            //controller->setTargetPosition(this->getControllableEntity()->getPosition());
    140163            controller->targetPosition_ = this->getControllableEntity()->getPosition();
    141         }
    142 
     164            controller->bHasTargetPosition_ = true;
     165        }
     166*/
    143167    }
    144168
    145169    void ArtificialController::freeAllSlaves()
    146170    {
     171
    147172        for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it; ++it)
    148173        {
    149174            ArtificialController *controller = static_cast<ArtificialController*>(it->getController());
    150             if (controller && controller->getState() != MASTER)
     175            if (controller && controller->getState() != SLAVE)
    151176                continue;
    152177
Note: See TracChangeset for help on using the changeset viewer.