mirror of
https://github.com/The-Powder-Toy/The-Powder-Toy.git
synced 2025-08-17 05:44:00 +02:00
Move IsHeatInsulator where it belongs
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
@@ -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))
|
||||
|
@@ -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<false, const Simulation>(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)
|
||||
|
@@ -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);
|
||||
|
@@ -8,6 +8,7 @@
|
||||
#include "MenuSection.h"
|
||||
#include "Misc.h"
|
||||
#include "graphics/Renderer.h"
|
||||
#include "simulation/elements/PIPE.h"
|
||||
|
||||
const std::array<BuiltinGOL, NGOL> 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);
|
||||
}
|
||||
|
@@ -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
|
||||
{
|
||||
|
@@ -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))
|
||||
{
|
||||
|
@@ -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;
|
||||
|
@@ -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<class BinaryPredicate>
|
||||
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;
|
||||
}
|
||||
|
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -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;
|
||||
|
@@ -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;
|
||||
|
Reference in New Issue
Block a user