[Orxonox-commit 128] r2820 - branches/miniprojects/src/orxonox/objects/gametypes

landauf at orxonox.net landauf at orxonox.net
Mon Mar 23 00:44:22 CET 2009


Author: landauf
Date: 2009-03-22 23:44:10 +0000 (Sun, 22 Mar 2009)
New Revision: 2820

Added:
   branches/miniprojects/src/orxonox/objects/gametypes/Deathmatch.cc
   branches/miniprojects/src/orxonox/objects/gametypes/Deathmatch.h
Modified:
   branches/miniprojects/src/orxonox/objects/gametypes/CMakeLists.txt
   branches/miniprojects/src/orxonox/objects/gametypes/Gametype.cc
   branches/miniprojects/src/orxonox/objects/gametypes/Gametype.h
   branches/miniprojects/src/orxonox/objects/gametypes/TeamGametype.cc
   branches/miniprojects/src/orxonox/objects/gametypes/TeamGametype.h
Log:
Split Gametype into Gametype+Deathmatch. The only difference is output like "player x killed player y" which only appears in Deathmatch now. TeamGametype inherits from Deathmatch (and will shortly be renamed into TeamDeathmatch).

Modified: branches/miniprojects/src/orxonox/objects/gametypes/CMakeLists.txt
===================================================================
--- branches/miniprojects/src/orxonox/objects/gametypes/CMakeLists.txt	2009-03-22 20:59:34 UTC (rev 2819)
+++ branches/miniprojects/src/orxonox/objects/gametypes/CMakeLists.txt	2009-03-22 23:44:10 UTC (rev 2820)
@@ -1,4 +1,5 @@
 ADD_SOURCE_FILES(ORXONOX_SRC_FILES
   Gametype.cc
+  Deathmatch.cc
   TeamGametype.cc
 )

Added: branches/miniprojects/src/orxonox/objects/gametypes/Deathmatch.cc
===================================================================
--- branches/miniprojects/src/orxonox/objects/gametypes/Deathmatch.cc	                        (rev 0)
+++ branches/miniprojects/src/orxonox/objects/gametypes/Deathmatch.cc	2009-03-22 23:44:10 UTC (rev 2820)
@@ -0,0 +1,119 @@
+/*
+ *   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 "OrxonoxStableHeaders.h"
+#include "Deathmatch.h"
+
+#include "core/CoreIncludes.h"
+#include "objects/infos/PlayerInfo.h"
+#include "objects/worldentities/pawns/Pawn.h"
+
+#include "network/Host.h"
+
+namespace orxonox
+{
+    CreateUnloadableFactory(Deathmatch);
+
+    Deathmatch::Deathmatch(BaseObject* creator) : Gametype(creator)
+    {
+        RegisterObject(Deathmatch);
+    }
+
+    void Deathmatch::start()
+    {
+        Gametype::start();
+
+        COUT(0) << "game started" << std::endl;
+    }
+
+    void Deathmatch::end()
+    {
+        Gametype::end();
+
+        COUT(0) << "game ended" << std::endl;
+    }
+
+    void Deathmatch::playerEntered(PlayerInfo* player)
+    {
+        Gametype::playerEntered(player);
+
+        std::string message = player->getName() + " entered the game";
+        COUT(0) << message << std::endl;
+        Host::Broadcast(message);
+    }
+
+    bool Deathmatch::playerLeft(PlayerInfo* player)
+    {
+        bool valid_player = Gametype::playerLeft(player);
+
+        if (valid_player)
+        {
+            std::string message = player->getName() + " left the game";
+            COUT(0) << message << std::endl;
+            Host::Broadcast(message);
+        }
+
+        return valid_player;
+    }
+
+    bool Deathmatch::playerChangedName(PlayerInfo* player)
+    {
+        bool valid_player = Gametype::playerChangedName(player);
+
+        if (valid_player)
+        {
+            std::string message = player->getOldName() + " changed name to " + player->getName();
+            COUT(0) << message << std::endl;
+            Host::Broadcast(message);
+        }
+
+        return valid_player;
+    }
+
+    void Deathmatch::pawnKilled(Pawn* victim, Pawn* killer)
+    {
+        if (victim && victim->getPlayer())
+        {
+            std::string message;
+            if (killer)
+            {
+                if (killer->getPlayer())
+                    message = victim->getPlayer()->getName() + " was killed by " + killer->getPlayer()->getName();
+                else
+                    message = victim->getPlayer()->getName() + " was killed";
+            }
+            else
+                message = victim->getPlayer()->getName() + " died";
+
+            COUT(0) << message << std::endl;
+            Host::Broadcast(message);
+        }
+
+        Gametype::pawnKilled(victim, killer);
+    }
+}

Added: branches/miniprojects/src/orxonox/objects/gametypes/Deathmatch.h
===================================================================
--- branches/miniprojects/src/orxonox/objects/gametypes/Deathmatch.h	                        (rev 0)
+++ branches/miniprojects/src/orxonox/objects/gametypes/Deathmatch.h	2009-03-22 23:44:10 UTC (rev 2820)
@@ -0,0 +1,54 @@
+/*
+ *   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 _Deathmatch_H__
+#define _Deathmatch_H__
+
+#include "OrxonoxPrereqs.h"
+
+#include "Gametype.h"
+
+namespace orxonox
+{
+    class _OrxonoxExport Deathmatch : public Gametype
+    {
+        public:
+            Deathmatch(BaseObject* creator);
+            virtual ~Deathmatch() {}
+
+            virtual void start();
+            virtual void end();
+            virtual void playerEntered(PlayerInfo* player);
+            virtual bool playerLeft(PlayerInfo* player);
+            virtual bool playerChangedName(PlayerInfo* player);
+
+            virtual void pawnKilled(Pawn* victim, Pawn* killer = 0);
+    };
+}
+
+#endif /* _Deathmatch_H__ */

