Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 6795


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.

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

Legend:

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

    r6696 r6795  
    4949    AIController::~AIController()
    5050    {
    51         if (this->state_ == MASTER) freeAllSlaves();
     51COUT(0) << "~AIController 1" << std::endl;
     52        if (this->state_ == MASTER) setNewMasterWithinFormation();
     53COUT(0) << "~AIController 2" << std::endl;
    5254        if (this->state_ == SLAVE) unregisterSlave();
    53         this->slaves.clear();
     55COUT(0) << "~AIController 3" << std::endl;
     56        this->slaves_.clear();
     57COUT(0) << "~AIController 4" << std::endl;
    5458    }
    5559
     
    8488            // lose master status (only if less than 4 slaves in formation)
    8589            random = rnd(maxrand);
    86             if(random < 5/(this->slaves.size()+1) && this->slaves.size() < 5 )
     90            if(random < 5/(this->slaves_.size()+1) && this->slaves_.size() < 5 )
    8791                this->loseMasterState();
    8892
    8993            // look out for outher masters if formation is small
    90             if(this->slaves.size() < 3)
     94            if(this->slaves_.size() < 3)
    9195                this->searchNewMaster();
    9296
  • 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;
  • code/branches/ai/src/orxonox/controllers/ArtificialController.h

    r6696 r6795  
    4747            void abandonTarget(Pawn* target);
    4848
    49             inline void setTeam(int team)//new
     49            inline void setTeam(int team)
    5050                { this->team_ = team; }
    5151            inline int getTeam() const
    5252                { return this->team_; }
     53            virtual void changedControllableEntity();
    5354
    5455
     
    6162            enum State {SLAVE, MASTER, FREE};
    6263            int getState();
    63             std::list<ArtificialController*> slaves;
     64            std::list<ArtificialController*> slaves_;
    6465            void unregisterSlave();
    6566            void searchNewMaster();
    6667            void commandSlaves();
     68            void setNewMasterWithinFormation();
    6769            void freeAllSlaves();
    6870            void loseMasterState();
     
    8991
    9092
    91             State state_;//new master: 1 slave: -1  free: 0
    92             int team_;//new
     93            State state_;
     94            int team_;
    9395
    9496        private:
Note: See TracChangeset for help on using the changeset viewer.