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