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