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