Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 5826


Ignore:
Timestamp:
Sep 28, 2009, 9:05:56 PM (15 years ago)
Author:
landauf
Message:

Using a WeakPtr instead of a PawnListener-callback in UnderAttack to observe the Destroyer
HUDHealthBar also uses a WeakPtr now (before it displayed the health of already destroyed pawns)

Location:
code/branches/core5/src
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • code/branches/core5/src/modules/overlays/hud/HUDHealthBar.cc

    r5800 r5826  
    8585            this->textoverlay_->setCaption(multi_cast<std::string>(static_cast<int>(this->owner_->getHealth())));
    8686        }
     87        else
     88        {
     89            this->setValue(0);
     90            this->textoverlay_->setCaption("0");
     91        }
    8792
    8893        if (this->bUseBarColour_)
  • code/branches/core5/src/modules/overlays/hud/HUDHealthBar.h

    r5738 r5826  
    111111
    112112        private:
    113             Pawn* owner_;
     113            WeakPtr<Pawn> owner_;
    114114            OverlayText* textoverlay_;
    115115            bool bUseBarColour_;
  • code/branches/core5/src/orxonox/gametypes/UnderAttack.cc

    r5806 r5826  
    4646        this->teams_ = 2;
    4747        this->destroyer_ = 0;
     48        this->destroyer_.addCallback(createFunctor(&UnderAttack::killedDestroyer)->setObject(this));
    4849        this->gameEnded_ = false;
    4950
     
    6566
    6667
    67     void UnderAttack::destroyedPawn(Pawn* pawn)
     68    void UnderAttack::killedDestroyer()
    6869    {
    69         if (pawn == this->destroyer_)
     70        this->end(); //end gametype
     71        std::string message = "Ship destroyed! Team 0 has won!";
     72        COUT(0) << message << std::endl;
     73        Host::Broadcast(message);
     74        this->gameEnded_ = true;
     75
     76        for (std::map<PlayerInfo*, int>::iterator it = this->teamnumbers_.begin(); it != this->teamnumbers_.end(); ++it)
    7077        {
    71             this->end(); //end gametype
    72             std::string message = "Ship destroyed! Team 0 has won!";
    73             COUT(0) << message << std::endl;
    74             Host::Broadcast(message);
    75             this->gameEnded_ = true;
     78            if (it->first->getClientID() == CLIENTID_UNKNOWN)
     79                continue;
    7680
    77             for (std::map<PlayerInfo*, int>::iterator it = this->teamnumbers_.begin(); it != this->teamnumbers_.end(); ++it)
    78             {
    79                 if (it->first->getClientID() == CLIENTID_UNKNOWN)
    80                     continue;
    81 
    82                 if (it->second == 0)
    83                     this->gtinfo_->sendAnnounceMessage("You have won the match!", it->first->getClientID());
    84                 else
    85                     this->gtinfo_->sendAnnounceMessage("You have lost the match!", it->first->getClientID());
    86             }
     81            if (it->second == 0)
     82                this->gtinfo_->sendAnnounceMessage("You have won the match!", it->first->getClientID());
     83            else
     84                this->gtinfo_->sendAnnounceMessage("You have lost the match!", it->first->getClientID());
    8785        }
    8886    }
  • code/branches/core5/src/orxonox/gametypes/UnderAttack.h

    r5738 r5826  
    3232#include "OrxonoxPrereqs.h"
    3333
    34 #include "interfaces/PawnListener.h"
    3534#include "TeamDeathmatch.h"
    3635
    3736namespace orxonox
    3837{
    39     class _OrxonoxExport UnderAttack : public TeamDeathmatch, public PawnListener
     38    class _OrxonoxExport UnderAttack : public TeamDeathmatch
    4039    {
    4140        public:
     
    5453
    5554        protected:
    56             virtual void destroyedPawn(Pawn* pawn);
     55            virtual void killedDestroyer();
    5756
    58             Destroyer* destroyer_;
     57            WeakPtr<Destroyer> destroyer_;
    5958            unsigned int teams_;
    6059            float gameTime_;
Note: See TracChangeset for help on using the changeset viewer.