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