rnd-20140218-2-src
[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   struct Rect sound_music;
96   struct Rect sound_loops;
97   struct Rect sound_simple;
98 };
99
100 #else
101
102 struct GamePanelInfo
103 {
104   struct XY level;
105   struct XY gems;
106   struct XY inventory;
107   struct XY keys;
108   struct XY score;
109   struct XY time;
110 };
111 #endif
112
113 struct GameInfo
114 {
115   /* values for control panel */
116   struct GamePanelInfo panel;
117   struct GameButtonInfo button;
118
119   /* values for graphics engine customization */
120   boolean use_native_emc_graphics_engine;
121   boolean use_native_sp_graphics_engine;
122   boolean use_masked_pushing;
123   int forced_scroll_delay_value;
124   int scroll_delay_value;
125   int tile_size;
126
127   /* values for engine initialization */
128   int default_push_delay_fixed;
129   int default_push_delay_random;
130
131   /* constant within running game */
132   int engine_version;
133   int emulation;
134   int initial_move_delay[MAX_PLAYERS];
135   int initial_move_delay_value[MAX_PLAYERS];
136   int initial_push_delay_value;
137
138   /* flag for single or multi-player mode (needed for playing tapes) */
139   /* (when playing/recording games, this is identical to "setup.team_mode" */
140   boolean team_mode;
141
142   /* flags to handle bugs in and changes between different engine versions */
143   /* (for the latest engine version, these flags should always be "FALSE") */
144   boolean use_change_when_pushing_bug;
145   boolean use_block_last_field_bug;
146   boolean max_num_changes_per_frame;
147   boolean use_reverse_scan_direction;
148
149   /* variable within running game */
150   int yamyam_content_nr;
151   boolean robot_wheel_active;
152   boolean magic_wall_active;
153   int magic_wall_time_left;
154   int light_time_left;
155   int timegate_time_left;
156   int belt_dir[4];
157   int belt_dir_nr[4];
158   int switchgate_pos;
159   int wind_direction;
160   boolean gravity;
161   boolean explosions_delayed;
162   boolean envelope_active;
163   boolean no_time_limit;        /* (variable only in very special case) */
164
165   /* values for the new EMC elements */
166   int lenses_time_left;
167   int magnify_time_left;
168   boolean ball_state;
169   int ball_content_nr;
170
171   /* values for player idle animation (no effect on engine) */
172   int player_boring_delay_fixed;
173   int player_boring_delay_random;
174   int player_sleeping_delay_fixed;
175   int player_sleeping_delay_random;
176
177   /* values for special game initialization control */
178   boolean restart_level;
179
180   /* values for special game control */
181   int centered_player_nr;
182   int centered_player_nr_next;
183   boolean set_centered_player;
184
185   /* values for random number generator initialization after snapshot */
186   unsigned int num_random_calls;
187 };
188
189 struct PlayerInfo
190 {
191   boolean present;              /* player present in level playfield */
192   boolean connected;            /* player connected (locally or via network) */
193   boolean active;               /* player present and connected */
194   boolean mapped;               /* player already mapped to input device */
195
196   boolean killed;               /* player maybe present/active, but killed */
197   boolean reanimated;           /* player maybe killed, but reanimated */
198
199   int index_nr;                 /* player number (0 to 3) */
200   int index_bit;                /* player number bit (1 << 0 to 1 << 3) */
201   int element_nr;               /* element (EL_PLAYER_1 to EL_PLAYER_4) */
202   int client_nr;                /* network client identifier */
203
204   byte action;                  /* action from local input device */
205   byte mapped_action;           /* action mapped from device to player */
206   byte effective_action;        /* action acknowledged from network server
207                                    or summarized over all configured input
208                                    devices when in single player mode */
209   byte programmed_action;       /* action forced by game itself (like moving
210                                    through doors); overrides other actions */
211
212   int jx, jy, last_jx, last_jy;
213   int MovDir, MovPos, GfxDir, GfxPos;
214   int Frame, StepFrame;
215
216   int GfxAction;
217
218   int initial_element;          /* EL_PLAYER_1 to EL_PLAYER_4 or EL_SP_MURPHY */
219   int artwork_element;
220   boolean use_murphy;
221
222   boolean block_last_field;
223   int block_delay_adjustment;   /* needed for different engine versions */
224
225   boolean can_fall_into_acid;
226
227   boolean gravity;
228
229   boolean LevelSolved, GameOver;
230
231   boolean LevelSolved_GameWon;
232   boolean LevelSolved_GameEnd;
233   boolean LevelSolved_PanelOff;
234   boolean LevelSolved_SaveTape;
235   boolean LevelSolved_SaveScore;
236   int LevelSolved_CountingTime;
237   int LevelSolved_CountingScore;
238
239   int last_move_dir;
240
241   boolean is_active;
242
243   boolean is_waiting;
244   boolean is_moving;
245   boolean is_auto_moving;
246   boolean is_digging;
247   boolean is_snapping;
248   boolean is_collecting;
249   boolean is_pushing;
250   boolean is_switching;
251   boolean is_dropping;
252   boolean is_dropping_pressed;
253
254   boolean is_bored;
255   boolean is_sleeping;
256
257   boolean cannot_move;
258
259   int frame_counter_bored;
260   int frame_counter_sleeping;
261
262   int anim_delay_counter;
263   int post_delay_counter;
264
265   int dir_waiting;
266   int action_waiting, last_action_waiting;
267   int special_action_bored;
268   int special_action_sleeping;
269
270   int num_special_action_bored;
271   int num_special_action_sleeping;
272
273   int switch_x, switch_y;
274   int drop_x, drop_y;
275
276   int show_envelope;
277
278   int move_delay;
279   int move_delay_value;
280   int move_delay_value_next;
281   int move_delay_reset_counter;
282
283   int push_delay;
284   int push_delay_value;
285
286   unsigned int actual_frame_counter;
287
288   int drop_delay;
289   int drop_pressed_delay;
290
291   int step_counter;
292
293   int score;
294   int score_final;
295
296   int gems_still_needed;
297   int sokobanfields_still_needed;
298   int lights_still_needed;
299   int friends_still_needed;
300   int key[MAX_NUM_KEYS];
301   int num_white_keys;
302   int dynabomb_count, dynabomb_size, dynabombs_left, dynabomb_xl;
303   int shield_normal_time_left;
304   int shield_deadly_time_left;
305
306   int inventory_element[MAX_INVENTORY_SIZE];
307   int inventory_infinite_element;
308   int inventory_size;
309 };
310
311 extern struct GameInfo          game;
312 extern struct PlayerInfo        stored_player[MAX_PLAYERS], *local_player;
313
314
315 #ifdef DEBUG
316 void DEBUG_SetMaximumDynamite();
317 #endif
318
319 void GetPlayerConfig(void);
320 int GetElementFromGroupElement(int);
321
322 void DrawGameValue_Time(int);
323 void DrawGameDoorValues(void);
324
325 void UpdateAndDisplayGameControlValues();
326
327 void InitGameSound();
328 void InitGame();
329
330 void UpdateEngineValues(int, int);
331 void GameWon(void);
332 void GameEnd(void);
333
334 void InitPlayerGfxAnimation(struct PlayerInfo *, int, int);
335 void Moving2Blocked(int, int, int *, int *);
336 void Blocked2Moving(int, int, int *, int *);
337 void DrawDynamite(int, int);
338
339 void StartGameActions(boolean, boolean, int);
340
341 void GameActions(void);
342 void GameActions_EM_Main();
343 void GameActions_SP_Main();
344 void GameActions_RND();
345
346 void ScrollLevel(int, int);
347
348 void InitPlayLevelSound();
349 void PlayLevelSound_EM(int, int, int, int);
350 void PlayLevelSound_SP(int, int, int, int);
351
352 void RaiseScore(int);
353 void RaiseScoreElement(int);
354
355 void RequestQuitGameExt(boolean, boolean, char *);
356 void RequestQuitGame(boolean);
357
358 unsigned int InitEngineRandom_RND(int);
359 unsigned int RND(int);
360
361 void FreeEngineSnapshot();
362 void LoadEngineSnapshot();
363 void SaveEngineSnapshot();
364 boolean CheckEngineSnapshot();
365
366 void CreateGameButtons();
367 void FreeGameButtons();
368 void UnmapGameButtons();
369 void RedrawGameButtons();
370
371 void HandleSoundButtonKeys(Key);
372
373 #endif