improved handling mouse actions (for MM engine)
[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
237   int jx, jy, last_jx, last_jy;
238   int MovDir, MovPos, GfxDir, GfxPos;
239   int Frame, StepFrame;
240
241   int GfxAction;
242
243   int initial_element;          /* EL_PLAYER_1 to EL_PLAYER_4 or EL_SP_MURPHY */
244   int artwork_element;
245   boolean use_murphy;
246
247   boolean block_last_field;
248   int block_delay_adjustment;   /* needed for different engine versions */
249
250   boolean can_fall_into_acid;
251
252   boolean gravity;
253
254   boolean LevelSolved, GameOver;
255
256   boolean LevelSolved_GameWon;
257   boolean LevelSolved_GameEnd;
258   boolean LevelSolved_PanelOff;
259   boolean LevelSolved_SaveTape;
260   boolean LevelSolved_SaveScore;
261   int LevelSolved_CountingTime;
262   int LevelSolved_CountingScore;
263
264   int last_move_dir;
265
266   boolean is_active;
267
268   boolean is_waiting;
269   boolean is_moving;
270   boolean is_auto_moving;
271   boolean is_digging;
272   boolean is_snapping;
273   boolean is_collecting;
274   boolean is_pushing;
275   boolean is_switching;
276   boolean is_dropping;
277   boolean is_dropping_pressed;
278
279   boolean is_bored;
280   boolean is_sleeping;
281
282   boolean was_waiting;
283   boolean was_moving;
284   boolean was_snapping;
285   boolean was_dropping;
286
287   boolean cannot_move;
288
289   boolean force_dropping;       /* needed for single step mode */
290
291   int frame_counter_bored;
292   int frame_counter_sleeping;
293
294   int anim_delay_counter;
295   int post_delay_counter;
296
297   int dir_waiting;
298   int action_waiting, last_action_waiting;
299   int special_action_bored;
300   int special_action_sleeping;
301
302   int num_special_action_bored;
303   int num_special_action_sleeping;
304
305   int switch_x, switch_y;
306   int drop_x, drop_y;
307
308   int show_envelope;
309
310   int move_delay;
311   int move_delay_value;
312   int move_delay_value_next;
313   int move_delay_reset_counter;
314
315   int push_delay;
316   int push_delay_value;
317
318   unsigned int actual_frame_counter;
319
320   int drop_delay;
321   int drop_pressed_delay;
322
323   int step_counter;
324
325   int score;
326   int score_final;
327
328   int gems_still_needed;
329   int sokobanfields_still_needed;
330   int lights_still_needed;
331   int friends_still_needed;
332   int key[MAX_NUM_KEYS];
333   int num_white_keys;
334   int dynabomb_count, dynabomb_size, dynabombs_left, dynabomb_xl;
335   int shield_normal_time_left;
336   int shield_deadly_time_left;
337
338   int inventory_element[MAX_INVENTORY_SIZE];
339   int inventory_infinite_element;
340   int inventory_size;
341 };
342
343 extern struct GameInfo          game;
344 extern struct PlayerInfo        stored_player[MAX_PLAYERS], *local_player;
345
346
347 #ifdef DEBUG
348 void DEBUG_SetMaximumDynamite();
349 #endif
350
351 void GetPlayerConfig(void);
352 int GetElementFromGroupElement(int);
353
354 int getPlayerInventorySize(int);
355
356 void DrawGameValue_Time(int);
357 void DrawGameDoorValues(void);
358
359 void UpdateAndDisplayGameControlValues();
360
361 void InitGameSound();
362 void InitGame();
363
364 void UpdateEngineValues(int, int, int, int);
365 void GameWon(void);
366 void GameEnd(void);
367
368 void InitPlayerGfxAnimation(struct PlayerInfo *, int, int);
369 void Moving2Blocked(int, int, int *, int *);
370 void Blocked2Moving(int, int, int *, int *);
371 void DrawDynamite(int, int);
372
373 void StartGameActions(boolean, boolean, int);
374
375 void GameActions(void);
376 void GameActions_EM_Main();
377 void GameActions_SP_Main();
378 void GameActions_MM_Main();
379 void GameActions_RND_Main();
380 void GameActions_RND();
381
382 void ScrollLevel(int, int);
383
384 void InitPlayLevelSound();
385 void PlayLevelSound_EM(int, int, int, int);
386 void PlayLevelSound_SP(int, int, int, int);
387
388 void RaiseScore(int);
389 void RaiseScoreElement(int);
390
391 void RequestQuitGameExt(boolean, boolean, char *);
392 void RequestQuitGame(boolean);
393
394 unsigned int InitEngineRandom_RND(int);
395 unsigned int RND(int);
396
397 void FreeEngineSnapshotSingle();
398 void FreeEngineSnapshotList();
399 void LoadEngineSnapshotSingle();
400 void SaveEngineSnapshotSingle();
401 boolean CheckSaveEngineSnapshotToList();
402 void SaveEngineSnapshotToList();
403 void SaveEngineSnapshotToListInitial();
404 boolean CheckEngineSnapshotSingle();
405 boolean CheckEngineSnapshotList();
406
407 void CreateGameButtons();
408 void FreeGameButtons();
409 void MapUndoRedoButtons();
410 void UnmapUndoRedoButtons();
411 void MapGameButtons();
412 void UnmapGameButtons();
413 void RedrawGameButtons();
414
415 void HandleSoundButtonKeys(Key);
416
417 #endif