X-Git-Url: https://git.artsoft.org/?a=blobdiff_plain;f=src%2Fgame_bd%2Fbd_cave.h;h=f792feb3dc576b7e294845680b9b27a2b7c09169;hb=3e2f5b80c9748e74cb33fd6f570678bf51c992ba;hp=189e2777d69687375c72e2a86bd283d57050f359;hpb=2be47982a3acd069ebfdb2a75b26f770257932a6;p=rocksndiamonds.git diff --git a/src/game_bd/bd_cave.h b/src/game_bd/bd_cave.h index 189e2777..f792feb3 100644 --- a/src/game_bd/bd_cave.h +++ b/src/game_bd/bd_cave.h @@ -17,69 +17,9 @@ #ifndef BD_CAVE_H #define BD_CAVE_H -#include - #include "bd_elements.h" - - -// colors - -typedef guint32 GdColor; - -/* color internal: - XXRRGGBB; - XX is 0 for RGB, - 1 for c64 colors (bb=index) - 3 for c64dtv (bb=index) - 2 for atari colors (bb=index) -*/ - -typedef enum _color_type -{ - GD_COLOR_TYPE_RGB = 0, - GD_COLOR_TYPE_C64 = 1, - GD_COLOR_TYPE_C64DTV = 2, - GD_COLOR_TYPE_ATARI = 3, - - GD_COLOR_TYPE_UNKNOWN /* should be the last one */ -} GdColorType; - -/* traditional c64 color indexes. */ -#define GD_COLOR_INDEX_BLACK (0) -#define GD_COLOR_INDEX_WHITE (1) -#define GD_COLOR_INDEX_RED (2) -#define GD_COLOR_INDEX_CYAN (3) -#define GD_COLOR_INDEX_PURPLE (4) -#define GD_COLOR_INDEX_GREEN (5) -#define GD_COLOR_INDEX_BLUE (6) -#define GD_COLOR_INDEX_YELLOW (7) -#define GD_COLOR_INDEX_ORANGE (8) -#define GD_COLOR_INDEX_BROWN (9) -#define GD_COLOR_INDEX_LIGHTRED (10) -#define GD_COLOR_INDEX_GRAY1 (11) -#define GD_COLOR_INDEX_GRAY2 (12) -#define GD_COLOR_INDEX_LIGHTGREEN (13) -#define GD_COLOR_INDEX_LIGHTBLUE (14) -#define GD_COLOR_INDEX_GRAY3 (15) - -#define GD_GDASH_BLACK (0x000000) -#define GD_GDASH_WHITE (0xFFFFFF) -#define GD_GDASH_RED (0x880000) -#define GD_GDASH_CYAN (0xAAFFEE) -#define GD_GDASH_PURPLE (0xCC44CC) -#define GD_GDASH_GREEN (0x00CC55) -#define GD_GDASH_BLUE (0x0000AA) -#define GD_GDASH_YELLOW (0xEEEE77) -#define GD_GDASH_ORANGE (0xDD8855) -#define GD_GDASH_BROWN (0x664400) -#define GD_GDASH_LIGHTRED (0xFF7777) -#define GD_GDASH_GRAY1 (0x333333) -#define GD_GDASH_GRAY2 (0x777777) -#define GD_GDASH_LIGHTGREEN (0xAAFF66) -#define GD_GDASH_LIGHTBLUE (0x0088FF) -#define GD_GDASH_GRAY3 (0xBBBBBB) - -#define GD_COLOR_INVALID (0xFFFFFFFF) +#include "bd_colors.h" +#include "bd_random.h" /****************************************** @@ -141,7 +81,7 @@ typedef struct _gd_property_default } GdPropertyDefault; -void gd_struct_set_defaults_from_array(gpointer str, const GdStructDescriptor *properties, GdPropertyDefault *defaults); +void gd_struct_set_defaults_from_array(void *str, const GdStructDescriptor *properties, GdPropertyDefault *defaults); /* these define the number of the cells in the png file */ #define GD_NUM_OF_CELLS_X 8 @@ -149,7 +89,10 @@ void gd_struct_set_defaults_from_array(gpointer str, const GdStructDescriptor *p /* +80: placeholder for cells which are rendered by the game; for example diamond + arrow = falling diamond */ -#define GD_NUM_OF_CELLS (GD_NUM_OF_CELLS_X*GD_NUM_OF_CELLS_Y+80) +#define GD_NUM_OF_CELLS (GD_NUM_OF_CELLS_X * GD_NUM_OF_CELLS_Y + 80) + +/* maximum replay size (maximum seconds x game cycles per second) */ +#define MAX_REPLAY_LEN (10000 * FRAMES_PER_SECOND / 8) extern const GdColor gd_flash_color; extern const GdColor gd_select_color; @@ -167,6 +110,7 @@ enum _element_property E_P_BLOWS_UP_FLIES, /* flies blow up, if they touch this */ E_P_EXPLODES_BY_HIT, /* explodes if hit by a stone */ + E_P_EXPLOSION, /* set for every stage of every explosion. */ E_P_EXPLOSION_FIRST_STAGE, /* set for first stage of every explosion. helps slower/faster explosions changing */ @@ -179,6 +123,8 @@ enum _element_property E_P_PLAYER, /* easier to find out if it is a player element */ E_P_MOVED_BY_CONVEYOR_TOP, /* can be moved by conveyor belt */ E_P_MOVED_BY_CONVEYOR_BOTTOM, /* can be moved UNDER the conveyor belt */ + + E_P_COLLECTIBLE, /* can be collected */ }; /* properties */ @@ -200,6 +146,7 @@ enum _element_property #define P_BLOWS_UP_FLIES (1 << E_P_BLOWS_UP_FLIES) #define P_EXPLODES_BY_HIT (1 << E_P_EXPLODES_BY_HIT) +#define P_EXPLOSION (1 << E_P_EXPLOSION) #define P_EXPLOSION_FIRST_STAGE (1 << E_P_EXPLOSION_FIRST_STAGE) #define P_NON_EXPLODABLE (1 << E_P_NON_EXPLODABLE) @@ -210,6 +157,8 @@ enum _element_property #define P_MOVED_BY_CONVEYOR_TOP (1 << E_P_MOVED_BY_CONVEYOR_TOP) #define P_MOVED_BY_CONVEYOR_BOTTOM (1 << E_P_MOVED_BY_CONVEYOR_BOTTOM) +#define P_COLLECTIBLE (1 << E_P_COLLECTIBLE) + /* These are states of the magic wall. */ typedef enum _magic_wall_state { @@ -306,27 +255,33 @@ typedef struct _highscore int score; } GdHighScore; +typedef struct _replay_movements +{ + unsigned char data[MAX_REPLAY_LEN]; + unsigned int len; +} GdReplayMovements; + /* maximum seed value for the cave random generator. should be smaller than a signed int. */ #define GD_CAVE_SEED_MAX (1 << 30) typedef struct _gd_cave_replay { int level; /* replay for level n */ - guint32 seed; /* seed the cave is to be rendered with */ + unsigned int seed; /* seed the cave is to be rendered with */ boolean saved; /* also store it in the saved bdcff */ GdString recorded_with; /* recorded with - application name and version */ GdString player_name; /* who played this */ GdString date; /* when played */ - GString *comment; /* some comments from the player */ + char *comment; /* some comments from the player */ int score; /* score collected */ int duration; /* number of seconds played */ boolean success; /* successful playing of cave? */ - guint32 checksum; /* checksum of the rendered cave. */ + unsigned int checksum; /* checksum of the rendered cave. */ boolean wrong_checksum; - GByteArray *movements; + GdReplayMovements *movements; int current_playing_pos; } GdReplay; @@ -362,8 +317,8 @@ typedef struct _gd_cave GdString difficulty; /* difficulty of the game, for info purposes */ GdString www; /* link to author's webpage */ GdString date; /* date of creation */ - GString *story; /* story for the cave - will be shown when the cave is played. */ - GString *remark; /* some note */ + char *story; /* story for the cave - will be shown when the cave is played. */ + char *remark; /* some note */ GdString charset; /* these are not used by gdash */ GdString fontset; @@ -371,11 +326,11 @@ typedef struct _gd_cave /* and this one the highscores */ GdHighScore highscore[GD_HIGHSCORE_NUM]; - GHashTable *tags; /* stores read-but-not-understood strings from bdcff, so we can save them later. */ + HashTable *tags; /* stores read-but-not-understood strings from bdcff, so we can save them later. */ GdElement **map; /* pointer to data for map, non-null if has a map */ - GList *objects; - GList *replays; + List *objects; + List *replays; boolean intermission; /* is this cave an intermission? */ boolean intermission_instantlife; /* one life extra, if the intermission is reached */ @@ -550,15 +505,21 @@ typedef struct _gd_cave boolean pneumatic_hammer_sound; /* internal variables, used during the game. private data :) */ - 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. */ + + /* returns range corrected x/y position (points to perfect or line shifting get function) */ + int (*getx) (const struct _gd_cave*, int x, int y); + int (*gety) (const struct _gd_cave*, int x, int y); + + /* returns pointer to element at x, y (points to perfect border or a line shifting get function) */ + GdElement* (*getp) (const struct _gd_cave*, int x, int y); boolean hatched; /* hatching has happened. (timers may run, ...) */ boolean gate_open; /* self-explaining */ - guint32 render_seed; /* the seed value, which was used to render the cave, is saved here. will be used by record&playback */ - GRand *random; /* random number generator of rendered cave */ + unsigned int render_seed; /* the seed value, which was used to render the cave, is saved here. will be used by record&playback */ + GdRand *random; /* random number generator of rendered cave */ int rendered; /* if not zero, rendered at level x */ int timing_factor; /* number of "milliseconds" in each second :) 1000 for ntsc, 1200 for pal. */ - 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. */ + void ***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. */ int **hammered_reappear; /* integer map of cave; if non-zero, a brick wall will appear there */ int speed; /* Time between game cycles in ms */ @@ -616,7 +577,7 @@ typedef struct _gd_cave } GdCave; -#define CAVE_OFFSET(property) (G_STRUCT_OFFSET(GdCave, property)) +#define CAVE_OFFSET(property) (STRUCT_OFFSET(GdCave, property)) /* arrays for movements */ /* also no1 and bd2 cave data import helpers; line direction coordinates */ @@ -625,18 +586,18 @@ extern const int gd_dx[], gd_dy[]; extern GdElement gd_char_to_element[]; void gd_create_char_to_element_table(void); -GdElement gd_get_element_from_character(guint8 character); +GdElement gd_get_element_from_character(unsigned char character); GdElement gd_get_element_from_string(const char *string); /* init cave engine */ void gd_cave_init(void); /* for cave tags hash table */ -boolean gd_str_case_equal(gconstpointer s1, gconstpointer s2); -guint gd_str_case_hash(gconstpointer v); +int gd_str_case_equal(void *s1, void *s2); +unsigned int gd_str_case_hash(void *v); /* cave highscore functions */ -int gd_highscore_compare(gconstpointer a, gconstpointer b); +int gd_highscore_compare(const void *a, const void *b); boolean gd_is_highscore(GdHighScore *scores, int score); int gd_add_highscore(GdHighScore *highscores, const char *name, int score); void gd_clear_highscore(GdHighScore *hs); @@ -662,13 +623,14 @@ unsigned int gd_c64_random(GdC64RandomGenerator *rand); unsigned int gd_cave_c64_random(GdCave *); void gd_c64_random_set_seed(GdC64RandomGenerator *rand, int seed1, int seed2); void gd_cave_c64_random_set_seed(GdCave *cave, int seed1, int seed2); +void gd_cave_set_random_c64_colors(GdCave *cave); /* support */ -gpointer gd_cave_map_new_for_cave(const GdCave *cave, const int cell_size); -gpointer gd_cave_map_dup_size(const GdCave * cave, const gpointer map, const int cell_size); +void *gd_cave_map_new_for_cave(const GdCave *cave, const int cell_size); +void *gd_cave_map_dup_size(const GdCave * cave, const void *map, const int cell_size); #define gd_cave_map_new(CAVE, TYPE) ((TYPE **)gd_cave_map_new_for_cave((CAVE), sizeof(TYPE))) -#define gd_cave_map_dup(CAVE, MAP) ((gpointer)gd_cave_map_dup_size((CAVE), (gpointer *)(CAVE)->MAP, sizeof((CAVE)->MAP[0][0]))) -void gd_cave_map_free(gpointer map); +#define gd_cave_map_dup(CAVE, MAP) ((void *)gd_cave_map_dup_size((CAVE), (void **)(CAVE)->MAP, sizeof((CAVE)->MAP[0][0]))) +void gd_cave_map_free(void *map); void gd_cave_store_rc(GdCave * cave, int x, int y, const GdElement element, const void* order); GdElement gd_cave_get_rc (const GdCave *cave, int x, int y); @@ -690,10 +652,9 @@ void gd_drawcave_game(const GdCave *cave, int **element_buffer, int **gfx_buffer boolean bonus_life_flash, int animcycle, boolean hate_invisible_outbox); /* function to copy a GdString */ -static inline int -gd_strcpy(GdString dest, const GdString src) +static inline char *gd_strcpy(GdString dest, const GdString src) { - return g_strlcpy(dest, src, sizeof(GdString)); + return strncpy(dest, src, sizeof(GdString)); } int gd_cave_time_show(const GdCave *cave, int internal_time); @@ -702,14 +663,8 @@ GdReplay *gd_replay_new(void); GdReplay *gd_replay_new_from_replay(GdReplay *orig); void gd_replay_free(GdReplay *replay); void gd_replay_store_movement(GdReplay *replay, GdDirection player_move, boolean player_fire, boolean suicide); -boolean gd_replay_get_next_movement(GdReplay *replay, GdDirection *player_move, boolean *player_fire, boolean *suicide); -void gd_replay_rewind(GdReplay *replay); - -char *gd_replay_movements_to_bdcff(GdReplay *replay); - -guint32 gd_cave_adler_checksum(GdCave *cave); -void gd_cave_adler_checksum_more(GdCave *cave, guint32 *a, guint32 *b); -GdColor gd_c64_color(int); +unsigned int gd_cave_adler_checksum(GdCave *cave); +void gd_cave_adler_checksum_more(GdCave *cave, unsigned int *a, unsigned int *b); #endif // BD_CAVE_H