[Orxonox-commit 3770] r8450 - in code/branches/tutoriallevel2: data/overlays src/modules/notifications src/modules/overlays/hud src/orxonox/gametypes src/orxonox/infos
dafrick at orxonox.net
dafrick at orxonox.net
Thu May 12 00:11:53 CEST 2011
Author: dafrick
Date: 2011-05-12 00:11:53 +0200 (Thu, 12 May 2011)
New Revision: 8450
Removed:
code/branches/tutoriallevel2/src/modules/overlays/hud/GametypeStatus.cc
code/branches/tutoriallevel2/src/modules/overlays/hud/GametypeStatus.h
Modified:
code/branches/tutoriallevel2/data/overlays/debug.oxo
code/branches/tutoriallevel2/src/modules/notifications/NotificationQueueCEGUI.cc
code/branches/tutoriallevel2/src/modules/notifications/NotificationQueueCEGUI.h
code/branches/tutoriallevel2/src/modules/overlays/hud/CMakeLists.txt
code/branches/tutoriallevel2/src/orxonox/gametypes/Gametype.cc
code/branches/tutoriallevel2/src/orxonox/gametypes/Gametype.h
code/branches/tutoriallevel2/src/orxonox/infos/GametypeInfo.cc
code/branches/tutoriallevel2/src/orxonox/infos/GametypeInfo.h
Log:
Replacing GametypeStatus overlay with notifications.
Modified: code/branches/tutoriallevel2/data/overlays/debug.oxo
===================================================================
--- code/branches/tutoriallevel2/data/overlays/debug.oxo 2011-05-11 20:55:30 UTC (rev 8449)
+++ code/branches/tutoriallevel2/data/overlays/debug.oxo 2011-05-11 22:11:53 UTC (rev 8450)
@@ -83,13 +83,5 @@
align = "center"
/>
- <GametypeStatus
- name = "state"
- position = "0.5, 0.85"
- font = "VeraMono"
- textsize = 0.05
- colour = "1.0, 1.0, 0.0, 0.8"
- align = "center"
- />
</OverlayGroup>
</Template>
Modified: code/branches/tutoriallevel2/src/modules/notifications/NotificationQueueCEGUI.cc
===================================================================
--- code/branches/tutoriallevel2/src/modules/notifications/NotificationQueueCEGUI.cc 2011-05-11 20:55:30 UTC (rev 8449)
+++ code/branches/tutoriallevel2/src/modules/notifications/NotificationQueueCEGUI.cc 2011-05-11 22:11:53 UTC (rev 8450)
@@ -49,6 +49,8 @@
// Register tolua_open function when loading the library.
DeclareToluaInterface(Notifications);
+ /*static*/ const std::string NotificationQueueCEGUI::NOTIFICATION_LAYER("NotificationLayer");
+
NotificationQueueCEGUI::NotificationQueueCEGUI(const std::string& name, const std::string& senders, unsigned int size, unsigned int displayTime) : NotificationQueue(name, senders, size, displayTime)
{
RegisterObject(NotificationQueueCEGUI);
@@ -80,7 +82,7 @@
{
// Remove the NotificationQueue in lua.
if(GameMode::showsGraphics() && !noGraphics)
- GUIManager::getInstance().getLuaState()->doString("NotificationLayer.removeQueue(\"" + this->getName() + "\")");
+ GUIManager::getInstance().getLuaState()->doString(NotificationQueueCEGUI::NOTIFICATION_LAYER + ".removeQueue(\"" + this->getName() + "\")");
NotificationQueue::destroy();
}
@@ -109,9 +111,9 @@
this->displaySize_ = size;
if(size.z == 0.0 && size.w == 0.0)
- GUIManager::getInstance().getLuaState()->doString("NotificationLayer.resizeQueue(\"" + this->getName() + "\", " + multi_cast<std::string>(this->displaySize_.x) + ", " + multi_cast<std::string>(this->displaySize_.y) + ")");
+ GUIManager::getInstance().getLuaState()->doString(NotificationQueueCEGUI::NOTIFICATION_LAYER + ".resizeQueue(\"" + this->getName() + "\", " + multi_cast<std::string>(this->displaySize_.x) + ", " + multi_cast<std::string>(this->displaySize_.y) + ")");
else
- GUIManager::getInstance().getLuaState()->doString("NotificationLayer.resizeQueue(\"" + this->getName() + "\", " + multi_cast<std::string>(this->displaySize_.x) + ", " + multi_cast<std::string>(this->displaySize_.y) + ", " + multi_cast<std::string>(this->displaySize_.z) + ", " + multi_cast<std::string>(this->displaySize_.w) + ")");
+ GUIManager::getInstance().getLuaState()->doString(NotificationQueueCEGUI::NOTIFICATION_LAYER + ".resizeQueue(\"" + this->getName() + "\", " + multi_cast<std::string>(this->displaySize_.x) + ", " + multi_cast<std::string>(this->displaySize_.y) + ", " + multi_cast<std::string>(this->displaySize_.z) + ", " + multi_cast<std::string>(this->displaySize_.w) + ")");
}
/**
@@ -136,7 +138,7 @@
}
this->position_ = position;
- GUIManager::getInstance().getLuaState()->doString("NotificationLayer.moveQueue(\"" + this->getName() + "\", " + multi_cast<std::string>(this->position_.x) + ", " + multi_cast<std::string>(this->position_.y) + ", " + multi_cast<std::string>(this->position_.z) + ", " + multi_cast<std::string>(this->position_.w) + ")");
+ GUIManager::getInstance().getLuaState()->doString(NotificationQueueCEGUI::NOTIFICATION_LAYER + ".moveQueue(\"" + this->getName() + "\", " + multi_cast<std::string>(this->position_.x) + ", " + multi_cast<std::string>(this->position_.y) + ", " + multi_cast<std::string>(this->position_.z) + ", " + multi_cast<std::string>(this->position_.w) + ")");
}
/**
@@ -153,7 +155,7 @@
// TODO: Check whether the alignment string is correct?
this->alignment_ = alignment;
- GUIManager::getInstance().getLuaState()->doString("NotificationLayer.changeQueueAlignment(\"" + this->getName() + "\", \"" + this->alignment_ + "\")");
+ GUIManager::getInstance().getLuaState()->doString(NotificationQueueCEGUI::NOTIFICATION_LAYER + ".changeQueueAlignment(\"" + this->getName() + "\", \"" + this->alignment_ + "\")");
}
/**
@@ -168,7 +170,7 @@
return;
this->fontSize_ = size;
- GUIManager::getInstance().getLuaState()->doString("NotificationLayer.changeQueueFontSize(\"" + this->getName() + "\", " + multi_cast<std::string>(this->fontSize_) + ")");
+ GUIManager::getInstance().getLuaState()->doString(NotificationQueueCEGUI::NOTIFICATION_LAYER + ".changeQueueFontSize(\"" + this->getName() + "\", " + multi_cast<std::string>(this->fontSize_) + ")");
}
/**
@@ -188,7 +190,7 @@
for(unsigned int i = 0; i < 4; i++)
stream << std::hex << std::setw(2) << std::setfill('0') << int(this->fontColor_[(i+3)%4]*255);
this->fontColorStr_ = stream.str();
- GUIManager::getInstance().getLuaState()->doString("NotificationLayer.changeQueueFontColor(\"" + this->getName() + "\", \"" + this->fontColorStr_ + "\")");
+ GUIManager::getInstance().getLuaState()->doString(NotificationQueueCEGUI::NOTIFICATION_LAYER + ".changeQueueFontColor(\"" + this->getName() + "\", \"" + this->fontColorStr_ + "\")");
}
/**
@@ -217,7 +219,7 @@
{
// Push the Notification to the GUI.
if(GameMode::showsGraphics())
- GUIManager::getInstance().getLuaState()->doString("NotificationLayer.pushNotification(\"" + this->getName() + "\", \"" + notification->getMessage() + "\")");
+ GUIManager::getInstance().getLuaState()->doString(NotificationQueueCEGUI::NOTIFICATION_LAYER + ".pushNotification(\"" + this->getName() + "\", \"" + notification->getMessage() + "\")");
}
/**
@@ -228,7 +230,7 @@
{
// Pops the Notification from the GUI.
if(GameMode::showsGraphics())
- GUIManager::getInstance().getLuaState()->doString("NotificationLayer.popNotification(\"" + this->getName() + "\")");
+ GUIManager::getInstance().getLuaState()->doString(NotificationQueueCEGUI::NOTIFICATION_LAYER + ".popNotification(\"" + this->getName() + "\")");
}
/**
@@ -239,7 +241,7 @@
{
// Removes the Notification from the GUI.
if(GameMode::showsGraphics())
- GUIManager::getInstance().getLuaState()->doString("NotificationLayer.removeNotification(\"" + this->getName() + "\", " + multi_cast<std::string>(index) + ")");
+ GUIManager::getInstance().getLuaState()->doString(NotificationQueueCEGUI::NOTIFICATION_LAYER + ".removeNotification(\"" + this->getName() + "\", " + multi_cast<std::string>(index) + ")");
}
/**
@@ -254,7 +256,7 @@
// Clear the NotificationQueue in the GUI.
if(GameMode::showsGraphics() && !noGraphics)
- GUIManager::getInstance().getLuaState()->doString("NotificationLayer.clearQueue(\"" + this->getName() + "\")");
+ GUIManager::getInstance().getLuaState()->doString(NotificationQueueCEGUI::NOTIFICATION_LAYER + ".clearQueue(\"" + this->getName() + "\")");
}
/**
@@ -264,7 +266,7 @@
void NotificationQueueCEGUI::create(void)
{
if(GameMode::showsGraphics())
- GUIManager::getInstance().getLuaState()->doString("NotificationLayer.createQueue(\"" + this->getName() + "\", " + multi_cast<std::string>(this->getMaxSize()) + ")");
+ GUIManager::getInstance().getLuaState()->doString(NotificationQueueCEGUI::NOTIFICATION_LAYER + ".createQueue(\"" + this->getName() + "\", " + multi_cast<std::string>(this->getMaxSize()) + ")");
}
}
Modified: code/branches/tutoriallevel2/src/modules/notifications/NotificationQueueCEGUI.h
===================================================================
--- code/branches/tutoriallevel2/src/modules/notifications/NotificationQueueCEGUI.h 2011-05-11 20:55:30 UTC (rev 8449)
+++ code/branches/tutoriallevel2/src/modules/notifications/NotificationQueueCEGUI.h 2011-05-11 22:11:53 UTC (rev 8450)
@@ -126,7 +126,7 @@
inline const std::string& getFontColorStr(void) const
{ return this->fontColorStr_; }
- static NotificationQueueCEGUI* getQueue(const std::string& name); // tolua_export
+ static NotificationQueueCEGUI* getQueue(const std::string& name); // tolua_export // Get the NotificationQueueCEGUI with the input name.
protected:
virtual void notificationPushed(Notification* notification); // Is called by the NotificationQueue when a notification was pushed
@@ -134,6 +134,9 @@
virtual void notificationRemoved(unsigned int index); // Is called when a notification was removed.
virtual void clear(bool noGraphics = false); // Clears the NotificationQueue by removing all NotificationContainers.
+
+ protected:
+ static const std::string NOTIFICATION_LAYER; //!< The name of the NotificationLayer menu sheet.
private:
Vector4 displaySize_; //!< The size of the window that displays the NotificationQueue.
Modified: code/branches/tutoriallevel2/src/modules/overlays/hud/CMakeLists.txt
===================================================================
--- code/branches/tutoriallevel2/src/modules/overlays/hud/CMakeLists.txt 2011-05-11 20:55:30 UTC (rev 8449)
+++ code/branches/tutoriallevel2/src/modules/overlays/hud/CMakeLists.txt 2011-05-11 22:11:53 UTC (rev 8450)
@@ -6,7 +6,6 @@
HUDHealthBar.cc
HUDTimer.cc
ChatOverlay.cc
- GametypeStatus.cc
AnnounceMessage.cc
KillMessage.cc
DeathMessage.cc
Deleted: code/branches/tutoriallevel2/src/modules/overlays/hud/GametypeStatus.cc
===================================================================
--- code/branches/tutoriallevel2/src/modules/overlays/hud/GametypeStatus.cc 2011-05-11 20:55:30 UTC (rev 8449)
+++ code/branches/tutoriallevel2/src/modules/overlays/hud/GametypeStatus.cc 2011-05-11 22:11:53 UTC (rev 8450)
@@ -1,126 +0,0 @@
-/*
- * ORXONOX - the hottest 3D action shooter ever to exist
- * > www.orxonox.net <
- *
- *
- * License notice:
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * Author:
- * Fabian 'x3n' Landau
- * Co-authors:
- * ...
- *
- */
-
-#include "GametypeStatus.h"
-
-#include "util/Convert.h"
-#include "core/CoreIncludes.h"
-#include "core/command/ConsoleCommand.h"
-#include "infos/GametypeInfo.h"
-#include "infos/PlayerInfo.h"
-#include "worldentities/ControllableEntity.h"
-#include "worldentities/pawns/Spectator.h"
-//#include "gametypes/Gametype.h"
-
-namespace orxonox
-{
- CreateFactory(GametypeStatus);
-
- static const std::string __CC_GametypeStatus_name = "GametypeStatus";
- static const std::string __CC_displayCaption_name = "displayCaption";
-
- SetConsoleCommand(__CC_GametypeStatus_name, __CC_displayCaption_name, &GametypeStatus::setDisplayCaption);
-
- GametypeStatus::GametypeStatus(BaseObject* creator) : OverlayText(creator)
- {
- RegisterObject(GametypeStatus);
-
- //this->game_ = 0;
- this->owner_ = 0;
- this->bNoCaption_ = false;
- //this->bForcedSpawn_ = false;
-
- ModifyConsoleCommand(__CC_GametypeStatus_name, __CC_displayCaption_name).setObject(this);
- }
-
- GametypeStatus::~GametypeStatus()
- {
- ModifyConsoleCommand(__CC_GametypeStatus_name, __CC_displayCaption_name).setObject(0);
- }
-
- void GametypeStatus::tick(float dt)
- {
- SUPER(GametypeStatus, tick, dt);
-
- if (this->owner_ && this->owner_->getGametypeInfo() && this->owner_->getControllableEntity())
- {
- //if (this->game_)
- // this->bForcedSpawn_ = this->game_->getForceSpawn();
- //else
- // this->bForcedSpawn_ = false;
-
- const GametypeInfo* gtinfo = this->owner_->getGametypeInfo();
- ControllableEntity* ce = this->owner_->getControllableEntity();
-
- if (this->bNoCaption_) // No captions are displayed.
- {
- this->setCaption("");
- return;
- }
-
- if (!gtinfo->hasStarted() && !gtinfo->isStartCountdownRunning())
- {
- if (!this->owner_->isReadyToSpawn())
- this->setCaption("Press [Fire] to start the match");
- else
- this->setCaption("Waiting for other players");
- }
- else if (!gtinfo->hasEnded())
- {
- if (gtinfo->isStartCountdownRunning())
- this->setCaption(multi_cast<std::string>(static_cast<int>(ceil(gtinfo->getStartCountdown()))));
- else if (ce->isA(Class(Spectator))/*&&(!bForcedSpawn_)*/)
- this->setCaption("Press [Fire] to respawn");
- else
- this->setCaption("");
- }
- else
- this->setCaption("Game has ended");
- }
- }
-
-
- void GametypeStatus::changedOwner()
- {
- SUPER(GametypeStatus, changedOwner);
- //this->game_ = orxonox_cast<Gametype*>(this->getOwner());
- this->owner_ = orxonox_cast<PlayerInfo*>(this->getOwner());
- }
-
- /**
- @brief
- Sets whether the gametype status is displayed.
- @param bValue
- If true captions are displayed, if false, not.
- */
- void GametypeStatus::setDisplayCaption(bool bValue)
- {
- this->bNoCaption_ = !bValue;
- }
-
-}
Deleted: code/branches/tutoriallevel2/src/modules/overlays/hud/GametypeStatus.h
===================================================================
--- code/branches/tutoriallevel2/src/modules/overlays/hud/GametypeStatus.h 2011-05-11 20:55:30 UTC (rev 8449)
+++ code/branches/tutoriallevel2/src/modules/overlays/hud/GametypeStatus.h 2011-05-11 22:11:53 UTC (rev 8450)
@@ -1,58 +0,0 @@
-/*
- * ORXONOX - the hottest 3D action shooter ever to exist
- * > www.orxonox.net <
- *
- *
- * License notice:
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * Author:
- * Fabian 'x3n' Landau
- * Co-authors:
- * ...
- *
- */
-
-#ifndef _GametypeStatus_H__
-#define _GametypeStatus_H__
-
-#include "overlays/OverlaysPrereqs.h"
-
-#include "tools/interfaces/Tickable.h"
-#include "overlays/OverlayText.h"
-
-namespace orxonox
-{
- class _OverlaysExport GametypeStatus : public OverlayText, public Tickable
- {
- public:
- GametypeStatus(BaseObject* creator);
- virtual ~GametypeStatus();
-
- virtual void tick(float dt);
- virtual void changedOwner();
-
- void setDisplayCaption(bool bValue); //!< Toggles whether the gametype status is displayed.
-
- private:
- //Gametype* game_;
- PlayerInfo* owner_;
- bool bNoCaption_;
- //bool bForcedSpawn_;
-
- };
-}
-#endif /* _GametypeStatus_H__ */
Modified: code/branches/tutoriallevel2/src/orxonox/gametypes/Gametype.cc
===================================================================
--- code/branches/tutoriallevel2/src/orxonox/gametypes/Gametype.cc 2011-05-11 20:55:30 UTC (rev 8449)
+++ code/branches/tutoriallevel2/src/orxonox/gametypes/Gametype.cc 2011-05-11 22:11:53 UTC (rev 8450)
@@ -58,6 +58,8 @@
this->defaultControllableEntity_ = Class(Spectator);
+ this->bFirstTick_ = true;
+
this->bAutoStart_ = false;
this->bForceSpawn_ = false;
this->numberOfBots_ = 0;
@@ -111,6 +113,13 @@
{
SUPER(Gametype, tick, dt);
+ // Activate the GametypeInfo.
+ if(this->bFirstTick_)
+ {
+ this->gtinfo_->setActive(true);
+ this->bFirstTick_ = false;
+ }
+
//count timer
if (timerIsActive_)
{
@@ -120,12 +129,12 @@
this->time_ -= dt;
}
- if (this->gtinfo_->bStartCountdownRunning_ && !this->gtinfo_->bStarted_)
- this->gtinfo_->startCountdown_ -= dt;
+ if (this->gtinfo_->isStartCountdownRunning() && !this->gtinfo_->hasStarted())
+ this->gtinfo_->countdownStartCountdown(dt);
- if (!this->gtinfo_->bStarted_)
+ if (!this->gtinfo_->hasStarted())
this->checkStart();
- else if (!this->gtinfo_->bEnded_)
+ else if (!this->gtinfo_->hasEnded())
this->spawnDeadPlayersIfRequested();
this->assignDefaultPawnsIfNeeded();
@@ -135,14 +144,14 @@
{
this->addBots(this->numberOfBots_);
- this->gtinfo_->bStarted_ = true;
+ this->gtinfo_->start();
this->spawnPlayersIfRequested();
}
void Gametype::end()
{
- this->gtinfo_->bEnded_ = true;
+ this->gtinfo_->end();
for (std::map<PlayerInfo*, Player>::iterator it = this->players_.begin(); it != this->players_.end(); ++it)
{
@@ -269,6 +278,9 @@
}
}
+ if(victim->getPlayer()->isHumanPlayer())
+ this->gtinfo_->pawnKilled(victim->getPlayer());
+
ControllableEntity* entity = this->defaultControllableEntity_.fabricate(victim->getCreator());
if (victim->getCamera())
{
@@ -345,7 +357,7 @@
{
it->second.state_ = PlayerState::Dead;
- if (!it->first->isReadyToSpawn() || !this->gtinfo_->bStarted_)
+ if (!it->first->isReadyToSpawn() || !this->gtinfo_->hasStarted())
{
this->spawnPlayerAsDefaultPawn(it->first);
it->second.state_ = PlayerState::Dead;
@@ -356,14 +368,14 @@
void Gametype::checkStart()
{
- if (!this->gtinfo_->bStarted_)
+ if (!this->gtinfo_->hasStarted())
{
- if (this->gtinfo_->bStartCountdownRunning_)
+ if (this->gtinfo_->isStartCountdownRunning())
{
- if (this->gtinfo_->startCountdown_ <= 0)
+ if (this->gtinfo_->getStartCountdown() <= 0.0f)
{
- this->gtinfo_->bStartCountdownRunning_ = false;
- this->gtinfo_->startCountdown_ = 0;
+ this->gtinfo_->stopStartCountdown();
+ this->gtinfo_->setStartCountdown(0.0f);;
this->start();
}
}
@@ -383,15 +395,20 @@
allplayersready = false;
if (it->first->isHumanPlayer())
hashumanplayers = true;
+
+ // Inform the GametypeInfo that the player is ready to spawn.
+ // TODO: Can it happen, that that changes?
+ if(it->first->isHumanPlayer() && it->first->isReadyToSpawn())
+ this->gtinfo_->playerReadyToSpawn(it->first);
}
if (allplayersready && hashumanplayers)
{
// If in developer's mode, there is no start countdown.
if(Core::getInstance().inDevMode())
- this->gtinfo_->startCountdown_ = 0;
+ this->start();
else
- this->gtinfo_->startCountdown_ = this->initialStartCountdown_;
- this->gtinfo_->bStartCountdownRunning_ = true;
+ this->gtinfo_->setStartCountdown(this->initialStartCountdown_);
+ this->gtinfo_->startStartCountdown();
}
}
}
@@ -401,8 +418,10 @@
void Gametype::spawnPlayersIfRequested()
{
for (std::map<PlayerInfo*, Player>::iterator it = this->players_.begin(); it != this->players_.end(); ++it)
+ {
if (it->first->isReadyToSpawn() || this->bForceSpawn_)
this->spawnPlayer(it->first);
+ }
}
void Gametype::spawnDeadPlayersIfRequested()
@@ -421,6 +440,10 @@
this->playerPreSpawn(player);
player->startControl(spawnpoint->spawn());
this->players_[player].state_ = PlayerState::Alive;
+
+ if(player->isHumanPlayer())
+ this->gtinfo_->playerSpawned(player);
+
this->playerPostSpawn(player);
}
else
Modified: code/branches/tutoriallevel2/src/orxonox/gametypes/Gametype.h
===================================================================
--- code/branches/tutoriallevel2/src/orxonox/gametypes/Gametype.h 2011-05-11 20:55:30 UTC (rev 8449)
+++ code/branches/tutoriallevel2/src/orxonox/gametypes/Gametype.h 2011-05-11 22:11:53 UTC (rev 8450)
@@ -77,9 +77,9 @@
{ return this->gtinfo_; }
inline bool hasStarted() const
- { return this->gtinfo_->bStarted_; }
+ { return this->gtinfo_->hasStarted(); }
inline bool hasEnded() const
- { return this->gtinfo_->bEnded_; }
+ { return this->gtinfo_->hasEnded(); }
virtual void start();
virtual void end();
@@ -113,14 +113,14 @@
{ this->spawnpoints_.insert(spawnpoint); }
inline bool isStartCountdownRunning() const
- { return this->gtinfo_->bStartCountdownRunning_; }
+ { return this->gtinfo_->isStartCountdownRunning(); }
inline float getStartCountdown() const
- { return this->gtinfo_->startCountdown_; }
+ { return this->gtinfo_->getStartCountdown(); }
inline void setHUDTemplate(const std::string& name)
- { this->gtinfo_->hudtemplate_ = name; }
+ { this->gtinfo_->setHUDTemplate(name); }
inline const std::string& getHUDTemplate() const
- { return this->gtinfo_->hudtemplate_; }
+ { return this->gtinfo_->getHUDTemplate(); }
void addBots(unsigned int amount);
void killBots(unsigned int amount = 0);
@@ -167,6 +167,8 @@
SmartPtr<GametypeInfo> gtinfo_;
+ bool bFirstTick_; //!< Whether this is the first tick or not.
+
bool bAutoStart_;
bool bForceSpawn_;
Modified: code/branches/tutoriallevel2/src/orxonox/infos/GametypeInfo.cc
===================================================================
--- code/branches/tutoriallevel2/src/orxonox/infos/GametypeInfo.cc 2011-05-11 20:55:30 UTC (rev 8449)
+++ code/branches/tutoriallevel2/src/orxonox/infos/GametypeInfo.cc 2011-05-11 22:11:53 UTC (rev 8450)
@@ -22,18 +22,28 @@
* Author:
* Fabian 'x3n' Landau
* Co-authors:
- * ...
+ * Damian 'Mozork' Frick
*
*/
+/**
+ @file GametypeInfo.cc
+ @brief Implementation of the GametypeInfo class
+*/
+
#include "GametypeInfo.h"
#include "core/CoreIncludes.h"
#include "core/GameMode.h"
+#include "network/Host.h"
#include "network/NetworkFunction.h"
-#include "network/Host.h"
+#include "util/Convert.h"
+
#include "interfaces/GametypeMessageListener.h"
+#include "interfaces/NotificationListener.h"
+#include "PlayerInfo.h"
+
namespace orxonox
{
CreateUnloadableFactory(GametypeInfo);
@@ -44,14 +54,23 @@
registerMemberNetworkFunction(GametypeInfo, dispatchStaticMessage);
registerMemberNetworkFunction(GametypeInfo, dispatchFadingMessage);
+ /*static*/ const std::string GametypeInfo::NOTIFICATION_SENDER("gameinfo");
+
+ /**
+ @brief
+ Registers and initializes the object.
+ */
GametypeInfo::GametypeInfo(BaseObject* creator) : Info(creator)
{
RegisterObject(GametypeInfo);
+ this->bActive_ = false; // At first the GametypeInfo is inactive.
+
this->bStarted_ = false;
this->bEnded_ = false;
- this->startCountdown_ = 0;
+ this->startCountdown_ = 0.0f;
this->bStartCountdownRunning_ = false;
+ this->counter_ = 0;
this->registerVariables();
}
@@ -62,13 +81,226 @@
void GametypeInfo::registerVariables()
{
- registerVariable(this->bStarted_, VariableDirection::ToClient);
- registerVariable(this->bEnded_, VariableDirection::ToClient);
+ registerVariable(this->bStarted_, VariableDirection::ToClient, new NetworkCallback<GametypeInfo>(this, &GametypeInfo::changedStarted));
+ registerVariable(this->bEnded_, VariableDirection::ToClient, new NetworkCallback<GametypeInfo>(this, &GametypeInfo::changedEnded));
+ registerVariable(this->bStartCountdownRunning_, VariableDirection::ToClient, new NetworkCallback<GametypeInfo>(this, &GametypeInfo::changedStartCountdownRunning));
registerVariable(this->startCountdown_, VariableDirection::ToClient);
- registerVariable(this->bStartCountdownRunning_, VariableDirection::ToClient);
+ registerVariable(this->counter_, VariableDirection::ToClient, new NetworkCallback<GametypeInfo>(this, &GametypeInfo::changedCountdownCounter));
registerVariable(this->hudtemplate_, VariableDirection::ToClient);
}
+ /**
+ @brief
+ Is called when the activity has changed.
+ */
+ void GametypeInfo::changedActivity(void)
+ {
+ SUPER(GametypeInfo, changedActivity);
+
+ // If the GametypeInfo has become active the "Press [Fire] to start the match" notification is sent.
+ if(this->isActive())
+ NotificationListener::sendNotification("Press [Fire] to start the match", GametypeInfo::NOTIFICATION_SENDER);
+ }
+
+ /**
+ @brief
+ Is called when the game has changed to started.
+ */
+ void GametypeInfo::changedStarted(void)
+ {
+
+ }
+
+ /**
+ @brief
+ Is called when the game has changed to ended.
+ */
+ void GametypeInfo::changedEnded(void)
+ {
+ // If the game has ended, a "Game has ended" notification is displayed.
+ if(this->hasEnded())
+ NotificationListener::sendNotification("Game has ended", GametypeInfo::NOTIFICATION_SENDER);
+ }
+
+ /**
+ @brief
+ Is called when the start countdown has been either started or stopped.
+ */
+ void GametypeInfo::changedStartCountdownRunning(void)
+ {
+ // Clear the notifications if the countdown has stopped running.
+ if(!this->hasStarted() && !this->isStartCountdownRunning() && !this->hasEnded())
+ NotificationListener::sendCommand("clear", GametypeInfo::NOTIFICATION_SENDER);
+ // Send first countdown notification if the countdown has started.
+ if(!this->hasStarted() && this->isStartCountdownRunning() && !this->hasEnded())
+ NotificationListener::sendNotification(multi_cast<std::string>(this->counter_), GametypeInfo::NOTIFICATION_SENDER);
+ }
+
+ /**
+ @brief
+ Is called when the start countdown counter has changed.
+ */
+ void GametypeInfo::changedCountdownCounter(void)
+ {
+ // Send countdown notification if the counter has gone down.
+ if(!this->hasStarted() && this->isStartCountdownRunning() && !this->hasEnded())
+ NotificationListener::sendNotification(multi_cast<std::string>(this->counter_), GametypeInfo::NOTIFICATION_SENDER);
+ }
+
+ /**
+ @brief
+ Is called when a player has become ready to spawn.
+ @param player
+ The player that has become ready to spawn.
+ */
+ void GametypeInfo::changedReadyToSpawn(PlayerInfo* player)
+ {
+ // Send "Waiting for other players" over the network to the right player if a player has become ready to spawn.
+ if(!this->hasStarted() && !this->isStartCountdownRunning() && !this->hasEnded())
+ NotificationListener::sendNotification("Waiting for other players", GametypeInfo::NOTIFICATION_SENDER, notificationMessageType::info, notificationSendMode::network, player->getClientID());
+ // Clear the notifications if the player has respawned.
+ if(this->hasStarted() && !this->hasEnded())
+ NotificationListener::sendCommand("clear", GametypeInfo::NOTIFICATION_SENDER, notificationSendMode::network, player->getClientID());
+ }
+
+ /**
+ @brief
+ Inform the GametypeInfo that the game has started.
+ */
+ void GametypeInfo::start(void)
+ {
+ if(this->bStarted_)
+ return;
+
+ this->bStarted_ = true;
+ this->changedStarted();
+ }
+
+ /**
+ @brief
+ Inform the GametypeInfo that the game has ended.
+ */
+ void GametypeInfo::end(void)
+ {
+ if(this->bEnded_)
+ return;
+
+ this->bEnded_ = true;
+ this->changedEnded();
+ }
+
+ /**
+ @brief
+ Set the start countdown to the input value.
+ @param countdown
+ The countdown to be set.
+ */
+ void GametypeInfo::setStartCountdown(float countdown)
+ {
+ if(this->startCountdown_ == countdown || countdown < 0.0f)
+ return;
+
+ this->startCountdown_ = countdown;
+ // Set the counter to the ceiling of the current countdown.
+ this->counter_ = ceil(countdown);
+ this->changedCountdownCounter();
+ }
+
+ /**
+ @brief
+ Count down the start countdown by the specified value.
+ @param countDown
+ The amount by which we count down.
+ */
+ void GametypeInfo::countdownStartCountdown(float countDown)
+ {
+ float newCountdown = this->startCountdown_ - countDown;
+ // If we have switched integers or arrived at zero, we also count down the start countdown counter.
+ if(ceil(newCountdown) != ceil(this->startCountdown_) || newCountdown <= 0.0f)
+ this->countDown();
+ this->startCountdown_ = newCountdown;
+ }
+
+ /**
+ @brief
+ Count down the start countdown counter.
+ */
+ void GametypeInfo::countDown()
+ {
+ if(this->counter_ == 0)
+ return;
+
+ this->counter_--;
+ this->changedCountdownCounter();
+ }
+
+ /**
+ @brief
+ Inform the GametypeInfo about the start of the start countdown.
+ */
+ void GametypeInfo::startStartCountdown(void)
+ {
+ if(this->bStartCountdownRunning_)
+ return;
+
+ this->bStartCountdownRunning_ = true;
+ this->changedStartCountdownRunning();
+ }
+
+ /**
+ @brief
+ Inform the GametypeInfo about the stop of the start countdown.
+ */
+ void GametypeInfo::stopStartCountdown(void)
+ {
+ if(!this->bStartCountdownRunning_)
+ return;
+
+ this->bStartCountdownRunning_ = false;
+ this->changedStartCountdownRunning();
+ }
+
+ /**
+ @brief
+ Inform the GametypeInfo about a player that is ready to spawn.
+ @param player
+ The player that is ready to spawn.
+ */
+ void GametypeInfo::playerReadyToSpawn(PlayerInfo* player)
+ {
+ // If the player has spawned already.
+ if(this->spawned_.find(player) != this->spawned_.end())
+ return;
+
+ this->spawned_.insert(player);
+ this->changedReadyToSpawn(player);
+ }
+
+ /**
+ @brief
+ Inform the GametypeInfo about a player whose Pawn has been killed.
+ @param player
+ The player whose Pawn has been killed.
+ */
+ void GametypeInfo::pawnKilled(PlayerInfo* player)
+ {
+ NotificationListener::sendNotification("Press [Fire] to respawn", GametypeInfo::NOTIFICATION_SENDER, notificationMessageType::info, notificationSendMode::network, player->getClientID());
+ // Remove the player from the list of players that have spawned, since it currently is not.
+ this->spawned_.erase(player);
+ }
+
+ /**
+ @brief
+ Inform the GametypeInfo about a player that has spawned.
+ @param player
+ The player that has spawned.
+ */
+ void GametypeInfo::playerSpawned(PlayerInfo* player)
+ {
+ if(this->hasStarted() && !this->hasEnded())
+ NotificationListener::sendCommand("clear", GametypeInfo::NOTIFICATION_SENDER, notificationSendMode::network, player->getClientID());
+ }
+
void GametypeInfo::sendAnnounceMessage(const std::string& message)
{
if (GameMode::isMaster())
Modified: code/branches/tutoriallevel2/src/orxonox/infos/GametypeInfo.h
===================================================================
--- code/branches/tutoriallevel2/src/orxonox/infos/GametypeInfo.h 2011-05-11 20:55:30 UTC (rev 8449)
+++ code/branches/tutoriallevel2/src/orxonox/infos/GametypeInfo.h 2011-05-11 22:11:53 UTC (rev 8450)
@@ -22,20 +22,36 @@
* Author:
* Fabian 'x3n' Landau
* Co-authors:
- * ...
+ * Damian 'Mozork' Frick
*
*/
+/**
+ @file GametypeInfo.h
+ @brief Definition of the GametypeInfo class
+*/
+
#ifndef _GametypeInfo_H__
#define _GametypeInfo_H__
#include "OrxonoxPrereqs.h"
#include <string>
+
#include "Info.h"
namespace orxonox
{
+
+ /**
+ @brief
+ The GametypeInfo class keeps track of the state of the game and provides facilities to inform the player about it.
+
+ @author
+ Fabian 'x3n' Landau
+ @author
+ Damian 'Mozork' Frick
+ */
class _OrxonoxExport GametypeInfo : public Info
{
friend class Gametype;
@@ -44,16 +60,48 @@
GametypeInfo(BaseObject* creator);
virtual ~GametypeInfo();
+ virtual void changedActivity(void); // Is called when the activity has changed.
+
+ /**
+ @brief Get whether the game has started yet.
+ @return Returns true if the game has started, false if not.
+ */
inline bool hasStarted() const
{ return this->bStarted_; }
+ void changedStarted(void); // Is called when the game has changed to started.
+
+ /**
+ @brief Get whether the game has ended yet.
+ @return Returns true if the game has ended, false if not.
+ */
inline bool hasEnded() const
{ return this->bEnded_; }
+ void changedEnded(void); // Is called when the game has changed to ended.
+ /**
+ @brief Get whether the start countdown is currently running.
+ @return Returns true if the countdown is running, false if not.
+ */
inline bool isStartCountdownRunning() const
{ return this->bStartCountdownRunning_; }
+ void changedStartCountdownRunning(void); // Is called when the start countdown has been either started or stopped.
+
+ /**
+ @brief Get the current value of the start countdown.
+ @return Returns the current value of the start countdown.
+ */
inline float getStartCountdown() const
{ return this->startCountdown_; }
+ /**
+ @brief Get the current start countdown counter.
+ The start countdown counter only has integer values that correspond to the actually displayed countdown.
+ @return Returns the current integer countdown counter.
+ */
+ inline unsigned int getStartCountdownCounter() const
+ { return this->counter_; }
+ void changedCountdownCounter(void); // Is called when the start countdown counter has changed.
+
inline const std::string& getHUDTemplate() const
{ return this->hudtemplate_; }
@@ -69,15 +117,37 @@
void dispatchDeathMessage(const std::string& message);
void dispatchStaticMessage(const std::string& message,const ColourValue& colour);
void dispatchFadingMessage(const std::string& message);
+
+ protected:
+ void changedReadyToSpawn(PlayerInfo* player); // Is called when a player has become ready to spawn.
+
+ void start(void); // Inform the GametypeInfo that the game has started.
+ void end(void); // Inform the GametypeInfo that the game has ended.
+ void setStartCountdown(float countdown); // Set the start countdown to the input value.
+ void countdownStartCountdown(float countDown); // Count down the start countdown by the specified value.
+ void countDown(); // Count down the start countdown counter.
+ void startStartCountdown(void); // Inform the GametypeInfo about the start of the start countdown.
+ void stopStartCountdown(void); // Inform the GametypeInfo about the stop of the start countdown.
+ void playerReadyToSpawn(PlayerInfo* player); // Inform the GametypeInfo about a player that is ready to spawn.
+ void pawnKilled(PlayerInfo* player); // Inform the GametypeInfo about a player whose Pawn has been killed.
+ void playerSpawned(PlayerInfo* player); // Inform the GametypeInfo about a player that has spawned.
+ inline void setHUDTemplate(const std::string& templateName)
+ { this->hudtemplate_ = templateName; };
+
private:
void registerVariables();
- bool bStarted_;
- bool bEnded_;
- bool bStartCountdownRunning_;
- float startCountdown_;
+ static const std::string NOTIFICATION_SENDER; //!< The name of the sender for the sending of notifications.
+
+ bool bStarted_; //!< Whether the game has started,
+ bool bEnded_; //!< Whether the game has ended.
+ bool bStartCountdownRunning_; //!< Whether the start countdown is running.
+ float startCountdown_; //!< The current value of the start countdown.
+ unsigned int counter_; //!< The current integer value of the start countdown, the start countdown counter.
std::string hudtemplate_;
+
+ std::set<PlayerInfo*> spawned_; //!< A set of players that are currently spawned.
};
}
More information about the Orxonox-commit
mailing list