Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Apr 26, 2010, 5:02:49 PM (15 years ago)
Author:
solex
Message:

death of master results in forming a new formation. Correct response to master death still to solve.

File:
1 edited

Legend:

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

    r6696 r6795  
    5151        this->bHasTargetPosition_ = false;
    5252        this->targetPosition_ = Vector3::ZERO;
     53        //this->slaves_ = new std::list<ArtificialController*>;
    5354
    5455        this->target_.setCallback(createFunctor(&ArtificialController::targetDied, this));
     
    100101        if(myMaster_)
    101102        {
    102             myMaster_->slaves.remove(this);
     103            myMaster_->slaves_.remove(this);
    103104        }
    104105    }
     
    132133            if (static_cast<ControllableEntity*>(*it) != this->getControllableEntity()) //&& it->getPosition().squaredDistance(this->getControllableEntity()->getPosition()) < 1000
    133134            {
    134                 if(controller->slaves.size() > 9) continue;
     135                if(controller->slaves_.size() > 9) continue;
    135136
    136137                this->freeAllSlaves();
    137                 this->slaves.clear();
     138                this->slaves_.clear();
    138139                this->state_ = SLAVE;
    139140
    140141                this->myMaster_ = controller;
    141                 controller->slaves.push_back(this);
     142                controller->slaves_.push_back(this);
    142143
    143144                break;
     
    152153    void ArtificialController::commandSlaves() {
    153154
    154         for(std::list<ArtificialController*>::iterator it = slaves.begin(); it != slaves.end(); it++)
     155        for(std::list<ArtificialController*>::iterator it = slaves_.begin(); it != slaves_.end(); it++)
    155156        {
    156157            (*it)->setTargetPosition(this->getControllableEntity()->getPosition());
     
    173174    }
    174175
     176    // binds slaves to new Master within formation
     177    void ArtificialController::setNewMasterWithinFormation()
     178    {
     179COUT(0) << "~setNewMasterWithinFormation 1" << std::endl;
     180        if (this->slaves_.empty())
     181            return;
     182COUT(0) << "~setNewMasterWithinFormation 1b" << std::endl;
     183
     184        ArtificialController *newMaster = this->slaves_.back();
     185COUT(0) << "~setNewMasterWithinFormation 2" << std::endl;
     186        this->slaves_.pop_back();
     187COUT(0) << "~setNewMasterWithinFormation 3" << std::endl;
     188        if(!newMaster) return;
     189COUT(0) << "~setNewMasterWithinFormation 4" << std::endl;
     190        newMaster->state_ = MASTER;
     191        newMaster->slaves_ = this->slaves_;
     192        //this->slaves_.clear();
     193
     194        this->state_ = SLAVE;
     195        this->myMaster_ = newMaster;
     196
     197COUT(0) << "~setNewMasterWithinFormation 5" << std::endl;
     198        for(std::list<ArtificialController*>::iterator it = newMaster->slaves_.begin(); it != newMaster->slaves_.end(); it++)
     199        {
     200COUT(0) << "~setNewMasterWithinFormation 6" << std::endl;
     201            (*it)->myMaster_ = newMaster;
     202        }
     203COUT(0) << "~setNewMasterWithinFormation 7" << std::endl;
     204
     205    }
     206
    175207    void ArtificialController::freeAllSlaves()
    176208    {
    177209
    178210
    179         for(std::list<ArtificialController*>::iterator it = slaves.begin(); it != slaves.end(); it++)
     211        for(std::list<ArtificialController*>::iterator it = slaves_.begin(); it != slaves_.end(); it++)
    180212        {
    181213            (*it)->state_ = FREE;
Note: See TracChangeset for help on using the changeset viewer.