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