Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Apr 9, 2013, 3:49:06 PM (11 years ago)
Author:
maxima
Message:

A few changes to find the slaves of a pawn.

Location:
code/branches/formationupdate
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • code/branches/formationupdate/data/levels/maxim.oxw

    r9584 r9613  
    33 description = "Intelligent Formation"
    44 tags = "test"
    5  screenshot = "presentationxi.png"
    65/>
    76
  • code/branches/formationupdate/src/orxonox/controllers/FormationController.h

    r9583 r9613  
    100100      /* Just for testing purposes: report the master. */
    101101      FormationController* getMaster( void ) { return myMaster_; }
     102      FormationController* getThis( void ) { return this; }
    102103
    103104  protected:
  • code/branches/formationupdate/src/orxonox/worldentities/pawns/Pawn.cc

    r9584 r9613  
    308308    }
    309309
     310    // Two functions to find the slaves of a Pawn
     311    bool Pawn::hasSlaves()
     312    {
     313        /* TEST TEST This is used to find out if the current pawn is also
     314                 * the master of the formation and to find his slaves.
     315                 *
     316                 */
     317                for (ObjectList<FormationController>::iterator it =
     318                         ObjectList<FormationController>::begin();
     319                         it != ObjectList<FormationController>::end(); ++it )
     320                {
     321                        // checks if the dying Pawn has a slave
     322                        if (this->hasHumanController() && it->getMaster() == this->getPlayer()->getController())
     323                        {
     324                                orxout(user_warning) << "This is a Slave of the HumanController: " << it->getThis() << endl;
     325                                return true;
     326                        }
     327                }
     328                return false;
     329                /* TEST TEST */
     330    }
     331
     332    Controller* Pawn::getSlave(){
     333        for (ObjectList<FormationController>::iterator it =
     334                                 ObjectList<FormationController>::begin();
     335                                 it != ObjectList<FormationController>::end(); ++it )
     336        {
     337                if (this->hasHumanController() && it->getMaster() == this->getPlayer()->getController())
     338                        return it->getThis();
     339        }
     340        return 0;
     341    }
     342
     343
    310344    void Pawn::death()
    311345    {
    312         /* TEST TEST This is used to find out if the current pawn is also
    313          * the master of the formation.
    314          *
    315          * NOTE: This does not yet check if the current pawn is actually
    316          *       the humanplayer or not!
    317          */
    318         for (ObjectList<FormationController>::iterator it =
    319           ObjectList<FormationController>::begin();
    320           it != ObjectList<FormationController>::end(); ++it )
    321         {
    322           orxout(user_warning) << "Test! Master: " << it->getMaster()
    323             << " My controller: " << this->getPlayer()->getController() << endl;
    324         }
    325         /* TEST TEST */
    326 
    327            
    328 
    329 
    330346        this->setHealth(1);
    331347        if (this->getGametype() && this->getGametype()->allowPawnDeath(this, this->lastHitOriginator_))
     
    339355                this->getGametype()->pawnKilled(this, this->lastHitOriginator_);
    340356
     357
    341358            if (this->getPlayer() && this->getPlayer()->getControllableEntity() == this)
     359            {
     360                if(this->hasSlaves())
     361                {
     362                                // start to control a slave
     363                                this->getPlayer()->startControl(this->getSlave()->getControllableEntity());
     364                }
    342365                this->getPlayer()->stopControl();
    343 
    344             if (GameMode::isMaster())
     366            }
     367            /*if (GameMode::isMaster())
    345368            {
    346369//                this->deathEffect();
    347370                this->goWithStyle();
    348             }
     371            }*/
    349372        }
    350373    }
  • code/branches/formationupdate/src/orxonox/worldentities/pawns/Pawn.h

    r9348 r9613  
    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.