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