| 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" | 
|---|
| 20 | #include "factory.h" | 
|---|
| 21 |  | 
|---|
| 22 | #include "render2D/billboard.h" | 
|---|
| 23 | #include "state.h" | 
|---|
| 24 |  | 
|---|
| 25 | #include "player.h" | 
|---|
| 26 | #include "playable.h" | 
|---|
| 27 |  | 
|---|
| 28 |  | 
|---|
| 29 | using namespace std; | 
|---|
| 30 |  | 
|---|
| 31 |  | 
|---|
| 32 | CREATE_FACTORY(MultiplayerTeamDeathmatch, CL_MULTIPLAYER_TEAM_DEATHMATCH); | 
|---|
| 33 |  | 
|---|
| 34 |  | 
|---|
| 35 | /** | 
|---|
| 36 |  * constructor | 
|---|
| 37 |  */ | 
|---|
| 38 | MultiplayerTeamDeathmatch::MultiplayerTeamDeathmatch(const TiXmlElement* root) | 
|---|
| 39 |   : GameRules(root) | 
|---|
| 40 | { | 
|---|
| 41 |   this->setClassID(CL_MULTIPLAYER_TEAM_DEATHMATCH, "MultiplayerTeamDeathmatch"); | 
|---|
| 42 |  | 
|---|
| 43 |   this->bLocalPlayerDead = false; | 
|---|
| 44 |   this->deathTimeout = 10.0f;     // 5 seconds | 
|---|
| 45 |   this->timeout = 0.0f; | 
|---|
| 46 |  | 
|---|
| 47 |   this->deathScreen = new Billboard(); | 
|---|
| 48 |   this->deathScreen->setSize(State::getResX()/4.0, State::getResY()/4.0); | 
|---|
| 49 |   this->deathScreen->setAbsCoor2D(State::getResX()/2.0f, State::getResY()/2.0f); | 
|---|
| 50 |   this->deathScreen->setVisibility(false); | 
|---|
| 51 |  | 
|---|
| 52 |   this->localPlayer = State::getPlayer(); | 
|---|
| 53 |  | 
|---|
| 54 |   if( root != NULL) | 
|---|
| 55 |     this->loadParams(root); | 
|---|
| 56 | } | 
|---|
| 57 |  | 
|---|
| 58 | /** | 
|---|
| 59 |  * decontsructor | 
|---|
| 60 |  */ | 
|---|
| 61 | MultiplayerTeamDeathmatch::~MultiplayerTeamDeathmatch() | 
|---|
| 62 | { | 
|---|
| 63 |   if( this->deathScreen) | 
|---|
| 64 |     delete this->deathScreen; | 
|---|
| 65 | } | 
|---|
| 66 |  | 
|---|
| 67 |  | 
|---|
| 68 |  | 
|---|
| 69 | void MultiplayerTeamDeathmatch::loadParams(const TiXmlElement* root) | 
|---|
| 70 | { | 
|---|
| 71 |   GameRules::loadParams(root) ; | 
|---|
| 72 |  | 
|---|
| 73 |   LoadParam(root, "death-penalty-timeout", this, MultiplayerTeamDeathmatch, setDeathPenaltyTimeout) | 
|---|
| 74 |       .describe("sets the time in seconds a player has to wait for respawn"); | 
|---|
| 75 |  | 
|---|
| 76 |   LoadParam(root, "max-kills", this, MultiplayerTeamDeathmatch, setMaxKills) | 
|---|
| 77 |       .describe("sets the maximal kills for winning condition"); | 
|---|
| 78 |  | 
|---|
| 79 |   LoadParam(root, "death-screen-image", this, MultiplayerTeamDeathmatch, setDeathScreen) | 
|---|
| 80 |       .describe("sets the death screen image"); | 
|---|
| 81 |  | 
|---|
| 82 | } | 
|---|
| 83 |  | 
|---|
| 84 |  | 
|---|
| 85 |  | 
|---|
| 86 | void MultiplayerTeamDeathmatch::setDeathScreen(const char* imageName) | 
|---|
| 87 | { | 
|---|
| 88 |   if( this->deathScreen) | 
|---|
| 89 |     this->deathScreen->setTexture(imageName); | 
|---|
| 90 | } | 
|---|
| 91 |  | 
|---|
| 92 |  | 
|---|
| 93 |  | 
|---|
| 94 | /** | 
|---|
| 95 |  * called when the player enters the game | 
|---|
| 96 |  * @param player the spawned player | 
|---|
| 97 |  */ | 
|---|
| 98 | void MultiplayerTeamDeathmatch::onPlayerSpawn() | 
|---|
| 99 | { | 
|---|
| 100 |   this->bLocalPlayerDead = false; | 
|---|
| 101 |   this->deathScreen->setVisibility(false); | 
|---|
| 102 | } | 
|---|
| 103 |  | 
|---|
| 104 |  | 
|---|
| 105 | /** | 
|---|
| 106 |  * when the player is killed | 
|---|
| 107 |  * @param player the killed player | 
|---|
| 108 |  */ | 
|---|
| 109 | void MultiplayerTeamDeathmatch::onPlayerDeath() | 
|---|
| 110 | { | 
|---|
| 111 |   this->bLocalPlayerDead = true; | 
|---|
| 112 |   this->deathScreen->setVisibility(true); | 
|---|
| 113 | } | 
|---|
| 114 |  | 
|---|
| 115 |  | 
|---|
| 116 | /** | 
|---|
| 117 |  * time tick | 
|---|
| 118 |  * @param dt time | 
|---|
| 119 |  */ | 
|---|
| 120 | void MultiplayerTeamDeathmatch::tick(float dt) | 
|---|
| 121 | { | 
|---|
| 122 |   this->checkGameRules(); | 
|---|
| 123 |  | 
|---|
| 124 |   // is the local player dead and inactive | 
|---|
| 125 |   if( unlikely(this->bLocalPlayerDead)) | 
|---|
| 126 |   { | 
|---|
| 127 |     this->timeout += dt; | 
|---|
| 128 |     PRINTF(0)("TICK DEATH: %f of %f\n", dt, this->timeout); | 
|---|
| 129 |     // long enough dead? | 
|---|
| 130 |     if( this->timeout >= this->deathTimeout) | 
|---|
| 131 |     { | 
|---|
| 132 |       this->timeout = 0.0f; | 
|---|
| 133 |       // respawn | 
|---|
| 134 |       PRINTF(0)("RESPAWN\n"); | 
|---|
| 135 |       (State::getPlayer())->getPlayable()->respawn(); | 
|---|
| 136 |       this->onPlayerDeath(); | 
|---|
| 137 |     } | 
|---|
| 138 |   } | 
|---|
| 139 | } | 
|---|
| 140 |  | 
|---|
| 141 |  | 
|---|
| 142 | /** | 
|---|
| 143 |  * draws the stuff | 
|---|
| 144 |  */ | 
|---|
| 145 | void MultiplayerTeamDeathmatch::draw() | 
|---|
| 146 | { | 
|---|
| 147 |   if( unlikely( this->bLocalPlayerDead)) | 
|---|
| 148 |   { | 
|---|
| 149 |  | 
|---|
| 150 |   } | 
|---|
| 151 | } | 
|---|
| 152 |  | 
|---|
| 153 |  | 
|---|
| 154 | /** | 
|---|
| 155 |  * check the game rules for consistency | 
|---|
| 156 |  */ | 
|---|
| 157 | void MultiplayerTeamDeathmatch::checkGameRules() | 
|---|
| 158 | { | 
|---|
| 159 |   // | 
|---|
| 160 |   // check for max killing count | 
|---|
| 161 |   if( this->teamAKills >= this->maxKills) | 
|---|
| 162 |   { | 
|---|
| 163 |     // team A winns | 
|---|
| 164 |   } | 
|---|
| 165 |   else if( this->teamBKills >= this->maxKills) | 
|---|
| 166 |   { | 
|---|
| 167 |     // team B winns | 
|---|
| 168 |   } | 
|---|
| 169 | } | 
|---|
| 170 |  | 
|---|
| 171 |  | 
|---|
| 172 |  | 
|---|
| 173 |  | 
|---|
| 174 |  | 
|---|
| 175 |  | 
|---|