Debian Codegraph @

src/game/gamemode.cpp

raw symbols SCIP
1
2 /**
3 *
4 * @file gamemode.cpp
5 *
6 * Part of the OpenJazz project
7 *
8 * @par History:
9 * - 23rd August 2005: Created level.c and menu.c
10 * - 3rd of February 2009: Renamed level.c to level.cpp and menu.c to menu.cpp
11 * - 9th March 2009: Created game.cpp from parts of menu.cpp and level.cpp
12 * - 18th July 2009: Created servergame.cpp from parts of game.cpp
13 * - 2nd August 2009: Created gamemode.cpp from parts of servergame.cpp
14 *
15 * @par Licence:
16 * Copyright (c) 2005-2017 AJ Thomson
17 *
18 * OpenJazz is distributed under the terms of
19 * the GNU General Public License, version 2.0
20 *
21 */
22
23
24 #include "game.h"cxx . . $ `<file>/src/game/game.h`/
25 #include "gamemode.h"cxx . . $ `<file>/src/game/gamemode.h`/
26
27 #include "io/gfx/font.h"cxx . . $ `<file>/src/io/gfx/font.h`/
28 #include "player/player.h"cxx . . $ `<file>/src/player/player.h`/
29
30
31 /**
32 * Outcome of player being hit
33 *
34 * @param source Player responsible for the hit
35 * @param victim Player victim of the hit
36 *
37 * @return Whether or not the hit should result in energy loss (true)
38 */
39 bool GameModecxx . . $ GameMode#::hitcxx . . $ GameMode#hit(e1486006e22d1cdc). (Playercxx . . $ Player# *source, Playercxx . . $ Player# *victim) {
40
41 OJ_UNUSEDcxx . . $ `src/types.h:67:9`!(source);
42 OJ_UNUSEDcxx . . $ `src/types.h:67:9`!(victim);
43
44 return true;
45
46 }
47
48
49 /**
50 * Outcome of player being killed
51 *
52 * @param game The current game
53 * @param source Player responsible for the kill
54 * @param victim Player victim of the kill
55 *
56 * @return Whether or not the player should be be killed (true)
57 */
58 bool GameModecxx . . $ GameMode#::killcxx . . $ GameMode#kill(ed28dcf7b803e269). (Gamecxx . . $ Game#* game, Playercxx . . $ Player# *source, Playercxx . . $ Player# *victim) {
59
60 if (source && (victim == localPlayercxx . . $ localPlayer.)) game->scorecxx . . $ Game#score(ac50b47256ae7414).(source->getTeamcxx . . $ Player#getTeam(7c4be072098b358f).());
61
62 return true;
63
64 }
65
66
67 /**
68 * Outcome of level being completed
69 *
70 * @param game The current game
71 * @param player Player that has completed level
72 * @param gridX X-coordinate (in tiles) of finishing position
73 * @param gridY Y-coordinate (in tiles) of finishing position
74 *
75 * @return Whether or not the level should end (true)
76 */
77 bool GameModecxx . . $ GameMode#::endOfLevelcxx . . $ GameMode#endOfLevel(58252f3afe5a5e7). (Gamecxx . . $ Game#* game, Playercxx . . $ Player# *player, int gridX, int gridY) {
78
79 (void)player;
80
81 game->setCheckpointcxx . . $ Game#setCheckpoint(3e454b8ccf442868).(gridX, gridY);
82
83 return true;
84
85 }
86
87
88 /**
89 * Outcome of time running out
90 */
91 void GameModecxx . . $ GameMode#::outOfTimecxx . . $ GameMode#outOfTime(49f6e7a06ebc5aa8). () {
92
93 }
94
95
96 /**
97 * Get the game mode type
98 *
99 * @return Game mode type (M_SINGLE)
100 */
101 GameModeTypecxx . . $ GameModeType# SingleGameModecxx . . $ SingleGameMode#::getModecxx . . $ SingleGameMode#getMode(e679e067a917a25c). () {
102
103 return M_SINGLEcxx . . $ M_SINGLE.;
104
105 }
106
107
108 /**
109 * Choose a team for a new player
110 *
111 * @return New player's team (0)
112 */
113 unsigned char SingleGameModecxx . . $ SingleGameMode#::chooseTeamcxx . . $ SingleGameMode#chooseTeam(7c4be072098b358f). () {
114
115 return 0;
116
117 }
118
119
120 /**
121 * Draw the player's team's score (not in single-player mode)
122 *
123 * @param font Font to use to draw score
124 */
125 void SingleGameModecxx . . $ SingleGameMode#::drawScorecxx . . $ SingleGameMode#drawScore(ae6dc2419597cce5). (Fontcxx . . $ Font#* font) {
126
127 (void)font;
128
129 }
130
131
132 /**
133 * Choose a team for a new player
134 *
135 * @return New player's team (0)
136 */
137 unsigned char CooperativeGameModecxx . . $ CooperativeGameMode#::chooseTeamcxx . . $ CooperativeGameMode#chooseTeam(7c4be072098b358f). () {
138
139 // All players are on the same team
140
141 return 0;
142
143 }
144
145
146 /**
147 * Draw the player's team's score (not in cooperative mode)
148 *
149 * @param font Font to use to draw score
150 */
151 void CooperativeGameModecxx . . $ CooperativeGameMode#::drawScorecxx . . $ CooperativeGameMode#drawScore(ae6dc2419597cce5). (Fontcxx . . $ Font#* font) {
152
153 (void)font;
154
155 // Do nothing
156
157 }
158
159
160 /**
161 * Choose a team for a new player
162 *
163 * @return New player's team (unique)
164 */
165 unsigned char FreeForAllGameModecxx . . $ FreeForAllGameMode#::chooseTeamcxx . . $ FreeForAllGameMode#chooseTeam(7c4be072098b358f). () {
166
167 // Every player is on a separate team
168
169 int count;
170 unsigned char team;
171
172 team = 1;
173
174 // Find a team number higher than any other
175 for (count = nPlayerscxx . . $ nPlayers. - 1; count >= 0; count--) {
176
177 if (playerscxx . . $ players.[count].getTeamcxx . . $ Player#getTeam(7c4be072098b358f).() > team)
178 team = playerscxx . . $ players.[count].getTeamcxx . . $ Player#getTeam(7c4be072098b358f).() + 1;
179
180 }
181
182 return team;
183
184 }
185
186
187 /**
188 * Draw the player's team's score
189 *
190 * @param font Font to use to draw score
191 */
192 void FreeForAllGameModecxx . . $ FreeForAllGameMode#::drawScorecxx . . $ FreeForAllGameMode#drawScore(ae6dc2419597cce5). (Fontcxx . . $ Font#* font) {
193
194 font->showNumbercxx . . $ Font#showNumber(b1146eedae1e1d0b).(localPlayercxx . . $ localPlayer.->teamScorecxx . . $ Player#teamScore., 64, 4);
195
196 }
197
198
199 /**
200 * Choose a team for a new player
201 *
202 * @return New player's team (0 or 1)
203 */
204 unsigned char TeamGameModecxx . . $ TeamGameMode#::chooseTeamcxx . . $ TeamGameMode#chooseTeam(7c4be072098b358f). () {
205
206 // Players are split between two teams
207
208 int count, difference;
209
210 // Calculate team imbalance
211
212 difference = 0;
213
214 for (count = 0; count < nPlayerscxx . . $ nPlayers.; count++) {
215
216 if (playerscxx . . $ players.[count].getTeamcxx . . $ Player#getTeam(7c4be072098b358f).()) difference++;
217 else difference--;
218
219 }
220
221 // Assign to the team with the least players
222
223 if (difference >= 0) return 0;
224
225 return 1;
226
227 }
228
229
230 /**
231 * Draw the player's team's score
232 *
233 * @param font Font to use to draw score
234 */
235 void TeamGameModecxx . . $ TeamGameMode#::drawScorecxx . . $ TeamGameMode#drawScore(ae6dc2419597cce5). (Fontcxx . . $ Font#* font) {
236
237 font->showNumbercxx . . $ Font#showNumber(b1146eedae1e1d0b).(localPlayercxx . . $ localPlayer.->teamScorecxx . . $ Player#teamScore., 64, 4);
238
239 }
240
241
242 /**
243 * Get the game mode type
244 *
245 * @return Game mode type (M_COOP)
246 */
247 GameModeTypecxx . . $ GameModeType# CoopGameModecxx . . $ CoopGameMode#::getModecxx . . $ CoopGameMode#getMode(e679e067a917a25c). () {
248
249 return M_COOPcxx . . $ M_COOP.;
250
251 }
252
253
254 /**
255 * Get the game mode type
256 *
257 * @return Game mode type (M_BATTLE)
258 */
259 GameModeTypecxx . . $ GameModeType# BattleGameModecxx . . $ BattleGameMode#::getModecxx . . $ BattleGameMode#getMode(e679e067a917a25c). () {
260
261 return M_BATTLEcxx . . $ M_BATTLE.;
262
263 }
264
265
266 /**
267 * Get the game mode type
268 *
269 * @return Game mode type (M_TEAMBATTLE)
270 */
271 GameModeTypecxx . . $ GameModeType# TeamBattleGameModecxx . . $ TeamBattleGameMode#::getModecxx . . $ TeamBattleGameMode#getMode(e679e067a917a25c). () {
272
273 return M_TEAMBATTLEcxx . . $ M_TEAMBATTLE.;
274
275 }
276
277
278 /**
279 * Get the game mode type
280 *
281 * @return Game mode type (M_RACE)
282 */
283 GameModeTypecxx . . $ GameModeType# RaceGameModecxx . . $ RaceGameMode#::getModecxx . . $ RaceGameMode#getMode(e679e067a917a25c). () {
284
285 return M_RACEcxx . . $ M_RACE.;
286
287 }
288
289
290 /**
291 * Outcome of player being hit
292 *
293 * @param source Player responsible for the hit
294 * @param victim Player victim of the hit
295 *
296 * @return Whether or not the hit should result in energy loss (false)
297 */
298 bool RaceGameModecxx . . $ RaceGameMode#::hitcxx . . $ RaceGameMode#hit(e1486006e22d1cdc). (Playercxx . . $ Player# *source, Playercxx . . $ Player# *victim) {
299
300 OJ_UNUSEDcxx . . $ `src/types.h:67:9`!(source);
301 OJ_UNUSEDcxx . . $ `src/types.h:67:9`!(victim);
302
303 return false;
304
305 }
306
307
308 /**
309 * Outcome of level being completed
310 *
311 * @param game The current game
312 * @param player Player that has completed level
313 * @param gridX X-coordinate (in tiles) of finishing position
314 * @param gridY Y-coordinate (in tiles) of finishing position
315 *
316 * @return Whether or not the level should end (false)
317 */
318 bool RaceGameModecxx . . $ RaceGameMode#::endOfLevelcxx . . $ RaceGameMode#endOfLevel(58252f3afe5a5e7). (Gamecxx . . $ Game#* game, Playercxx . . $ Player# *player, int gridX, int gridY) {
319
320 (void)gridX;
321 (void)gridY;
322
323 if (player == localPlayercxx . . $ localPlayer.) game->scorecxx . . $ Game#score(ac50b47256ae7414).(localPlayercxx . . $ localPlayer.->getTeamcxx . . $ Player#getTeam(7c4be072098b358f).());
324
325 game->resetPlayercxx . . $ Game#resetPlayer(34e2c302b1f0e5dd).(player);
326
327 return false;
328
329 }