From 692f4b18c257f8c40937f58a473893f557bf3294 Mon Sep 17 00:00:00 2001 From: jacob1 Date: Sat, 26 Oct 2013 00:00:39 -0400 Subject: [PATCH] fix sim.decoBox arguments, add a sim.canMove function --- src/cat/LuaScriptInterface.cpp | 34 +++++++++++++++++++++++++++------- src/cat/LuaScriptInterface.h | 1 + 2 files changed, 28 insertions(+), 7 deletions(-) diff --git a/src/cat/LuaScriptInterface.cpp b/src/cat/LuaScriptInterface.cpp index d7f683503..d0b3b6149 100644 --- a/src/cat/LuaScriptInterface.cpp +++ b/src/cat/LuaScriptInterface.cpp @@ -479,6 +479,7 @@ void LuaScriptInterface::initSimulationAPI() {"waterEqualization", simulation_waterEqualisation}, {"ambientAirTemp", simulation_ambientAirTemp}, {"elementCount", simulation_elementCount}, + {"can_move", simulation_canMove}, {"parts", simulation_parts}, {"pmap", simulation_pmap}, {"neighbours", simulation_neighbours}, @@ -1230,13 +1231,11 @@ int LuaScriptInterface::simulation_decoBox(lua_State * l) int y1 = luaL_optint(l,2,-1); int x2 = luaL_optint(l,3,-1); int y2 = luaL_optint(l,4,-1); - int rx = luaL_optint(l,5,5); - int ry = luaL_optint(l,6,5); - int r = luaL_optint(l,7,255); - int g = luaL_optint(l,8,255); - int b = luaL_optint(l,9,255); - int a = luaL_optint(l,10,255); - int tool = luaL_optint(l,11,0); + int r = luaL_optint(l,5,255); + int g = luaL_optint(l,6,255); + int b = luaL_optint(l,7,255); + int a = luaL_optint(l,8,255); + int tool = luaL_optint(l,9,0); luacon_sim->ApplyDecorationBox(x1, y1, x2, y2, r, g, b, a, tool); return 0; @@ -1503,6 +1502,27 @@ int LuaScriptInterface::simulation_elementCount(lua_State * l) return 1; } +int LuaScriptInterface::simulation_canMove(lua_State * l) +{ + int movingElement = luaL_checkint(l, 1); + int destinationElement = luaL_checkint(l, 2); + if (movingElement < 0 || movingElement >= PT_NUM) + return luaL_error(l, "Invalid element ID (%d)", movingElement); + if (destinationElement < 0 || destinationElement >= PT_NUM) + return luaL_error(l, "Invalid element ID (%d)", destinationElement); + + if (lua_gettop(l) < 3) + { + lua_pushnumber(l, luacon_sim->can_move[movingElement][destinationElement]); + return 1; + } + else + { + luacon_sim->can_move[movingElement][destinationElement] = luaL_checkint(l, 3); + return 0; + } +} + int PartsClosure(lua_State * l) { int i = lua_tointeger(l, lua_upvalueindex(1)); diff --git a/src/cat/LuaScriptInterface.h b/src/cat/LuaScriptInterface.h index a443a9de4..b99d18cc9 100644 --- a/src/cat/LuaScriptInterface.h +++ b/src/cat/LuaScriptInterface.h @@ -97,6 +97,7 @@ class LuaScriptInterface: public CommandInterface static int simulation_waterEqualisation(lua_State * l); static int simulation_ambientAirTemp(lua_State * l); static int simulation_elementCount(lua_State * l); + static int simulation_canMove(lua_State * l); static int simulation_parts(lua_State * l); static int simulation_pmap(lua_State * l); static int simulation_neighbours(lua_State * l);