Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/storymodeHS14/src/orxonox/gametypes/Gametype.h @ 10251

Last change on this file since 10251 was 9980, checked in by jo, 10 years ago

Adding delay timer to show the main menu after a game ended automatically.

  • Property svn:eol-style set to native
File size: 6.4 KB
Line 
1/*
2 *   ORXONOX - the hottest 3D action shooter ever to exist
3 *                    > www.orxonox.net <
4 *
5 *
6 *   License notice:
7 *
8 *   This program is free software; you can redistribute it and/or
9 *   modify it under the terms of the GNU General Public License
10 *   as published by the Free Software Foundation; either version 2
11 *   of the License, or (at your option) any later version.
12 *
13 *   This program is distributed in the hope that it will be useful,
14 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
15 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 *   GNU General Public License for more details.
17 *
18 *   You should have received a copy of the GNU General Public License
19 *   along with this program; if not, write to the Free Software
20 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
21 *
22 *   Author:
23 *      Fabian 'x3n' Landau
24 *   Co-authors:
25 *      ...
26 *
27 */
28
29#ifndef _Gametype_H__
30#define _Gametype_H__
31
32#include "OrxonoxPrereqs.h"
33
34#include <map>
35#include <set>
36#include <string>
37
38#include "core/BaseObject.h"
39#include "core/class/SubclassIdentifier.h"
40#include "tools/interfaces/Tickable.h"
41#include "infos/GametypeInfo.h"
42#include "tools/Timer.h"
43
44namespace orxonox
45{
46    namespace PlayerState
47    {
48        enum Value
49        {
50            Uninitialized,
51            Joined,
52            Alive,
53            Dead
54        };
55    }
56
57    struct Player
58    {
59        PlayerInfo* info_;
60        PlayerState::Value state_;
61        int frags_;
62        int killed_;
63    };
64
65    class _OrxonoxExport Gametype : public BaseObject, public Tickable
66    {
67        friend class PlayerInfo;
68
69        public:
70            Gametype(Context* context);
71            virtual ~Gametype();
72
73            void setConfigValues();
74
75            virtual void tick(float dt);
76
77            inline const GametypeInfo* getGametypeInfo() const
78                { return this->gtinfo_; }
79
80            inline bool hasStarted() const
81                { return this->gtinfo_->hasStarted(); }
82            inline bool hasEnded() const
83                { return this->gtinfo_->hasEnded(); }
84
85            virtual void start();
86            virtual void end();
87            virtual void playerEntered(PlayerInfo* player);
88            virtual bool playerLeft(PlayerInfo* player);
89            virtual void playerSwitched(PlayerInfo* player, Gametype* newgametype);
90            virtual void playerSwitchedBack(PlayerInfo* player, Gametype* oldgametype);
91            virtual bool playerChangedName(PlayerInfo* player);
92
93            virtual void playerScored(PlayerInfo* player, int score = 1);
94
95            virtual bool allowPawnHit(Pawn* victim, Pawn* originator = 0);
96            virtual bool allowPawnDamage(Pawn* victim, Pawn* originator = 0);
97            virtual bool allowPawnDeath(Pawn* victim, Pawn* originator = 0);
98
99            virtual void pawnKilled(Pawn* victim, Pawn* killer = 0);
100            virtual void pawnPreSpawn(Pawn* pawn);
101            virtual void pawnPostSpawn(Pawn* pawn);
102            virtual void playerPreSpawn(PlayerInfo* player);
103            virtual void playerPostSpawn(PlayerInfo* player);
104
105            virtual void playerStartsControllingPawn(PlayerInfo* player, Pawn* pawn);
106            virtual void playerStopsControllingPawn(PlayerInfo* player, Pawn* pawn);
107
108            inline const std::map<PlayerInfo*, Player>& getPlayers() const
109                { return this->players_; }
110
111            int getScore(PlayerInfo* player) const;
112
113            inline void registerSpawnPoint(SpawnPoint* spawnpoint)
114                { this->spawnpoints_.insert(spawnpoint); }
115
116            inline bool isStartCountdownRunning() const
117                { return this->gtinfo_->isStartCountdownRunning(); }
118            inline float getStartCountdown() const
119                { return this->gtinfo_->getStartCountdown(); }
120
121            inline void setHUDTemplate(const std::string& name)
122                { this->gtinfo_->setHUDTemplate(name); }
123            inline const std::string& getHUDTemplate() const
124                { return this->gtinfo_->getHUDTemplate(); }
125
126            virtual void addBots(unsigned int amount);
127            void killBots(unsigned int amount = 0);
128
129            virtual void addTime(float t);
130            virtual void removeTime(float t);
131
132            inline  void startTimer()
133            {
134                this->time_ = this->timeLimit_;
135                this->timerIsActive_ = true;
136            }
137
138            inline void stopTimer()
139              { this->timerIsActive_ = false; }
140
141            inline float getTime()
142              { return this->time_; }
143
144            inline bool getTimerIsActive()
145              { return timerIsActive_; }
146
147            inline void setTimeLimit(float t)
148              { this->timeLimit_ = t; }
149
150            //inline bool getForceSpawn()
151            //  { return this->bForceSpawn_; }
152
153            virtual void resetTimer();
154            virtual void resetTimer(float t);
155
156            /**
157            @brief Get number of Players in game.
158            */
159            inline unsigned int getNumberOfPlayers() const
160                { return this->players_.size(); }
161            void showMenu();
162
163
164        protected:
165            virtual SpawnPoint* getBestSpawnPoint(PlayerInfo* player) const;
166
167            virtual void assignDefaultPawnsIfNeeded();
168            virtual void checkStart();
169            virtual void spawnPlayer(PlayerInfo* player);
170            virtual void spawnPlayerAsDefaultPawn(PlayerInfo* player);
171            virtual void spawnPlayersIfRequested();
172            virtual void spawnDeadPlayersIfRequested();
173
174            SmartPtr<GametypeInfo> gtinfo_;
175
176            bool bAutoStart_;
177            bool bForceSpawn_;
178            bool bAutoEnd_;
179
180            float time_;
181            float timeLimit_;
182            bool timerIsActive_;
183
184            float initialStartCountdown_;
185            unsigned int numberOfBots_;
186            SubclassIdentifier<Bot> botclass_;
187
188            std::map<PlayerInfo*, Player> players_;
189            std::set<SpawnPoint*> spawnpoints_;
190            SubclassIdentifier<ControllableEntity> defaultControllableEntity_;
191
192            OverlayGroup* scoreboard_;
193
194            // Config Values
195            std::string scoreboardTemplate_;
196
197            /* HACK HACK HACK */
198            ConsoleCommand* dedicatedAddBots_;
199            ConsoleCommand* dedicatedKillBots_;
200            /* HACK HACK HACK */
201            Timer showMenuTimer_;
202    };
203}
204
205#endif /* _Gametype_H__ */
Note: See TracBrowser for help on using the repository browser.