[7034] | 1 | /* |
---|
| 2 | orxonox - the future of 3D-vertical-scrollers |
---|
| 3 | |
---|
| 4 | Copyright (C) 2004 orx |
---|
| 5 | |
---|
| 6 | This program is free software; you can redistribute it and/or modify |
---|
| 7 | it under the terms of the GNU General Public License as published by |
---|
| 8 | the Free Software Foundation; either version 2, or (at your option) |
---|
| 9 | any later version. |
---|
| 10 | |
---|
| 11 | ### File Specific: |
---|
| 12 | main-programmer: Patrick Boenzli |
---|
| 13 | */ |
---|
| 14 | |
---|
| 15 | #define DEBUG_MODULE_GAME_RULES |
---|
| 16 | |
---|
| 17 | #include "multiplayer_team_deathmatch.h" |
---|
| 18 | |
---|
| 19 | #include "load_param.h" |
---|
[7035] | 20 | #include "factory.h" |
---|
[7034] | 21 | |
---|
[7039] | 22 | #include "render2D/billboard.h" |
---|
| 23 | #include "state.h" |
---|
[7101] | 24 | #include "class_list.h" |
---|
[7034] | 25 | |
---|
[7044] | 26 | #include "player.h" |
---|
| 27 | #include "playable.h" |
---|
[7101] | 28 | #include "space_ships/space_ship.h" |
---|
[7039] | 29 | |
---|
[7101] | 30 | #include "shared_network_data.h" |
---|
[7044] | 31 | |
---|
[7101] | 32 | #include <list> |
---|
| 33 | |
---|
[7034] | 34 | using namespace std; |
---|
| 35 | |
---|
| 36 | |
---|
[7035] | 37 | CREATE_FACTORY(MultiplayerTeamDeathmatch, CL_MULTIPLAYER_TEAM_DEATHMATCH); |
---|
| 38 | |
---|
| 39 | |
---|
[7034] | 40 | /** |
---|
| 41 | * constructor |
---|
| 42 | */ |
---|
[7035] | 43 | MultiplayerTeamDeathmatch::MultiplayerTeamDeathmatch(const TiXmlElement* root) |
---|
[7034] | 44 | : GameRules(root) |
---|
[7035] | 45 | { |
---|
| 46 | this->setClassID(CL_MULTIPLAYER_TEAM_DEATHMATCH, "MultiplayerTeamDeathmatch"); |
---|
[7034] | 47 | |
---|
[7037] | 48 | this->bLocalPlayerDead = false; |
---|
| 49 | this->deathTimeout = 10.0f; // 5 seconds |
---|
[7082] | 50 | this->timeout = 0.0f; |
---|
[7040] | 51 | |
---|
[7039] | 52 | this->deathScreen = new Billboard(); |
---|
[7044] | 53 | this->deathScreen->setSize(State::getResX()/4.0, State::getResY()/4.0); |
---|
[7040] | 54 | this->deathScreen->setAbsCoor2D(State::getResX()/2.0f, State::getResY()/2.0f); |
---|
[7044] | 55 | this->deathScreen->setVisibility(false); |
---|
[7037] | 56 | |
---|
[7044] | 57 | this->localPlayer = State::getPlayer(); |
---|
| 58 | |
---|
[7035] | 59 | if( root != NULL) |
---|
| 60 | this->loadParams(root); |
---|
| 61 | } |
---|
| 62 | |
---|
[7034] | 63 | /** |
---|
| 64 | * decontsructor |
---|
| 65 | */ |
---|
| 66 | MultiplayerTeamDeathmatch::~MultiplayerTeamDeathmatch() |
---|
[7044] | 67 | { |
---|
| 68 | if( this->deathScreen) |
---|
| 69 | delete this->deathScreen; |
---|
| 70 | } |
---|
[7034] | 71 | |
---|
| 72 | |
---|
| 73 | |
---|
| 74 | void MultiplayerTeamDeathmatch::loadParams(const TiXmlElement* root) |
---|
[7035] | 75 | { |
---|
[7040] | 76 | GameRules::loadParams(root) ; |
---|
[7037] | 77 | |
---|
| 78 | LoadParam(root, "death-penalty-timeout", this, MultiplayerTeamDeathmatch, setDeathPenaltyTimeout) |
---|
| 79 | .describe("sets the time in seconds a player has to wait for respawn"); |
---|
| 80 | |
---|
| 81 | LoadParam(root, "max-kills", this, MultiplayerTeamDeathmatch, setMaxKills) |
---|
| 82 | .describe("sets the maximal kills for winning condition"); |
---|
[7039] | 83 | |
---|
| 84 | LoadParam(root, "death-screen-image", this, MultiplayerTeamDeathmatch, setDeathScreen) |
---|
| 85 | .describe("sets the death screen image"); |
---|
| 86 | |
---|
[7035] | 87 | } |
---|
| 88 | |
---|
| 89 | |
---|
[7039] | 90 | |
---|
| 91 | void MultiplayerTeamDeathmatch::setDeathScreen(const char* imageName) |
---|
| 92 | { |
---|
| 93 | if( this->deathScreen) |
---|
| 94 | this->deathScreen->setTexture(imageName); |
---|
| 95 | } |
---|
| 96 | |
---|
| 97 | |
---|
| 98 | |
---|
[7035] | 99 | /** |
---|
| 100 | * called when the player enters the game |
---|
| 101 | * @param player the spawned player |
---|
| 102 | */ |
---|
[7044] | 103 | void MultiplayerTeamDeathmatch::onPlayerSpawn() |
---|
[7039] | 104 | { |
---|
[7044] | 105 | this->bLocalPlayerDead = false; |
---|
| 106 | this->deathScreen->setVisibility(false); |
---|
[7039] | 107 | } |
---|
[7034] | 108 | |
---|
[7035] | 109 | |
---|
| 110 | /** |
---|
| 111 | * when the player is killed |
---|
| 112 | * @param player the killed player |
---|
| 113 | */ |
---|
[7044] | 114 | void MultiplayerTeamDeathmatch::onPlayerDeath() |
---|
[7039] | 115 | { |
---|
| 116 | this->bLocalPlayerDead = true; |
---|
[7044] | 117 | this->deathScreen->setVisibility(true); |
---|
[7039] | 118 | } |
---|
[7035] | 119 | |
---|
| 120 | |
---|
| 121 | /** |
---|
| 122 | * time tick |
---|
| 123 | * @param dt time |
---|
| 124 | */ |
---|
| 125 | void MultiplayerTeamDeathmatch::tick(float dt) |
---|
[7037] | 126 | { |
---|
[7039] | 127 | this->checkGameRules(); |
---|
[7035] | 128 | |
---|
[7039] | 129 | // is the local player dead and inactive |
---|
| 130 | if( unlikely(this->bLocalPlayerDead)) |
---|
| 131 | { |
---|
| 132 | this->timeout += dt; |
---|
[7088] | 133 | PRINTF(0)("TICK DEATH: %f of %f\n", this->timeout, this->deathTimeout); |
---|
[7039] | 134 | // long enough dead? |
---|
[7044] | 135 | if( this->timeout >= this->deathTimeout) |
---|
[7039] | 136 | { |
---|
| 137 | this->timeout = 0.0f; |
---|
| 138 | // respawn |
---|
[7079] | 139 | PRINTF(0)("RESPAWN\n"); |
---|
[7044] | 140 | (State::getPlayer())->getPlayable()->respawn(); |
---|
[7039] | 141 | } |
---|
| 142 | } |
---|
[7037] | 143 | } |
---|
[7035] | 144 | |
---|
[7037] | 145 | |
---|
[7035] | 146 | /** |
---|
| 147 | * draws the stuff |
---|
| 148 | */ |
---|
| 149 | void MultiplayerTeamDeathmatch::draw() |
---|
[7039] | 150 | { |
---|
| 151 | if( unlikely( this->bLocalPlayerDead)) |
---|
| 152 | { |
---|
[7035] | 153 | |
---|
[7039] | 154 | } |
---|
| 155 | } |
---|
[7035] | 156 | |
---|
[7039] | 157 | |
---|
[7035] | 158 | /** |
---|
| 159 | * check the game rules for consistency |
---|
| 160 | */ |
---|
| 161 | void MultiplayerTeamDeathmatch::checkGameRules() |
---|
[7039] | 162 | { |
---|
[7101] | 163 | |
---|
| 164 | Vector big_left(-201, 0, 0); |
---|
| 165 | float rBig = 176.0f; |
---|
| 166 | Vector big_right(177, 0, 0); |
---|
| 167 | Vector small_left(10, 0, 0); |
---|
| 168 | Vector small_middle(0, 0, 0); |
---|
| 169 | Vector small_right(-10, 0, 0); |
---|
| 170 | float rSmall = 90.0f; |
---|
| 171 | |
---|
| 172 | |
---|
[7039] | 173 | // check for max killing count |
---|
| 174 | if( this->teamAKills >= this->maxKills) |
---|
| 175 | { |
---|
| 176 | // team A winns |
---|
| 177 | } |
---|
| 178 | else if( this->teamBKills >= this->maxKills) |
---|
| 179 | { |
---|
| 180 | // team B winns |
---|
| 181 | } |
---|
[7101] | 182 | |
---|
| 183 | |
---|
| 184 | |
---|
| 185 | |
---|
| 186 | std::list<BaseObject*>::const_iterator it; |
---|
| 187 | const std::list<BaseObject*>* list = ClassList::getList(CL_PLAYABLE); |
---|
| 188 | |
---|
| 189 | if( SharedNetworkData::getInstance()->isGameServer()) |
---|
| 190 | { |
---|
| 191 | for(it = list->begin(); it != list->end(); it++) |
---|
| 192 | { |
---|
| 193 | float dist = (dynamic_cast<Playable*>(*it)->getAbsCoor() - big_left).len(); |
---|
| 194 | if( (dynamic_cast<Playable*>(*it)->getAbsCoor() - big_left).len() > rBig && |
---|
| 195 | (dynamic_cast<Playable*>(*it)->getAbsCoor() - big_right).len() > rBig && |
---|
| 196 | (dynamic_cast<Playable*>(*it)->getAbsCoor() - small_left).len() > rSmall && |
---|
| 197 | (dynamic_cast<Playable*>(*it)->getAbsCoor() - small_middle).len() > rSmall && |
---|
| 198 | (dynamic_cast<Playable*>(*it)->getAbsCoor() - small_right).len() > rSmall) |
---|
| 199 | { |
---|
| 200 | PRINTF(0)("KILLLLLLLL\n"); |
---|
| 201 | |
---|
| 202 | if((*it)->isA(CL_SPACE_SHIP)) |
---|
| 203 | dynamic_cast<SpaceShip*>(*it)->doCollideNetwork(116369220.33434f); |
---|
| 204 | } |
---|
| 205 | } |
---|
| 206 | } |
---|
| 207 | |
---|
| 208 | |
---|
[7039] | 209 | } |
---|
[7035] | 210 | |
---|
| 211 | |
---|
| 212 | |
---|
| 213 | |
---|
| 214 | |
---|
| 215 | |
---|