Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Dec 10, 2008, 3:37:48 AM (16 years ago)
Author:
landauf
Message:
  • Added a health bar
  • Some changes in CameraManager to handle the case when no camera exists after removing the last one, but this is still somehow buggy (freezes and later crashes reproducible but inexplicable after a few respawns)
  • Added PawnManager to handle destruction of Pawns without using delete within tick()
Location:
code/branches/objecthierarchy2/src/orxonox/objects/worldentities/pawns
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/branches/objecthierarchy2/src/orxonox/objects/worldentities/pawns/Pawn.cc

    r2256 r2369  
    3333#include "core/XMLPort.h"
    3434#include "util/Math.h"
     35#include "PawnManager.h"
    3536#include "objects/infos/PlayerInfo.h"
    3637#include "objects/gametypes/Gametype.h"
     
    4546        RegisterObject(Pawn);
    4647
    47         this->bAlive_ = false;
     48        PawnManager::touch();
     49
     50        this->bAlive_ = true;
    4851
    4952        this->health_ = 0;
     
    7073    Pawn::~Pawn()
    7174    {
     75        if (this->isInitialized())
     76        {
     77            for (ObjectList<PawnListener>::iterator it = ObjectList<PawnListener>::begin(); it != ObjectList<PawnListener>::end(); ++it)
     78                it->destroyedPawn(this);
     79        }
    7280    }
    7381
     
    7684        SUPER(Pawn, XMLPort, xmlelement, mode);
    7785
    78         XMLPortParam(Pawn, "health", setHealth, getHealht, xmlelement, mode).defaultValues(100);
     86        XMLPortParam(Pawn, "health", setHealth, getHealth, xmlelement, mode).defaultValues(100);
    7987        XMLPortParam(Pawn, "maxhealth", setMaxHealth, getMaxHealth, xmlelement, mode).defaultValues(200);
    8088        XMLPortParam(Pawn, "initialhealth", setInitialHealth, getInitialHealth, xmlelement, mode).defaultValues(100);
     
    8593        REGISTERDATA(this->bAlive_, direction::toclient);
    8694        REGISTERDATA(this->health_, direction::toclient);
     95        REGISTERDATA(this->initialHealth_, direction::toclient);
    8796    }
    8897
     
    9099    {
    91100        SUPER(Pawn, tick, dt);
     101
     102        this->health_ -= 15 * dt * rnd();
    92103
    93104        if (this->health_ <= 0)
     
    129140    void Pawn::death()
    130141    {
     142        // Set bAlive_ to false and wait for PawnManager to do the destruction
    131143        this->bAlive_ = false;
     144
    132145        if (this->getGametype())
    133146            this->getGametype()->pawnKilled(this, this->lastHitOriginator_);
     147
     148        this->setDestroyWhenPlayerLeft(false);
     149
    134150        if (this->getPlayer())
    135151            this->getPlayer()->stopControl(this);
    136 
    137         delete this;
    138152
    139153        // play death effect
     
    151165        this->spawn();
    152166    }
     167
     168    ///////////////////
     169    // Pawn Listener //
     170    ///////////////////
     171    PawnListener::PawnListener()
     172    {
     173        RegisterRootObject(PawnListener);
     174    }
    153175}
  • code/branches/objecthierarchy2/src/orxonox/objects/worldentities/pawns/Pawn.h

    r2256 r2369  
    5555            inline void removeHealth(float health)
    5656                { this->setHealth(this->health_ - health); }
    57             inline float getHealht() const
     57            inline float getHealth() const
    5858                { return this->health_; }
    5959
     
    9696            WeaponSystem* weaponSystem_;
    9797    };
     98
     99    class _OrxonoxExport PawnListener : public OrxonoxClass
     100    {
     101        friend class Pawn;
     102
     103        public:
     104            PawnListener();
     105            virtual ~PawnListener() {}
     106
     107        protected:
     108            virtual void destroyedPawn(Pawn* pawn) = 0;
     109    };
    98110}
    99111
Note: See TracChangeset for help on using the changeset viewer.