diff --git a/LUA_API.rst b/LUA_API.rst index d8d53a4d1..bb1ef803e 100644 --- a/LUA_API.rst +++ b/LUA_API.rst @@ -807,7 +807,7 @@ Maps module Returns a map block object for given df::coord or x,y,z in local tile coordinates. -* ``dfhack.maps.getRegionBiome(region_coord2d)`` +* ``dfhack.maps.getRegionBiome(region_coord2d)``, or ``getRegionBiome(x,y)`` Returns the biome info struct for the given global map region. @@ -823,6 +823,10 @@ Maps module Returns the local feature object with the given region coords and index. +* ``dfhack.maps.getTileBiomeRgn(coords)``, or ``getTileBiomeRgn(x,y,z)`` + + Returns *x, y* for use with ``getRegionBiome``. + * ``dfhack.maps.canWalkBetween(pos1, pos2)`` Checks if a dwarf may be able to walk between the two tiles, diff --git a/Lua API.html b/Lua API.html index 846299a35..3e023ebd3 100644 --- a/Lua API.html +++ b/Lua API.html @@ -1026,7 +1026,7 @@ Returns false in case of error.
dfhack.maps.getTileBlock(coords), or getTileBlock(x,y,z)
Returns a map block object for given df::coord or x,y,z in local tile coordinates.
dfhack.maps.getRegionBiome(region_coord2d)
+dfhack.maps.getRegionBiome(region_coord2d), or getRegionBiome(x,y)
Returns the biome info struct for the given global map region.
dfhack.maps.enableBlockUpdates(block[,flow,temperature])
@@ -1038,6 +1038,9 @@ Returns false in case of error.dfhack.maps.getLocalInitFeature(region_coord2d,index)
Returns the local feature object with the given region coords and index.
dfhack.maps.getTileBiomeRgn(coords), or getTileBiomeRgn(x,y,z)
+Returns x, y for use with getRegionBiome.
+dfhack.maps.canWalkBetween(pos1, pos2)
Checks if a dwarf may be able to walk between the two tiles,
using a pathfinding cache maintained by the game. Note that
diff --git a/library/LuaApi.cpp b/library/LuaApi.cpp
index 1baa4045d..529bdd077 100644
--- a/library/LuaApi.cpp
+++ b/library/LuaApi.cpp
@@ -94,6 +94,26 @@ void Lua::Push(lua_State *state, const Units::NoblePosition &pos)
lua_setfield(state, -2, "position");
}
+void Lua::Push(lua_State *state, df::coord pos)
+{
+ lua_createtable(state, 0, 3);
+ lua_pushinteger(state, pos.x);
+ lua_setfield(state, -2, "x");
+ lua_pushinteger(state, pos.y);
+ lua_setfield(state, -2, "y");
+ lua_pushinteger(state, pos.z);
+ lua_setfield(state, -2, "z");
+}
+
+void Lua::Push(lua_State *state, df::coord2d pos)
+{
+ lua_createtable(state, 0, 2);
+ lua_pushinteger(state, pos.x);
+ lua_setfield(state, -2, "x");
+ lua_pushinteger(state, pos.y);
+ lua_setfield(state, -2, "y");
+}
+
int Lua::PushPosXYZ(lua_State *state, df::coord pos)
{
if (!pos.isValid())
@@ -110,6 +130,21 @@ int Lua::PushPosXYZ(lua_State *state, df::coord pos)
}
}
+int Lua::PushPosXY(lua_State *state, df::coord2d pos)
+{
+ if (!pos.isValid())
+ {
+ lua_pushnil(state);
+ return 1;
+ }
+ else
+ {
+ lua_pushinteger(state, pos.x);
+ lua_pushinteger(state, pos.y);
+ return 2;
+ }
+}
+
static df::coord2d CheckCoordXY(lua_State *state, int base, bool vararg = false)
{
df::coord2d p;
@@ -754,7 +789,6 @@ static const luaL_Reg dfhack_items_funcs[] = {
static const LuaWrapper::FunctionReg dfhack_maps_module[] = {
WRAPN(getBlock, (df::map_block* (*)(int32_t,int32_t,int32_t))Maps::getBlock),
- WRAPM(Maps, getRegionBiome),
WRAPM(Maps, enableBlockUpdates),
WRAPM(Maps, getGlobalInitFeature),
WRAPM(Maps, getLocalInitFeature),
@@ -769,8 +803,24 @@ static int maps_getTileBlock(lua_State *L)
return 1;
}
+static int maps_getRegionBiome(lua_State *L)
+{
+ auto pos = CheckCoordXY(L, 1, true);
+ Lua::PushDFObject(L, Maps::getRegionBiome(pos));
+ return 1;
+}
+
+static int maps_getTileBiomeRgn(lua_State *L)
+{
+ auto pos = CheckCoordXYZ(L, 1, true);
+ Lua::PushPosXY(L, Maps::getTileBiomeRgn(pos));
+ return 1;
+}
+
static const luaL_Reg dfhack_maps_funcs[] = {
{ "getTileBlock", maps_getTileBlock },
+ { "getRegionBiome", maps_getRegionBiome },
+ { "getTileBiomeRgn", maps_getTileBiomeRgn },
{ NULL, NULL }
};
diff --git a/library/include/LuaTools.h b/library/include/LuaTools.h
index a52db2572..d3c7a65d2 100644
--- a/library/include/LuaTools.h
+++ b/library/include/LuaTools.h
@@ -264,11 +264,14 @@ namespace DFHack {namespace Lua {
inline void Push(lua_State *state, bool value) {
lua_pushboolean(state, value);
}
+ inline void Push(lua_State *state, const char *str) {
+ lua_pushstring(state, str);
+ }
inline void Push(lua_State *state, const std::string &str) {
lua_pushlstring(state, str.data(), str.size());
}
- inline void Push(lua_State *state, df::coord &obj) { PushDFObject(state, &obj); }
- inline void Push(lua_State *state, df::coord2d &obj) { PushDFObject(state, &obj); }
+ DFHACK_EXPORT void Push(lua_State *state, df::coord obj);
+ DFHACK_EXPORT void Push(lua_State *state, df::coord2d obj);
void Push(lua_State *state, const Units::NoblePosition &pos);
template