[Orxonox-commit 330] r2952 - in branches/gametypes/src/orxonox/objects: gametypes worldentities

mockm at orxonox.net mockm at orxonox.net
Mon May 4 16:34:48 CEST 2009


Author: mockm
Date: 2009-05-04 16:34:48 +0200 (Mon, 04 May 2009)
New Revision: 2952

Modified:
   branches/gametypes/src/orxonox/objects/gametypes/Gametype.cc
   branches/gametypes/src/orxonox/objects/gametypes/Gametype.h
   branches/gametypes/src/orxonox/objects/gametypes/UnderAttack.cc
   branches/gametypes/src/orxonox/objects/gametypes/UnderAttack.h
   branches/gametypes/src/orxonox/objects/worldentities/SpawnPoint.cc
Log:
new revision of gametype UnderAttack: Ship is now moving

Modified: branches/gametypes/src/orxonox/objects/gametypes/Gametype.cc
===================================================================
--- branches/gametypes/src/orxonox/objects/gametypes/Gametype.cc	2009-05-04 14:03:02 UTC (rev 2951)
+++ branches/gametypes/src/orxonox/objects/gametypes/Gametype.cc	2009-05-04 14:34:48 UTC (rev 2952)
@@ -92,7 +92,7 @@
 
         if (!this->gtinfo_.bStarted_)
             this->checkStart();
-        else
+        else if (!this->gtinfo_.bEnded_)
             this->spawnDeadPlayersIfRequested();
 
         this->assignDefaultPawnsIfNeeded();
@@ -110,6 +110,31 @@
     void Gametype::end()
     {
         this->gtinfo_.bEnded_ = true;
+
+        for (std::map<PlayerInfo*, Player>::iterator it = this->players_.begin(); it != this->players_.end(); ++it)
+        {
+            if (it->first->getControllableEntity())
+            {
+                ControllableEntity* oldentity = it->first->getControllableEntity();
+        
+                ControllableEntity* entity = this->defaultControllableEntity_.fabricate(oldentity->getCreator());
+                if (oldentity->getCamera())
+                {
+                    entity->setPosition(oldentity->getCamera()->getWorldPosition());
+                    entity->setOrientation(oldentity->getCamera()->getWorldOrientation());
+                }
+                else
+                {
+                    entity->setPosition(oldentity->getWorldPosition());
+                    entity->setOrientation(oldentity->getWorldOrientation());
+                }
+
+                it->first->stopControl(oldentity, true);
+                it->first->startControl(entity);
+            }
+            else
+                this->spawnPlayerAsDefaultPawn(it->first);
+        }
     }
 
     void Gametype::playerEntered(PlayerInfo* player)
@@ -253,20 +278,8 @@
 
                 if (!it->first->isReadyToSpawn() || !this->gtinfo_.bStarted_)
                 {
-                    SpawnPoint* spawn = this->getBestSpawnPoint(it->first);
-                    if (spawn)
-                    {
-                        // force spawn at spawnpoint with default pawn
-                        ControllableEntity* entity = this->defaultControllableEntity_.fabricate(spawn);
-                        spawn->spawn(entity);
-                        it->first->startControl(entity);
-                        it->second.state_ = PlayerState::Dead;
-                    }
-                    else
-                    {
-                        COUT(1) << "Error: No SpawnPoints in current Gametype" << std::endl;
-                        abort();
-                    }
+                    this->spawnPlayerAsDefaultPawn(it->first);
+                    it->second.state_ = PlayerState::Dead;
                 }
             }
         }
@@ -344,6 +357,23 @@
         }
     }
 
