Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 10575 was 10575, checked in by landauf, 10 years ago

create the scoreboard directly with the correct gametype. this prevents that we have to re-set the gametype (and pass it to sub-overlays).

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