summaryrefslogtreecommitdiff
path: root/src/cat/LuaScriptInterface.cpp
diff options
context:
space:
mode:
authorSimon Robertshaw <simon@hardwired.org.uk>2012-04-17 17:13:17 (GMT)
committer Simon Robertshaw <simon@hardwired.org.uk>2012-04-17 17:13:17 (GMT)
commitfdb4dff4d77d36e45e48847a602b53f786380ba0 (patch)
treecf46155bfe55f32597bb64f60a56887059569e09 /src/cat/LuaScriptInterface.cpp
parent2417ad3b41589f07eecb6e32c913c8858589c13c (diff)
downloadpowder-fdb4dff4d77d36e45e48847a602b53f786380ba0.zip
powder-fdb4dff4d77d36e45e48847a602b53f786380ba0.tar.gz
TPT: Lua methods for reading/writing the bmap and emap (no mapped walltypes yet) 1c4bce1f22
Diffstat (limited to 'src/cat/LuaScriptInterface.cpp')
-rw-r--r--src/cat/LuaScriptInterface.cpp118
1 files changed, 118 insertions, 0 deletions
diff --git a/src/cat/LuaScriptInterface.cpp b/src/cat/LuaScriptInterface.cpp
index 84d1569..5d07279 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; nx<x1+width; nx++)
+ for (ny = y1; ny<y1+height; ny++)
+ {
+ luacon_sim->bmap[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; nx<x1+width; nx++)
+ for (ny = y1; ny<y1+height; ny++)
+ {
+ luacon_sim->emap[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;