summaryrefslogtreecommitdiff
path: root/src/cat/LuaScriptInterface.cpp
diff options
context:
space:
mode:
authorSimon Robertshaw <simon@hardwired.org.uk>2012-09-05 21:43:37 (GMT)
committer Simon Robertshaw <simon@hardwired.org.uk>2012-09-05 21:43:37 (GMT)
commit9432eb63a2165eeaea7725c1ca8e9a0cbef39cb2 (patch)
treef6302f82e23713c717e21cf82cee8eed7eea0624 /src/cat/LuaScriptInterface.cpp
parent9be4f418098d37be164e14d2cf0530bb93cb9454 (diff)
downloadpowder-9432eb63a2165eeaea7725c1ca8e9a0cbef39cb2.zip
powder-9432eb63a2165eeaea7725c1ca8e9a0cbef39cb2.tar.gz
Some simulation API
Diffstat (limited to 'src/cat/LuaScriptInterface.cpp')
-rw-r--r--src/cat/LuaScriptInterface.cpp13
1 files changed, 8 insertions, 5 deletions
diff --git a/src/cat/LuaScriptInterface.cpp b/src/cat/LuaScriptInterface.cpp
index c543941..7a74a4c 100644
--- a/src/cat/LuaScriptInterface.cpp
+++ b/src/cat/LuaScriptInterface.cpp
@@ -59,6 +59,7 @@ LuaScriptInterface::LuaScriptInterface(GameController * c, GameModel * m):
lua_pushlightuserdata(l, this);
lua_settable(l, LUA_REGISTRYINDEX);
+ initSimulationAPI();
initInterfaceAPI();
initRendererAPI();
initElementsAPI();
@@ -346,12 +347,12 @@ void LuaScriptInterface::initSimulationAPI()
{NULL, NULL}
};
luaL_register(l, "simulation", simulationAPIMethods);
+ int simulationAPI = lua_gettop(l);
//Sim shortcut
- lua_getglobal(l, "simlation");
+ lua_getglobal(l, "simulation");
lua_setglobal(l, "sim");
- int simulationAPI = lua_gettop(l);
}
int LuaScriptInterface::simulation_partNeighbours(lua_State * l)
@@ -364,7 +365,8 @@ int LuaScriptInterface::simulation_partNeighbours(lua_State * l)
for (ry = -r; ry <= r; ry++)
if (x+rx >= 0 && y+ry >= 0 && x+rx < XRES && y+ry < YRES && (rx || ry))
{
- if(n = luacon_sim->pmap[y][x] && (n&0xFF) == t)
+ n = luacon_sim->pmap[y+ry][x+rx];
+ if(n && (n&0xFF) == t)
{
ids++;
lua_pushinteger(l, n>>8);
@@ -375,12 +377,13 @@ int LuaScriptInterface::simulation_partNeighbours(lua_State * l)
else
{
int x = lua_tointeger(l, 1), y = lua_tointeger(l, 2), r = lua_tointeger(l, 3), rx, ry, n;
- int ids = 0;
+ std::cout << x << " " << y << " " << r << std::endl;
for (rx = -r; rx <= r; rx++)
for (ry = -r; ry <= r; ry++)
if (x+rx >= 0 && y+ry >= 0 && x+rx < XRES && y+ry < YRES && (rx || ry))
{
- if(n = luacon_sim->pmap[y][x])
+ n = luacon_sim->pmap[y+ry][x+rx];
+ if(n)
{
ids++;
lua_pushinteger(l, n>>8);