Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 6695


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

master now lists slaves

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

Legend:

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

    r6683 r6695  
    5050    {
    5151        if (this->state_ == MASTER) freeAllSlaves();
     52        if (this->state_ == SLAVE) unregisterSlave();
     53        this->slaves.clear();
    5254    }
    5355
     
    6062        {
    6163
     64            //this->state_ = MASTER;
    6265            // search master
    63             random = rnd(maxrand);
    64             if (random < 50 && (!this->target_))
     66            //random = rnd(maxrand);
     67            //if (random < 101 && (!this->target_))
    6568                this->searchNewMaster();
    66 
    67 
    6869
    6970        }
     
    7879            // command slaves
    7980            this->commandSlaves();
     81
    8082            // search enemy
    8183            random = rnd(maxrand);
     
    130132                this->aimAtTarget();
    131133
    132             /*if (this->bHasTargetPosition_)
     134            if (this->bHasTargetPosition_)
    133135                this->moveToTargetPosition();
    134 */
     136
    135137            if (this->getControllableEntity() && this->bShooting_ && this->isCloseAtTarget(1000) && this->isLookingAtTarget(Ogre::Math::PI / 20.0f))
    136138                this->getControllableEntity()->fire(0);
    137139        }
    138140
    139         if (this->state_==SLAVE)
     141        if (this->state_ == SLAVE)
    140142        {
    141143
  • 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
  • code/branches/ai/src/orxonox/controllers/ArtificialController.h

    r6683 r6695  
    6161            enum State {SLAVE, MASTER, FREE};
    6262            int getState();
     63            std::list<ArtificialController*> slaves;
     64            void unregisterSlave();
    6365            void searchNewMaster();
    6466            void commandSlaves();
    6567            void freeAllSlaves();
     68
     69            ArtificialController *myMaster_;
    6670
    6771            void setTargetPosition(const Vector3& target);
Note: See TracChangeset for help on using the changeset viewer.