From fdb4dff4d77d36e45e48847a602b53f786380ba0 Mon Sep 17 00:00:00 2001 From: Simon Robertshaw Date: Tue, 17 Apr 2012 18:13:17 +0100 Subject: [PATCH] TPT: Lua methods for reading/writing the bmap and emap (no mapped walltypes yet) 1c4bce1f22 --- src/cat/LuaScriptHelper.h | 8 +++ src/cat/LuaScriptInterface.cpp | 118 +++++++++++++++++++++++++++++++++ 2 files changed, 126 insertions(+) diff --git a/src/cat/LuaScriptHelper.h b/src/cat/LuaScriptHelper.h index b5b885dba..079a32e53 100644 --- a/src/cat/LuaScriptHelper.h +++ b/src/cat/LuaScriptHelper.h @@ -81,6 +81,14 @@ int luatpt_set_property(lua_State* l); int luatpt_get_property(lua_State* l); +int luatpt_set_wallmap(lua_State* l); + +int luatpt_get_wallmap(lua_State* l); + +int luatpt_set_elecmap(lua_State* l); + +int luatpt_get_elecmap(lua_State* l); + int luatpt_drawpixel(lua_State* l); int luatpt_drawrect(lua_State* l); diff --git a/src/cat/LuaScriptInterface.cpp b/src/cat/LuaScriptInterface.cpp index 84d1569d3..5d0727937 100644 --- a/src/cat/LuaScriptInterface.cpp +++ b/src/cat/LuaScriptInterface.cpp @@ -34,6 +34,10 @@ LuaScriptInterface::LuaScriptInterface(GameModel * m): {"reset_spark", &luatpt_reset_spark}, {"set_property", &luatpt_set_property}, {"get_property", &luatpt_get_property}, + {"set_wallmap", &luatpt_set_wallmap}, + {"get_wallmap", &luatpt_get_wallmap}, + {"set_elecmap", &luatpt_set_elecmap}, + {"get_elecmap", &luatpt_get_elecmap}, {"drawpixel", &luatpt_drawpixel}, {"drawrect", &luatpt_drawrect}, {"fillrect", &luatpt_fillrect}, @@ -1240,6 +1244,120 @@ int luatpt_set_property(lua_State* l) return 0; } +int luatpt_set_wallmap(lua_State* l) +{ + int nx, ny, acount; + int x1, y1, width, height; + float value; + acount = lua_gettop(l); + + x1 = abs(luaL_optint(l, 1, 0)); + y1 = abs(luaL_optint(l, 2, 0)); + width = abs(luaL_optint(l, 3, XRES/CELL)); + height = abs(luaL_optint(l, 4, YRES/CELL)); + value = (float)luaL_optint(l, acount, 0); + + if(acount==5) //Draw rect + { + if(x1 > (XRES/CELL)) + x1 = (XRES/CELL); + if(y1 > (YRES/CELL)) + y1 = (YRES/CELL); + if(x1+width > (XRES/CELL)) + width = (XRES/CELL)-x1; + if(y1+height > (YRES/CELL)) + height = (YRES/CELL)-y1; + for (nx = x1; nxbmap[ny][nx] = value; + } + } + else //Set point + { + if(x1 > (XRES/CELL)) + x1 = (XRES/CELL); + if(y1 > (YRES/CELL)) + y1 = (YRES/CELL); + luacon_sim->bmap[y1][x1] = value; + } + return 0; +} + +int luatpt_get_wallmap(lua_State* l) +{ + int nx, ny, acount; + int x1, y1, width, height; + float value; + acount = lua_gettop(l); + + x1 = abs(luaL_optint(l, 1, 0)); + y1 = abs(luaL_optint(l, 2, 0)); + + if(x1 > (XRES/CELL) || y1 > (YRES/CELL)) + return luaL_error(l, "Out of range"); + + lua_pushinteger(l, luacon_sim->bmap[y1][x1]); + return 1; +} + +int luatpt_set_elecmap(lua_State* l) +{ + int nx, ny, acount; + int x1, y1, width, height; + float value; + acount = lua_gettop(l); + + x1 = abs(luaL_optint(l, 1, 0)); + y1 = abs(luaL_optint(l, 2, 0)); + width = abs(luaL_optint(l, 3, XRES/CELL)); + height = abs(luaL_optint(l, 4, YRES/CELL)); + value = (float)luaL_optint(l, acount, 0); + + if(acount==5) //Draw rect + { + if(x1 > (XRES/CELL)) + x1 = (XRES/CELL); + if(y1 > (YRES/CELL)) + y1 = (YRES/CELL); + if(x1+width > (XRES/CELL)) + width = (XRES/CELL)-x1; + if(y1+height > (YRES/CELL)) + height = (YRES/CELL)-y1; + for (nx = x1; nxemap[ny][nx] = value; + } + } + else //Set point + { + if(x1 > (XRES/CELL)) + x1 = (XRES/CELL); + if(y1 > (YRES/CELL)) + y1 = (YRES/CELL); + luacon_sim->emap[y1][x1] = value; + } + return 0; +} + +int luatpt_get_elecmap(lua_State* l) +{ + int nx, ny, acount; + int x1, y1, width, height; + float value; + acount = lua_gettop(l); + + x1 = abs(luaL_optint(l, 1, 0)); + y1 = abs(luaL_optint(l, 2, 0)); + + if(x1 > (XRES/CELL) || y1 > (YRES/CELL)) + return luaL_error(l, "Out of range"); + + lua_pushinteger(l, luacon_sim->emap[y1][x1]); + return 1; +} + int luatpt_get_property(lua_State* l) { int i, r, y;