if (cave->tags)
hashtable_destroy(cave->tags);
- if (cave->random) /* random generator is a GRand * */
- g_rand_free(cave->random);
+ if (cave->random) /* random generator is a GdRand * */
+ gd_rand_free(cave->random);
/* free strings */
for (i = 0; gd_cave_properties[i].identifier != NULL; i++)
/* copy random number generator */
if (src->random)
- dest->random = g_rand_copy(src->random);
+ dest->random = gd_rand_copy(src->random);
}
/* create new cave, which is a copy of the cave given. */
{
/* blinking and tapping is started at the beginning of animation sequences. */
/* 1/4 chance of blinking, every sequence. */
- player_blinking = g_random_int_range(0, 4) == 0;
+ player_blinking = gd_random_int_range(0, 4) == 0;
/* 1/16 chance of starting or stopping tapping. */
- if (g_random_int_range(0, 16) == 0)
+ if (gd_random_int_range(0, 16) == 0)
player_tapping = !player_tapping;
}
}
#include <glib.h>
#include "bd_elements.h"
+#include "bd_random.h"
// colors
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 */
+ 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. */
}
if (is_space_dir(cave, x, y, GD_MV_TWICE + player_move) &&
- g_rand_int_range(cave->random, 0, 1000000) < prob)
+ gd_rand_int_range(cave->random, 0, 1000000) < prob)
{
/* if decided that he will be able to push, */
store_dir(cave, x, y, GD_MV_TWICE + player_move, what);
{
int px = cave->px[0];
int py = cave->py[0];
- boolean horizontal = g_rand_boolean(cave->random);
+ boolean horizontal = gd_rand_boolean(cave->random);
boolean dont_move = FALSE;
int i = 3;
};
GdDirection random_dir;
- random_dir = dirs[g_rand_int_range(cave->random, 0, G_N_ELEMENTS(dirs))];
+ random_dir = dirs[gd_rand_int_range(cave->random, 0, G_N_ELEMENTS(dirs))];
if (is_space_dir(cave, x, y, random_dir))
{
move(cave, x, y, random_dir, O_GHOST);
/* if alive, check in which dir to grow (or not) */
if (cave->amoeba_state == GD_AM_AWAKE)
{
- if (g_rand_int_range(cave->random, 0, 1000000) < cave->amoeba_growth_prob)
+ if (gd_rand_int_range(cave->random, 0, 1000000) < cave->amoeba_growth_prob)
{
- switch (g_rand_int_range(cave->random, 0, 4))
+ switch (gd_rand_int_range(cave->random, 0, 4))
{
/* decided to grow, choose a random direction. */
case 0: /* let this be up. numbers indifferent. */
/* if it is alive, decide if it attempts to grow */
if (cave->amoeba_2_state == GD_AM_AWAKE)
- if (g_rand_int_range(cave->random, 0, 1000000) < cave->amoeba_2_growth_prob)
+ if (gd_rand_int_range(cave->random, 0, 1000000) < cave->amoeba_2_growth_prob)
{
- switch (g_rand_int_range(cave->random, 0, 4))
+ switch (gd_rand_int_range(cave->random, 0, 4))
{
/* decided to grow, choose a random direction. */
case 0: /* let this be up. numbers indifferent. */
case O_ACID:
/* choose randomly, if it spreads */
- if (g_rand_int_range(cave->random, 0, 1000000) <= cave->acid_spread_ratio)
+ if (gd_rand_int_range(cave->random, 0, 1000000) <= cave->acid_spread_ratio)
{
/* the current one explodes */
store(cave, x, y, cave->acid_turns_to);
(rrr & cave->slime_permeability_c64) == 0);
#endif
/*
- * unpredictable: g_rand_int
+ * unpredictable: gd_rand_int
* predictable: c64 predictable random generator.
* for predictable, a random number is generated,
* whether or not it is even possible that the stone will be able to pass.
*/
- if (cave->slime_predictable ? ((rrr /* XXX */ & cave->slime_permeability_c64) == 0) : g_rand_int_range(cave->random, 0, 1000000) < cave->slime_permeability)
+ if (cave->slime_predictable ? ((rrr /* XXX */ & cave->slime_permeability_c64) == 0) : gd_rand_int_range(cave->random, 0, 1000000) < cave->slime_permeability)
{
GdDirection grav = cave->gravity;
GdDirection oppos = opposite[cave->gravity];
O_WAITING_STONE, O_BITER_1
};
- store(cave, x, y, ghost_explode[g_rand_int_range(cave->random, 0, G_N_ELEMENTS(ghost_explode))]);
+ store(cave, x, y, ghost_explode[gd_rand_int_range(cave->random, 0, G_N_ELEMENTS(ghost_explode))]);
}
break;
/* create a maze in a boolean **maze. */
/* recursive algorithm. */
-static void mazegen(GRand *rand, boolean **maze, int width, int height, int x, int y, int horiz)
+static void mazegen(GdRand *rand, boolean **maze, int width, int height, int x, int y, int horiz)
{
int dirmask = 15;
int dir;
/* horiz or vert */
- dir = g_rand_int_range(rand, 0, 100) <horiz ? 2 : 0;
+ dir = gd_rand_int_range(rand, 0, 100) < horiz ? 2 : 0;
/* if no horizontal movement possible, choose vertical */
if (dir == 2 && (dirmask & 12) == 0)
else if (dir == 0 && (dirmask & 3) == 0) /* and vice versa */
dir = 2;
- dir += g_rand_int_range(rand, 0, 2); /* dir */
+ dir += gd_rand_int_range(rand, 0, 2); /* dir */
if (dirmask & (1 << dir))
{
dirmask &= ~(1 << dir);
}
}
-static void braidmaze(GRand *rand, boolean **maze, int w, int h)
+static void braidmaze(GdRand *rand, boolean **maze, int w, int h)
{
int x, y;
if (closed == 3 && dirs != 0)
{
/* make up a random direction, and open in that direction, so dead end is removed */
- int dir = closed_dirs[g_rand_int_range(rand, 0, dirs)];
+ int dir = closed_dirs[gd_rand_int_range(rand, 0, dirs)];
switch (dir)
{
int y2 = object->y2;
int w, h, path, wall;
int xk, yk;
- GRand *rand;
+ GdRand *rand;
int i,j;
/* change coordinates if not in correct order */
/* start generation, if map is big enough.
otherwise the application would crash, as the editor places maze objects
during mouse click & drag that have no sense */
- rand = g_rand_new_with_seed(object->seed[level] == -1 ?
- g_rand_int(cave->random) : object->seed[level]);
+ rand = gd_rand_new_with_seed(object->seed[level] == -1 ?
+ gd_rand_int(cave->random) : object->seed[level]);
if (w >= 1 && h >= 1)
mazegen(rand, map, w, h, 0, 0, object->horiz);
if (object->type == GD_MAZE_BRAID)
braidmaze(rand, map, w, h);
- g_rand_free(rand);
+ gd_rand_free(rand);
if (w >= 1 && h >= 1 && object->type == GD_MAZE_UNICURSAL)
{
int y1 = object->y1;
int x2 = object->x2;
int y2 = object->y2;
- GRand *rand;
+ GdRand *rand;
GdC64RandomGenerator c64_rand;
guint32 seed;
/* -1 means that it should be different every time played. */
if (object->seed[level] == -1)
- seed = g_rand_int(cave->random);
+ seed = gd_rand_int(cave->random);
else
seed = object->seed[level];
- rand = g_rand_new_with_seed(seed);
+ rand = gd_rand_new_with_seed(seed);
/* for c64 random, use the 2*8 lsb. */
gd_c64_random_set_seed(&c64_rand, seed / 256 % 256, seed % 256);
randm = gd_c64_random(&c64_rand);
else
/* use the much better glib random generator */
- randm = g_rand_int_range(rand, 0, 256);
+ randm = gd_rand_int_range(rand, 0, 256);
element = object->fill_element;
if (randm < object->random_fill_probability[0])
}
}
- g_rand_free(rand);
+ gd_rand_free(rand);
}
cave->rendered = level + 1;
cave->render_seed = seed;
- cave->random = g_rand_new_with_seed(cave->render_seed);
+ cave->random = gd_rand_new_with_seed(cave->render_seed);
/* maps needed during drawing and gameplay */
cave->objects_order = gd_cave_map_new(cave, gpointer);
/* IF CAVE HAS NO MAP, USE THE RANDOM NUMBER GENERATOR */
/* init c64 randomgenerator */
if (data->level_rand[level] < 0)
- gd_cave_c64_random_set_seed(cave, g_rand_int_range(cave->random, 0, 256),
- g_rand_int_range(cave->random, 0, 256));
+ gd_cave_c64_random_set_seed(cave, gd_rand_int_range(cave->random, 0, 256),
+ gd_rand_int_range(cave->random, 0, 256));
else
gd_cave_c64_random_set_seed(cave, 0, data->level_rand[level]);
if (data->level_rand[level] < 0)
/* use the much better glib random generator */
- randm = g_rand_int_range(cave->random, 0, 256);
+ randm = gd_rand_int_range(cave->random, 0, 256);
else
/* use c64 */
randm = gd_cave_c64_random(cave);
* this way the uncovering is the same speed also for intermissions. */
for (j = 0; j < game->cave->w * game->cave->h / 40; j++)
{
- y = g_random_int_range(0, game->cave->h);
- x = g_random_int_range(0, game->cave->w);
+ y = gd_random_int_range(0, game->cave->h);
+ x = gd_random_int_range(0, game->cave->w);
game->cave->map[y][x] &= ~COVERED;
}
/* covering eight times faster than uncovering. */
for (j = 0; j < game->cave->w * game->cave->h * 8 / 40; j++)
- game->cave->map[g_random_int_range(0, game->cave->h)][g_random_int_range (0, game->cave->w)] |= COVERED;
+ game->cave->map[gd_random_int_range(0, game->cave->h)][gd_random_int_range (0, game->cave->w)] |= COVERED;
}
return_state = GD_GAME_NOTHING;
/* change diamond falling random to a selected diamond falling sound. */
if (sound == GD_S_DIAMOND_FALLING_RANDOM)
- sound = diamond_falling_sounds[g_random_int_range(0, 8)];
+ sound = diamond_falling_sounds[gd_random_int_range(0, 8)];
else if (sound == GD_S_DIAMOND_IMPACT_RANDOM)
- sound = diamond_impact_sounds[g_random_int_range(0, 8)];
+ sound = diamond_impact_sounds[gd_random_int_range(0, 8)];
else if (sound == GD_S_FLYING_DIAMOND_FALLING_RANDOM)
- sound = flying_diamond_falling_sounds[g_random_int_range(0, 8)];
+ sound = flying_diamond_falling_sounds[gd_random_int_range(0, 8)];
else if (sound == GD_S_FLYING_DIAMOND_IMPACT_RANDOM)
- sound = flying_diamond_impact_sounds[g_random_int_range(0, 8)];
+ sound = flying_diamond_impact_sounds[gd_random_int_range(0, 8)];
/* channel 1 may have been changed to channel 4 above. */
if (seed == NEW_RANDOMIZE)
{
// get randomly selected seed to render the cave
- seed = g_random_int_range(0, GD_CAVE_SEED_MAX);
+ seed = gd_random_int_range(0, GD_CAVE_SEED_MAX);
}
game_bd.random_seed = seed;