Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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:
2 edited

Legend:

Unmodified
Added
Removed
  • code/trunk

  • 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}
Note: See TracChangeset for help on using the changeset viewer.