Generate seeds from the core seed so that levels will look different.
This commit is contained in:
parent
bc9d37eb91
commit
ce2a3482d1
|
@ -43,7 +43,7 @@ local function generate_path ()
|
|||
end
|
||||
|
||||
local cx, cy = 1, 1
|
||||
local seed = get_random_seed()
|
||||
local seed = get_random_seed(CURRENT_LEVEL)
|
||||
info("Map generation seed: " .. seed)
|
||||
randomseed(seed)
|
||||
local direction = 0
|
||||
|
|
|
@ -534,7 +534,7 @@ function module.load_textures(map)
|
|||
t_pit0 = add_texture(map, "Objects/Pit0.png")
|
||||
t_pit1 = add_texture(map, "Objects/Pit1.png")
|
||||
|
||||
local seed = get_random_seed();
|
||||
local seed = get_random_seed(CURRENT_LEVEL);
|
||||
info("Map room random seed: " .. seed)
|
||||
math.randomseed(seed)
|
||||
local xo = (random(3) - 1) * 112
|
||||
|
|
|
@ -470,7 +470,8 @@ l_read_file(lua_State *L)
|
|||
static int
|
||||
l_get_random_seed(lua_State *L)
|
||||
{
|
||||
lua_pushnumber(L, get_random_seed());
|
||||
unsigned int level = (unsigned int) luaL_checkinteger(L, 1);
|
||||
lua_pushnumber(L, get_random_map_seed(level));
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
|
29
src/random.c
29
src/random.c
|
@ -23,14 +23,31 @@
|
|||
#include "util.h"
|
||||
|
||||
static unsigned int seed = 0;
|
||||
static unsigned int map_seeds[20];
|
||||
static unsigned int runtime_seed = 0;
|
||||
|
||||
static void
|
||||
generate_random_seeds(void)
|
||||
{
|
||||
// Use seed for generating map seeds
|
||||
srand(seed);
|
||||
info("Core random seed: %d", seed);
|
||||
for (int i = 0; i < 20; ++i) {
|
||||
map_seeds[i] = rand();
|
||||
}
|
||||
|
||||
// Set a more random seed for runtime random
|
||||
runtime_seed = (unsigned int) time(NULL);
|
||||
srand(runtime_seed);
|
||||
info("Runtime random seed: %d", runtime_seed);
|
||||
}
|
||||
|
||||
static void
|
||||
init_seed(void)
|
||||
{
|
||||
if (seed == 0) {
|
||||
seed = (unsigned int) time(NULL);
|
||||
srand(seed);
|
||||
info("Core random seed: %d", seed);
|
||||
generate_random_seeds();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -38,7 +55,7 @@ void
|
|||
set_random_seed(unsigned int s)
|
||||
{
|
||||
seed = s;
|
||||
info("Core random seed: %d", seed);
|
||||
generate_random_seeds();
|
||||
}
|
||||
|
||||
unsigned int
|
||||
|
@ -48,6 +65,12 @@ get_random_seed(void)
|
|||
return seed;
|
||||
}
|
||||
|
||||
unsigned int
|
||||
get_random_map_seed(unsigned int level)
|
||||
{
|
||||
return map_seeds[level-1];
|
||||
}
|
||||
|
||||
unsigned int
|
||||
get_random(unsigned int max)
|
||||
{
|
||||
|
|
|
@ -19,6 +19,9 @@
|
|||
#ifndef RANDOM_H_
|
||||
#define RANDOM_H_
|
||||
|
||||
unsigned int
|
||||
get_random_map_seed(unsigned int level);
|
||||
|
||||
unsigned int
|
||||
get_random_seed(void);
|
||||
|
||||
|
|
Loading…
Reference in New Issue