summaryrefslogtreecommitdiff
path: root/library/LuaApi.cpp
diff options
context:
space:
mode:
authorAlexander Gavrilov2012-05-01 18:55:30 +0400
committerAlexander Gavrilov2012-05-01 18:55:30 +0400
commit4cffb6428d5e25b0c3cb09044f65dbf5d43667e9 (patch)
tree5a78cac5f5c3bfb1e9004c451f97adcae4b6571d /library/LuaApi.cpp
parent2303a25bdefab30bea67f32d27d35e5002448e8a (diff)
downloaddfhack-4cffb6428d5e25b0c3cb09044f65dbf5d43667e9.tar.gz
dfhack-4cffb6428d5e25b0c3cb09044f65dbf5d43667e9.tar.bz2
dfhack-4cffb6428d5e25b0c3cb09044f65dbf5d43667e9.tar.xz
Update building creation code with new knowledge, and fix zone.
Also, document new lua api, and add a more convenient wrapper.
Diffstat (limited to 'library/LuaApi.cpp')
-rw-r--r--library/LuaApi.cpp36
1 files changed, 30 insertions, 6 deletions
diff --git a/library/LuaApi.cpp b/library/LuaApi.cpp
index 82c8bb84..11cf73c3 100644
--- a/library/LuaApi.cpp
+++ b/library/LuaApi.cpp
@@ -768,7 +768,8 @@ static const luaL_Reg dfhack_burrows_funcs[] = {
static const LuaWrapper::FunctionReg dfhack_buildings_module[] = {
WRAPM(Buildings, allocInstance),
WRAPM(Buildings, checkFreeTiles),
- WRAPM(Buildings, setSize),
+ WRAPM(Buildings, countExtentTiles),
+ WRAPM(Buildings, hasSupport),
WRAPM(Buildings, constructWithItems),
WRAPM(Buildings, constructWithFilters),
{ NULL, NULL }
@@ -776,15 +777,16 @@ static const LuaWrapper::FunctionReg dfhack_buildings_module[] = {
static int buildings_getCorrectSize(lua_State *state)
{
- int w = luaL_optint(state, 1, 1);
- int h = luaL_optint(state, 2, 1);
- int t = luaL_optint(state, 3, -1);
+ df::coord2d size(luaL_optint(state, 1, 1), luaL_optint(state, 2, 1));
+
+ auto t = (df::building_type)luaL_optint(state, 3, -1);
int st = luaL_optint(state, 4, -1);
int cu = luaL_optint(state, 5, -1);
int d = luaL_optint(state, 6, 0);
- df::coord2d size(w,h);
+
df::coord2d center;
- bool flexible = Buildings::getCorrectSize(size, center, df::building_type(t), st, cu, d);
+ bool flexible = Buildings::getCorrectSize(size, center, t, st, cu, d);
+
lua_pushboolean(state, flexible);
lua_pushinteger(state, size.x);
lua_pushinteger(state, size.y);
@@ -793,8 +795,30 @@ static int buildings_getCorrectSize(lua_State *state)
return 5;
}
+static int buildings_setSize(lua_State *state)
+{
+ auto bld = Lua::CheckDFObject<df::building>(state, 1);
+ df::coord2d size(luaL_optint(state, 2, 1), luaL_optint(state, 3, 1));
+ int dir = luaL_optint(state, 4, 0);
+ bool ok = Buildings::setSize(bld, size, dir);
+ lua_pushboolean(state, ok);
+ if (ok)
+ {
+ auto size = Buildings::getSize(bld).second;
+ int area = size.x*size.y;
+ lua_pushinteger(state, size.x);
+ lua_pushinteger(state, size.y);
+ lua_pushinteger(state, area);
+ lua_pushinteger(state, Buildings::countExtentTiles(&bld->room, area));
+ return 5;
+ }
+ else
+ return 1;
+}
+
static const luaL_Reg dfhack_buildings_funcs[] = {
{ "getCorrectSize", buildings_getCorrectSize },
+ { "setSize", buildings_setSize },
{ NULL, NULL }
};