added counting remaining health to score after solved game (MM engine)
[rocksndiamonds.git] / src / game.h
1 // ============================================================================
2 // Rocks'n'Diamonds - McDuffin Strikes Back!
3 // ----------------------------------------------------------------------------
4 // (c) 1995-2014 by Artsoft Entertainment
5 //                  Holger Schemel
6 //                  info@artsoft.org
7 //                  http://www.artsoft.org/
8 // ----------------------------------------------------------------------------
9 // game.h
10 // ============================================================================
11
12 #ifndef GAME_H
13 #define GAME_H
14
15 /* (not included here due to collisions with Emerald Mine engine definitions) */
16 /* #include "main.h" */
17
18 #define MAX_INVENTORY_SIZE              1000
19
20 #define MAX_HEALTH                      100
21
22 #define STD_NUM_KEYS                    4
23 #define MAX_NUM_KEYS                    8
24
25 #define NUM_BELTS                       4
26 #define NUM_BELT_PARTS                  3
27
28 #define NUM_PANEL_INVENTORY             8
29 #define NUM_PANEL_GRAPHICS              8
30 #define NUM_PANEL_ELEMENTS              8
31 #define NUM_PANEL_CE_SCORE              8
32
33 #define STR_SNAPSHOT_MODE_OFF           "off"
34 #define STR_SNAPSHOT_MODE_EVERY_STEP    "every_step"
35 #define STR_SNAPSHOT_MODE_EVERY_MOVE    "every_move"
36 #define STR_SNAPSHOT_MODE_EVERY_COLLECT "every_collect"
37 #define STR_SNAPSHOT_MODE_DEFAULT       STR_SNAPSHOT_MODE_OFF
38
39 #define SNAPSHOT_MODE_OFF               0
40 #define SNAPSHOT_MODE_EVERY_STEP        1
41 #define SNAPSHOT_MODE_EVERY_MOVE        2
42 #define SNAPSHOT_MODE_EVERY_COLLECT     3
43 #define SNAPSHOT_MODE_DEFAULT           SNAPSHOT_MODE_OFF
44
45
46 struct GamePanelInfo
47 {
48   struct TextPosInfo level_number;
49   struct TextPosInfo gems;
50   struct TextPosInfo inventory_count;
51   struct TextPosInfo inventory_first[NUM_PANEL_INVENTORY];
52   struct TextPosInfo inventory_last[NUM_PANEL_INVENTORY];
53   struct TextPosInfo key[MAX_NUM_KEYS];
54   struct TextPosInfo key_white;
55   struct TextPosInfo key_white_count;
56   struct TextPosInfo score;
57   struct TextPosInfo highscore;
58   struct TextPosInfo time;
59   struct TextPosInfo time_hh;
60   struct TextPosInfo time_mm;
61   struct TextPosInfo time_ss;
62   struct TextPosInfo time_anim;
63   struct TextPosInfo health;
64   struct TextPosInfo health_anim;
65   struct TextPosInfo frame;
66   struct TextPosInfo shield_normal;
67   struct TextPosInfo shield_normal_time;
68   struct TextPosInfo shield_deadly;
69   struct TextPosInfo shield_deadly_time;
70   struct TextPosInfo exit;
71   struct TextPosInfo emc_magic_ball;
72   struct TextPosInfo emc_magic_ball_switch;
73   struct TextPosInfo light_switch;
74   struct TextPosInfo light_switch_time;
75   struct TextPosInfo timegate_switch;
76   struct TextPosInfo timegate_switch_time;
77   struct TextPosInfo switchgate_switch;
78   struct TextPosInfo emc_lenses;
79   struct TextPosInfo emc_lenses_time;
80   struct TextPosInfo emc_magnifier;
81   struct TextPosInfo emc_magnifier_time;
82   struct TextPosInfo balloon_switch;
83   struct TextPosInfo dynabomb_number;
84   struct TextPosInfo dynabomb_size;
85   struct TextPosInfo dynabomb_power;
86   struct TextPosInfo penguins;
87   struct TextPosInfo sokoban_objects;
88   struct TextPosInfo sokoban_fields;
89   struct TextPosInfo robot_wheel;
90   struct TextPosInfo conveyor_belt[NUM_BELTS];
91   struct TextPosInfo conveyor_belt_switch[NUM_BELTS];
92   struct TextPosInfo magic_wall;
93   struct TextPosInfo magic_wall_time;
94   struct TextPosInfo gravity_state;
95   struct TextPosInfo graphic[NUM_PANEL_GRAPHICS];
96   struct TextPosInfo element[NUM_PANEL_ELEMENTS];
97   struct TextPosInfo element_count[NUM_PANEL_ELEMENTS];
98   struct TextPosInfo ce_score[NUM_PANEL_CE_SCORE];
99   struct TextPosInfo ce_score_element[NUM_PANEL_CE_SCORE];
100   struct TextPosInfo player_name;
101   struct TextPosInfo level_name;
102   struct TextPosInfo level_author;
103 };
104
105 struct GameButtonInfo
106 {
107   struct XY stop;
108   struct XY pause;
109   struct XY play;
110
111   struct XY undo;
112   struct XY redo;
113
114   struct XY save;
115   struct XY pause2;
116   struct XY load;
117
118   struct XY sound_music;
119   struct XY sound_loops;
120   struct XY sound_simple;
121 };
122
123 struct GameSnapshotInfo
124 {
125   int mode;
126
127   byte last_action[MAX_PLAYERS];
128   boolean changed_action;
129   boolean collected_item;
130
131   boolean save_snapshot;
132 };
133
134 struct GameInfo
135 {
136   /* values for control panel */
137   struct GamePanelInfo panel;
138   struct GameButtonInfo button;
139
140   /* values for graphics engine customization */
141   int graphics_engine_version;
142   boolean use_native_emc_graphics_engine;
143   boolean use_native_sp_graphics_engine;
144   boolean use_masked_pushing;
145   int forced_scroll_delay_value;
146   int scroll_delay_value;
147   int tile_size;
148
149   /* values for engine initialization */
150   int default_push_delay_fixed;
151   int default_push_delay_random;
152
153   /* constant within running game */
154   int engine_version;
155   int emulation;
156   int initial_move_delay[MAX_PLAYERS];
157   int initial_move_delay_value[MAX_PLAYERS];
158   int initial_push_delay_value;
159
160   /* flag for single or multi-player mode (needed for playing tapes) */
161   /* (when playing/recording games, this is identical to "setup.team_mode" */
162   boolean team_mode;
163
164   /* flags to handle bugs in and changes between different engine versions */
165   /* (for the latest engine version, these flags should always be "FALSE") */
166   boolean use_change_when_pushing_bug;
167   boolean use_block_last_field_bug;
168   boolean max_num_changes_per_frame;
169   boolean use_reverse_scan_direction;
170
171   /* variable within running game */
172   int yamyam_content_nr;
173   boolean robot_wheel_active;
174   boolean magic_wall_active;
175   int magic_wall_time_left;
176   int light_time_left;
177   int timegate_time_left;
178   int belt_dir[4];
179   int belt_dir_nr[4];
180   int switchgate_pos;
181   int wind_direction;
182   boolean gravity;
183   boolean explosions_delayed;
184   boolean envelope_active;
185   boolean no_time_limit;        /* (variable only in very special case) */
186
187   /* values for the new EMC elements */
188   int lenses_time_left;
189   int magnify_time_left;
190   boolean ball_state;
191   int ball_content_nr;
192
193   /* values for player idle animation (no effect on engine) */
194   int player_boring_delay_fixed;
195   int player_boring_delay_random;
196   int player_sleeping_delay_fixed;
197   int player_sleeping_delay_random;
198
199   /* values for special game initialization control */
200   boolean restart_level;
201
202   /* values for special game control */
203   int centered_player_nr;
204   int centered_player_nr_next;
205   boolean set_centered_player;
206
207   /* values for random number generator initialization after snapshot */
208   unsigned int num_random_calls;
209
210   /* values for game engine snapshot control */
211   struct GameSnapshotInfo snapshot;
212 };
213
214 struct PlayerInfo
215 {
216   boolean present;              /* player present in level playfield */
217   boolean connected;            /* player connected (locally or via network) */
218   boolean active;               /* player present and connected */
219   boolean mapped;               /* player already mapped to input device */
220
221   boolean killed;               /* player maybe present/active, but killed */
222   boolean reanimated;           /* player maybe killed, but reanimated */
223
224   int index_nr;                 /* player number (0 to 3) */
225   int index_bit;                /* player number bit (1 << 0 to 1 << 3) */
226   int element_nr;               /* element (EL_PLAYER_1 to EL_PLAYER_4) */
227   int client_nr;                /* network client identifier */
228
229   byte action;                  /* action from local input device */
230   byte mapped_action;           /* action mapped from device to player */
231   byte effective_action;        /* action acknowledged from network server
232                                    or summarized over all configured input
233                                    devices when in single player mode */
234   byte programmed_action;       /* action forced by game itself (like moving
235                                    through doors); overrides other actions */
236
237   struct MouseActionInfo mouse_action;           /* (used by MM engine only) */
238   struct MouseActionInfo effective_mouse_action; /* (used by MM engine only) */
239
240   int jx, jy, last_jx, last_jy;
241   int MovDir, MovPos, GfxDir, GfxPos;
242   int Frame, StepFrame;
243
244   int GfxAction;
245
246   int initial_element;          /* EL_PLAYER_1 to EL_PLAYER_4 or EL_SP_MURPHY */
247   int artwork_element;
248   boolean use_murphy;
249
250   boolean block_last_field;
251   int block_delay_adjustment;   /* needed for different engine versions */
252
253   boolean can_fall_into_acid;
254
255   boolean gravity;
256
257   boolean LevelSolved, GameOver;
258
259   boolean LevelSolved_GameWon;
260   boolean LevelSolved_GameEnd;
261   boolean LevelSolved_PanelOff;
262   boolean LevelSolved_SaveTape;
263   boolean LevelSolved_SaveScore;
264
265   int LevelSolved_CountingTime;
266   int LevelSolved_CountingScore;
267   int LevelSolved_CountingHealth;
268
269   int last_move_dir;
270
271   boolean is_active;
272
273   boolean is_waiting;
274   boolean is_moving;
275   boolean is_auto_moving;
276   boolean is_digging;
277   boolean is_snapping;
278   boolean is_collecting;
279   boolean is_pushing;
280   boolean is_switching;
281   boolean is_dropping;
282   boolean is_dropping_pressed;
283
284   boolean is_bored;
285   boolean is_sleeping;
286
287   boolean was_waiting;
288   boolean was_moving;
289   boolean was_snapping;
290   boolean was_dropping;
291
292   boolean cannot_move;
293
294   boolean force_dropping;       /* needed for single step mode */
295
296   int frame_counter_bored;
297   int frame_counter_sleeping;
298
299   int anim_delay_counter;
300   int post_delay_counter;
301
302   int dir_waiting;
303   int action_waiting, last_action_waiting;
304   int special_action_bored;
305   int special_action_sleeping;
306
307   int num_special_action_bored;
308   int num_special_action_sleeping;
309
310   int switch_x, switch_y;
311   int drop_x, drop_y;
312
313   int show_envelope;
314
315   int move_delay;
316   int move_delay_value;
317   int move_delay_value_next;
318   int move_delay_reset_counter;
319
320   int push_delay;
321   int push_delay_value;
322
323   unsigned int actual_frame_counter;
324
325   int drop_delay;
326   int drop_pressed_delay;
327
328   int step_counter;
329
330   int score;
331   int score_final;
332
333   int health;
334   int health_final;
335
336   int gems_still_needed;
337   int sokobanfields_still_needed;
338   int lights_still_needed;
339   int friends_still_needed;
340   int key[MAX_NUM_KEYS];
341   int num_white_keys;
342   int dynabomb_count, dynabomb_size, dynabombs_left, dynabomb_xl;
343   int shield_normal_time_left;
344   int shield_deadly_time_left;
345
346   int inventory_element[MAX_INVENTORY_SIZE];
347   int inventory_infinite_element;
348   int inventory_size;
349 };
350
351 extern struct GameInfo          game;
352 extern struct PlayerInfo        stored_player[MAX_PLAYERS], *local_player;
353
354
355 #ifdef DEBUG
356 void DEBUG_SetMaximumDynamite();
357 #endif
358
359 void GetPlayerConfig(void);
360 int GetElementFromGroupElement(int);
361
362 int getPlayerInventorySize(int);
363
364 void DrawGameValue_Time(int);
365 void DrawGameDoorValues(void);
366
367 void UpdateAndDisplayGameControlValues();
368
369 void InitGameSound();
370 void InitGame();
371
372 void UpdateEngineValues(int, int, int, int);
373 void GameWon(void);
374 void GameEnd(void);
375
376 void InitPlayerGfxAnimation(struct PlayerInfo *, int, int);
377 void Moving2Blocked(int, int, int *, int *);
378 void Blocked2Moving(int, int, int *, int *);
379 void DrawDynamite(int, int);
380
381 void StartGameActions(boolean, boolean, int);
382
383 void GameActions(void);
384 void GameActions_EM_Main();
385 void GameActions_SP_Main();
386 void GameActions_MM_Main();
387 void GameActions_RND_Main();
388 void GameActions_RND();
389
390 void ScrollLevel(int, int);
391
392 void InitPlayLevelSound();
393 void PlayLevelSound_EM(int, int, int, int);
394 void PlayLevelSound_SP(int, int, int, int);
395 void PlayLevelSound_MM(int, int, int, int);
396 void PlaySound_MM(int);
397 void PlaySoundLoop_MM(int);
398 void StopSound_MM(int);
399
400 void RaiseScore(int);
401 void RaiseScoreElement(int);
402
403 void RequestQuitGameExt(boolean, boolean, char *);
404 void RequestQuitGame(boolean);
405
406 unsigned int InitEngineRandom_RND(int);
407 unsigned int RND(int);
408
409 void FreeEngineSnapshotSingle();
410 void FreeEngineSnapshotList();
411 void LoadEngineSnapshotSingle();
412 void SaveEngineSnapshotSingle();
413 boolean CheckSaveEngineSnapshotToList();
414 void SaveEngineSnapshotToList();
415 void SaveEngineSnapshotToListInitial();
416 boolean CheckEngineSnapshotSingle();
417 boolean CheckEngineSnapshotList();
418
419 void CreateGameButtons();
420 void FreeGameButtons();
421 void MapUndoRedoButtons();
422 void UnmapUndoRedoButtons();
423 void MapGameButtons();
424 void UnmapGameButtons();
425 void RedrawGameButtons();
426
427 void HandleSoundButtonKeys(Key);
428
429 #endif