[Orxonox-commit 4329] r9000 - code/branches/presentation2011/src/modules/gametypes

jo at orxonox.net jo at orxonox.net
Sun Dec 18 15:24:21 CET 2011


Author: jo
Date: 2011-12-18 15:24:21 +0100 (Sun, 18 Dec 2011)
New Revision: 9000

Added:
   code/branches/presentation2011/src/modules/gametypes/OldRaceCheckPoint.cc
   code/branches/presentation2011/src/modules/gametypes/OldRaceCheckPoint.h
   code/branches/presentation2011/src/modules/gametypes/OldSpaceRace.cc
   code/branches/presentation2011/src/modules/gametypes/OldSpaceRace.h
Log:
Forgot to add new files.

Added: code/branches/presentation2011/src/modules/gametypes/OldRaceCheckPoint.cc
===================================================================
--- code/branches/presentation2011/src/modules/gametypes/OldRaceCheckPoint.cc	                        (rev 0)
+++ code/branches/presentation2011/src/modules/gametypes/OldRaceCheckPoint.cc	2011-12-18 14:24:21 UTC (rev 9000)
@@ -0,0 +1,120 @@
+/*
+ *   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:
+ *      Mauro Salomon
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+#include "OldRaceCheckPoint.h"
+
+#include "util/Convert.h"
+#include "core/CoreIncludes.h"
+#include "core/XMLPort.h"
+#include "chat/ChatManager.h"
+
+#include "OldSpaceRace.h"
+
+namespace orxonox
+{
+    CreateFactory(OldRaceCheckPoint);
+
+    OldRaceCheckPoint::OldRaceCheckPoint(BaseObject* creator): DistanceTrigger(creator), RadarViewable(creator, static_cast<WorldEntity*>(this))
+    {
+        RegisterObject(OldRaceCheckPoint);
+
+        this->bCheckpointIndex_ = 0;
+        this->bIsLast_ = false;
+        this->bTimeLimit_ = 0;
+
+        this->setRadarObjectColour(ColourValue::Blue);
+        this->setRadarObjectShape(RadarViewable::Triangle);
+        this->setRadarVisibility(false);
+    }
+
+    OldRaceCheckPoint::~OldRaceCheckPoint()
+    {
+    }
+
+    void OldRaceCheckPoint::tick(float dt)
+    {
+        SUPER(OldRaceCheckPoint, tick, dt);
+
+        OldSpaceRace* gametype = orxonox_cast<OldSpaceRace*>(this->getGametype().get());
+        assert(gametype);
+        if (this->getCheckpointIndex() == gametype->getCheckpointsReached())
+            this->setRadarVisibility(true);
+        else
+            this->setRadarVisibility(false);
+    }
+
+    void OldRaceCheckPoint::XMLPort(Element& xmlelement, XMLPort::Mode mode)
+    {
+        SUPER(OldRaceCheckPoint, XMLPort, xmlelement, mode);
+
+        XMLPortParam(OldRaceCheckPoint, "checkpointindex", setCheckpointIndex, getCheckpointIndex, xmlelement, mode).defaultValues(0);
+        XMLPortParam(OldRaceCheckPoint, "islast", setLast, getLast, xmlelement, mode).defaultValues(false);
+        XMLPortParam(OldRaceCheckPoint, "timelimit", setTimelimit, getTimeLimit, xmlelement, mode).defaultValues(0);
+    }
+
+    void OldRaceCheckPoint::triggered(bool bIsTriggered)
+    {
+        DistanceTrigger::triggered(bIsTriggered);
+
+        OldSpaceRace* gametype = orxonox_cast<OldSpaceRace*>(this->getGametype().get());
+        if (gametype && this->getCheckpointIndex() == gametype->getCheckpointsReached() && bIsTriggered)
+        {
+            gametype->clock_.capture();
+            float time = gametype->clock_.getSecondsPrecise();
+            if (this->bTimeLimit_!=0 && time > this->bTimeLimit_)
+            {
+                gametype->timeIsUp();
+                gametype->end();
+            }
+            else if (this->getLast())
+                gametype->end();
+            else
+            {
+                gametype->newCheckpointReached();
+                this->setRadarObjectColour(ColourValue::Green); //sets the radar colour of the checkpoint to green if it is reached, else it is red.
+            }
+        }
+    }
+
+    void OldRaceCheckPoint::setTimelimit(float timeLimit)
+    {
+        this->bTimeLimit_ = timeLimit;
+        if (this->bTimeLimit_ != 0)
+        {
+            OldSpaceRace* gametype = orxonox_cast<OldSpaceRace*>(this->getGametype().get());
+            if (gametype)
+            {
+                const std::string& message =  "You have " + multi_cast<std::string>(this->bTimeLimit_)
+                            + " seconds to reach the check point " + multi_cast<std::string>(this->bCheckpointIndex_+1);
+                const_cast<GametypeInfo*>(gametype->getGametypeInfo())->sendAnnounceMessage(message);
+                ChatManager::message(message);
+            }
+        }
+    }
+
+}

Added: code/branches/presentation2011/src/modules/gametypes/OldRaceCheckPoint.h
===================================================================
--- code/branches/presentation2011/src/modules/gametypes/OldRaceCheckPoint.h	                        (rev 0)
+++ code/branches/presentation2011/src/modules/gametypes/OldRaceCheckPoint.h	2011-12-18 14:24:21 UTC (rev 9000)
@@ -0,0 +1,77 @@
+/*
+ *   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:
+ *      Mauro Salomon
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+#ifndef _OldRaceCheckPoint_H__
+#define _OldRaceCheckPoint_H__
+
+#include "gametypes/GametypesPrereqs.h"
+
+#include "objects/triggers/DistanceTrigger.h"
+#include "interfaces/RadarViewable.h"
+
+namespace orxonox
+{
+    /**
+    @brief
+        The OldRaceCheckPoint class enables the creation of a check point to use in a OldSpaceRace level.
+        !!! Don't forget to control the indexes of your check points and to set one last check point!!!
+    */
+    class _GametypesExport OldRaceCheckPoint : public DistanceTrigger, public RadarViewable
+    {
+        public:
+            OldRaceCheckPoint(BaseObject* creator);
+            virtual ~OldRaceCheckPoint();
+
+            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
+            virtual void tick(float dt);
+
+            protected:
+            virtual void triggered(bool bIsTriggered);
+            inline void setLast(bool isLast)
+                { this->bIsLast_ = isLast; }
+            inline bool getLast()
+                { return this->bIsLast_; }
+            inline void setCheckpointIndex(int checkpointIndex)
+                { this->bCheckpointIndex_ = checkpointIndex; }
+            inline int getCheckpointIndex()
+                { return this->bCheckpointIndex_; }
+            virtual void setTimelimit(float timeLimit);
+            inline float getTimeLimit()
+                { return this->bTimeLimit_;}
+            inline const WorldEntity* getWorldEntity() const
+                { return this; }
+
+        private:
+            int bCheckpointIndex_; //The index of this check point. This value will be compared with the number of check points reached in the level. The check points must be indexed in ascending order beginning from zero and without any jumps between the indexes.
+            bool bIsLast_; //True if this check point is the last of the level. There can be only one last check point for each level and there must be a last check point in the level.
+            float bTimeLimit_; //The time limit (from the start of the level) to reach this check point. If the check point is reached after this time, the game ends and the player looses.
+      
+    };
+}
+
+#endif /* _OldRaceCheckPoint_H__ */

