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