+    void Gametype::spawnPlayerAsDefaultPawn(PlayerInfo* player)
+    {
+        SpawnPoint* spawn = this->getBestSpawnPoint(player);
+        if (spawn)
+        {
+            // force spawn at spawnpoint with default pawn
+            ControllableEntity* entity = this->defaultControllableEntity_.fabricate(spawn);
+            spawn->spawn(entity);
+            player->startControl(entity);
+        }
+        else
+        {
+            COUT(1) << "Error: No SpawnPoints in current Gametype" << std::endl;
+            abort();
+        }
+    }
+
     void Gametype::addBots(unsigned int amount)
     {
         for (unsigned int i = 0; i < amount; ++i)

Modified: branches/gametypes/src/orxonox/objects/gametypes/Gametype.h
===================================================================
--- branches/gametypes/src/orxonox/objects/gametypes/Gametype.h	2009-05-04 14:03:02 UTC (rev 2951)
+++ branches/gametypes/src/orxonox/objects/gametypes/Gametype.h	2009-05-04 14:34:48 UTC (rev 2952)
@@ -131,6 +131,7 @@
             virtual void assignDefaultPawnsIfNeeded();
             virtual void checkStart();
             virtual void spawnPlayer(PlayerInfo* player);
+            virtual void spawnPlayerAsDefaultPawn(PlayerInfo* player);
             virtual void spawnPlayersIfRequested();
             virtual void spawnDeadPlayersIfRequested();
 

Modified: branches/gametypes/src/orxonox/objects/gametypes/UnderAttack.cc
===================================================================
--- branches/gametypes/src/orxonox/objects/gametypes/UnderAttack.cc	2009-05-04 14:03:02 UTC (rev 2951)
+++ branches/gametypes/src/orxonox/objects/gametypes/UnderAttack.cc	2009-05-04 14:34:48 UTC (rev 2952)
@@ -34,6 +34,7 @@
 #include "objects/Teamcolourable.h"
 #include "objects/worldentities/TeamSpawnPoint.h"
 
+#include "network/Host.h"
 namespace orxonox
 {
     CreateUnloadableFactory(UnderAttack);
@@ -49,6 +50,11 @@
         this->setConfigValues();
     }
 
+    void UnderAttack::setConfigValues()
+    {
+        SetConfigValue(gameTime_, 30);
+    }
+
     void UnderAttack::addDestroyer(Destroyer* destroyer)
     {
         this->destroyer_ = destroyer;
@@ -59,9 +65,10 @@
     {
         if (pawn == this->destroyer_)
         {
-
-            COUT(0) << "Ship destroyed! Team 0 has won!" << std::endl;
-            // Todo: end game
+            this->end(); //end gametype
+            std::string message = "Ship destroyed! Team 0 has won!";
+            COUT(0) << message << std::endl;
+            Host::Broadcast(message);
         }
     }
 
@@ -128,7 +135,10 @@
             if (gameTime_<= 0 && !gameEnded_)
             {
                 gameEnded_ = true;
-                COUT(0) << "Time is up! Team 1 has won!" << std::endl;
+                this->end();
+                std::string message = "Time is up! Team 1 has won!";
+                COUT(0) << message << std::endl;
+                Host::Broadcast(message);
             }
         }
     }

Modified: branches/gametypes/src/orxonox/objects/gametypes/UnderAttack.h
===================================================================
--- branches/gametypes/src/orxonox/objects/gametypes/UnderAttack.h	2009-05-04 14:03:02 UTC (rev 2951)
+++ branches/gametypes/src/orxonox/objects/gametypes/UnderAttack.h	2009-05-04 14:34:48 UTC (rev 2952)
@@ -43,6 +43,9 @@
         public:
             UnderAttack(BaseObject* creator);
             virtual ~UnderAttack() {}
+
+            void setConfigValues();
+
             void tick (float dt);
             void addDestroyer(Destroyer* destroyer);
             inline Destroyer* getDestroyer() const

Modified: branches/gametypes/src/orxonox/objects/worldentities/SpawnPoint.cc
===================================================================
--- branches/gametypes/src/orxonox/objects/worldentities/SpawnPoint.cc	2009-05-04 14:03:02 UTC (rev 2951)
+++ branches/gametypes/src/orxonox/objects/worldentities/SpawnPoint.cc	2009-05-04 14:34:48 UTC (rev 2952)
@@ -94,7 +94,7 @@
 
     void SpawnPoint::spawn(ControllableEntity* entity)
     {
-        entity->setPosition(this->getPosition());
-        entity->setOrientation(this->getOrientation());
+        entity->setPosition(this->getWorldPosition());
+        entity->setOrientation(this->getWorldOrientation());
     }
 }




More information about the Orxonox-commit mailing list