Modified: branches/miniprojects/src/orxonox/objects/gametypes/Gametype.cc
===================================================================
--- branches/miniprojects/src/orxonox/objects/gametypes/Gametype.cc	2009-03-22 20:59:34 UTC (rev 2819)
+++ branches/miniprojects/src/orxonox/objects/gametypes/Gametype.cc	2009-03-22 23:44:10 UTC (rev 2820)
@@ -43,8 +43,6 @@
 #include "objects/worldentities/SpawnPoint.h"
 #include "objects/worldentities/Camera.h"
 
-#include "network/Host.h"
-
 namespace orxonox
 {
     CreateUnloadableFactory(Gametype);
@@ -104,7 +102,6 @@
     {
         this->addBots(this->numberOfBots_);
 
-        COUT(0) << "game started" << std::endl;
         this->gtinfo_.bStarted_ = true;
 
         this->spawnPlayersIfRequested();
@@ -112,30 +109,23 @@
 
     void Gametype::end()
     {
-        COUT(0) << "game ended" << std::endl;
         this->gtinfo_.bEnded_ = true;
     }
 
     void Gametype::playerEntered(PlayerInfo* player)
     {
         this->players_[player].state_ = PlayerState::Joined;
-
-        std::string message = player->getName() + " entered the game";
-        COUT(0) << message << std::endl;
-        Host::Broadcast(message);
     }
 
-    void Gametype::playerLeft(PlayerInfo* player)
+    bool Gametype::playerLeft(PlayerInfo* player)
     {
         std::map<PlayerInfo*, Player>::iterator it = this->players_.find(player);
         if (it != this->players_.end())
         {
             this->players_.erase(it);
-
-            std::string message = player->getName() + " left the game";
-            COUT(0) << message << std::endl;
-            Host::Broadcast(message);
+            return true;
         }
+        return false;
     }
 
     void Gametype::playerSwitched(PlayerInfo* player, Gametype* newgametype)
@@ -146,17 +136,16 @@
     {
     }
 
-    void Gametype::playerChangedName(PlayerInfo* player)
+    bool Gametype::playerChangedName(PlayerInfo* player)
     {
         if (this->players_.find(player) != this->players_.end())
         {
             if (player->getName() != player->getOldName())
             {
-                std::string message = player->getOldName() + " changed name to " + player->getName();
-                COUT(0) << message << std::endl;
-                Host::Broadcast(message);
+                return true;
             }
         }
+        return false;
     }
 
     void Gametype::pawnPreSpawn(Pawn* pawn)
@@ -202,23 +191,6 @@
     {
         if (victim && victim->getPlayer())
         {
-            std::string message;
-            if (killer)
-            {
-                if (killer->getPlayer())
-                    message = victim->getPlayer()->getName() + " was killed by " + killer->getPlayer()->getName();
-                else
-                    message = victim->getPlayer()->getName() + " was killed";
-            }
-            else
-                message = victim->getPlayer()->getName() + " died";
-
-            COUT(0) << message << std::endl;
-            Host::Broadcast(message);
-        }
-
-        if (victim && victim->getPlayer())
-        {
             std::map<PlayerInfo*, Player>::iterator it = this->players_.find(victim->getPlayer());
             if (it != this->players_.end())
             {

Modified: branches/miniprojects/src/orxonox/objects/gametypes/Gametype.h
===================================================================
--- branches/miniprojects/src/orxonox/objects/gametypes/Gametype.h	2009-03-22 20:59:34 UTC (rev 2819)
+++ branches/miniprojects/src/orxonox/objects/gametypes/Gametype.h	2009-03-22 23:44:10 UTC (rev 2820)
@@ -83,10 +83,10 @@
             virtual void start();
             virtual void end();
             virtual void playerEntered(PlayerInfo* player);
-            virtual void playerLeft(PlayerInfo* player);
+            virtual bool playerLeft(PlayerInfo* player);
             virtual void playerSwitched(PlayerInfo* player, Gametype* newgametype);
             virtual void playerSwitchedBack(PlayerInfo* player, Gametype* oldgametype);
-            virtual void playerChangedName(PlayerInfo* player);
+            virtual bool playerChangedName(PlayerInfo* player);
 
             virtual void playerScored(Player& player);
 

Modified: branches/miniprojects/src/orxonox/objects/gametypes/TeamGametype.cc
===================================================================
--- branches/miniprojects/src/orxonox/objects/gametypes/TeamGametype.cc	2009-03-22 20:59:34 UTC (rev 2819)
+++ branches/miniprojects/src/orxonox/objects/gametypes/TeamGametype.cc	2009-03-22 23:44:10 UTC (rev 2820)
@@ -38,7 +38,7 @@
 {
     CreateUnloadableFactory(TeamGametype);
 
-    TeamGametype::TeamGametype(BaseObject* creator) : Gametype(creator)
+    TeamGametype::TeamGametype(BaseObject* creator) : Deathmatch(creator)
     {
         RegisterObject(TeamGametype);
 
@@ -65,7 +65,7 @@
 
     void TeamGametype::playerEntered(PlayerInfo* player)
     {
-        Gametype::playerEntered(player);
+        Deathmatch::playerEntered(player);
 
         std::vector<unsigned int> playersperteam(this->teams_, 0);
 
@@ -87,11 +87,14 @@
         this->teamnumbers_[player] = minplayersteam;
     }
 
-    void TeamGametype::playerLeft(PlayerInfo* player)
+    bool TeamGametype::playerLeft(PlayerInfo* player)
     {
-        Gametype::playerLeft(player);
+        bool valid_player = Deathmatch::playerLeft(player);
 
-        this->players_.erase(player);
+        if (valid_player)
+            this->players_.erase(player);
+
+        return valid_player;
     }
 
     bool TeamGametype::allowPawnHit(Pawn* victim, Pawn* originator)

Modified: branches/miniprojects/src/orxonox/objects/gametypes/TeamGametype.h
===================================================================
--- branches/miniprojects/src/orxonox/objects/gametypes/TeamGametype.h	2009-03-22 20:59:34 UTC (rev 2819)
+++ branches/miniprojects/src/orxonox/objects/gametypes/TeamGametype.h	2009-03-22 23:44:10 UTC (rev 2820)
@@ -33,11 +33,11 @@
 
 #include <vector>
 
-#include "Gametype.h"
+#include "Deathmatch.h"
 
 namespace orxonox
 {
-    class _OrxonoxExport TeamGametype : public Gametype
+    class _OrxonoxExport TeamGametype : public Deathmatch
     {
         public:
             TeamGametype(BaseObject* creator);
@@ -46,7 +46,7 @@
             void setConfigValues();
 
             virtual void playerEntered(PlayerInfo* player);
-            virtual void playerLeft(PlayerInfo* player);
+            virtual bool playerLeft(PlayerInfo* player);
 
             virtual bool allowPawnHit(Pawn* victim, Pawn* originator = 0);
             virtual bool allowPawnDamage(Pawn* victim, Pawn* originator = 0);




More information about the Orxonox-commit mailing list