summaryrefslogtreecommitdiff
path: root/src/cat/LuaScriptInterface.cpp
diff options
context:
space:
mode:
authorjacob1 <jfu614@gmail.com>2013-01-17 03:53:46 (GMT)
committer jacob1 <jfu614@gmail.com>2013-01-17 03:53:46 (GMT)
commitf9f79e4f530c38dd93b32505d630797a7ec2002e (patch)
tree79aa8ad4c9456802ea159e04071024ce7e811e8e /src/cat/LuaScriptInterface.cpp
parentfc9f263961ae84c2c517270a0be4c6d62065324d (diff)
downloadpowder-f9f79e4f530c38dd93b32505d630797a7ec2002e.zip
powder-f9f79e4f530c38dd93b32505d630797a7ec2002e.tar.gz
combine pressure functions, add sim.ambientHeat, sim.velocityX, sim.velocityY
Diffstat (limited to 'src/cat/LuaScriptInterface.cpp')
-rw-r--r--src/cat/LuaScriptInterface.cpp127
1 files changed, 116 insertions, 11 deletions
diff --git a/src/cat/LuaScriptInterface.cpp b/src/cat/LuaScriptInterface.cpp
index e814f78..4528b2b 100644
--- a/src/cat/LuaScriptInterface.cpp
+++ b/src/cat/LuaScriptInterface.cpp
@@ -406,8 +406,10 @@ void LuaScriptInterface::initSimulationAPI()
{"partChangeType", simulation_partChangeType},
{"partCreate", simulation_partCreate},
{"partKill", simulation_partKill},
- {"setPressure", simulation_setPressure},
- {"getPressure", simulation_getPressure},
+ {"pressure", simulation_pressure},
+ {"ambientHeat", simulation_ambientHeat},
+ {"velocityX", simulation_velocityX},
+ {"velocityY", simulation_velocityY},
{NULL, NULL}
};
luaL_register(l, "simulation", simulationAPIMethods);
@@ -521,17 +523,24 @@ int LuaScriptInterface::simulation_partKill(lua_State * l)
return 0;
}
-int LuaScriptInterface::simulation_setPressure(lua_State* l)
+int LuaScriptInterface::simulation_pressure(lua_State* l)
{
int argCount = lua_gettop(l);
luaL_checktype(l, 1, LUA_TNUMBER);
luaL_checktype(l, 2, LUA_TNUMBER);
- luaL_checktype(l, 3, LUA_TNUMBER);
+ int x = lua_tointeger(l, 1);
+ int y = lua_tointeger(l, 2);
+ if (x*CELL<0 || y*CELL<0 || x*CELL>=XRES || y*CELL>=YRES)
+ return luaL_error(l, "coordinates out of range (%d,%d)", x, y);
- int x, y, width = 1, height = 1;
+ if (argCount == 2)
+ {
+ lua_pushnumber(l, luacon_sim->pv[y][x]);
+ return 1;
+ }
+ int width = 1, height = 1;
float value;
- x = lua_tointeger(l, 1);
- y = lua_tointeger(l, 2);
+ luaL_checktype(l, 3, LUA_TNUMBER);
if (argCount == 3)
value = (float)lua_tonumber(l, 3);
else
@@ -547,23 +556,119 @@ int LuaScriptInterface::simulation_setPressure(lua_State* l)
else if(value < -256.0f)
value = -256.0f;
+ set_map(x, y, width, height, value, 1);
+ return 0;
+}
+
+int LuaScriptInterface::simulation_ambientHeat(lua_State* l)
+{
+ int argCount = lua_gettop(l);
+ luaL_checktype(l, 1, LUA_TNUMBER);
+ luaL_checktype(l, 2, LUA_TNUMBER);
+ int x = lua_tointeger(l, 1);
+ int y = lua_tointeger(l, 2);
if (x*CELL<0 || y*CELL<0 || x*CELL>=XRES || y*CELL>=YRES)
return luaL_error(l, "coordinates out of range (%d,%d)", x, y);
- set_map(x, y, width, height, value, 1);
+ if (argCount == 2)
+ {
+ lua_pushnumber(l, luacon_sim->hv[y][x]);
+ return 1;
+ }
+ int width = 1, height = 1;
+ float value;
+ luaL_checktype(l, 3, LUA_TNUMBER);
+ if (argCount == 3)
+ value = (float)lua_tonumber(l, 3);
+ else
+ {
+ luaL_checktype(l, 4, LUA_TNUMBER);
+ luaL_checktype(l, 5, LUA_TNUMBER);
+ width = lua_tointeger(l, 3);
+ height = lua_tointeger(l, 4);
+ value = (float)lua_tonumber(l, 5);
+ }
+ if(value > MAX_TEMP)
+ value = MAX_TEMP;
+ else if(value < MIN_TEMP)
+ value = MIN_TEMP;
+
+ set_map(x, y, width, height, value, 2);
return 0;
}
-int LuaScriptInterface::simulation_getPressure(lua_State* l)
+int LuaScriptInterface::simulation_velocityX(lua_State* l)
{
+ int argCount = lua_gettop(l);
luaL_checktype(l, 1, LUA_TNUMBER);
luaL_checktype(l, 2, LUA_TNUMBER);
int x = lua_tointeger(l, 1);
int y = lua_tointeger(l, 2);
if (x*CELL<0 || y*CELL<0 || x*CELL>=XRES || y*CELL>=YRES)
return luaL_error(l, "coordinates out of range (%d,%d)", x, y);
- lua_pushnumber(l, luacon_sim->pv[y][x]);
- return 1;
+
+ if (argCount == 2)
+ {
+ lua_pushnumber(l, luacon_sim->vx[y][x]);
+ return 1;
+ }
+ int width = 1, height = 1;
+ float value;
+ luaL_checktype(l, 3, LUA_TNUMBER);
+ if (argCount == 3)
+ value = (float)lua_tonumber(l, 3);
+ else
+ {
+ luaL_checktype(l, 4, LUA_TNUMBER);
+ luaL_checktype(l, 5, LUA_TNUMBER);
+ width = lua_tointeger(l, 3);
+ height = lua_tointeger(l, 4);
+ value = (float)lua_tonumber(l, 5);
+ }
+ if(value > 256.0f)
+ value = 256.0f;
+ else if(value < -256.0f)
+ value = -256.0f;
+
+ set_map(x, y, width, height, value, 3);
+ return 0;
+}
+
+int LuaScriptInterface::simulation_velocityY(lua_State* l)
+{
+ int argCount = lua_gettop(l);
+ luaL_checktype(l, 1, LUA_TNUMBER);
+ luaL_checktype(l, 2, LUA_TNUMBER);
+ int x = lua_tointeger(l, 1);
+ int y = lua_tointeger(l, 2);
+ if (x*CELL<0 || y*CELL<0 || x*CELL>=XRES || y*CELL>=YRES)
+ return luaL_error(l, "coordinates out of range (%d,%d)", x, y);
+
+ if (argCount == 2)
+ {
+ lua_pushnumber(l, luacon_sim->vy[y][x]);
+ return 1;
+ }
+ int width = 1, height = 1;
+ float value;
+ luaL_checktype(l, 3, LUA_TNUMBER);
+ if (argCount == 3)
+ value = (float)lua_tonumber(l, 3);
+ else
+ {
+ luaL_checktype(l, 4, LUA_TNUMBER);
+ luaL_checktype(l, 5, LUA_TNUMBER);
+ width = lua_tointeger(l, 3);
+ height = lua_tointeger(l, 4);
+ value = (float)lua_tonumber(l, 5);
+ }
+ if(value > 256.0f)
+ value = 256.0f;
+ else if(value < -256.0f)
+ value = -256.0f;
+
+ set_map(x, y, width, height, value, 4);
+ return 0;
}
//// Begin Renderer API