diff --git a/src/lua/LuaSimulation.cpp b/src/lua/LuaSimulation.cpp index c753cd1e4..cdd605d09 100644 --- a/src/lua/LuaSimulation.cpp +++ b/src/lua/LuaSimulation.cpp @@ -934,7 +934,7 @@ static int resetTemp(lua_State *L) bool onlyConductors = luaL_optint(L, 1, 0); for (int i = 0; i < sim->parts.lastActiveIndex; i++) { - if (sim->parts[i].type && (!onlyConductors || !sim->IsHeatInsulator(sim->parts[i]))) + if (sim->parts[i].type && (!onlyConductors || !sd.IsHeatInsulator(sim->parts[i]))) { sim->parts[i].temp = elements[sim->parts[i].type].DefaultProperties.temp; } diff --git a/src/simulation/Air.cpp b/src/simulation/Air.cpp index 8537943ad..512402411 100644 --- a/src/simulation/Air.cpp +++ b/src/simulation/Air.cpp @@ -485,7 +485,7 @@ void Air::ApproximateBlockAirMaps() } } // mostly accurate insulator blocking, besides checking GEL - else if (sim.IsHeatInsulator(sim.parts[i]) || elements[type].HeatConduct <= (sim.rng()%250)) + else if (sd.IsHeatInsulator(sim.parts[i]) || elements[type].HeatConduct <= (sim.rng()%250)) { int x = ((int)(sim.parts[i].x+0.5f))/CELL, y = ((int)(sim.parts[i].y+0.5f))/CELL; if (InBounds(x, y) && !(bmap_blockairh[y][x]&0x8)) diff --git a/src/simulation/Simulation.cpp b/src/simulation/Simulation.cpp index 81feebce4..bac3338b2 100644 --- a/src/simulation/Simulation.cpp +++ b/src/simulation/Simulation.cpp @@ -1199,7 +1199,7 @@ int Simulation::try_move(int i, int x, int y, int nx, int ny) if (rt == PT_COAL || rt == PT_BCOL) parts[ID(r)].temp = parts[i].temp; - if (rt < PT_NUM && !IsHeatInsulator(parts[ID(r)]) && rt != PT_FILT) + if (rt < PT_NUM && !sd.IsHeatInsulator(parts[ID(r)]) && rt != PT_FILT) parts[i].temp = parts[ID(r)].temp = restrict_flt((parts[ID(r)].temp+parts[i].temp)/2, MIN_TEMP, MAX_TEMP); } else if ((parts[i].type==PT_NEUT || parts[i].type==PT_ELEC) && (rt==PT_CLNE || rt==PT_PCLN || rt==PT_BCLN || rt==PT_PBCN)) @@ -2205,11 +2205,6 @@ Simulation::PlanMoveResult Simulation::PlanMove(Sim &sim, int i, int x, int y) template Simulation::PlanMoveResult Simulation::PlanMove(const Simulation &sim, int i, int x, int y); -bool Simulation::IsHeatInsulator(Particle p) const -{ - return SimulationData::CRef().elements[p.type].HeatConduct == 0 || (p.type == PT_HSWC && p.life != 10) || ((p.type == PT_PIPE || p.type == PT_PPIP) && (p.tmp & PFLAG_CAN_CONDUCT) == 0); -} - void Simulation::UpdateParticles(int start, int end) { //the main particle loop function, goes over all particles. @@ -2367,7 +2362,7 @@ void Simulation::UpdateParticles(int start, int end) //heat transfer code auto h_count = 0; bool cond; - cond = t && !IsHeatInsulator(parts[i]) && rng.chance(int(elements[t].HeatConduct*gel_scale), 250); + cond = t && !sd.IsHeatInsulator(parts[i]) && rng.chance(int(elements[t].HeatConduct*gel_scale), 250); if (cond) { @@ -2390,7 +2385,7 @@ void Simulation::UpdateParticles(int start, int end) auto rt = TYP(r); - if (!rt || IsHeatInsulator(parts[ID(r)]) + if (!rt || sd.IsHeatInsulator(parts[ID(r)]) || (t == PT_FILT && (rt == PT_BRAY || rt == PT_BIZR || rt == PT_BIZRG)) || (rt == PT_FILT && (t == PT_BRAY || t == PT_PHOT || t == PT_BIZR || t == PT_BIZRG)) || (t == PT_ELEC && rt == PT_DEUT) diff --git a/src/simulation/Simulation.h b/src/simulation/Simulation.h index 7601c22df..cbf0536e6 100644 --- a/src/simulation/Simulation.h +++ b/src/simulation/Simulation.h @@ -199,7 +199,6 @@ public: int is_wire_off(int x, int y); void set_emap(int x, int y); int parts_avg(int ci, int ni, int t); - bool IsHeatInsulator(Particle) const; void UpdateParticles(int start, int end); // Dispatches an update to the range [start, end). void SimulateGoL(); void RecalcFreeParticles(bool do_life_dec); diff --git a/src/simulation/SimulationData.cpp b/src/simulation/SimulationData.cpp index f4cbd56fa..d1231a45a 100644 --- a/src/simulation/SimulationData.cpp +++ b/src/simulation/SimulationData.cpp @@ -8,6 +8,7 @@ #include "MenuSection.h" #include "Misc.h" #include "graphics/Renderer.h" +#include "simulation/elements/PIPE.h" const std::array SimulationData::builtinGol = {{ // * Ruleset: @@ -333,3 +334,8 @@ SimulationData::SimulationData() elements = GetElements(); init_can_move(); } + +bool SimulationData::IsHeatInsulator(const Particle &p) const +{ + return elements[p.type].HeatConduct == 0 || (p.type == PT_HSWC && p.life != 10) || ((p.type == PT_PIPE || p.type == PT_PPIP) && (p.tmp & PFLAG_CAN_CONDUCT) == 0); +} diff --git a/src/simulation/SimulationData.h b/src/simulation/SimulationData.h index adabe17a7..631d7cc66 100644 --- a/src/simulation/SimulationData.h +++ b/src/simulation/SimulationData.h @@ -158,6 +158,7 @@ public: String ElementResolve(int type, int ctype) const; String BasicParticleInfo(Particle const &sample_part) const; int GetParticleType(ByteString type) const; + bool IsHeatInsulator(const Particle &p) const; bool IsElement(int type) const { diff --git a/src/simulation/elements/C5.cpp b/src/simulation/elements/C5.cpp index 3e5f60356..5b8ff0573 100644 --- a/src/simulation/elements/C5.cpp +++ b/src/simulation/elements/C5.cpp @@ -49,6 +49,7 @@ void Element::Element_C5() static int update(UPDATE_FUNC_ARGS) { + auto &sd = SimulationData::CRef(); for (auto rx = -2; rx <= 2; rx++) { for (auto ry = -2; ry <= 2; ry++) @@ -58,7 +59,7 @@ static int update(UPDATE_FUNC_ARGS) auto r = pmap[y+ry][x+rx]; if (!r) continue; - if ((TYP(r)!=PT_C5 && parts[ID(r)].temp<100 && !sim->IsHeatInsulator(parts[ID(r)])) || TYP(r)==PT_CFLM) + if ((TYP(r)!=PT_C5 && parts[ID(r)].temp<100 && !sd.IsHeatInsulator(parts[ID(r)])) || TYP(r)==PT_CFLM) { if (sim->rng.chance(1, 6)) { diff --git a/src/simulation/elements/DEST.cpp b/src/simulation/elements/DEST.cpp index 7e92ae26f..01649c829 100644 --- a/src/simulation/elements/DEST.cpp +++ b/src/simulation/elements/DEST.cpp @@ -87,7 +87,7 @@ static int update(UPDATE_FUNC_ARGS) if (parts[i].life<=0) parts[i].life=1; } - else if (!sim->IsHeatInsulator(parts[ID(r)])) + else if (!sd.IsHeatInsulator(parts[ID(r)])) parts[ID(r)].temp = MAX_TEMP; parts[i].temp=MAX_TEMP; sim->pv[y/CELL][x/CELL]+=80.0f; diff --git a/src/simulation/elements/HEAC.cpp b/src/simulation/elements/HEAC.cpp index ebcfe394f..8b6bed1ec 100644 --- a/src/simulation/elements/HEAC.cpp +++ b/src/simulation/elements/HEAC.cpp @@ -47,10 +47,6 @@ void Element::Element_HEAC() Update = &update; } -static const auto isInsulator = [](Simulation* sim, int p) -> bool { - return p && sim->IsHeatInsulator(sim->parts[ID(p)]); -}; - // If this is used elsewhere (GOLD), it should be moved into Simulation.h template bool CheckLine(Simulation* sim, int x1, int y1, int x2, int y2, BinaryPredicate func) @@ -118,6 +114,7 @@ bool CheckLine(Simulation* sim, int x1, int y1, int x2, int y2, BinaryPredicate static int update(UPDATE_FUNC_ARGS) { + auto &sd = SimulationData::CRef(); const int rad = 4; int rry, rrx, r, count = 0; float tempAgg = 0; @@ -127,16 +124,18 @@ static int update(UPDATE_FUNC_ARGS) { rry = ry * rad; rrx = rx * rad; - if (x+rrx >= 0 && x+rrx < XRES && y+rry >= 0 && y+rry < YRES && !CheckLine(sim, x, y, x+rrx, y+rry, isInsulator)) + if (x+rrx >= 0 && x+rrx < XRES && y+rry >= 0 && y+rry < YRES && !CheckLine(sim, x, y, x+rrx, y+rry, [&sd](Simulation* sim, int p) { + return p && sd.IsHeatInsulator(sim->parts[ID(p)]); + })) { r = pmap[y+rry][x+rrx]; - if (r && !sim->IsHeatInsulator(parts[ID(r)])) + if (r && !sd.IsHeatInsulator(parts[ID(r)])) { count++; tempAgg += parts[ID(r)].temp; } r = sim->photons[y+rry][x+rrx]; - if (r && !sim->IsHeatInsulator(parts[ID(r)])) + if (r && !sd.IsHeatInsulator(parts[ID(r)])) { count++; tempAgg += parts[ID(r)].temp; @@ -155,15 +154,17 @@ static int update(UPDATE_FUNC_ARGS) { rry = ry * rad; rrx = rx * rad; - if (x+rrx >= 0 && x+rrx < XRES && y+rry >= 0 && y+rry < YRES && !CheckLine(sim, x, y, x+rrx, y+rry, isInsulator)) + if (x+rrx >= 0 && x+rrx < XRES && y+rry >= 0 && y+rry < YRES && !CheckLine(sim, x, y, x+rrx, y+rry, [&sd](Simulation* sim, int p) { + return p && sd.IsHeatInsulator(sim->parts[ID(p)]); + })) { r = pmap[y+rry][x+rrx]; - if (r && !sim->IsHeatInsulator(parts[ID(r)])) + if (r && !sd.IsHeatInsulator(parts[ID(r)])) { parts[ID(r)].temp = parts[i].temp; } r = sim->photons[y+rry][x+rrx]; - if (r && !sim->IsHeatInsulator(parts[ID(r)])) + if (r && !sd.IsHeatInsulator(parts[ID(r)])) { parts[ID(r)].temp = parts[i].temp; } diff --git a/src/simulation/elements/LIGH.cpp b/src/simulation/elements/LIGH.cpp index ede0c1452..20e4a4b12 100644 --- a/src/simulation/elements/LIGH.cpp +++ b/src/simulation/elements/LIGH.cpp @@ -154,7 +154,7 @@ static int update(UPDATE_FUNC_ARGS) if ((elements[TYP(r)].Properties&PROP_CONDUCTS) && parts[ID(r)].life==0) sim->create_part(ID(r),x+rx,y+ry,PT_SPRK); sim->pv[y/CELL][x/CELL] += powderful/400; - if (!sim->IsHeatInsulator(parts[ID(r)])) parts[ID(r)].temp = restrict_flt(parts[ID(r)].temp+powderful/1.3, MIN_TEMP, MAX_TEMP); + if (!sd.IsHeatInsulator(parts[ID(r)])) parts[ID(r)].temp = restrict_flt(parts[ID(r)].temp+powderful/1.3, MIN_TEMP, MAX_TEMP); } } } diff --git a/src/simulation/elements/STKM.cpp b/src/simulation/elements/STKM.cpp index f4863d522..0e11e787b 100644 --- a/src/simulation/elements/STKM.cpp +++ b/src/simulation/elements/STKM.cpp @@ -639,7 +639,7 @@ void Element_STKM_interact(Simulation *sim, playerst *playerp, int i, int x, int damage += sim->rng.between(32, 51); } - if (!sim->IsHeatInsulator(sim->parts[ID(r)]) && ((playerp->elem!=PT_LIGH && sim->parts[ID(r)].temp>=323) || sim->parts[ID(r)].temp<=243) && (!playerp->rocketBoots || TYP(r)!=PT_PLSM)) + if (!sd.IsHeatInsulator(sim->parts[ID(r)]) && ((playerp->elem!=PT_LIGH && sim->parts[ID(r)].temp>=323) || sim->parts[ID(r)].temp<=243) && (!playerp->rocketBoots || TYP(r)!=PT_PLSM)) { damage += 2; playerp->accs[3] -= 1; diff --git a/src/simulation/elements/VIBR.cpp b/src/simulation/elements/VIBR.cpp index ab1d8494f..9bbbf8295 100644 --- a/src/simulation/elements/VIBR.cpp +++ b/src/simulation/elements/VIBR.cpp @@ -105,7 +105,7 @@ int Element_VIBR_update(UPDATE_FUNC_ARGS) auto rx = rndstore%7-3; auto ry = (rndstore>>3)%7-3; auto r = pmap[y+ry][x+rx]; - if (TYP(r) && TYP(r) != PT_VIBR && TYP(r) != PT_BVBR && (!sim->IsHeatInsulator(parts[ID(r)]))) + if (TYP(r) && TYP(r) != PT_VIBR && TYP(r) != PT_BVBR && (!sd.IsHeatInsulator(parts[ID(r)]))) { parts[ID(r)].temp = restrict_flt(parts[ID(r)].temp + parts[i].tmp * 3, MIN_TEMP, MAX_TEMP); parts[i].tmp = 0;