[10097] | 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 | * ... |
---|
| 24 | * Co-authors: |
---|
| 25 | * Johannes Ritz |
---|
| 26 | * |
---|
| 27 | * |
---|
| 28 | * |
---|
| 29 | * |
---|
| 30 | *TASK c) end the game in a nicer way |
---|
| 31 | *TASK d) save the highscore |
---|
| 32 | *TASK e) eye candy |
---|
| 33 | */ |
---|
| 34 | |
---|
| 35 | /** |
---|
| 36 | @file Tetris.cc |
---|
| 37 | @brief Implementation of the Mini4Dgame class. |
---|
| 38 | */ |
---|
| 39 | |
---|
| 40 | #include "Mini4Dgame.h" |
---|
| 41 | |
---|
| 42 | #include "core/CoreIncludes.h" |
---|
[10101] | 43 | #include "core/EventIncludes.h" |
---|
[10097] | 44 | #include "core/command/Executor.h" |
---|
| 45 | #include "core/config/ConfigValueIncludes.h" |
---|
[10101] | 46 | #include "infos/PlayerInfo.h" |
---|
[10131] | 47 | #include "core/command/ConsoleCommand.h" |
---|
[10097] | 48 | |
---|
| 49 | #include "gamestates/GSLevel.h" |
---|
| 50 | #include "chat/ChatManager.h" |
---|
| 51 | |
---|
| 52 | namespace orxonox |
---|
| 53 | { |
---|
| 54 | |
---|
[10131] | 55 | SetConsoleCommand("Mini4Dgame", "setStone", &Mini4Dgame::setStone).addShortcut(); |
---|
[10168] | 56 | SetConsoleCommand("Mini4Dgame", "undoStone", &Mini4Dgame::undoStone).addShortcut(); |
---|
[10131] | 57 | |
---|
[10097] | 58 | RegisterUnloadableClass(Mini4Dgame); |
---|
| 59 | |
---|
| 60 | /** |
---|
| 61 | @brief |
---|
| 62 | Constructor. Registers and initializes the object. |
---|
| 63 | */ |
---|
| 64 | Mini4Dgame::Mini4Dgame(Context* context) : Deathmatch(context) |
---|
| 65 | { |
---|
| 66 | RegisterObject(Mini4Dgame); |
---|
| 67 | |
---|
[10131] | 68 | this->board_ = 0; |
---|
| 69 | |
---|
| 70 | // Set the type of Bots for this particular Gametype. |
---|
| 71 | //this->botclass_ = Class(Mini4DgameBot); |
---|
[10097] | 72 | } |
---|
| 73 | |
---|
| 74 | /** |
---|
| 75 | @brief |
---|
| 76 | Destructor. Cleans up, if initialized. |
---|
| 77 | */ |
---|
| 78 | Mini4Dgame::~Mini4Dgame() |
---|
| 79 | { |
---|
| 80 | if (this->isInitialized()) |
---|
| 81 | this->cleanup(); |
---|
| 82 | } |
---|
| 83 | |
---|
| 84 | /** |
---|
| 85 | @brief |
---|
| 86 | Cleans up the Gametype. |
---|
| 87 | */ |
---|
| 88 | void Mini4Dgame::cleanup() |
---|
| 89 | { |
---|
[10168] | 90 | if(this->board_ != NULL)// Destroy the board, if present. |
---|
| 91 | { |
---|
| 92 | //this->board_->destroy(); |
---|
| 93 | this->board_ = 0; |
---|
| 94 | } |
---|
[10097] | 95 | } |
---|
| 96 | |
---|
| 97 | /** |
---|
| 98 | @brief |
---|
[10131] | 99 | Starts the mini4Dgame. |
---|
[10097] | 100 | */ |
---|
| 101 | void Mini4Dgame::start() |
---|
| 102 | { |
---|
[10156] | 103 | if (this->board_ != NULL) // There needs to be a Mini4DgameCenterpoint, i.e. the area the game takes place. |
---|
[10097] | 104 | { |
---|
[10156] | 105 | /* |
---|
[10131] | 106 | if (this->board_ == NULL) |
---|
| 107 | { |
---|
[10156] | 108 | this->board_ = new Mini4DgameBoard(this->board_->getContext()); |
---|
[10131] | 109 | // Apply the template for the ball specified by the centerpoint. |
---|
| 110 | this->board_->addTemplate(this->center_->getBoardtemplate()); |
---|
| 111 | } |
---|
[10156] | 112 | */ |
---|
[10131] | 113 | |
---|
| 114 | // Attach the board to the centerpoint and set the parameters as specified in the centerpoint, the ball is attached to. |
---|
[10156] | 115 | |
---|
[10131] | 116 | this->board_->setPosition(0, 0, 0); |
---|
| 117 | |
---|
[10097] | 118 | } |
---|
| 119 | else // If no centerpoint was specified, an error is thrown and the level is exited. |
---|
| 120 | { |
---|
| 121 | orxout(internal_error) << "Mini4Dgame: No Centerpoint specified." << endl; |
---|
| 122 | GSLevel::startMainMenu(); |
---|
| 123 | return; |
---|
| 124 | } |
---|
| 125 | |
---|
| 126 | // Set variable to temporarily force the player to spawn. |
---|
| 127 | bool temp = this->bForceSpawn_; |
---|
| 128 | this->bForceSpawn_ = true; |
---|
| 129 | |
---|
| 130 | // Call start for the parent class. |
---|
| 131 | Deathmatch::start(); |
---|
| 132 | |
---|
| 133 | // Reset the variable. |
---|
| 134 | this->bForceSpawn_ = temp; |
---|
| 135 | } |
---|
| 136 | |
---|
| 137 | /** |
---|
| 138 | @brief |
---|
| 139 | Ends the Mini4Dgame minigame. |
---|
| 140 | */ |
---|
| 141 | void Mini4Dgame::end() |
---|
| 142 | { |
---|
| 143 | this->cleanup(); |
---|
| 144 | |
---|
| 145 | // Call end for the parent class. |
---|
| 146 | Deathmatch::end(); |
---|
| 147 | } |
---|
| 148 | |
---|
| 149 | |
---|
| 150 | /** |
---|
| 151 | @brief |
---|
| 152 | Spawns player. |
---|
| 153 | */ |
---|
| 154 | void Mini4Dgame::spawnPlayersIfRequested() |
---|
| 155 | { |
---|
[10100] | 156 | // first spawn human players to assign always the left bat to the player in singleplayer |
---|
[10097] | 157 | for (std::map<PlayerInfo*, Player>::iterator it = this->players_.begin(); it != this->players_.end(); ++it) |
---|
| 158 | if (it->first->isHumanPlayer() && (it->first->isReadyToSpawn() || this->bForceSpawn_)) |
---|
| 159 | this->spawnPlayer(it->first); |
---|
[10100] | 160 | // now spawn bots |
---|
| 161 | for (std::map<PlayerInfo*, Player>::iterator it = this->players_.begin(); it != this->players_.end(); ++it) |
---|
| 162 | if (!it->first->isHumanPlayer() && (it->first->isReadyToSpawn() || this->bForceSpawn_)) |
---|
| 163 | this->spawnPlayer(it->first); |
---|
[10097] | 164 | } |
---|
| 165 | |
---|
| 166 | /** |
---|
| 167 | @brief |
---|
| 168 | Spawns the input player. |
---|
| 169 | @param player |
---|
| 170 | The player to be spawned. |
---|
| 171 | */ |
---|
[10100] | 172 | void Mini4Dgame::spawnPlayer(PlayerInfo* player) |
---|
[10097] | 173 | { |
---|
| 174 | assert(player); |
---|
| 175 | |
---|
[10100] | 176 | if(false)//this->player_ == NULL) |
---|
[10097] | 177 | { |
---|
[10100] | 178 | //this->player_ = player; |
---|
[10097] | 179 | this->players_[player].state_ = PlayerState::Alive; |
---|
| 180 | } |
---|
| 181 | } |
---|
| 182 | |
---|
[10168] | 183 | void Mini4Dgame::undoStone()//Vector4 move, const int playerColor) |
---|
| 184 | { |
---|
| 185 | ObjectList<Mini4DgameBoard>::iterator it = ObjectList<Mini4DgameBoard>::begin(); |
---|
| 186 | it->undoMove(); |
---|
| 187 | } |
---|
| 188 | |
---|
[10156] | 189 | //void Mini4Dgame::setStone(Vector4 move, const int playerColor, Mini4DgameBoard* board) |
---|
| 190 | void Mini4Dgame::setStone(int x,int y,int z,int w)//Vector4 move, const int playerColor) |
---|
[10131] | 191 | { |
---|
[10156] | 192 | Vector4 move = Vector4(x,y,z,w); |
---|
| 193 | ObjectList<Mini4DgameBoard>::iterator it = ObjectList<Mini4DgameBoard>::begin(); |
---|
[10168] | 194 | it->makeMove(move); |
---|
[10131] | 195 | } |
---|
[10097] | 196 | |
---|
[10131] | 197 | void Mini4Dgame::win(Mini4DgameWinner winner) |
---|
| 198 | { |
---|
| 199 | |
---|
| 200 | } |
---|
[10097] | 201 | } |
---|