From f9017bc7bbaf74729552897e98093923318b8e76 Mon Sep 17 00:00:00 2001 From: mniip Date: Thu, 25 Apr 2013 22:56:41 +0400 Subject: [PATCH 1/8] fixed dropper debug printing --- src/gui/game/GameModel.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/gui/game/GameModel.cpp b/src/gui/game/GameModel.cpp index 37194a516..1494d6d31 100644 --- a/src/gui/game/GameModel.cpp +++ b/src/gui/game/GameModel.cpp @@ -513,7 +513,9 @@ Menu * GameModel::GetActiveMenu() Tool * GameModel::GetElementTool(int elementID) { +#ifdef DEBUG std::cout << elementID << std::endl; +#endif for(std::vector::iterator iter = elementTools.begin(), end = elementTools.end(); iter != end; ++iter) { if((*iter)->GetToolID() == elementID) From 9f7d45f8fd663a043c5eee26583372d51440d6ff Mon Sep 17 00:00:00 2001 From: mniip Date: Fri, 26 Apr 2013 17:15:33 +0400 Subject: [PATCH 2/8] print does implicit tostring, also generates a list ouside of console too --- src/cat/LegacyLuaAPI.cpp | 40 +++++++++++++++++++++++++++++++--------- 1 file changed, 31 insertions(+), 9 deletions(-) diff --git a/src/cat/LegacyLuaAPI.cpp b/src/cat/LegacyLuaAPI.cpp index df019fa7d..302f2f130 100644 --- a/src/cat/LegacyLuaAPI.cpp +++ b/src/cat/LegacyLuaAPI.cpp @@ -843,22 +843,44 @@ int luatpt_setconsole(lua_State* l) luacon_controller->HideConsole(); return 0; } - +static int luaL_tostring (lua_State *L, int n) { + luaL_checkany(L, n); + switch (lua_type(L, n)) { + case LUA_TNUMBER: + lua_pushstring(L, lua_tostring(L, n)); + break; + case LUA_TSTRING: + lua_pushvalue(L, n); + break; + case LUA_TBOOLEAN: + lua_pushstring(L, (lua_toboolean(L, n) ? "true" : "false")); + break; + case LUA_TNIL: + lua_pushliteral(L, "nil"); + break; + default: + lua_pushfstring(L, "%s: %p", luaL_typename(L, n), lua_topointer(L, n)); + break; + } + return 1; +} int luatpt_log(lua_State* l) { int args = lua_gettop(l); + std::string text = ""; for(int i = 1; i <= args; i++) { - if((*luacon_currentCommand)) - { - if(!(*luacon_lastError).length()) - (*luacon_lastError) = luaL_optstring(l, i, ""); - else - (*luacon_lastError) += ", " + std::string(luaL_optstring(l, i, "")); - } + luaL_tostring(l, lua_gettop(l)); + if(text.length()) + text=std::string(luaL_optstring(l, lua_gettop(l), "")) + ", " + text; else - luacon_ci->Log(CommandInterface::LogNotice, luaL_optstring(l, i, "")); + text=std::string(luaL_optstring(l, lua_gettop(l), "")); + lua_pop(l, 2); } + if((*luacon_currentCommand)) + (*luacon_lastError) = text; + else + luacon_ci->Log(CommandInterface::LogNotice, text.c_str()); return 0; } From a1cdef4c901b7e115a2c883594f28f80f7bb1ab0 Mon Sep 17 00:00:00 2001 From: mniip Date: Sat, 27 Apr 2013 01:25:18 +0400 Subject: [PATCH 3/8] a major rewrite of event registration, it's fully compatible, yet has new advantages --- src/cat/LegacyLuaAPI.cpp | 430 +++++++++++++++++++-------------- src/cat/LuaScriptHelper.h | 5 - src/cat/LuaScriptInterface.cpp | 5 - 3 files changed, 254 insertions(+), 186 deletions(-) diff --git a/src/cat/LegacyLuaAPI.cpp b/src/cat/LegacyLuaAPI.cpp index 302f2f130..a04c3bc47 100644 --- a/src/cat/LegacyLuaAPI.cpp +++ b/src/cat/LegacyLuaAPI.cpp @@ -489,86 +489,162 @@ int luacon_elementwrite(lua_State* l){ return 0; } bool shortcuts = true; -int luacon_keyevent(int key, int modifier, int event){ - int i = 0, kpcontinue = 1, callret; - char tempkey[] = {key, 0}; - if(keypress_function_count){ - for(i = 0; i < keypress_function_count && kpcontinue; i++){ - lua_rawgeti(luacon_ci->l, LUA_REGISTRYINDEX, keypress_functions[i]); - lua_pushstring(luacon_ci->l, tempkey); - lua_pushinteger(luacon_ci->l, key); - lua_pushinteger(luacon_ci->l, modifier); - lua_pushinteger(luacon_ci->l, event); - callret = lua_pcall(luacon_ci->l, 4, 1, 0); - if (callret) +int luacon_keyevent(int key, int modifier, int event) +{ + int kycontinue = 1, i, j, callret; + lua_State* l=luacon_ci->l; + lua_pushstring(l, "keyfunctions"); + lua_rawget(l, LUA_REGISTRYINDEX); + if(!lua_istable(l, -1)) + { + lua_pop(l, 1); + lua_newtable(l); + lua_pushstring(l, "keyfunctions"); + lua_pushvalue(l, -2); + lua_rawset(l, LUA_REGISTRYINDEX); + } + int c=lua_objlen(l, -1); + for(i=1;i<=c && kycontinue;i++) + { + lua_rawgeti(l, -1, i); + lua_pushlstring(l, (const char*)&key, 1); + lua_pushinteger(l, key); + lua_pushinteger(l, modifier); + lua_pushinteger(l, event); + callret = lua_pcall(l, 4, 1, 0); + if (callret) + { + if (!strcmp(luaL_optstring(l, -1, ""), "Error: Script not responding")) { - luacon_ci->Log(CommandInterface::LogError, luacon_geterror()); + ui::Engine::Ref().LastTick(clock()); + for(j=i;j<=c-1;j++) + { + lua_rawgeti(l, -2, j+1); + lua_rawseti(l, -3, j); + } + lua_pushnil(l); + lua_rawseti(l, -3, c); + c--; + i--; } - if(lua_isboolean(luacon_ci->l, -1)){ - kpcontinue = lua_toboolean(luacon_ci->l, -1); - } - lua_pop(luacon_ci->l, 1); + lua_pop(l, 1); + luacon_ci->Log(CommandInterface::LogError, luacon_geterror()); + } + else + { + if(!lua_isnoneornil(l, -1)) + kycontinue = lua_toboolean(l, -1); + lua_pop(l, 1); } } - return kpcontinue && shortcuts; + lua_pop(l, 1); + return kycontinue && shortcuts; } -int luacon_mouseevent(int mx, int my, int mb, int event, int mouse_wheel){ - int i = 0, mpcontinue = 1, callret; - if(mouseclick_function_count){ - for(i = 0; i < mouseclick_function_count && mpcontinue; i++){ - lua_rawgeti(luacon_ci->l, LUA_REGISTRYINDEX, mouseclick_functions[i]); - lua_pushinteger(luacon_ci->l, mx); - lua_pushinteger(luacon_ci->l, my); - lua_pushinteger(luacon_ci->l, mb); - lua_pushinteger(luacon_ci->l, event); - lua_pushinteger(luacon_ci->l, mouse_wheel); - callret = lua_pcall(luacon_ci->l, 5, 1, 0); - if (callret) +int luacon_mouseevent(int mx, int my, int mb, int event, int mouse_wheel) +{ + int mpcontinue = 1, i, j, callret; + lua_State* l=luacon_ci->l; + lua_pushstring(l, "mousefunctions"); + lua_rawget(l, LUA_REGISTRYINDEX); + if(!lua_istable(l, -1)) + { + lua_pop(l, 1); + lua_newtable(l); + lua_pushstring(l, "mousefunctions"); + lua_pushvalue(l, -2); + lua_rawset(l, LUA_REGISTRYINDEX); + } + int c=lua_objlen(l, -1); + for(i=1;i<=c && mpcontinue;i++) + { + lua_rawgeti(l, -1, i); + lua_pushinteger(l, mx); + lua_pushinteger(l, my); + lua_pushinteger(l, mb); + lua_pushinteger(l, event); + lua_pushinteger(l, mouse_wheel); + callret = lua_pcall(l, 5, 1, 0); + if (callret) + { + if (!strcmp(luaL_optstring(l, -1, ""), "Error: Script not responding")) { - luacon_ci->Log(CommandInterface::LogError, luacon_geterror()); + ui::Engine::Ref().LastTick(clock()); + for(j=i;j<=c-1;j++) + { + lua_rawgeti(l, -2, j+1); + lua_rawseti(l, -3, j); + } + lua_pushnil(l); + lua_rawseti(l, -3, c); + c--; + i--; } - if(lua_isboolean(luacon_ci->l, -1)){ - mpcontinue = lua_toboolean(luacon_ci->l, -1); - } - lua_pop(luacon_ci->l, 1); + luacon_ci->Log(CommandInterface::LogError, luaL_optstring(l, -1, "")); + lua_pop(l, 1); + } + else + { + if(!lua_isnoneornil(l, -1)) + mpcontinue = lua_toboolean(l, -1); + lua_pop(l, 1); } } + lua_pop(l, 1); return mpcontinue; } - -int luacon_step(int mx, int my, std::string selectl, std::string selectr, std::string selectalt, int bsx, int bsy){ - int tempret = 0, tempb, i, callret; - lua_pushinteger(luacon_ci->l, bsy); - lua_pushinteger(luacon_ci->l, bsx); - lua_pushstring(luacon_ci->l, selectalt.c_str()); - lua_pushstring(luacon_ci->l, selectr.c_str()); - lua_pushstring(luacon_ci->l, selectl.c_str()); - lua_pushinteger(luacon_ci->l, my); - lua_pushinteger(luacon_ci->l, mx); - lua_setfield(luacon_ci->l, tptProperties, "mousex"); - lua_setfield(luacon_ci->l, tptProperties, "mousey"); - lua_setfield(luacon_ci->l, tptProperties, "selectedl"); - lua_setfield(luacon_ci->l, tptProperties, "selectedr"); - lua_setfield(luacon_ci->l, tptProperties, "selecteda"); - lua_setfield(luacon_ci->l, tptProperties, "brushx"); - lua_setfield(luacon_ci->l, tptProperties, "brushy"); - for(i = 0; i<6; i++){ - if(step_functions[i]){ - lua_rawgeti(luacon_ci->l, LUA_REGISTRYINDEX, step_functions[i]); - callret = lua_pcall(luacon_ci->l, 0, 0, 0); - if (callret) +int luacon_step(int mx, int my, std::string selectl, std::string selectr, std::string selectalt, int bsx, int bsy) +{ + int i, j, callret; + lua_State* l=luacon_ci->l; + lua_pushinteger(l, bsy); + lua_pushinteger(l, bsx); + lua_pushstring(l, selectalt.c_str()); + lua_pushstring(l, selectr.c_str()); + lua_pushstring(l, selectl.c_str()); + lua_pushinteger(l, my); + lua_pushinteger(l, mx); + lua_setfield(l, tptProperties, "mousex"); + lua_setfield(l, tptProperties, "mousey"); + lua_setfield(l, tptProperties, "selectedl"); + lua_setfield(l, tptProperties, "selectedr"); + lua_setfield(l, tptProperties, "selecteda"); + lua_setfield(l, tptProperties, "brushx"); + lua_setfield(l, tptProperties, "brushy"); + lua_pushstring(l, "stepfunctions"); + lua_rawget(l, LUA_REGISTRYINDEX); + if(!lua_istable(l, -1)) + { + lua_pop(l, 1); + lua_newtable(l); + lua_pushstring(l, "stepfunctions"); + lua_pushvalue(l, -2); + lua_rawset(l, LUA_REGISTRYINDEX); + } + int c=lua_objlen(l, -1); + for(i=1;i<=c;i++) + { + lua_rawgeti(l, -1, i); + callret = lua_pcall(l, 0, 0, 0); + if (callret) + { + if (!strcmp(luaL_optstring(l, -1, ""), "Error: Script not responding")) { - if (!strcmp(luacon_geterror(),"Error: Script not responding")) + ui::Engine::Ref().LastTick(clock()); + for(j=i;j<=c-1;j++) { - ui::Engine::Ref().LastTick(clock()); - lua_pushcfunction(luacon_ci->l, &luatpt_unregister_step); - lua_rawgeti(luacon_ci->l, LUA_REGISTRYINDEX, step_functions[i]); - lua_pcall(luacon_ci->l, 1, 0, 0); + lua_rawgeti(l, -2, j+1); + lua_rawseti(l, -3, j); } - luacon_ci->Log(CommandInterface::LogError, luacon_geterror()); + lua_pushnil(l); + lua_rawseti(l, -3, c); + c--; + i--; } + luacon_ci->Log(CommandInterface::LogError, luaL_optstring(l, -1, "")); + lua_pop(l, 1); } } + lua_pop(l, 1); return 0; } @@ -870,11 +946,11 @@ int luatpt_log(lua_State* l) std::string text = ""; for(int i = 1; i <= args; i++) { - luaL_tostring(l, lua_gettop(l)); + luaL_tostring(l, -1); if(text.length()) - text=std::string(luaL_optstring(l, lua_gettop(l), "")) + ", " + text; + text=std::string(luaL_optstring(l, -1, "")) + ", " + text; else - text=std::string(luaL_optstring(l, lua_gettop(l), "")); + text=std::string(luaL_optstring(l, -1, "")); lua_pop(l, 2); } if((*luacon_currentCommand)) @@ -1485,155 +1561,157 @@ int luatpt_delete(lua_State* l) int luatpt_register_step(lua_State* l) { - int ref, i, ifree = -1; - if(lua_isfunction(l, 1)){ - for(i = 0; i<6; i++){ - if(!step_functions[i]){ - if (ifree<0) ifree = i; - } else { - lua_rawgeti(l, LUA_REGISTRYINDEX, step_functions[i]); - if(lua_equal(l, 1, lua_gettop(l))){ - lua_pop(l, 1); - return luaL_error(l, "Function already registered"); - } - lua_pop(l, 1); - } - } - if (ifree>=0) + if(lua_isfunction(l, 1)) + { + lua_pushstring(l, "stepfunctions"); + lua_rawget(l, LUA_REGISTRYINDEX); + if(!lua_istable(l, -1)) { - ref = luaL_ref(l, LUA_REGISTRYINDEX); - step_functions[ifree] = ref; - return 0; + lua_pop(l, -1); + lua_newtable(l); + lua_pushstring(l, "stepfunctions"); + lua_pushvalue(l, -2); + lua_rawset(l, LUA_REGISTRYINDEX); } - else return luaL_error(l, "Step function limit reached"); + int c = lua_objlen(l, -1); + lua_pushvalue(l, 1); + lua_rawseti(l, -2, c+1); } return 0; } int luatpt_unregister_step(lua_State* l) { - int i; - if(lua_isfunction(l, 1)){ - for(i = 0; i<6; i++){ - if (step_functions[i]){ - lua_rawgeti(l, LUA_REGISTRYINDEX, step_functions[i]); - if(lua_equal(l, 1, lua_gettop(l))){ - lua_pop(l, 1); - luaL_unref(l, LUA_REGISTRYINDEX, step_functions[i]); - step_functions[i] = 0; - } - else lua_pop(l, 1); + if(lua_isfunction(l, 1)) + { + lua_pushstring(l, "stepfunctions"); + lua_rawget(l, LUA_REGISTRYINDEX); + if(!lua_istable(l, -1)) + { + lua_pop(l, -1); + lua_newtable(l); + lua_pushstring(l, "stepfunctions"); + lua_pushvalue(l, -2); + lua_rawset(l, LUA_REGISTRYINDEX); + } + int c = lua_objlen(l, -1); + int d = 0; + int i = 0; + for(i=1;i<=c;i++) + { + lua_rawgeti(l, -1, i+d); + if(lua_equal(l, 1, -1)) + { + lua_pop(l, 1); + d++; + i--; } + else + lua_rawseti(l, -2, i); } } return 0; } int luatpt_register_keypress(lua_State* l) { - int *newfunctions, i; - if(lua_isfunction(l, 1)){ - for(i = 0; i 0){ - newfunctions = (int*)calloc(keypress_function_count-1, sizeof(int)); - memcpy(newfunctions, keypress_functions, (keypress_function_count-1)*sizeof(int)); - free(keypress_functions); - keypress_functions = newfunctions; - } else { - free(keypress_functions); - keypress_functions = NULL; - } - keypress_function_count--; - } else { - return luaL_error(l, "Function not registered"); } return 0; } int luatpt_register_mouseclick(lua_State* l) { - int *newfunctions, i; - if(lua_isfunction(l, 1)){ - for(i = 0; i 0){ - newfunctions = (int*)calloc(mouseclick_function_count-1, sizeof(int)); - memcpy(newfunctions, mouseclick_functions, (mouseclick_function_count-1)*sizeof(int)); - free(mouseclick_functions); - mouseclick_functions = newfunctions; - } else { - free(mouseclick_functions); - mouseclick_functions = NULL; - } - mouseclick_function_count--; - } else { - return luaL_error(l, "Function not registered"); } return 0; } diff --git a/src/cat/LuaScriptHelper.h b/src/cat/LuaScriptHelper.h index 860d919ea..fde1eb4a1 100644 --- a/src/cat/LuaScriptHelper.h +++ b/src/cat/LuaScriptHelper.h @@ -14,11 +14,6 @@ extern std::string *luacon_lastError; extern int *lua_el_func, *lua_el_mode, *lua_gr_func; extern int getPartIndex_curIdx; -extern int step_functions[6];//[6] = {0, 0, 0, 0, 0, 0}; -extern int keypress_function_count;// = 0; -extern int *keypress_functions;// = NULL; -extern int mouseclick_function_count;// = 0; -extern int *mouseclick_functions;// = NULL; extern int tptProperties; //Table for some TPT properties extern int tptPropertiesVersion; extern int tptElements; //Table for TPT element names diff --git a/src/cat/LuaScriptInterface.cpp b/src/cat/LuaScriptInterface.cpp index 7719add79..74757e5d3 100644 --- a/src/cat/LuaScriptInterface.cpp +++ b/src/cat/LuaScriptInterface.cpp @@ -61,11 +61,6 @@ std::string *luacon_lastError; int *lua_el_func, *lua_el_mode, *lua_gr_func; int getPartIndex_curIdx; -int step_functions[6] = {0, 0, 0, 0, 0, 0}; -int keypress_function_count = 0; -int *keypress_functions = NULL; -int mouseclick_function_count = 0; -int *mouseclick_functions = NULL; int tptProperties; //Table for some TPT properties int tptPropertiesVersion; int tptElements; //Table for TPT element names From 77e837c77528965d3c98e722a55f62b45dc67cfe Mon Sep 17 00:00:00 2001 From: mniip Date: Sat, 27 Apr 2013 02:20:06 +0400 Subject: [PATCH 4/8] Fixed graphics function crash when unable to catch errors --- src/cat/LegacyLuaAPI.cpp | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/src/cat/LegacyLuaAPI.cpp b/src/cat/LegacyLuaAPI.cpp index a04c3bc47..96b895872 100644 --- a/src/cat/LegacyLuaAPI.cpp +++ b/src/cat/LegacyLuaAPI.cpp @@ -775,20 +775,24 @@ int luacon_graphicsReplacement(GRAPHICS_FUNC_ARGS, int i) lua_pushinteger(luacon_ci->l, *colb); callret = lua_pcall(luacon_ci->l, 4, 10, 0); if (callret) - luacon_ci->Log(CommandInterface::LogError, luacon_geterror()); - - cache = luaL_optint(luacon_ci->l, -10, 0); - *pixel_mode = luaL_optint(luacon_ci->l, -9, *pixel_mode); - *cola = luaL_optint(luacon_ci->l, -8, *cola); - *colr = luaL_optint(luacon_ci->l, -7, *colr); - *colg = luaL_optint(luacon_ci->l, -6, *colg); - *colb = luaL_optint(luacon_ci->l, -5, *colb); - *firea = luaL_optint(luacon_ci->l, -4, *firea); - *firer = luaL_optint(luacon_ci->l, -3, *firer); - *fireg = luaL_optint(luacon_ci->l, -2, *fireg); - *fireb = luaL_optint(luacon_ci->l, -1, *fireb); - lua_pop(luacon_ci->l, 10); - + { + luacon_ci->Log(CommandInterface::LogError, luaL_optstring(luacon_ci->l, -1, "")); + lua_pop(luacon_ci->l, 1); + } + else + { + cache = luaL_optint(luacon_ci->l, -10, 0); + *pixel_mode = luaL_optint(luacon_ci->l, -9, *pixel_mode); + *cola = luaL_optint(luacon_ci->l, -8, *cola); + *colr = luaL_optint(luacon_ci->l, -7, *colr); + *colg = luaL_optint(luacon_ci->l, -6, *colg); + *colb = luaL_optint(luacon_ci->l, -5, *colb); + *firea = luaL_optint(luacon_ci->l, -4, *firea); + *firer = luaL_optint(luacon_ci->l, -3, *firer); + *fireg = luaL_optint(luacon_ci->l, -2, *fireg); + *fireb = luaL_optint(luacon_ci->l, -1, *fireb); + lua_pop(luacon_ci->l, 10); + } return cache; } From bfe00dc1f318aed693130e384ae0c3da147c5798 Mon Sep 17 00:00:00 2001 From: mniip Date: Sat, 27 Apr 2013 02:57:41 +0400 Subject: [PATCH 5/8] Ooooooohh --- src/cat/LegacyLuaAPI.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cat/LegacyLuaAPI.cpp b/src/cat/LegacyLuaAPI.cpp index 96b895872..75b67806b 100644 --- a/src/cat/LegacyLuaAPI.cpp +++ b/src/cat/LegacyLuaAPI.cpp @@ -1571,7 +1571,7 @@ int luatpt_register_step(lua_State* l) lua_rawget(l, LUA_REGISTRYINDEX); if(!lua_istable(l, -1)) { - lua_pop(l, -1); + lua_pop(l, 1); lua_newtable(l); lua_pushstring(l, "stepfunctions"); lua_pushvalue(l, -2); From 828569415f678d03087883876e0c18efc0068ac5 Mon Sep 17 00:00:00 2001 From: Simon Robertshaw Date: Sat, 27 Apr 2013 11:38:20 +0100 Subject: [PATCH 6/8] BREAKING NEWS: Hell has frozen over New element, GOLD, a corrosion resistant metal that can conduct electricity faster, molten GOLD will turn into molten VIBR on contact with EXOT --- src/simulation/elements/EXOT.cpp | 2 +- src/simulation/elements/GOLD.cpp | 92 ++++++++++++++++++++++++++++++++ 2 files changed, 93 insertions(+), 1 deletion(-) create mode 100644 src/simulation/elements/GOLD.cpp diff --git a/src/simulation/elements/EXOT.cpp b/src/simulation/elements/EXOT.cpp index 52bf4622a..8f8d8749d 100644 --- a/src/simulation/elements/EXOT.cpp +++ b/src/simulation/elements/EXOT.cpp @@ -70,7 +70,7 @@ int Element_EXOT::update(UPDATE_FUNC_ARGS) { } else if (rt == PT_LAVA) { - if (parts[r>>8].ctype == PT_TTAN && !(rand()%10)) + if ((parts[r>>8].ctype == PT_TTAN || parts[r>>8].ctype == PT_GOLD) && !(rand()%10)) { parts[r>>8].ctype = PT_VIBR; sim->kill_part(i); diff --git a/src/simulation/elements/GOLD.cpp b/src/simulation/elements/GOLD.cpp new file mode 100644 index 000000000..00eb7bf76 --- /dev/null +++ b/src/simulation/elements/GOLD.cpp @@ -0,0 +1,92 @@ +#include "simulation/Elements.h" +#include "simulation/Air.h" +//#TPT-Directive ElementClass Element_GOLD PT_GOLD 170 +Element_GOLD::Element_GOLD() +{ + Identifier = "DEFAULT_PT_GOLD"; + Name = "GOLD"; + Colour = PIXPACK(0xDCAD2C); + MenuVisible = 1; + MenuSection = SC_SOLIDS; + Enabled = 1; + + Advection = 0.0f; + AirDrag = 0.00f * CFDS; + AirLoss = 0.90f; + Loss = 0.00f; + Collision = 0.0f; + Gravity = 0.0f; + Diffusion = 0.00f; + HotAir = 0.000f * CFDS; + Falldown = 0; + + Flammable = 0; + Explosive = 0; + Meltable = 1; + Hardness = 0; + + Weight = 100; + + Temperature = R_TEMP+0.0f +273.15f; + HeatConduct = 251; + Description = "Corrosion resistant metal, will reverse corrosion of iron"; + + State = ST_SOLID; + Properties = TYPE_SOLID|PROP_CONDUCTS|PROP_HOT_GLOW|PROP_LIFE_DEC; + + LowPressure = IPL; + LowPressureTransition = NT; + HighPressure = IPH; + HighPressureTransition = NT; + LowTemperature = ITL; + LowTemperatureTransition = NT; + HighTemperature = 1941.0f; + HighTemperatureTransition = PT_LAVA; + + Update = &Element_GOLD::update; + +} + +//#TPT-Directive ElementHeader Element_GOLD static int update(UPDATE_FUNC_ARGS) +int Element_GOLD::update(UPDATE_FUNC_ARGS) + { + int rx, ry, r, blocking = 0; + static int checkCoordsX[] = { -4, 4, 0, 0 }; + static int checkCoordsY[] = { 0, 0, -4, 4 }; + //Find nearby rusted iron (BMTL with tmp 1+) + for(int j = 0; j < 8; j++){ + rx = (rand()%9)-4; + ry = (rand()%9)-4; + if ((!rx != !ry) && BOUNDS_CHECK) { + r = pmap[y+ry][x+rx]; + if(!r) continue; + if((r&0xFF)==PT_BMTL && parts[r>>8].tmp) + { + parts[r>>8].tmp = 0; + sim->part_change_type(r>>8, x+rx, y+ry, PT_IRON); + } + } + } + //Find sparks + if(!parts[i].life) + { + for(int j = 0; j < 4; j++){ + rx = checkCoordsX[j]; + ry = checkCoordsY[j]; + if ((!rx != !ry) && BOUNDS_CHECK) { + r = pmap[y+ry][x+rx]; + if(!r) continue; + if((r&0xFF)==PT_SPRK && parts[r>>8].life) + { + parts[i].life = 4; + parts[i].type = PT_SPRK; + parts[i].ctype = PT_GOLD; + } + } + } + } + return 0; +} + + +Element_GOLD::~Element_GOLD() {} From 9bc939d4223ce0d7e7209f2192dbc5779d7d6217 Mon Sep 17 00:00:00 2001 From: jacksonmj Date: Sat, 27 Apr 2013 13:54:16 +0100 Subject: [PATCH 7/8] Less dependence on particle order for GOLD fast electricity conduction --- src/simulation/elements/GOLD.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/simulation/elements/GOLD.cpp b/src/simulation/elements/GOLD.cpp index 00eb7bf76..e3837d76e 100644 --- a/src/simulation/elements/GOLD.cpp +++ b/src/simulation/elements/GOLD.cpp @@ -76,7 +76,7 @@ int Element_GOLD::update(UPDATE_FUNC_ARGS) if ((!rx != !ry) && BOUNDS_CHECK) { r = pmap[y+ry][x+rx]; if(!r) continue; - if((r&0xFF)==PT_SPRK && parts[r>>8].life) + if((r&0xFF)==PT_SPRK && parts[r>>8].life && parts[r>>8].life<4) { parts[i].life = 4; parts[i].type = PT_SPRK; From b83043e2a6293e83d5d7fbad70a7e20b131ba33b Mon Sep 17 00:00:00 2001 From: jacksonmj Date: Sat, 27 Apr 2013 15:48:34 +0100 Subject: [PATCH 8/8] Remove obsolete code from TPTScriptInterface --- src/cat/TPTScriptInterface.cpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/cat/TPTScriptInterface.cpp b/src/cat/TPTScriptInterface.cpp index 5d9a5e05b..bf08f1e06 100644 --- a/src/cat/TPTScriptInterface.cpp +++ b/src/cat/TPTScriptInterface.cpp @@ -261,10 +261,7 @@ AnyType TPTScriptInterface::tptS_set(std::deque * words) newValue = GetParticleType(((StringType)value).Value()); if (newValue < 0 || newValue >= PT_NUM) { - if (((StringType)value).Value() == "GOLD" || ((StringType)value).Value() == "gold") - throw GeneralException("No, GOLD will not be an element"); - else - throw GeneralException("Invalid element"); + throw GeneralException("Invalid element"); } } else