diff --git a/src/cat/LuaScriptInterface.cpp b/src/cat/LuaScriptInterface.cpp index d981fe7a4..ef0c1f6a3 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); diff --git a/src/cat/LuaScriptInterface.h b/src/cat/LuaScriptInterface.h index 90c212290..20dada176 100644 --- a/src/cat/LuaScriptInterface.h +++ b/src/cat/LuaScriptInterface.h @@ -64,6 +64,7 @@ class LuaScriptInterface: public CommandInterface static int simulation_partCreate(lua_State * l); static int simulation_partProperty(lua_State * l); static int simulation_partPosition(lua_State * l); + static int simulation_partID(lua_State * l); static int simulation_partKill(lua_State * l); static int simulation_pressure(lua_State * l); static int simulation_velocityX(lua_State * l);