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