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
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • code/branches/objecthierarchy2/src/orxonox/objects/EventTarget.cc

    r2087 r2369  
    4848    void EventTarget::changedName()
    4949    {
     50        SUPER(EventTarget, changedName);
     51
    5052        for (ObjectList<BaseObject>::iterator it = ObjectList<BaseObject>::begin(); it != ObjectList<BaseObject>::end(); ++it)
    5153            if (it->getName() == this->getName())
  • code/branches/objecthierarchy2/src/orxonox/objects/gametypes/Gametype.cc

    r2361 r2369  
    169169        for (std::map<PlayerInfo*, PlayerState::Enum>::iterator it = this->players_.begin(); it != this->players_.end(); ++it)
    170170        {
    171             if (!it->first->getControllableEntity() && (!it->first->isReadyToSpawn() || !this->bStarted_))
    172             {
    173                 SpawnPoint* spawn = this->getBestSpawnPoint(it->first);
    174                 if (spawn)
    175                 {
    176                     // force spawn at spawnpoint with default pawn
    177                     ControllableEntity* entity = this->defaultControllableEntity_.fabricate(spawn);
    178                     spawn->spawn(entity);
    179                     it->first->startControl(entity);
    180                     it->second = PlayerState::Dead;
    181                 }
    182                 else
    183                 {
    184                     COUT(1) << "Error: No SpawnPoints in current Gametype" << std::endl;
    185                     abort();
     171            if (!it->first->getControllableEntity())
     172            {
     173                it->second = PlayerState::Dead;
     174
     175                if (!it->first->isReadyToSpawn() || !this->bStarted_)
     176                {
     177                    SpawnPoint* spawn = this->getBestSpawnPoint(it->first);
     178                    if (spawn)
     179                    {
     180                        // force spawn at spawnpoint with default pawn
     181                        ControllableEntity* entity = this->defaultControllableEntity_.fabricate(spawn);
     182                        spawn->spawn(entity);
     183                        it->first->startControl(entity);
     184                        it->second = PlayerState::Dead;
     185                    }
     186                    else
     187                    {
     188                        COUT(1) << "Error: No SpawnPoints in current Gametype" << std::endl;
     189                        abort();
     190                    }
    186191                }
    187192            }
     
    211216                {
    212217                    bool allplayersready = true;
     218                    bool hashumanplayers = false;
    213219                    for (std::map<PlayerInfo*, PlayerState::Enum>::iterator it = this->players_.begin(); it != this->players_.end(); ++it)
    214220                    {
    215221                        if (!it->first->isReadyToSpawn())
    216222                            allplayersready = false;
    217                     }
    218                     if (allplayersready)
     223                        if (it->first->isHumanPlayer())
     224                            hashumanplayers = true;
     225                    }
     226                    if (allplayersready && hashumanplayers)
    219227                    {
    220228                        this->startCountdown_ = this->initialStartCountdown_;
  • code/branches/objecthierarchy2/src/orxonox/objects/infos/PlayerInfo.cc

    r2362 r2369  
    7777    void PlayerInfo::changedName()
    7878    {
     79        SUPER(PlayerInfo, changedName);
     80
    7981        if (this->isInitialized() && this->getGametype())
    8082            this->getGametype()->playerChangedName(this);
  • code/branches/objecthierarchy2/src/orxonox/objects/worldentities/Camera.cc

    r2361 r2369  
    5454    {
    5555        RegisterObject(Camera);
    56 
     56COUT(0) << this << ": created camera" << std::endl;
    5757        if (!this->getScene() || !this->getScene()->getSceneManager())
    5858            ThrowException(AbortLoading, "Can't create Camera, no scene or no scene manager given.");
     
    7070        this->configvaluecallback_changedNearClipDistance();
    7171
    72         this->requestFocus(); // ! HACK ! REMOVE THIS !
     72//        this->requestFocus(); // ! HACK ! REMOVE THIS !
    7373    }
    7474
     
    8080            this->getScene()->getSceneManager()->destroyCamera(this->camera_);
    8181        }
     82COUT(0) << this << ": destroyed camera" << std::endl;
    8283    }
    8384
     
    122123    void Camera::removeFocus()
    123124    {
     125COUT(0) << this << ": remove focus" << std::endl;
    124126        this->bHasFocus_ = false;
    125127    }
     
    142144        this->bHasFocus_ = true;
    143145        viewport->setCamera(this->camera_);
     146COUT(0) << this << ": set focus" << std::endl;
    144147
    145148        // reactivate all visible compositors
  • 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.