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