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