Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/core7/src/orxonox/gametypes/Gametype.h @ 10554

Last change on this file since 10554 was 10554, checked in by landauf, 9 years ago

Gametype should store a WeakPtr to GametypeInfo to avoid circular reference if GametypeInfo references back to its Gametype

  • Property svn:eol-style set to native
File size: 6.7 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#include "gamestates/GSLevelMemento.h"
44
45namespace orxonox
46{
47    namespace PlayerState
48    {
49        enum Value
50        {
51            Uninitialized,
52            Joined,
53            Alive,
54            Dead
55        };
56    }
57
58    struct Player
59    {
60        PlayerInfo* info_;
61        PlayerState::Value state_;
62        int frags_;
63        int killed_;
64    };
65
66    class _OrxonoxExport Gametype : public BaseObject, public Tickable, public GSLevelMemento
67    {
68        friend class PlayerInfo;
69
70        public:
71            Gametype(Context* context);
72            virtual ~Gametype();
73
74            void setConfigValues();
75
76            virtual void tick(float dt);
77
78            inline const GametypeInfo* getGametypeInfo() const
79                { return this->gtinfo_; }
80
81            inline bool hasStarted() const
82                { return this->gtinfo_->hasStarted(); }
83            inline bool hasEnded() const
84                { return this->gtinfo_->hasEnded(); }
85
86            virtual void start();
87            virtual void end();
88            virtual void playerEntered(PlayerInfo* player);
89            virtual bool playerLeft(PlayerInfo* player);
90            virtual void playerSwitched(PlayerInfo* player, Gametype* newgametype);
91            virtual void playerSwitchedBack(PlayerInfo* player, Gametype* oldgametype);
92            virtual bool playerChangedName(PlayerInfo* player);
93
94            virtual void playerScored(PlayerInfo* player, int score = 1);
95
96            virtual bool allowPawnHit(Pawn* victim, Pawn* originator = 0);
97            virtual bool allowPawnDamage(Pawn* victim, Pawn* originator = 0);
98            virtual bool allowPawnDeath(Pawn* victim, Pawn* originator = 0);
99
100            virtual void pawnKilled(Pawn* victim, Pawn* killer = 0);
101            virtual void pawnPreSpawn(Pawn* pawn);
102            virtual void pawnPostSpawn(Pawn* pawn);
103            virtual void playerPreSpawn(PlayerInfo* player);
104            virtual void playerPostSpawn(PlayerInfo* player);
105
106            virtual void playerStartsControllingPawn(PlayerInfo* player, Pawn* pawn);
107            virtual void playerStopsControllingPawn(PlayerInfo* player, Pawn* pawn);
108
109            inline const std::map<PlayerInfo*, Player>& getPlayers() const
110                { return this->players_; }
111
112            int getScore(PlayerInfo* player) const;
113
114            inline void registerSpawnPoint(SpawnPoint* spawnpoint)
115                { this->spawnpoints_.insert(spawnpoint); }
116
117            inline bool isStartCountdownRunning() const
118                { return this->gtinfo_->isStartCountdownRunning(); }
119            inline float getStartCountdown() const
120                { return this->gtinfo_->getStartCountdown(); }
121
122            inline void setHUDTemplate(const std::string& name)
123                { this->gtinfo_->setHUDTemplate(name); }
124            inline const std::string& getHUDTemplate() const
125                { return this->gtinfo_->getHUDTemplate(); }
126
127            virtual void addBots(unsigned int amount);
128            void killBots(unsigned int amount = 0);
129
130            virtual void addTime(float t);
131            virtual void removeTime(float t);
132
133            inline  void startTimer()
134            {
135                this->time_ = this->timeLimit_;
136                this->timerIsActive_ = true;
137            }
138
139            inline void stopTimer()
140              { this->timerIsActive_ = false; }
141
142            inline float getTime()
143              { return this->time_; }
144
145            inline bool getTimerIsActive()
146              { return timerIsActive_; }
147
148            inline void setTimeLimit(float t)
149              { this->timeLimit_ = t; }
150
151            //inline bool getForceSpawn()
152            //  { return this->bForceSpawn_; }
153
154            virtual void resetTimer();
155            virtual void resetTimer(float t);
156
157            /**
158            @brief Get number of Players in game.
159            */
160            inline unsigned int getNumberOfPlayers() const
161                { return this->players_.size(); }
162            void showMenu();
163
164
165        protected:
166            virtual SpawnPoint* getBestSpawnPoint(PlayerInfo* player) const;
167
168            virtual void assignDefaultPawnsIfNeeded();
169            virtual void checkStart();
170            virtual void spawnPlayer(PlayerInfo* player);
171            virtual void spawnPlayerAsDefaultPawn(PlayerInfo* player);
172            virtual void spawnPlayersIfRequested();
173            virtual void spawnDeadPlayersIfRequested();
174
175            virtual GSLevelMementoState* exportMementoState();
176            virtual void importMementoState(const std::vector<GSLevelMementoState*>& states);
177
178            WeakPtr<GametypeInfo> gtinfo_;
179
180            bool bAutoStart_;
181            bool bForceSpawn_;
182            bool bAutoEnd_;
183
184            float time_;
185            float timeLimit_;
186            bool timerIsActive_;
187
188            float initialStartCountdown_;
189            unsigned int numberOfBots_;
190            SubclassIdentifier<Bot> botclass_;
191
192            std::map<PlayerInfo*, Player> players_;
193            std::set<SpawnPoint*> spawnpoints_;
194            SubclassIdentifier<ControllableEntity> defaultControllableEntity_;
195
196            OverlayGroup* scoreboard_;
197
198            // Config Values
199            std::string scoreboardTemplate_;
200
201            Timer showMenuTimer_;
202    };
203
204    /**
205        @brief Keeps position and orientation of the camera, as well as the name of current scene.
206    */
207    struct _OrxonoxExport GametypeMementoState : public GSLevelMementoState
208    {
209        Vector3 cameraPosition_;
210        Quaternion cameraOrientation_;
211        std::string sceneName_;
212    };
213}
214
215#endif /* _Gametype_H__ */
Note: See TracBrowser for help on using the repository browser.