Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 9625 for code/trunk


Ignore:
Timestamp:
May 21, 2013, 3:12:21 PM (11 years ago)
Author:
smerkli
Message:

Merged Maxim's Branch back into trunk.

Location:
code/trunk
Files:
7 edited
1 copied

Legend:

Unmodified
Added
Removed
  • code/trunk

  • code/trunk/src/orxonox/controllers/Controller.h

    r8706 r9625  
    6565            virtual void changedControllableEntity() {}
    6666
    67         protected:
    6867            // don't use this directly, use getPlayer()->startControl(entity) (unless you know exactly what you do)
    6968            inline void setControllableEntity(ControllableEntity* entity)
  • code/trunk/src/orxonox/controllers/FormationController.cc

    r9348 r9625  
    535535
    536536
     537    // Sets newMaster as the new master within the formation. Called by the master.
     538    void FormationController::setNewMasterWithinFormation(FormationController* newMaster)
     539        {
     540            if(this->state_ != MASTER || newMaster->myMaster_ != this) return;
     541
     542            if (!this->slaves_.empty())
     543            {
     544                                std::vector<FormationController*>::iterator it2 = std::find(this->slaves_.begin(), this->slaves_.end(), newMaster);
     545                                if (it2 != this->slaves_.end())
     546                                {
     547                                         this->slaves_.erase(it2);
     548                                }
     549
     550                newMaster->state_ = MASTER;
     551                newMaster->slaves_ = this->slaves_;
     552                newMaster->myMaster_ = 0;
     553
     554                for(std::vector<FormationController*>::iterator it = newMaster->slaves_.begin(); it != newMaster->slaves_.end(); it++)
     555                {
     556                    (*it)->myMaster_ = newMaster;
     557                }
     558            }
     559
     560            this->slaves_.clear();
     561            this->specificMasterAction_ = NONE;
     562            this->state_ = FREE;
     563        }
     564
     565
     566
    537567  /**
    538         @brief Frees all slaves form a master. Initiated by a master.
     568        @brief Frees all slaves from a master. Initiated by a master.
    539569    */
    540570    void FormationController::freeSlaves()
  • code/trunk/src/orxonox/controllers/FormationController.h

    r9348 r9625  
    5959      static void passivebehaviour(const bool passive);
    6060      static void formationsize(const int size);
     61      void setNewMasterWithinFormation(FormationController* newMaster);
    6162
    6263      inline void setFormationFlight(bool formation)
     
    9899      virtual void hit(Pawn* originator, btManifoldPoint& contactpoint, float damage);
    99100
     101      FormationController* getMaster( void ) { return myMaster_; }
     102      FormationController* getController( void ) { return this; }
     103      FormationController* getSlave( void ) { return this->slaves_.back(); }
     104
    100105  protected:
    101106      bool formationFlight_;
     
    127132      void searchNewMaster();
    128133      void commandSlaves();
     134      void takeLeadOfFormation();
     135      void loseMasterState();
    129136      void setNewMasterWithinFormation();
    130137
    131138      void freeSlaves();
    132139      void forceFreeSlaves();
    133       void loseMasterState();
    134140      void forceFreedom();
    135141      bool forcedFree();
    136142
    137       void takeLeadOfFormation();
    138143      void masterAttacked(Pawn* originator);
    139144
     
    159164
    160165      void setTarget(Pawn* target);
     166
    161167      void searchNewTarget();
    162168      void forgetTarget();
  • code/trunk/src/orxonox/controllers/HumanController.cc

    r9256 r9625  
    102102
    103103        // commandslaves when Master of a formation
    104         if (HumanController::localController_s && HumanController::localController_s->state_==MASTER)
     104        if (HumanController::localController_s && HumanController::localController_s->state_==MASTER && FormationController::slaves_.size() > 0)
    105105        {
    106106            if (HumanController::localController_s->formationMode_ != ATTACK)
  • code/trunk/src/orxonox/worldentities/pawns/Pawn.cc

    r9555 r9625  
    4747#include "weaponsystem/WeaponSet.h"
    4848
     49#include "controllers/FormationController.h"
     50
    4951namespace orxonox
    5052{
     
    306308    }
    307309
     310
    308311    void Pawn::death()
    309312    {
     
    320323
    321324            if (this->getPlayer() && this->getPlayer()->getControllableEntity() == this)
    322                 this->getPlayer()->stopControl();
    323 
     325            {
     326                // Start to control a new entity if you're the master of a formation
     327                if(this->hasSlaves())
     328                {
     329                        Controller* slave = this->getSlave();
     330                        ControllableEntity* entity = slave->getControllableEntity();
     331
     332
     333                        if(!entity->hasHumanController())
     334                        {
     335                                // delete the AIController
     336                                slave->setControllableEntity(0);
     337
     338                                                // set a new master within the formation
     339                                                orxonox_cast<FormationController*>(this->getController())->setNewMasterWithinFormation(orxonox_cast<FormationController*>(slave));
     340
     341                                                // start to control a slave
     342                                                this->getPlayer()->startControl(entity);
     343                        }
     344                        else
     345                        {
     346                                this->getPlayer()->stopControl();
     347                        }
     348
     349                }
     350                else
     351                {
     352                        this->getPlayer()->stopControl();
     353                }
     354            }
    324355            if (GameMode::isMaster())
    325356            {
     
    468499    }
    469500
     501
     502    // A function to check if this pawn's controller is the master of any formationcontroller
     503    bool Pawn::hasSlaves()
     504    {
     505        for (ObjectList<FormationController>::iterator it =
     506                         ObjectList<FormationController>::begin();
     507                         it != ObjectList<FormationController>::end(); ++it )
     508                {
     509                        // checks if the pawn's controller has a slave
     510                        if (this->hasHumanController() && it->getMaster() == this->getPlayer()->getController())
     511                                return true;
     512                }
     513                return false;
     514    }
     515
     516    // A function that returns a slave of the pawn's controller
     517    Controller* Pawn::getSlave(){
     518        for (ObjectList<FormationController>::iterator it =
     519                        ObjectList<FormationController>::begin();
     520                        it != ObjectList<FormationController>::end(); ++it )
     521        {
     522                if (this->hasHumanController() && it->getMaster() == this->getPlayer()->getController())
     523                        return it->getController();
     524        }
     525        return 0;
     526    }
     527
     528
     529
    470530}
  • code/trunk/src/orxonox/worldentities/pawns/Pawn.h

    r9348 r9625  
    185185
    186186            virtual void death();
     187            virtual bool hasSlaves();
     188            virtual Controller* getSlave();
    187189            virtual void goWithStyle();
    188190            virtual void deatheffect();
Note: See TracChangeset for help on using the changeset viewer.