189e2777d69687375c72e2a86bd283d57050f359
[rocksndiamonds.git] / src / game_bd / bd_cave.h
1 /*
2  * Copyright (c) 2007, 2008, 2009, Czirkos Zoltan <cirix@fw.hu>
3  *
4  * Permission to use, copy, modify, and distribute this software for any
5  * purpose with or without fee is hereby granted, provided that the above
6  * copyright notice and this permission notice appear in all copies.
7  *
8  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15  */
16
17 #ifndef BD_CAVE_H
18 #define BD_CAVE_H
19
20 #include <glib.h>
21
22 #include "bd_elements.h"
23
24
25 // colors
26
27 typedef guint32 GdColor;
28
29 /* color internal:
30    XXRRGGBB;
31    XX is 0 for RGB,
32          1 for c64 colors (bb=index)
33          3 for c64dtv (bb=index)
34          2 for atari colors (bb=index)
35 */
36
37 typedef enum _color_type
38 {
39   GD_COLOR_TYPE_RGB     = 0,
40   GD_COLOR_TYPE_C64     = 1,
41   GD_COLOR_TYPE_C64DTV  = 2,
42   GD_COLOR_TYPE_ATARI   = 3,
43
44   GD_COLOR_TYPE_UNKNOWN    /* should be the last one */
45 } GdColorType;
46
47 /* traditional c64 color indexes. */
48 #define GD_COLOR_INDEX_BLACK            (0)
49 #define GD_COLOR_INDEX_WHITE            (1)
50 #define GD_COLOR_INDEX_RED              (2)
51 #define GD_COLOR_INDEX_CYAN             (3)
52 #define GD_COLOR_INDEX_PURPLE           (4)
53 #define GD_COLOR_INDEX_GREEN            (5)
54 #define GD_COLOR_INDEX_BLUE             (6)
55 #define GD_COLOR_INDEX_YELLOW           (7)
56 #define GD_COLOR_INDEX_ORANGE           (8)
57 #define GD_COLOR_INDEX_BROWN            (9)
58 #define GD_COLOR_INDEX_LIGHTRED         (10)
59 #define GD_COLOR_INDEX_GRAY1            (11)
60 #define GD_COLOR_INDEX_GRAY2            (12)
61 #define GD_COLOR_INDEX_LIGHTGREEN       (13)
62 #define GD_COLOR_INDEX_LIGHTBLUE        (14)
63 #define GD_COLOR_INDEX_GRAY3            (15)
64
65 #define GD_GDASH_BLACK          (0x000000)
66 #define GD_GDASH_WHITE          (0xFFFFFF)
67 #define GD_GDASH_RED            (0x880000)
68 #define GD_GDASH_CYAN           (0xAAFFEE)
69 #define GD_GDASH_PURPLE         (0xCC44CC)
70 #define GD_GDASH_GREEN          (0x00CC55)
71 #define GD_GDASH_BLUE           (0x0000AA)
72 #define GD_GDASH_YELLOW         (0xEEEE77)
73 #define GD_GDASH_ORANGE         (0xDD8855)
74 #define GD_GDASH_BROWN          (0x664400)
75 #define GD_GDASH_LIGHTRED       (0xFF7777)
76 #define GD_GDASH_GRAY1          (0x333333)
77 #define GD_GDASH_GRAY2          (0x777777)
78 #define GD_GDASH_LIGHTGREEN     (0xAAFF66)
79 #define GD_GDASH_LIGHTBLUE      (0x0088FF)
80 #define GD_GDASH_GRAY3          (0xBBBBBB)
81
82 #define GD_COLOR_INVALID (0xFFFFFFFF)
83
84
85 /******************************************
86  *
87  * BIG STRUCT HANDLING
88  *
89  */
90
91 /* possible types handled */
92 typedef enum _gd_type
93 {
94   /* not real types, only used by editor to build ui */
95   GD_TAB,
96   GD_LABEL,
97
98   /* gd types */
99   GD_TYPE_STRING,        /* static string, fixed array of characters */
100   GD_TYPE_LONGSTRING,    /* long string which has its own notebook page in
101                             the editor */
102   GD_TYPE_INT,
103   GD_TYPE_RATIO,
104   GD_TYPE_ELEMENT,
105   GD_TYPE_BOOLEAN,
106   GD_TYPE_PROBABILITY,   /* probabilities are stored in parts per million,
107                             ie. *1E6, converted to int. */
108   GD_TYPE_COLOR,
109   GD_TYPE_EFFECT,
110   GD_TYPE_DIRECTION,
111   GD_TYPE_SCHEDULING,
112 } GdType;
113
114 enum _gd_property_flags
115 {
116   GD_ALWAYS_SAVE           = 1 << 0,
117   GD_DONT_SAVE             = 1 << 1,
118   GD_DONT_SHOW_IN_EDITOR   = 1 << 2,
119   GD_SHOW_LEVEL_LABEL      = 1 << 3,
120   GD_COMPATIBILITY_SETTING = 1 << 4,
121 };
122
123 typedef struct _gd_struct_descriptor
124 {
125   char *identifier; /* bdcff identifier */
126   GdType type;      /* data type */
127   int flags;        /* flags for bdcff saving/loading */
128   char *name;       /* name in editor */
129   int offset;       /* byte offset in a GdCave structure. use the CAVE_OFFSET macro */
130   int count;        /* size of array; usually 1, for non-arrays. */
131   char *tooltip;    /* tooltip text in editor */
132   int min, max;     /* integers have minimum and maximum */
133 } GdStructDescriptor;
134
135 typedef struct _gd_property_default
136 {
137   int offset;    /* data offset (bytes) in a cave structure */
138   int defval;    /* default value, converted to int. if type is a float, *1000000 */
139
140   int property_index;    /* index in gd_cave_properties; created at runtime */
141 } GdPropertyDefault;
142
143
144 void gd_struct_set_defaults_from_array(gpointer str, const GdStructDescriptor *properties, GdPropertyDefault *defaults);
145
146 /* these define the number of the cells in the png file */
147 #define GD_NUM_OF_CELLS_X 8
148 #define GD_NUM_OF_CELLS_Y 46
149
150 /* +80: placeholder for cells which are rendered by the game;
151    for example diamond + arrow = falling diamond */
152 #define GD_NUM_OF_CELLS (GD_NUM_OF_CELLS_X*GD_NUM_OF_CELLS_Y+80)
153
154 extern const GdColor gd_flash_color;
155 extern const GdColor gd_select_color;
156
157 enum _element_property
158 {
159   E_P_SLOPED_LEFT,      /* stones and diamonds roll down to left on this */
160   E_P_SLOPED_RIGHT,     /* stones and diamonds roll down to right on this */
161   E_P_SLOPED_UP,
162   E_P_SLOPED_DOWN,
163   E_P_BLADDER_SLOPED,   /* element act sloped also for the bladder */
164
165   E_P_AMOEBA_CONSUMES,  /* amoeba can eat this */
166   E_P_DIRT,             /* it is dirt, or something similar (dirt2 or sloped dirt) */
167   E_P_BLOWS_UP_FLIES,   /* flies blow up, if they touch this */
168   E_P_EXPLODES_BY_HIT,  /* explodes if hit by a stone */
169
170   E_P_EXPLOSION_FIRST_STAGE,    /* set for first stage of every explosion.
171                                    helps slower/faster explosions changing */
172
173   E_P_NON_EXPLODABLE,           /* selfexplaining */
174   E_P_CCW,                      /* this creature has a default counterclockwise
175                                    rotation (for example, o_fire_1) */
176   E_P_CAN_BE_HAMMERED,          /* can be broken by pneumatic hammer */
177   E_P_VISUAL_EFFECT,            /* if the element can use a visual effect.
178                                    used to check consistency of the code */
179   E_P_PLAYER,                   /* easier to find out if it is a player element */
180   E_P_MOVED_BY_CONVEYOR_TOP,    /* can be moved by conveyor belt */
181   E_P_MOVED_BY_CONVEYOR_BOTTOM, /* can be moved UNDER the conveyor belt */
182 };
183
184 /* properties */
185 #define P_SLOPED_LEFT                   (1 << E_P_SLOPED_LEFT)
186 #define P_SLOPED_RIGHT                  (1 << E_P_SLOPED_RIGHT)
187 #define P_SLOPED_UP                     (1 << E_P_SLOPED_UP)
188 #define P_SLOPED_DOWN                   (1 << E_P_SLOPED_DOWN)
189
190 /* flag to say "any direction" */
191 #define P_SLOPED                        (P_SLOPED_LEFT  |               \
192                                          P_SLOPED_RIGHT |               \
193                                          P_SLOPED_UP    |               \
194                                          P_SLOPED_DOWN)
195
196 #define P_BLADDER_SLOPED                (1 << E_P_BLADDER_SLOPED)
197
198 #define P_AMOEBA_CONSUMES               (1 << E_P_AMOEBA_CONSUMES)
199 #define P_DIRT                          (1 << E_P_DIRT)
200 #define P_BLOWS_UP_FLIES                (1 << E_P_BLOWS_UP_FLIES)
201
202 #define P_EXPLODES_BY_HIT               (1 << E_P_EXPLODES_BY_HIT)
203 #define P_EXPLOSION_FIRST_STAGE         (1 << E_P_EXPLOSION_FIRST_STAGE)
204
205 #define P_NON_EXPLODABLE                (1 << E_P_NON_EXPLODABLE)
206 #define P_CCW                           (1 << E_P_CCW)
207 #define P_CAN_BE_HAMMERED               (1 << E_P_CAN_BE_HAMMERED)
208 #define P_VISUAL_EFFECT                 (1 << E_P_VISUAL_EFFECT)
209 #define P_PLAYER                        (1 << E_P_PLAYER)
210 #define P_MOVED_BY_CONVEYOR_TOP         (1 << E_P_MOVED_BY_CONVEYOR_TOP)
211 #define P_MOVED_BY_CONVEYOR_BOTTOM      (1 << E_P_MOVED_BY_CONVEYOR_BOTTOM)
212
213 /* These are states of the magic wall. */
214 typedef enum _magic_wall_state
215 {
216   GD_MW_DORMANT,                /* Starting with this. */
217   GD_MW_ACTIVE,                 /* Boulder or diamond dropped into. */
218   GD_MW_EXPIRED                 /* Turned off after magic_wall_milling_time. */
219 } GdMagicWallState;
220
221 /* These are states of Player. */
222 typedef enum _player_state
223 {
224   GD_PL_NOT_YET,                /* Not yet living. Beginning of cave time. */
225   GD_PL_LIVING,                 /* Ok. */
226   GD_PL_TIMEOUT,                /* Time is up */
227   GD_PL_DIED,                   /* Died. */
228   GD_PL_EXITED                  /* Exited the cave, proceed to next one */
229 } GdPlayerState;
230
231 /* States of amoeba */
232 typedef enum _amoeba_state
233 {
234   GD_AM_SLEEPING,               /* sleeping - not yet let out. */
235   GD_AM_AWAKE,                  /* living, growing */
236   GD_AM_TOO_BIG,                /* grown too big, will convert to stones */
237   GD_AM_ENCLOSED,               /* enclosed, will convert to diamonds */
238 } GdAmoebaState;
239
240 typedef enum _direction
241 {
242   /* not moving */
243   GD_MV_STILL           = 0,
244   GD_MV_THIS            = 0,
245
246   /* directions */
247   GD_MV_UP              = 1,
248   GD_MV_UP_RIGHT        = 2,
249   GD_MV_RIGHT           = 3,
250   GD_MV_DOWN_RIGHT      = 4,
251   GD_MV_DOWN            = 5,
252   GD_MV_DOWN_LEFT       = 6,
253   GD_MV_LEFT            = 7,
254   GD_MV_UP_LEFT         = 8,
255
256   /* to be able to type GD_MV_TWICE + GD_MV_DOWN, for example */
257   GD_MV_TWICE           = 8,
258
259   /* directions * 2 */
260   GD_MV_UP_2            = 9,
261   GD_MV_UP_RIGHT_2      = 10,
262   GD_MV_RIGHT_2         = 11,
263   GD_MV_DOWN_RIGHT_2    = 12,
264   GD_MV_DOWN_2          = 13,
265   GD_MV_DOWN_LEFT_2     = 14,
266   GD_MV_LEFT_2          = 15,
267   GD_MV_UP_LEFT_2       = 16,
268
269   GD_MV_MAX,
270 } GdDirection;
271
272 enum
273 {
274   GD_REPLAY_MOVE_MASK    = 0x0f,
275   GD_REPLAY_FIRE_MASK    = 0x10,
276   GD_REPLAY_SUICIDE_MASK = 0x20,
277 };
278
279
280 /* ELEMENTS DESCRIPTION */
281 typedef struct _elements
282 {
283   GdElement element;    /* element number. for example O_DIRT */
284   char *name;           /* name in editor, for example "Dirt". some have
285                            different names than their real engine meaning! */
286   unsigned int properties; /* engine properties, like P_SLOPED or P_EXPLODES */
287   char *filename;       /* name in bdcff file, like "DIRT" */
288   char character;       /* character representation in bdcff file, like '.' */
289   int image;            /* image in editor (index in cells.png) */
290   int image_simple;     /* image for simple view in editor, and for combo box (index in cells.png) */
291   int image_game;       /* image for game. negative if animated */
292   int ckdelay;          /* ckdelay ratio - how much time required for a c64 to
293                            process this element - in microseconds. */
294
295   char *lowercase_name; /* lowercase of translated name. for editor; generated inside the game. */
296   char character_new;   /* character given automatically for elements which
297                            don't have one defined in original bdcff description */
298 } GdElements;
299
300
301 typedef char GdString[128];
302
303 typedef struct _highscore
304 {
305   GdString name;
306   int score;
307 } GdHighScore;
308
309 /* maximum seed value for the cave random generator. should be smaller than a signed int. */
310 #define GD_CAVE_SEED_MAX        (1 << 30)
311
312 typedef struct _gd_cave_replay
313 {
314   int level;                /* replay for level n */
315   guint32 seed;             /* seed the cave is to be rendered with */
316   boolean saved;            /* also store it in the saved bdcff */
317   GdString recorded_with;   /* recorded with - application name and version */
318
319   GdString player_name;     /* who played this */
320   GdString date;            /* when played */
321   GString *comment;         /* some comments from the player */
322
323   int score;                /* score collected */
324   int duration;             /* number of seconds played */
325   boolean success;          /* successful playing of cave? */
326   guint32 checksum;         /* checksum of the rendered cave. */
327
328   boolean wrong_checksum;
329   GByteArray *movements;
330   int current_playing_pos;
331 } GdReplay;
332
333 typedef enum _gd_scheduling
334 {
335   GD_SCHEDULING_MILLISECONDS,
336   GD_SCHEDULING_BD1,
337   GD_SCHEDULING_BD2,
338   GD_SCHEDULING_PLCK,
339   GD_SCHEDULING_CRDR,
340   GD_SCHEDULING_BD1_ATARI,
341   GD_SCHEDULING_BD2_PLCK_ATARI,
342   GD_SCHEDULING_MAX
343 } GdScheduling;
344
345 typedef struct _gd_c64_random_generator
346 {
347   int rand_seed_1, rand_seed_2;
348 } GdC64RandomGenerator;
349
350 /*
351     Structure holding all data belonging to a cave.
352 */
353
354 #define GD_HIGHSCORE_NUM 20
355
356 typedef struct _gd_cave
357 {
358   /* Defined by the editor. public data :) */
359   GdString name;                /* Name of cave */
360   GdString description;        /* Some words about the cave */
361   GdString author;            /* Author */
362   GdString difficulty;        /* difficulty of the game, for info purposes */
363   GdString www;                /* link to author's webpage */
364   GdString date;                /* date of creation */
365   GString *story;                /* story for the cave - will be shown when the cave is played. */
366   GString *remark;            /* some note */
367
368   GdString charset;            /* these are not used by gdash */
369   GdString fontset;
370
371   /* and this one the highscores */
372   GdHighScore highscore[GD_HIGHSCORE_NUM];
373
374   GHashTable *tags;            /* stores read-but-not-understood strings from bdcff, so we can save them later. */
375
376   GdElement **map;            /* pointer to data for map, non-null if has a map */
377   GList *objects;
378   GList *replays;
379
380   boolean intermission;        /* is this cave an intermission? */
381   boolean intermission_instantlife;    /* one life extra, if the intermission is reached */
382   boolean intermission_rewardlife;    /* one life extra, if the intermission is successfully finished */
383   boolean selectable;            /* is this selectable as an initial cave for a game? */
384   boolean diagonal_movements;    /* are diagonal movements allowed? */
385   GdElement snap_element;        /* snapping (press fire+move) usually leaves space behind, but can be other */
386   boolean short_explosions;        /* in >=1stb, diamond and creature explosions were of 5 stages */
387
388   GdScheduling scheduling;    /* scheduling type; see above */
389   boolean pal_timing;        /* use faster seconds */
390
391   boolean active_is_first_found;    /* active player is the uppermost. */
392   boolean lineshift;                /* true is line shifting emulation, false is perfect borders emulation */
393   boolean border_scan_first_and_last;    /* if true, scans the first and last line of the border. false for plck */
394   boolean wraparound_objects;    /* if this is true, object drawing (cave rendering) will wraparound as well. */
395
396   GdElement initial_fill;
397   GdElement initial_border;
398   GdElement random_fill[4];        /* Random fill elements. */
399   int random_fill_probability[4];    /* Random fill, probability of each element. */
400
401   int level_rand[5];            /* Random seed. */
402   int level_diamonds[5];        /* Must collect diamonds, on level x */
403   int level_speed[5];            /* Time between game cycles in ms */
404   int level_ckdelay[5];        /* Timing in original game units */
405   int level_time[5];            /* Available time, per level */
406   int level_timevalue[5];        /* points for each second remaining, when exiting level */
407
408   int max_time;            /* the maximum time in seconds. if above, it overflows */
409
410   int w, h;                /* Sizes of cave, width and height. */
411   int x1,y1,x2,y2;        /* Visible part of the cave */
412   GdColor colorb;            /* border color */
413   GdColor color0, color1, color2, color3, color4, color5;    /* c64-style colors; 4 and 5 are amoeba and slime. */
414
415   int diamond_value;            /* Score for a diamond. */
416   int extra_diamond_value;    /* Score for a diamond, when gate is open. */
417
418   boolean stone_sound;
419   boolean nut_sound;
420   boolean diamond_sound;
421   boolean nitro_sound;
422   boolean falling_wall_sound;
423   boolean expanding_wall_sound;
424   boolean bladder_spender_sound;
425   boolean bladder_convert_sound;
426
427   int level_magic_wall_time[5];    /* magic wall 'on' state for each level (seconds) */
428   boolean magic_wall_stops_amoeba;    /* Turning on magic wall changes amoeba to diamonds. Original BD: yes, constkit: no */
429   boolean magic_timer_wait_for_hatching;    /* magic wall timer does not start before player's birth */
430   boolean magic_wall_sound;    /* magic wall has sound */
431
432   int level_amoeba_time[5];        /* amoeba time for each level */
433   int amoeba_growth_prob;        /* Amoeba slow growth probability */
434   int amoeba_fast_growth_prob;    /* Amoeba fast growth probability */
435   int level_amoeba_threshold[5];        /* amoeba turns to stones; if count is bigger than this (number of cells) */
436   GdElement amoeba_enclosed_effect;    /* an enclosed amoeba converts to this element */
437   GdElement amoeba_too_big_effect;    /* an amoeba grown too big converts to this element */
438
439   int level_amoeba_2_time[5];        /* amoeba time for each level */
440   int amoeba_2_growth_prob;        /* Amoeba slow growth probability */
441   int amoeba_2_fast_growth_prob;    /* Amoeba fast growth probability */
442   int level_amoeba_2_threshold[5];        /* amoeba turns to stones; if count is bigger than this (number of cells) */
443   GdElement amoeba_2_enclosed_effect;    /* an enclosed amoeba converts to this element */
444   GdElement amoeba_2_too_big_effect;    /* an amoeba grown too big converts to this element */
445   boolean amoeba_2_explodes_by_amoeba;    /* amoeba 2 will explode if touched by amoeba1 */
446   GdElement amoeba_2_explosion_effect;    /* amoeba 2 explosion ends in ... */
447   GdElement amoeba_2_looks_like;    /* an amoeba 2 looks like this element */
448
449   boolean amoeba_timer_started_immediately;    /* FALSE: amoeba will start life at the first possibility of growing. */
450   boolean amoeba_timer_wait_for_hatching;    /* amoeba timer does not start before player's birth */
451   boolean amoeba_sound;            /* if the living amoeba has sound. */
452
453   GdElement acid_eats_this;        /* acid eats this element */
454   int acid_spread_ratio;        /* Probability of acid blowing up, each frame */
455   boolean acid_spread_sound;        /* acid has sound */
456   GdElement acid_turns_to;        /* whether acid converts to explosion on spreading or other */
457
458   GdElement nut_turns_to_when_crushed;    /* when a nut is hit by a stone, it converts to this element */
459
460   int level_slime_permeability[5];        /* true random slime */
461   int level_slime_permeability_c64[5];    /* Appearing in bd 2 */
462   int level_slime_seed_c64[5];            /* predictable slime random seed */
463   boolean slime_predictable;                /* predictable random start for slime. yes for plck. */
464   GdElement slime_eats_1, slime_converts_1;    /* slime eats element x and converts to element x; for example diamond -> falling diamond */
465   GdElement slime_eats_2, slime_converts_2;    /* this is usually stone -> stone_f */
466   GdElement slime_eats_3, slime_converts_3;    /* this is usually nut -> nut_f */
467   boolean slime_sound;            /* slime has sound */
468
469   boolean lava_sound;            /* elements sinking in lava have sound */
470
471   int level_hatching_delay_frame[5];        /* Scan frames before Player's birth. */
472   int level_hatching_delay_time[5];        /* Scan frames before Player's birth. */
473
474   int level_bonus_time[5];        /* bonus time for clock collected. */
475   int level_penalty_time[5];                /* Time penalty when voodoo destroyed. */
476   boolean voodoo_collects_diamonds;    /* Voodoo can collect diamonds */
477   boolean voodoo_dies_by_stone;        /* Voodoo can be killed by a falling stone */
478   boolean voodoo_disappear_in_explosion;    /* Voodoo can be destroyed by and explosion */
479   boolean voodoo_any_hurt_kills_player;    /* If any of the voodoos are hurt in any way, the player is killed. */
480
481   boolean water_does_not_flow_down;    /* if true, water will not grow downwards, only in other directions. */
482   boolean water_sound;            /* water has sound */
483
484   boolean bladder_sound;        /* bladder moving and pushing has sound */
485   GdElement bladder_converts_by;    /* bladder converts to clock by touching this element */
486
487   int biter_delay_frame;        /* frame count biters do move */
488   GdElement biter_eat;        /* biters eat this */
489   boolean biter_sound;        /* biters have sound */
490
491   boolean expanding_wall_changed;    /* expanding wall direction is changed */
492
493   int    replicator_delay_frame;        /* replicator delay in frames (number of frames to wait between creating a new element) */
494   boolean replicators_active;        /* replicators are active. */
495   boolean replicator_sound;        /* when replicating an element, play sound or not. */
496
497   boolean conveyor_belts_active;
498   boolean conveyor_belts_direction_changed;
499
500   /* effects */
501   GdElement explosion_effect;            /* explosion converts to this element after its last stage. diego effect. */
502   GdElement diamond_birth_effect;        /* a diamond birth converts to this element after its last stage. diego effect. */
503   GdElement bomb_explosion_effect;        /* bombs explode to this element. diego effect (almost). */
504   GdElement nitro_explosion_effect;    /* nitros explode to this */
505
506   GdElement firefly_explode_to;        /* fireflies explode to this when hit by a stone */
507   GdElement alt_firefly_explode_to;    /* alternative fireflies explode to this when hit by a stone */
508   GdElement butterfly_explode_to;        /* butterflies explode to this when hit by a stone */
509   GdElement alt_butterfly_explode_to;    /* alternative butterflies explode to this when hit by a stone */
510   GdElement stonefly_explode_to;        /* stoneflies explode to this when hit by a stone */
511   GdElement dragonfly_explode_to;        /* dragonflies explode to this when hit by a stone */
512
513   GdElement stone_falling_effect;        /* a falling stone converts to this element. diego effect. */
514   GdElement diamond_falling_effect;    /* a falling diamond converts to this element. diego effect. */
515   GdElement stone_bouncing_effect;    /* a bouncing stone converts to this element. diego effect. */
516   GdElement diamond_bouncing_effect;    /* a bouncing diamond converts to this element. diego effect. */
517
518   GdElement expanding_wall_looks_like;    /* an expanding wall looks like this element. diego effect. */
519   GdElement dirt_looks_like;            /* dirt looks like this element. diego effect. */
520
521   GdElement magic_stone_to;        /* magic wall converts falling stone to */
522   GdElement magic_diamond_to;        /* magic wall converts falling diamond to */
523   GdElement magic_mega_stone_to;    /* magic wall converts a falling mega stone to */
524   GdElement magic_nitro_pack_to;    /* magic wall converts a falling nitro pack to */
525   GdElement magic_nut_to;                /* magic wall converts a falling nut to */
526   GdElement magic_flying_stone_to;    /* flying stones are converted to */
527   GdElement magic_flying_diamond_to;    /* flying diamonds are converted to */
528
529   int pushing_stone_prob;        /* probability of pushing stone */
530   int pushing_stone_prob_sweet;    /* probability of pushing, after eating sweet */
531   boolean mega_stones_pushable_with_sweet;    /* mega stones may be pushed with sweet */
532
533   boolean creatures_backwards;    /* creatures changed direction */
534   boolean creatures_direction_auto_change_on_start;    /* the change occurs also at the start signal */
535   int creatures_direction_auto_change_time;    /* creatures automatically change direction every x seconds */
536   boolean creature_direction_auto_change_sound;    /* automatically changing creature direction may have the sound of the creature dir switch */
537
538   int skeletons_needed_for_pot;    /* how many skeletons to be collected, to use a pot */
539   int skeletons_worth_diamonds;    /* for crazy dream 7 compatibility: collecting skeletons might open the cave door. */
540
541   GdDirection gravity;
542   int gravity_change_time;
543   boolean gravity_change_sound;
544   boolean gravity_affects_all;    /* if true, gravity also affects falling wall, bladder and waiting stones */
545   boolean gravity_switch_active;    /* true if gravity switch is activated, and can be used. */
546
547   boolean hammered_walls_reappear;
548   int pneumatic_hammer_frame;
549   int hammered_wall_reappear_frame;
550   boolean pneumatic_hammer_sound;
551
552   /* internal variables, used during the game. private data :) */
553   GdElement* (*getp) (const struct _gd_cave*, int x, int y);    /* returns a pointer to the element at x, y. this points to a perfect border or a line shifting get function. */
554
555   boolean hatched;            /* hatching has happened. (timers may run, ...) */
556   boolean gate_open;            /* self-explaining */
557   guint32 render_seed;        /* the seed value, which was used to render the cave, is saved here. will be used by record&playback */
558   GRand *random;                /* random number generator of rendered cave */
559   int rendered;                /* if not zero, rendered at level x */
560   int timing_factor;            /* number of "milliseconds" in each second :) 1000 for ntsc, 1200 for pal. */
561   gpointer **objects_order;    /* two-dimensional map of cave; each cell is a pointer to the drawing object, which created this element. NULL if map or random. */
562   int **hammered_reappear;    /* integer map of cave; if non-zero, a brick wall will appear there */
563
564   int speed;                    /* Time between game cycles in ms */
565   int c64_timing;                /* a ckdelay value for the level this cave is rendered for */
566   int ckdelay;                /* ckdelay value for the current iteration */
567   int ckdelay_extra_for_animation;    /* bd1 and similar engines had animation bits in cave data, to set which elements to animate (firefly, butterfly, amoeba).
568                                             animating an element also caused some delay each frame; according to my measurements, around 2.6 ms/element. */
569
570   int frame;  /* XXX */
571
572   int hatching_delay_frame;
573   int hatching_delay_time;
574   int time_bonus;                /* bonus time for clock collected. */
575   int time_penalty;            /* Time penalty when voodoo destroyed. */
576   int time;                    /* milliseconds remaining to finish cave */
577   int timevalue;                /* points for remaining seconds - for current level */
578   int diamonds_needed;        /* diamonds needed to open outbox */
579   int diamonds_collected;        /* diamonds collected */
580   int skeletons_collected;    /* number of skeletons collected */
581   int gate_open_flash;        /* flashing of screen when gate opens */
582   int score;                    /* Score got this frame. */
583   int amoeba_time;            /* Amoeba growing slow (low probability, default 3%) for milliseconds. After that, fast growth default (25%) */
584   int amoeba_2_time;            /* Amoeba growing slow (low probability, default 3%) for milliseconds. After that, fast growth default (25%) */
585   int amoeba_max_count;            /* selected amoeba 1 threshold for this level */
586   int amoeba_2_max_count;            /* selected amoeba 2 threshold for this level */
587   GdAmoebaState amoeba_state;        /* state of amoeba 1 */
588   GdAmoebaState amoeba_2_state;    /* state of amoeba 2 */
589   int magic_wall_time;            /* magic wall 'on' state for seconds */
590   int slime_permeability;        /* true random slime */
591   int slime_permeability_c64;        /* Appearing in bd 2 */
592   GdMagicWallState magic_wall_state;        /* State of magic wall */
593   GdPlayerState player_state;        /* Player state. not yet living, living, exited... */
594   int player_seen_ago;            /* player was seen this number of scans ago */
595   boolean voodoo_touched;        /* as its name says */
596   boolean kill_player;            /* Voodoo died, or used pressed escape to restart level. */
597   boolean sweet_eaten;            /* player ate sweet, he's strong. prob_sweet applies, and also able to push chasing stones */
598   int player_x, player_y;            /* Coordinates of player (for scrolling) */
599   int px[16], py[16];                /* coordinates of player, for chasing stone */
600   int key1, key2, key3;            /* The player is holding this number of keys of each color */
601   boolean diamond_key_collected;    /* Key collected, so trapped diamonds convert to diamonds */
602   boolean inbox_flash_toggle;    /* negated every scan. helps drawing inboxes, and making players be born at different times. */
603   GdDirection last_direction;        /* last direction player moved. used by draw routines */
604   GdDirection last_horizontal_direction;
605   int biters_wait_frame;                /* number of frames to wait until biters will move again */
606   int replicators_wait_frame;            /* number of frames to wait until replicators are activated again */
607   int creatures_direction_will_change;    /* creatures automatically change direction every x seconds */
608   GdC64RandomGenerator c64_rand;    /* used for predictable random generator during the game. */
609
610   int gravity_will_change;    /* gravity will change in this number of milliseconds */
611   boolean gravity_disabled;    /* when the player is stirring the pot, there is no gravity. */
612   GdDirection gravity_next_direction;    /* next direction when the gravity changes. will be set by the player "getting" a gravity switch */
613   boolean got_pneumatic_hammer;    /* true if the player has a pneumatic hammer */
614   int pneumatic_hammer_active_delay;    /* number of frames to wait, till pneumatic hammer will destroy the wall */
615   GdSound sound1, sound2, sound3;    /* sound set for 3 channels after each iteration */
616 } GdCave;
617
618
619 #define CAVE_OFFSET(property) (G_STRUCT_OFFSET(GdCave, property))
620
621 /* arrays for movements */
622 /* also no1 and bd2 cave data import helpers; line direction coordinates */
623 extern const int gd_dx[], gd_dy[];
624
625 extern GdElement gd_char_to_element[];
626
627 void gd_create_char_to_element_table(void);
628 GdElement gd_get_element_from_character(guint8 character);
629 GdElement gd_get_element_from_string(const char *string);
630
631 /* init cave engine */
632 void gd_cave_init(void);
633
634 /* for cave tags hash table */
635 boolean gd_str_case_equal(gconstpointer s1, gconstpointer s2);
636 guint gd_str_case_hash(gconstpointer v);
637
638 /* cave highscore functions */
639 int gd_highscore_compare(gconstpointer a, gconstpointer b);
640 boolean gd_is_highscore(GdHighScore *scores, int score);
641 int gd_add_highscore(GdHighScore *highscores, const char *name, int score);
642 void gd_clear_highscore(GdHighScore *hs);
643 boolean gd_has_highscore(GdHighScore *hs);
644
645 /* cave creator and destructor functions */
646 GdCave *gd_cave_new(void);
647 GdCave *gd_cave_new_from_cave(const GdCave *orig);
648 void gd_cave_copy(GdCave *dest, const GdCave *src);
649 void gd_cave_free(GdCave *cave);
650
651 /* cave manipulation */
652 void gd_cave_set_gdash_defaults(GdCave *cave);
653 void gd_cave_set_defaults_from_array(GdCave* cave, GdPropertyDefault *defaults);
654 void gd_cave_correct_visible_size(GdCave *cave);
655 void gd_cave_auto_shrink(GdCave *cave);
656
657 void gd_cave_setup_for_game(GdCave *cave);
658 void gd_cave_count_diamonds(GdCave *cave);
659
660 /* c64 random generator support for cave fill */
661 unsigned int gd_c64_random(GdC64RandomGenerator *rand);
662 unsigned int gd_cave_c64_random(GdCave *);
663 void gd_c64_random_set_seed(GdC64RandomGenerator *rand, int seed1, int seed2);
664 void gd_cave_c64_random_set_seed(GdCave *cave, int seed1, int seed2);
665
666 /* support */
667 gpointer gd_cave_map_new_for_cave(const GdCave *cave, const int cell_size);
668 gpointer gd_cave_map_dup_size(const GdCave * cave, const gpointer map, const int cell_size);
669 #define gd_cave_map_new(CAVE, TYPE) ((TYPE **)gd_cave_map_new_for_cave((CAVE), sizeof(TYPE)))
670 #define gd_cave_map_dup(CAVE, MAP) ((gpointer)gd_cave_map_dup_size((CAVE), (gpointer *)(CAVE)->MAP, sizeof((CAVE)->MAP[0][0])))
671 void gd_cave_map_free(gpointer map);
672
673 void gd_cave_store_rc(GdCave * cave, int x, int y, const GdElement element, const void* order);
674 GdElement gd_cave_get_rc (const GdCave *cave, int x, int y);
675
676 /* direction */
677 const char *gd_direction_get_visible_name(GdDirection dir);
678 const char *gd_direction_get_filename(GdDirection dir);
679 GdDirection gd_direction_from_string(const char *str);
680
681 /* scheduling */
682 const char *gd_scheduling_get_visible_name(GdScheduling sched);
683 const char *gd_scheduling_get_filename(GdScheduling sched);
684 GdScheduling gd_scheduling_from_string(const char *str);
685
686 /* game playing helpers */
687 #define GD_REDRAW (1 << 10)
688
689 void gd_drawcave_game(const GdCave *cave, int **element_buffer, int **gfx_buffer,
690                       boolean bonus_life_flash, int animcycle, boolean hate_invisible_outbox);
691
692 /* function to copy a GdString */
693 static inline int
694 gd_strcpy(GdString dest, const GdString src)
695 {
696     return g_strlcpy(dest, src, sizeof(GdString));
697 }
698
699 int gd_cave_time_show(const GdCave *cave, int internal_time);
700
701 GdReplay *gd_replay_new(void);
702 GdReplay *gd_replay_new_from_replay(GdReplay *orig);
703 void gd_replay_free(GdReplay *replay);
704 void gd_replay_store_movement(GdReplay *replay, GdDirection player_move, boolean player_fire, boolean suicide);
705 boolean gd_replay_get_next_movement(GdReplay *replay, GdDirection *player_move, boolean *player_fire, boolean *suicide);
706 void gd_replay_rewind(GdReplay *replay);
707
708 char *gd_replay_movements_to_bdcff(GdReplay *replay);
709
710 guint32 gd_cave_adler_checksum(GdCave *cave);
711 void gd_cave_adler_checksum_more(GdCave *cave, guint32 *a, guint32 *b);
712
713 GdColor gd_c64_color(int);
714
715 #endif  // BD_CAVE_H