summaryrefslogtreecommitdiff
path: root/src/cat/LuaScriptInterface.cpp
diff options
context:
space:
mode:
authorSimon Robertshaw <simon@hardwired.org.uk>2013-02-17 15:53:34 (GMT)
committer Simon Robertshaw <simon@hardwired.org.uk>2013-02-17 15:53:34 (GMT)
commit27a60e7b7165388e3849ba4d6fe7e550c320f602 (patch)
tree642248d2993ba736e491724ae49f2e98ca1d99e2 /src/cat/LuaScriptInterface.cpp
parent52d0bb918d46bef822196c8f7ac3bfd2c0314305 (diff)
downloadpowder-27a60e7b7165388e3849ba4d6fe7e550c320f602.zip
powder-27a60e7b7165388e3849ba4d6fe7e550c320f602.tar.gz
Particle position lookup with sim.partID
Diffstat (limited to 'src/cat/LuaScriptInterface.cpp')
-rw-r--r--src/cat/LuaScriptInterface.cpp19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/cat/LuaScriptInterface.cpp b/src/cat/LuaScriptInterface.cpp
index d981fe7..ef0c1f6 100644
--- a/src/cat/LuaScriptInterface.cpp
+++ b/src/cat/LuaScriptInterface.cpp
@@ -435,6 +435,7 @@ void LuaScriptInterface::initSimulationAPI()
{"partCreate", simulation_partCreate},
{"partProperty", simulation_partProperty},
{"partPosition", simulation_partPosition},
+ {"partID", simulation_partID},
{"partKill", simulation_partKill},
{"pressure", simulation_pressure},
{"ambientHeat", simulation_ambientHeat},
@@ -558,6 +559,24 @@ int LuaScriptInterface::simulation_partCreate(lua_State * l)
return 1;
}
+int LuaScriptInterface::simulation_partID(lua_State * l)
+{
+ int x = lua_tointeger(l, 1);
+ int y = lua_tointeger(l, 2);
+
+ if(x < 0 || x >= XRES || y < 0 || y >= YRES)
+ {
+ lua_pushnil(l);
+ return 1;
+ }
+
+ int amalgam = luacon_sim->pmap[y][x];
+ if(!amalgam)
+ amalgam = luacon_sim->photons[y][x];
+ lua_pushinteger(l, amalgam >> 8);
+ return 1;
+}
+
int LuaScriptInterface::simulation_partPosition(lua_State * l)
{
int particleID = lua_tointeger(l, 1);