Added: code/branches/presentation2011/src/modules/gametypes/OldSpaceRace.cc
===================================================================
--- code/branches/presentation2011/src/modules/gametypes/OldSpaceRace.cc	                        (rev 0)
+++ code/branches/presentation2011/src/modules/gametypes/OldSpaceRace.cc	2011-12-18 14:24:21 UTC (rev 9000)
@@ -0,0 +1,104 @@
+/*
+ *   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:
+ *     Mauro Salomon
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+#include "OldSpaceRace.h"
+
+#include "core/CoreIncludes.h"
+#include "chat/ChatManager.h"
+#include "util/Convert.h"
+#include "util/Math.h"
+
+namespace orxonox
+{
+    CreateUnloadableFactory(OldSpaceRace);
+
+    OldSpaceRace::OldSpaceRace(BaseObject* creator) : Gametype(creator)
+    {
+        RegisterObject(OldSpaceRace);
+        this->checkpointsReached_ = 0;
+        this->bTimeIsUp_ = false;
+        this->numberOfBots_ = 0;
+    }
+
+    void OldSpaceRace::end()
+    {
+        this->Gametype::end();
+
+        if (this->bTimeIsUp_)
+        {
+            this->clock_.capture();
+            int s = this->clock_.getSeconds();
+            int ms = static_cast<int>(this->clock_.getMilliseconds()-1000*s);
+            const std::string& message = multi_cast<std::string>(s) + "." + multi_cast<std::string>(ms) + " seconds !!\n"
+                        + "You didn't reach the check point " + multi_cast<std::string>(this->checkpointsReached_+1)
+                        + " before the time limit. You lose!";
+            const_cast<GametypeInfo*>(this->getGametypeInfo())->sendAnnounceMessage(message);
+            ChatManager::message(message);
+        }
+        else
+        {
+            this->clock_.capture();
+            int s = this->clock_.getSeconds();
+            int ms = static_cast<int>(this->clock_.getMilliseconds()-1000*s);
+            const std::string& message = "You win!! You have reached the last check point after "+ multi_cast<std::string>(s)
+                        + "." + multi_cast<std::string>(ms) + " seconds.";
+            const_cast<GametypeInfo*>(this->getGametypeInfo())->sendAnnounceMessage(message);
+            ChatManager::message(message);
+/*
+            float time = this->clock_.getSecondsPrecise();
+            this->scores_.insert(time);
+            std::set<float>::iterator it;
+            for (it=this->scores_.begin(); it!=this->scores_.end(); it++)
+                orxout(level::message) << multi_cast<std::string>(*it) << endl;
+*/
+        }
+    }
+
+    void OldSpaceRace::start()
+    {
+        Gametype::start();
+
+        std::string message("The match has started! Reach the check points as quickly as possible!");
+        const_cast<GametypeInfo*>(this->getGametypeInfo())->sendAnnounceMessage(message);
+        ChatManager::message(message);
+    }
+
+    void OldSpaceRace::newCheckpointReached()
+    {
+        this->checkpointsReached_++;
+        this->clock_.capture();
+        int s = this->clock_.getSeconds();
+        int ms = static_cast<int>(this->clock_.getMilliseconds()-1000*s);
+        const std::string& message = "Checkpoint " + multi_cast<std::string>(this->getCheckpointsReached())
+                        + " reached after " + multi_cast<std::string>(s) + "." + multi_cast<std::string>(ms)
+                        + " seconds.";
+        const_cast<GametypeInfo*>(this->getGametypeInfo())->sendAnnounceMessage(message);
+        ChatManager::message(message);
+    }
+
+}

