diff --git a/changelog.txt b/changelog.txt index 1966e8ac2..5d0d14154 100644 --- a/changelog.txt +++ b/changelog.txt @@ -2,4 +2,6 @@ # It may also be used by mod owners using the starcatcher update server to write changelogs for their mods # Erase and replace the changelog for every release, do not just append changes to the end -Fix issue where Linux version couldn't be launched from some file managers +Fix air being able to go through walls for a frame after undoing +Show NONE in {ctype} signs instead of 0 when an element has no ctype +Fix some legacy lua api functions allowing you to set properties on element 0 diff --git a/src/gui/game/GameController.cpp b/src/gui/game/GameController.cpp index 91db38fd4..be5853ed4 100644 --- a/src/gui/game/GameController.cpp +++ b/src/gui/game/GameController.cpp @@ -943,7 +943,7 @@ void GameController::Update() if (activeTool->GetIdentifier().BeginsWith("DEFAULT_PT_")) { int sr = activeTool->GetToolID(); - if (sr && sim->IsValidElement(sr)) + if (sr && sim->IsElementOrNone(sr)) rightSelected = sr; } @@ -1562,9 +1562,9 @@ void GameController::ReloadSim() bool GameController::IsValidElement(int type) { - if(gameModel && gameModel->GetSimulation()) + if (gameModel && gameModel->GetSimulation()) { - return (type && gameModel->GetSimulation()->IsValidElement(type)); + return (type && gameModel->GetSimulation()->IsElement(type)); } else return false; diff --git a/src/lua/LegacyLuaAPI.cpp b/src/lua/LegacyLuaAPI.cpp index 52ca230fa..163be5f4e 100644 --- a/src/lua/LegacyLuaAPI.cpp +++ b/src/lua/LegacyLuaAPI.cpp @@ -171,7 +171,7 @@ int luacon_transitionread(lua_State* l) lua_rawget(l, 1); int i = lua_tointeger (l, lua_gettop(l)); lua_pop(l, 1); - if (!luacon_sim->IsValidElement(i)) + if (!luacon_sim->IsElement(i)) { return luaL_error(l, "Invalid index"); } @@ -194,7 +194,7 @@ int luacon_transitionwrite(lua_State* l) lua_rawget(l, 1); int i = lua_tointeger (l, lua_gettop(l)); lua_pop(l, 1); - if (!luacon_sim->IsValidElement(i)) + if (!luacon_sim->IsElement(i)) { return luaL_error(l, "Invalid index"); } @@ -202,7 +202,7 @@ int luacon_transitionwrite(lua_State* l) if (prop.Type == StructProperty::TransitionType) { int type = luaL_checkinteger(l, 3); - if (!luacon_sim->IsValidElement(type) && type != NT && type != ST) + if (!luacon_sim->IsElementOrNone(type) && type != NT && type != ST) { return luaL_error(l, "Invalid element"); } @@ -226,7 +226,7 @@ int luacon_elementread(lua_State* l) lua_rawget(l, 1); int i = lua_tointeger (l, lua_gettop(l)); lua_pop(l, 1); - if (!luacon_sim->IsValidElement(i)) + if (!luacon_sim->IsElement(i)) { return luaL_error(l, "Invalid index"); } @@ -249,7 +249,7 @@ int luacon_elementwrite(lua_State* l) lua_rawget(l, 1); int i = lua_tointeger (l, lua_gettop(l)); lua_pop(l, 1); - if (!luacon_sim->IsValidElement(i)) + if (!luacon_sim->IsElement(i)) { return luaL_error(l, "Invalid index"); } @@ -302,7 +302,7 @@ int luatpt_getelement(lua_State *l) if (lua_isnumber(l, 1)) { t = luaL_optint(l, 1, 1); - if (!luacon_sim->IsValidElement(t)) + if (!luacon_sim->IsElementOrNone(t)) { return luaL_error(l, "Unrecognised element number '%d'", t); } @@ -343,11 +343,11 @@ int luacon_elementReplacement(UPDATE_FUNC_ARGS) int luatpt_element_func(lua_State *l) { - if(lua_isfunction(l, 1)) + if (lua_isfunction(l, 1)) { int element = luaL_optint(l, 2, 0); int replace = luaL_optint(l, 3, 0); - if (luacon_sim->IsValidElement(element)) + if (luacon_sim->IsElement(element)) { lua_el_func[element].Assign(l, 1); if (replace == 2) @@ -363,10 +363,10 @@ int luatpt_element_func(lua_State *l) return luaL_error(l, "Invalid element"); } } - else if(lua_isnil(l, 1)) + else if (lua_isnil(l, 1)) { int element = luaL_optint(l, 2, 0); - if (luacon_sim->IsValidElement(element)) + if (luacon_sim->IsElement(element)) { lua_el_func[element].Clear(); lua_el_mode[element] = 0; @@ -427,7 +427,7 @@ int luatpt_graphics_func(lua_State *l) if(lua_isfunction(l, 1)) { int element = luaL_optint(l, 2, 0); - if (luacon_sim->IsValidElement(element)) + if (luacon_sim->IsElement(element)) { lua_gr_func[element].Assign(l, 1); luacon_ren->graphicscache[element].isready = 0; @@ -441,7 +441,7 @@ int luatpt_graphics_func(lua_State *l) else if (lua_isnil(l, 1)) { int element = luaL_optint(l, 2, 0); - if (luacon_sim->IsValidElement(element)) + if (luacon_sim->IsElement(element)) { lua_gr_func[element].Clear(); luacon_ren->graphicscache[element].isready = 0; @@ -497,10 +497,10 @@ int luatpt_create(lua_State* l) y = abs(luaL_optint(l, 2, 0)); if(x < XRES && y < YRES) { - if(lua_isnumber(l, 3)) + if (lua_isnumber(l, 3)) { t = luaL_optint(l, 3, 0); - if (!luacon_sim->IsValidElement(t)) + if (!luacon_sim->IsElement(t)) { return luaL_error(l, "Unrecognised element number '%d'", t); } @@ -730,7 +730,7 @@ int luatpt_set_property(lua_State* l) else t = luaL_optint(l, 2, 0); - if (!strcmp(prop, "type") && !luacon_sim->IsValidElement(t)) + if (!strcmp(prop, "type") && !luacon_sim->IsElementOrNone(t)) return luaL_error(l, "Unrecognised element number '%d'", t); } else if (lua_isstring(l, 2)) diff --git a/src/lua/LuaScriptInterface.cpp b/src/lua/LuaScriptInterface.cpp index a2c188aae..7895311f2 100644 --- a/src/lua/LuaScriptInterface.cpp +++ b/src/lua/LuaScriptInterface.cpp @@ -2856,7 +2856,7 @@ static bool luaCtypeDrawWrapper(CTYPEDRAW_FUNC_ARGS) int LuaScriptInterface::elements_element(lua_State * l) { int id = luaL_checkinteger(l, 1); - if (!luacon_sim->IsValidElement(id)) + if (!luacon_sim->IsElementOrNone(id)) { return luaL_error(l, "Invalid element"); } @@ -3007,7 +3007,7 @@ int LuaScriptInterface::elements_element(lua_State * l) int LuaScriptInterface::elements_property(lua_State * l) { int id = luaL_checkinteger(l, 1); - if (!luacon_sim->IsValidElement(id)) + if (!luacon_sim->IsElementOrNone(id)) { return luaL_error(l, "Invalid element"); } @@ -3027,7 +3027,7 @@ int LuaScriptInterface::elements_property(lua_State * l) if (prop->Type == StructProperty::TransitionType) { int type = luaL_checkinteger(l, 3); - if (!luacon_sim->IsValidElement(type) && type != NT && type != ST) + if (!luacon_sim->IsElementOrNone(type) && type != NT && type != ST) { return luaL_error(l, "Invalid element"); } @@ -3188,7 +3188,7 @@ int LuaScriptInterface::elements_property(lua_State * l) int LuaScriptInterface::elements_free(lua_State * l) { int id = luaL_checkinteger(l, 1); - if (!luacon_sim->IsValidElement(id)) + if (!luacon_sim->IsElement(id)) { return luaL_error(l, "Invalid element"); } diff --git a/src/simulation/Sign.cpp b/src/simulation/Sign.cpp index 2ab36c433..df33e2763 100644 --- a/src/simulation/Sign.cpp +++ b/src/simulation/Sign.cpp @@ -85,7 +85,7 @@ String sign::getDisplayText(Simulation *sim, int &x0, int &y0, int &w, int &h, b } else if (between_curlies == "ctype") { - formatted_text << (part ? ((part->ctype && sim->IsValidElement(part->ctype)) ? sim->ElementResolve(part->ctype, -1) : String::Build(part->ctype)) : (formatted_text.Size() ? String::Build("empty") : String::Build("Empty"))); + formatted_text << (part ? (sim->IsElementOrNone(part->ctype) ? sim->ElementResolve(part->ctype, -1) : String::Build(part->ctype)) : (formatted_text.Size() ? String::Build("empty") : String::Build("Empty"))); if (v95) *v95 = true; } diff --git a/src/simulation/Simulation.cpp b/src/simulation/Simulation.cpp index 47b010809..a44b55a74 100644 --- a/src/simulation/Simulation.cpp +++ b/src/simulation/Simulation.cpp @@ -3651,16 +3651,16 @@ void Simulation::UpdateParticles(int start, int end) ctemph = ctempl = pt; // change boiling point with pressure - if (((elements[t].Properties&TYPE_LIQUID) && IsValidElement(elements[t].HighTemperatureTransition) && (elements[elements[t].HighTemperatureTransition].Properties&TYPE_GAS)) + if (((elements[t].Properties&TYPE_LIQUID) && IsElementOrNone(elements[t].HighTemperatureTransition) && (elements[elements[t].HighTemperatureTransition].Properties&TYPE_GAS)) || t==PT_LNTG || t==PT_SLTW) ctemph -= 2.0f*pv[y/CELL][x/CELL]; - else if (((elements[t].Properties&TYPE_GAS) && IsValidElement(elements[t].LowTemperatureTransition) && (elements[elements[t].LowTemperatureTransition].Properties&TYPE_LIQUID)) + else if (((elements[t].Properties&TYPE_GAS) && IsElementOrNone(elements[t].LowTemperatureTransition) && (elements[elements[t].LowTemperatureTransition].Properties&TYPE_LIQUID)) || t==PT_WTRV) ctempl -= 2.0f*pv[y/CELL][x/CELL]; s = 1; //A fix for ice with ctype = 0 - if ((t==PT_ICEI || t==PT_SNOW) && (!parts[i].ctype || !IsValidElement(parts[i].ctype) || parts[i].ctype==PT_ICEI || parts[i].ctype==PT_SNOW)) + if ((t==PT_ICEI || t==PT_SNOW) && (!IsElement(parts[i].ctype) || parts[i].ctype==PT_ICEI || parts[i].ctype==PT_SNOW)) parts[i].ctype = PT_WATR; if (elements[t].HighTemperatureTransition>-1 && ctemph>=elements[t].HighTemperature) @@ -5317,9 +5317,7 @@ String Simulation::ElementResolve(int type, int ctype) return SerialiseGOLRule(ctype); } else if (type >= 0 && type < PT_NUM) - { return elements[type].Name; - } return "Empty"; } @@ -5329,13 +5327,13 @@ String Simulation::BasicParticleInfo(Particle const &sample_part) int type = sample_part.type; int ctype = sample_part.ctype; int pavg1int = (int)sample_part.pavg[1]; - if (type == PT_LAVA && ctype && IsValidElement(ctype)) + if (type == PT_LAVA && IsElement(ctype)) { sampleInfo << "Molten " << ElementResolve(ctype, -1); } - else if ((type == PT_PIPE || type == PT_PPIP) && ctype && IsValidElement(ctype)) + else if ((type == PT_PIPE || type == PT_PPIP) && IsElement(ctype)) { - if (ctype == PT_LAVA && pavg1int && IsValidElement(pavg1int)) + if (ctype == PT_LAVA && IsElement(pavg1int)) { sampleInfo << ElementResolve(type, -1) << " with molten " << ElementResolve(pavg1int, -1); } diff --git a/src/simulation/Simulation.h b/src/simulation/Simulation.h index 2ff0361cd..d76e94f5c 100644 --- a/src/simulation/Simulation.h +++ b/src/simulation/Simulation.h @@ -134,7 +134,10 @@ public: int eval_move(int pt, int nx, int ny, unsigned *rr); void init_can_move(); bool IsWallBlocking(int x, int y, int type); - bool IsValidElement(int type) { + bool IsElement(int type) { + return (type > 0 && type < PT_NUM && elements[type].Enabled); + } + bool IsElementOrNone(int type) { return (type >= 0 && type < PT_NUM && elements[type].Enabled); } void create_cherenkov_photon(int pp); diff --git a/src/simulation/elements/CONV.cpp b/src/simulation/elements/CONV.cpp index 681f2e9ed..19c0c2c37 100644 --- a/src/simulation/elements/CONV.cpp +++ b/src/simulation/elements/CONV.cpp @@ -75,7 +75,7 @@ static int update(UPDATE_FUNC_ARGS) } else { - int restrictElement = sim->IsValidElement(parts[i].tmp) ? parts[i].tmp : 0; + int restrictElement = sim->IsElement(parts[i].tmp) ? parts[i].tmp : 0; for (rx=-1; rx<2; rx++) for (ry=-1; ry<2; ry++) if (x+rx>=0 && y+ry>=0 && x+rxkill_part(ID(r)); } - else if (!TYP(parts[i].ctype) && TYP(r)==PT_STOR && parts[ID(r)].tmp>0 && sim->IsValidElement(parts[ID(r)].tmp) && (sim->elements[parts[ID(r)].tmp].Properties & (TYPE_PART | TYPE_LIQUID | TYPE_GAS | TYPE_ENERGY))) + else if (!TYP(parts[i].ctype) && TYP(r)==PT_STOR && sim->IsElement(parts[ID(r)].tmp) && (sim->elements[parts[ID(r)].tmp].Properties & (TYPE_PART | TYPE_LIQUID | TYPE_GAS | TYPE_ENERGY))) { // STOR stores properties in the same places as PIPE does transfer_pipe_to_pipe(parts+(ID(r)), parts+i, true); diff --git a/src/simulation/elements/PRTI.cpp b/src/simulation/elements/PRTI.cpp index 90a933409..d53f13ca4 100644 --- a/src/simulation/elements/PRTI.cpp +++ b/src/simulation/elements/PRTI.cpp @@ -94,7 +94,7 @@ static int update(UPDATE_FUNC_ARGS) { if (TYP(r) == PT_STOR) { - if (sim->IsValidElement(parts[ID(r)].tmp) && (sim->elements[parts[ID(r)].tmp].Properties & (TYPE_PART | TYPE_LIQUID | TYPE_GAS | TYPE_ENERGY))) + if (sim->IsElement(parts[ID(r)].tmp) && (sim->elements[parts[ID(r)].tmp].Properties & (TYPE_PART | TYPE_LIQUID | TYPE_GAS | TYPE_ENERGY))) { // STOR uses same format as PIPE, so we can use this function to do the transfer Element_PIPE_transfer_pipe_to_part(sim, parts+(ID(r)), &sim->portalp[parts[i].tmp][count][nnx], true); diff --git a/src/simulation/elements/STKM.cpp b/src/simulation/elements/STKM.cpp index 838aae58a..2b27f8859 100644 --- a/src/simulation/elements/STKM.cpp +++ b/src/simulation/elements/STKM.cpp @@ -112,7 +112,7 @@ int Element_STKM_run_stickman(playerst *playerp, UPDATE_FUNC_ARGS) float rocketBootsHeadEffectV = 0.3f;// stronger acceleration vertically, to counteract gravity float rocketBootsFeetEffectV = 0.45f; - if (!playerp->fan && parts[i].ctype && sim->IsValidElement(parts[i].ctype)) + if (!playerp->fan && parts[i].ctype && sim->IsElementOrNone(parts[i].ctype)) Element_STKM_set_element(sim, playerp, parts[i].ctype); playerp->frames++; diff --git a/src/simulation/elements/STOR.cpp b/src/simulation/elements/STOR.cpp index 8896d52e0..e9986505c 100644 --- a/src/simulation/elements/STOR.cpp +++ b/src/simulation/elements/STOR.cpp @@ -53,7 +53,7 @@ void Element::Element_STOR() static int update(UPDATE_FUNC_ARGS) { int r, rx, ry, np, rx1, ry1; - if (!sim->IsValidElement(parts[i].tmp)) + if (!sim->IsElementOrNone(parts[i].tmp)) parts[i].tmp = 0; if(parts[i].life && !parts[i].tmp) parts[i].life--;