36 #define ERR_NG LOG_STREAM(err, log_mapgen) 37 #define LOG_NG LOG_STREAM(info, log_mapgen) 38 #define DBG_NG LOG_STREAM(debug, log_mapgen) 46 template <member_callback method>
48 return ((lua_kernel_base::get_lua_kernel<mapgen_lua_kernel>(L)).*method)(L);
56 std::mt19937& rng = lua_kernel_base::get_lua_kernel<mapgen_lua_kernel>(L).get_default_rng();
58 double r = double (rng());
59 double r_max = double (rng.max());
67 min = lua_check<int32_t>(L, 1);
68 max = lua_check<int32_t>(L, 2);
72 max = lua_check<int32_t>(L, 1);
77 lua_push(L, min + static_cast<int>(rng() % (max - min + 1)));
87 std::mt19937& rng = lua_kernel_base::get_lua_kernel<mapgen_lua_kernel>(L).get_default_rng();
97 arg.
nplayers = cfg[
"nplayers"].to_int(2);
98 arg.
nvillages = cfg[
"nvillages"].to_int(0);
100 arg.
hill_size = cfg[
"hill_size"].to_int(0);
104 arg.
max_lakes = cfg[
"max_lakes"].to_int(0);
108 uint32_t seed = cfg[
"seed"].to_int(0);
125 std::mt19937& rng = lua_kernel_base::get_lua_kernel<mapgen_lua_kernel>(L).get_default_rng();
132 int iterations = cfg[
"iterations"].to_int(1);
133 int hill_size = cfg[
"hill_size"].to_int(1);
134 int island_size = cfg[
"island_size"].to_int(width/2);
135 int center_x = cfg[
"center_x"].to_int(width/2);
136 int center_y = cfg[
"center_y"].to_int(height/2);
137 bool flip_layout = cfg[
"flip_format"].to_bool();
138 uint32_t seed = cfg[
"seed"].to_int(0);
146 assert(
int(res.size()) == width);
147 assert((width == 0 ||
int(res[0].
size()) == height));
148 for(
int x = 0; x != width; ++x) {
149 for(
int y = 0; y != height; ++y) {
151 int i = flip_layout ? (y + x * height) : (x + y * width);
189 int nb = res.
steps.size();
191 for (
int i = 0;
i < nb; ++
i)
229 {
"get_variable", &dispatch<&mapgen_lua_kernel::intf_get_variable> },
258 static const config empty_cfg;
271 std::string
msg =
"expected a string, found a ";
287 std::string
msg =
"expected a config (table), found a ";
294 std::string
msg =
"expected a config, but it is malformed ";
#define lua_isnoneornil(L, n)
LUA_API void lua_createtable(lua_State *L, int narray, int nrec)
static int intf_random(lua_State *L)
Returns a random numer, same interface as math.random.
void luaW_pushconfig(lua_State *L, const config &cfg)
Converts a config object to a Lua table pushed at the top of the stack.
LUA_API void lua_settop(lua_State *L, int idx)
LUA_API int lua_type(lua_State *L, int idx)
std::optional< std::mt19937 > default_rng_
bool has_attribute(config_key_type key) const
static int intf_default_generate(lua_State *L)
calls the default mapgenerator.
LUA_API void lua_rawseti(lua_State *L, int idx, lua_Integer n)
LUA_API int lua_gettop(lua_State *L)
bool luaW_pushvariable(lua_State *L, variable_access_const &v)
LUA_API int lua_getglobal(lua_State *L, const char *name)
std::string register_metatables(lua_State *L)
static void msg(const char *act, debug_info &i, const char *to="", const char *result="")
#define luaL_typename(L, i)
void lua_push(lua_State *L, const T &val)
Definitions for the interface to Wesnoth Markup Language (WML).
int intf_terainmap_create(lua_State *L)
Create a map.
LUALIB_API int luaL_argerror(lua_State *L, int arg, const char *extramsg)
std::size_t size(const std::string &str)
Length in characters of a UTF-8 string.
std::vector< map_location > steps
LUA_API int lua_isstring(lua_State *L, int idx)
bool luaW_toboolean(lua_State *L, int n)
Structure which holds a single route between one location and another.
void user_config(const char *prog, const config &generator)
int intf_get_variable(lua_State *L)
int dispatch(lua_State *L)
bool protected_call(int nArgs, int nRets, error_handler)
std::string register_metatables(lua_State *L)
LUA_API void lua_pushnil(lua_State *L)
int move_cost
Movement cost for reaching the end of the route.
Encapsulates the map of the game.
std::string default_generate_map(generator_data data, std::map< map_location, std::string > *labels, const config &cfg)
Generate the map.
#define lua_isboolean(L, n)
bool luaW_toconfig(lua_State *L, int index, config &cfg)
Converts an optional table or vconfig to a config object.
int intf_terainfilter_create(lua_State *L)
Create a filter.
Cost function object relying on a Lua function.
LUALIB_API lua_Integer luaL_checkinteger(lua_State *L, int arg)
int(mapgen_lua_kernel::* member_callback)(lua_State *)
config luaW_checkconfig(lua_State *L, int index)
Converts an optional table or vconfig to a config object.
#define lua_isfunction(L, n)
virtual uint32_t get_random_seed()
#define lua_tostring(L, i)
LUA_API int lua_isnumber(lua_State *L, int idx)
virtual uint32_t get_random_seed()
rng * generator
This generator is automatically synced during synced context.
bool load_string(char const *prog, const std::string &name, error_handler)
std::string create_map(const char *prog, const config &generator, std::optional< uint32_t > seed)
LUA_API int lua_error(lua_State *L)
Information on a WML variable.
#define lua_istable(L, n)
static int intf_find_path(lua_State *L)
Finds a path between two locations.
virtual void throw_exception(char const *msg, char const *context="Lua error")
config create_scenario(const char *prog, const config &generator, std::optional< uint32_t > seed)
std::mt19937 & get_default_rng()
static lg::log_domain log_mapgen("mapgen")
Standard logging facilities (interface).
height_map generate_height_map(size_t width, size_t height, size_t iterations, size_t hill_size, size_t island_size, size_t island_off_center)
Generate a height-map.
static int intf_default_generate_height_map(lua_State *L)
calls the default mapgenerator.
LUA_API const char * lua_pushfstring(lua_State *L, const char *fmt,...)
mapgen_lua_kernel(const config *vars)
LUALIB_API void luaL_setfuncs(lua_State *L, const luaL_Reg *l, int nup)
void run_generator(const char *prog, const config &generator)
plain_route a_star_search(const map_location &src, const map_location &dst, double stop_at, const cost_calculator &calc, const std::size_t width, const std::size_t height, const teleport_map *teleports, bool border)
A config object defines a single node in a WML file, with access to child nodes.
LUA_API void lua_pushinteger(lua_State *L, lua_Integer n)
LUA_API void lua_setfield(lua_State *L, int idx, const char *k)
LUA_API const char * lua_typename(lua_State *L, int t)
std::optional< uint32_t > random_seed_
std::vector< std::vector< int > > height_map
#define luaL_checkstring(L, n)