Added: code/branches/presentation2011/src/modules/gametypes/OldSpaceRace.h
===================================================================
--- code/branches/presentation2011/src/modules/gametypes/OldSpaceRace.h	                        (rev 0)
+++ code/branches/presentation2011/src/modules/gametypes/OldSpaceRace.h	2011-12-18 14:24:21 UTC (rev 9000)
@@ -0,0 +1,79 @@
+/*
+ *   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:
+ *      Mauro Salomon
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+#ifndef _OldSpaceRace_H__
+#define _OldSpaceRace_H__
+
+#include "gametypes/GametypesPrereqs.h"
+
+#include <set>
+#include <string>
+
+#include <util/Clock.h>
+
+#include "gametypes/Gametype.h"
+
+#include "OldRaceCheckPoint.h"
+
+namespace orxonox
+{
+  /**
+  @brief
+    The OldSpaceRace class enables the creation of a space race level, where the player has to reach check points in a given order.
+  */
+    class _GametypesExport OldSpaceRace : public Gametype
+    {
+        friend class OldRaceCheckPoint;
+
+        public:
+            OldSpaceRace(BaseObject* creator);
+            virtual ~OldSpaceRace() {}
+
+            virtual void start();
+            virtual void end();
+
+            virtual void newCheckpointReached();
+
+            inline void setCheckpointsReached(int n)
+                { this->checkpointsReached_ = n;}
+            inline int getCheckpointsReached()
+                { return this->checkpointsReached_; }
+            inline void timeIsUp()
+                { this->bTimeIsUp_ = true;}
+
+        protected:
+
+        private:
+            int checkpointsReached_; //The current number of check points reached by the player.
+            std::set<float> scores_; //The times of the players are saved in a set.
+            bool bTimeIsUp_; //True if one of the check points is reached too late.
+            Clock clock_; //The clock starts running at the beginning of the game. It is used to give the time at each check point, the give the time at the end of the game, and to stop the game if a check point is reached too late.
+    };
+}
+
+#endif /* _OldSpaceRace_H__ */




More information about the Orxonox-commit mailing list