[Orxonox-commit 1105] r5826 - in code/branches/core5/src: modules/overlays/hud orxonox/gametypes
landauf at orxonox.net
landauf at orxonox.net
Mon Sep 28 21:05:57 CEST 2009
Author: landauf
Date: 2009-09-28 21:05:56 +0200 (Mon, 28 Sep 2009)
New Revision: 5826
Modified:
code/branches/core5/src/modules/overlays/hud/HUDHealthBar.cc
code/branches/core5/src/modules/overlays/hud/HUDHealthBar.h
code/branches/core5/src/orxonox/gametypes/UnderAttack.cc
code/branches/core5/src/orxonox/gametypes/UnderAttack.h
Log:
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)
Modified: code/branches/core5/src/modules/overlays/hud/HUDHealthBar.cc
===================================================================
--- code/branches/core5/src/modules/overlays/hud/HUDHealthBar.cc 2009-09-28 18:59:34 UTC (rev 5825)
+++ code/branches/core5/src/modules/overlays/hud/HUDHealthBar.cc 2009-09-28 19:05:56 UTC (rev 5826)
@@ -84,6 +84,11 @@
this->setValue(this->owner_->getHealth() / this->owner_->getInitialHealth());
this->textoverlay_->setCaption(multi_cast<std::string>(static_cast<int>(this->owner_->getHealth())));
}
+ else
+ {
+ this->setValue(0);
+ this->textoverlay_->setCaption("0");
+ }
if (this->bUseBarColour_)
this->textoverlay_->setColour(this->getCurrentBarColour());
Modified: code/branches/core5/src/modules/overlays/hud/HUDHealthBar.h
===================================================================
--- code/branches/core5/src/modules/overlays/hud/HUDHealthBar.h 2009-09-28 18:59:34 UTC (rev 5825)
+++ code/branches/core5/src/modules/overlays/hud/HUDHealthBar.h 2009-09-28 19:05:56 UTC (rev 5826)
@@ -110,7 +110,7 @@
{ return this->textoverlay_->getSpaceWidth(); }
private:
- Pawn* owner_;
+ WeakPtr<Pawn> owner_;
OverlayText* textoverlay_;
bool bUseBarColour_;
ColourValue textColour_;
Modified: code/branches/core5/src/orxonox/gametypes/UnderAttack.cc
===================================================================
--- code/branches/core5/src/orxonox/gametypes/UnderAttack.cc 2009-09-28 18:59:34 UTC (rev 5825)
+++ code/branches/core5/src/orxonox/gametypes/UnderAttack.cc 2009-09-28 19:05:56 UTC (rev 5826)
@@ -45,6 +45,7 @@
this->gameTime_ = 180;
this->teams_ = 2;
this->destroyer_ = 0;
+ this->destroyer_.addCallback(createFunctor(&UnderAttack::killedDestroyer)->setObject(this));
this->gameEnded_ = false;
this->setHUDTemplate("UnderAttackHUD");
@@ -64,26 +65,23 @@
}
- void UnderAttack::destroyedPawn(Pawn* pawn)
+ void UnderAttack::killedDestroyer()
{
- if (pawn == this->destroyer_)
+ this->end(); //end gametype
+ std::string message = "Ship destroyed! Team 0 has won!";
+ COUT(0) << message << std::endl;
+ Host::Broadcast(message);
+ this->gameEnded_ = true;
+
+ for (std::map<PlayerInfo*, int>::iterator it = this->teamnumbers_.begin(); it != this->teamnumbers_.end(); ++it)
{
- this->end(); //end gametype
- std::string message = "Ship destroyed! Team 0 has won!";
- COUT(0) << message << std::endl;
- Host::Broadcast(message);
- this->gameEnded_ = true;
+ if (it->first->getClientID() == CLIENTID_UNKNOWN)
+ continue;
- for (std::map<PlayerInfo*, int>::iterator it = this->teamnumbers_.begin(); it != this->teamnumbers_.end(); ++it)
- {
- if (it->first->getClientID() == CLIENTID_UNKNOWN)
- continue;
-
- if (it->second == 0)
- this->gtinfo_->sendAnnounceMessage("You have won the match!", it->first->getClientID());
- else
- this->gtinfo_->sendAnnounceMessage("You have lost the match!", it->first->getClientID());
- }
+ if (it->second == 0)
+ this->gtinfo_->sendAnnounceMessage("You have won the match!", it->first->getClientID());
+ else
+ this->gtinfo_->sendAnnounceMessage("You have lost the match!", it->first->getClientID());
}
}
Modified: code/branches/core5/src/orxonox/gametypes/UnderAttack.h
===================================================================
--- code/branches/core5/src/orxonox/gametypes/UnderAttack.h 2009-09-28 18:59:34 UTC (rev 5825)
+++ code/branches/core5/src/orxonox/gametypes/UnderAttack.h 2009-09-28 19:05:56 UTC (rev 5826)
@@ -31,12 +31,11 @@
#include "OrxonoxPrereqs.h"
-#include "interfaces/PawnListener.h"
#include "TeamDeathmatch.h"
namespace orxonox
{
- class _OrxonoxExport UnderAttack : public TeamDeathmatch, public PawnListener
+ class _OrxonoxExport UnderAttack : public TeamDeathmatch
{
public:
UnderAttack(BaseObject* creator);
@@ -53,9 +52,9 @@
virtual bool allowPawnDeath(Pawn* victim, Pawn* originator = 0);
protected:
- virtual void destroyedPawn(Pawn* pawn);
+ virtual void killedDestroyer();
- Destroyer* destroyer_;
+ WeakPtr<Destroyer> destroyer_;
unsigned int teams_;
float gameTime_;
int timesequence_;
More information about the Orxonox-commit
mailing list