Skip to content

Commit ea95540

Browse files
committed
Merge remote-tracking branch 'Rebmiami/paper' into alkali
2 parents da4fe72 + 347416c commit ea95540

23 files changed

+505
-68
lines changed

src/lua/LuaSimulation.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -872,7 +872,7 @@ static int resetTemp(lua_State *L)
872872
bool onlyConductors = luaL_optint(L, 1, 0);
873873
for (int i = 0; i < sim->parts.lastActiveIndex; i++)
874874
{
875-
if (sim->parts[i].type && (elements[sim->parts[i].type].HeatConduct || !onlyConductors))
875+
if (sim->parts[i].type && (!onlyConductors || !sim->IsHeatInsulator(sim->parts[i])))
876876
{
877877
sim->parts[i].temp = elements[sim->parts[i].type].DefaultProperties.temp;
878878
}

src/simulation/Air.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,7 @@ void Air::ApproximateBlockAirMaps()
436436
}
437437
}
438438
// mostly accurate insulator blocking, besides checking GEL
439-
else if ((type == PT_HSWC && sim.parts[i].life != 10) || elements[type].HeatConduct <= (sim.rng()%250))
439+
else if (sim.IsHeatInsulator(sim.parts[i]) || elements[type].HeatConduct <= (sim.rng()%250))
440440
{
441441
int x = ((int)(sim.parts[i].x+0.5f))/CELL, y = ((int)(sim.parts[i].y+0.5f))/CELL;
442442
if (InBounds(x, y) && !(bmap_blockairh[y][x]&0x8))

src/simulation/Simulation.cpp

Lines changed: 49 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1143,6 +1143,14 @@ int Simulation::eval_move(int pt, int nx, int ny, unsigned *rr) const
11431143
return 0;
11441144
}
11451145
break;
1146+
case PT_PAPR:
1147+
// BCOL can always pass through PAPR in order to color it
1148+
// Most elements are blocked by marked PAPR, except for certified "weird" elements where it's inverse
1149+
if ((pt == PT_BCOL) || (!parts[ID(r)].life != !(pt != PT_H2 && pt != PT_ANAR && pt != PT_BIZR && pt != PT_BIZRG)))
1150+
result = 2;
1151+
else
1152+
result = 0;
1153+
break;
11461154
default:
11471155
// This should never happen
11481156
// If it were to happen, try_move would interpret a 3 as a 1
@@ -1191,8 +1199,8 @@ int Simulation::try_move(int i, int x, int y, int nx, int ny)
11911199
{
11921200
if (rt == PT_COAL || rt == PT_BCOL)
11931201
parts[ID(r)].temp = parts[i].temp;
1194-
1195-
if (rt < PT_NUM && elements[rt].HeatConduct && (rt!=PT_HSWC||parts[ID(r)].life==10) && rt!=PT_FILT)
1202+
1203+
if (rt < PT_NUM && !IsHeatInsulator(parts[ID(r)]) && rt != PT_FILT && rt != PT_PAPR)
11961204
parts[i].temp = parts[ID(r)].temp = restrict_flt((parts[ID(r)].temp+parts[i].temp)/2, MIN_TEMP, MAX_TEMP);
11971205
}
11981206
else if ((parts[i].type==PT_NEUT || parts[i].type==PT_ELEC) && (rt==PT_CLNE || rt==PT_PCLN || rt==PT_BCLN || rt==PT_PBCN))
@@ -2198,6 +2206,11 @@ Simulation::PlanMoveResult Simulation::PlanMove(Sim &sim, int i, int x, int y)
21982206
template
21992207
Simulation::PlanMoveResult Simulation::PlanMove<false, const Simulation>(const Simulation &sim, int i, int x, int y);
22002208

2209+
bool Simulation::IsHeatInsulator(Particle p) const
2210+
{
2211+
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);
2212+
}
2213+
22012214
void Simulation::UpdateParticles(int start, int end)
22022215
{
22032216
//the main particle loop function, goes over all particles.
@@ -2355,7 +2368,7 @@ void Simulation::UpdateParticles(int start, int end)
23552368
//heat transfer code
23562369
auto h_count = 0;
23572370
bool cond;
2358-
cond = t && (t!=PT_HSWC||parts[i].life==10) && rng.chance(int(elements[t].HeatConduct*gel_scale), 250);
2371+
cond = t && !IsHeatInsulator(parts[i]) && rng.chance(int(elements[t].HeatConduct*gel_scale), 250);
23592372

23602373
if (cond)
23612374
{
@@ -2372,24 +2385,44 @@ void Simulation::UpdateParticles(int start, int end)
23722385
{
23732386
surround_hconduct[j] = i;
23742387
auto r = surround[j];
2388+
23752389
if (!r)
23762390
continue;
2391+
23772392
auto rt = TYP(r);
2378-
if (rt && elements[rt].HeatConduct && (rt!=PT_HSWC||parts[ID(r)].life==10)
2379-
&& (t!=PT_FILT||(rt!=PT_BRAY&&rt!=PT_BIZR&&rt!=PT_BIZRG))
2380-
&& (rt!=PT_FILT||(t!=PT_BRAY&&t!=PT_PHOT&&t!=PT_BIZR&&t!=PT_BIZRG))
2381-
&& (t!=PT_ELEC||rt!=PT_DEUT)
2382-
&& (t!=PT_DEUT||rt!=PT_ELEC)
2383-
&& (t!=PT_HSWC || rt!=PT_FILT || parts[i].tmp != 1)
2384-
&& (t!=PT_FILT || rt!=PT_HSWC || parts[ID(r)].tmp != 1))
2393+
2394+
if (!rt || IsHeatInsulator(parts[ID(r)])
2395+
|| (t == PT_FILT && (rt == PT_BRAY || rt == PT_BIZR || rt == PT_BIZRG))
2396+
|| (rt == PT_FILT && (t == PT_BRAY || t == PT_PHOT || t == PT_BIZR || t == PT_BIZRG))
2397+
|| (t == PT_ELEC && rt == PT_DEUT)
2398+
|| (t == PT_DEUT && rt == PT_ELEC)
2399+
|| (t == PT_HSWC && rt == PT_FILT && parts[i].tmp == 1)
2400+
|| (t == PT_FILT && rt == PT_HSWC && parts[ID(r)].tmp == 1)
2401+
|| (t == PT_PHOT && rt == PT_PAPR))
2402+
continue;
2403+
2404+
surround_hconduct[j] = ID(r);
2405+
c_heat += parts[ID(r)].temp;
2406+
2407+
if ((rt == PT_PIPE || rt == PT_PPIP) && parts[ID(r)].ctype != 0)
2408+
{
2409+
c_heat += parts[ID(r)].temp; // double count the particle to account for the heat capacity of both the PIPE/PPIP and its contents
2410+
}
2411+
2412+
h_count++;
2413+
2414+
if ((rt == PT_PIPE || rt == PT_PPIP) && parts[ID(r)].ctype != 0)
23852415
{
2386-
surround_hconduct[j] = ID(r);
2387-
c_heat += parts[ID(r)].temp;
2388-
h_count++;
2416+
h_count++; // double count the particle to account for the heat capacity of both the PIPE/PPIP and its contents
23892417
}
23902418
}
23912419
float pt = R_TEMP;
2392-
pt = (c_heat+parts[i].temp)/(h_count+1);
2420+
2421+
if ((t == PT_PIPE || t == PT_PPIP) && parts[i].ctype != 0)
2422+
pt = (c_heat+parts[i].temp*2.0f)/(h_count+2); // double count the particle to account for the heat capacity of both the PIPE/PPIP and its contents
2423+
else
2424+
pt = (c_heat+parts[i].temp)/(h_count+1);
2425+
23932426
pt = parts[i].temp = restrict_flt(pt, MIN_TEMP, MAX_TEMP);
23942427
for (auto j=0; j<8; j++)
23952428
{
@@ -3237,9 +3270,9 @@ void Simulation::RecalcFreeParticles(bool do_life_dec)
32373270
photons[y][x] = PMAP(i, t);
32383271
else
32393272
{
3240-
// Particles are sometimes allowed to go inside INVS and FILT
3273+
// Particles are sometimes allowed to go inside INVS, FILT, and PAPR
32413274
// To make particles collide correctly when inside these elements, these elements must not overwrite an existing pmap entry from particles inside them
3242-
if (!pmap[y][x] || (t!=PT_INVIS && t!= PT_FILT))
3275+
if (!pmap[y][x] || (t!=PT_INVIS && t!= PT_FILT && t != PT_PAPR))
32433276
pmap[y][x] = PMAP(i, t);
32443277
// (there are a few exceptions, including energy particles - currently no limit on stacking those)
32453278
if (t!=PT_THDR && t!=PT_EMBR && t!=PT_FIGH && t!=PT_PLSM)

src/simulation/Simulation.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ class Simulation : public RenderableSimulation
199199
int is_wire_off(int x, int y);
200200
void set_emap(int x, int y);
201201
int parts_avg(int ci, int ni, int t);
202+
bool IsHeatInsulator(Particle) const;
202203
void UpdateParticles(int start, int end); // Dispatches an update to the range [start, end).
203204
void SimulateGoL();
204205
void RecalcFreeParticles(bool do_life_dec);

src/simulation/SimulationData.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,10 @@ void SimulationData::init_can_move()
182182
//SAWD cannot be displaced by other powders
183183
if (elements[movingType].Properties & TYPE_PART)
184184
can_move[movingType][PT_SAWD] = 0;
185+
186+
// Let most non-solids pass through unmarked PAPR
187+
if (elements[movingType].Properties & (TYPE_GAS | TYPE_PART | TYPE_LIQUID) && (movingType != PT_FIRE && movingType != PT_SAWD))
188+
can_move[movingType][PT_PAPR] = 3;
185189
}
186190

187191
for (destinationType = 0; destinationType < PT_NUM; destinationType++)
@@ -211,6 +215,7 @@ void SimulationData::init_can_move()
211215
can_move[PT_ELEC][PT_EXOT] = 2;
212216
can_move[PT_ELEC][PT_GLOW] = 2;
213217
can_move[PT_PHOT][PT_LCRY] = 3; //varies according to LCRY life
218+
can_move[PT_PHOT][PT_PAPR] = 3; //varies according to PAPR life
214219
can_move[PT_PHOT][PT_GPMP] = 3;
215220

216221
can_move[PT_PHOT][PT_BIZR] = 2;
@@ -230,6 +235,9 @@ void SimulationData::init_can_move()
230235
can_move[PT_TRON][PT_SWCH] = 3;
231236
can_move[PT_ELEC][PT_RSST] = 2;
232237
can_move[PT_ELEC][PT_RSSS] = 2;
238+
239+
can_move[PT_MWAX][PT_SAWD] = 0;
240+
can_move[PT_SAWD][PT_MWAX] = 0;
233241
}
234242

235243
const CustomGOLData *SimulationData::GetCustomGOLByRule(int rule) const

src/simulation/elements/ACID.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,19 @@ static int update(UPDATE_FUNC_ARGS)
9898
sim->part_change_type(ID(r), x + rx, y + ry, PT_H2);
9999
break;
100100

101+
case PT_PAPR:
102+
if (sim->rng.chance(1, 2))
103+
{
104+
sim->create_part(ID(r), x + rx, y + ry, PT_COAL);
105+
parts[ID(r)].tmp = sim->rng.between(1, 39);
106+
}
107+
else
108+
{
109+
sim->create_part(ID(r), x + rx, y + ry, PT_WTRV);
110+
parts[ID(r)].temp = parts[i].temp;
111+
}
112+
break;
113+
101114
default:
102115
sim->kill_part(ID(r));
103116
break;

src/simulation/elements/ARAY.cpp

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,32 @@ static int update(UPDATE_FUNC_ARGS)
165165
{
166166
parts[r].life = 10;
167167
}
168+
}
169+
else if (rt == PT_PAPR)
170+
{
171+
// In reading/writing state?
172+
if (parts[r].tmp)
173+
{
174+
if (parts[r].tmp & 0x10) // Reading state
175+
{
176+
// End reading state early
177+
parts[r].tmp = 0;
178+
if (parts[r].life)
179+
{
180+
break;
181+
}
182+
}
183+
else // Writing state
184+
{
185+
parts[r].life = 1;
186+
parts[r].dcolour = 0xFF1A2222;
187+
}
188+
}
189+
else
190+
{
191+
// Enter writing state
192+
parts[r].tmp = 0x03;
193+
}
168194
// this if prevents BRAY from stopping on certain materials
169195
}
170196
else if (rt != PT_INWR && (rt != PT_SPRK || parts[r].ctype != PT_INWR) && rt != PT_ARAY && rt != PT_WIFI && !(rt == PT_SWCH && parts[r].life >= 10))
@@ -189,7 +215,7 @@ static int update(UPDATE_FUNC_ARGS)
189215
parts[r].dcolour = 0xFF000000;
190216
//this if prevents red BRAY from stopping on certain materials
191217
}
192-
else if (rt==PT_STOR || rt==PT_INWR || (rt==PT_SPRK && parts[r].ctype==PT_INWR) || rt==PT_ARAY || rt==PT_WIFI || rt==PT_FILT || (rt==PT_SWCH && parts[r].life>=10))
218+
else if (rt==PT_STOR || rt==PT_INWR || (rt==PT_SPRK && parts[r].ctype==PT_INWR) || rt==PT_ARAY || rt==PT_WIFI || rt==PT_FILT || (rt==PT_SWCH && parts[r].life>=10) || rt==PT_PAPR)
193219
{
194220
if (rt == PT_STOR)
195221
{
@@ -201,6 +227,32 @@ static int update(UPDATE_FUNC_ARGS)
201227
isBlackDeco = (parts[r].dcolour==0xFF000000);
202228
parts[r].life = 2;
203229
}
230+
else if (rt == PT_PAPR)
231+
{
232+
// In reading/writing state?
233+
if (parts[r].tmp)
234+
{
235+
if (parts[r].tmp & 0x10) // Reading state
236+
{
237+
// End reading state early
238+
parts[r].tmp = 0;
239+
if (parts[r].life)
240+
{
241+
break;
242+
}
243+
}
244+
else // Writing state
245+
{
246+
parts[r].life = 0;
247+
parts[r].dcolour = 0;
248+
}
249+
}
250+
else
251+
{
252+
// Enter reading state
253+
parts[r].tmp = 0x13;
254+
}
255+
}
204256
docontinue = 1;
205257
}
206258
else

src/simulation/elements/C5.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,6 @@ void Element::Element_C5()
4949

5050
static int update(UPDATE_FUNC_ARGS)
5151
{
52-
auto &sd = SimulationData::CRef();
53-
auto &elements = sd.elements;
5452
for (auto rx = -2; rx <= 2; rx++)
5553
{
5654
for (auto ry = -2; ry <= 2; ry++)
@@ -60,7 +58,7 @@ static int update(UPDATE_FUNC_ARGS)
6058
auto r = pmap[y+ry][x+rx];
6159
if (!r)
6260
continue;
63-
if ((TYP(r)!=PT_C5 && parts[ID(r)].temp<100 && elements[TYP(r)].HeatConduct && (TYP(r)!=PT_HSWC||parts[ID(r)].life==10)) || TYP(r)==PT_CFLM)
61+
if ((TYP(r)!=PT_C5 && parts[ID(r)].temp<100 && !sim->IsHeatInsulator(parts[ID(r)])) || TYP(r)==PT_CFLM)
6462
{
6563
if (sim->rng.chance(1, 6))
6664
{

src/simulation/elements/DEST.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ static int update(UPDATE_FUNC_ARGS)
8787
if (parts[i].life<=0)
8888
parts[i].life=1;
8989
}
90-
else if (elements[rt].HeatConduct)
90+
else if (!sim->IsHeatInsulator(parts[ID(r)]))
9191
parts[ID(r)].temp = MAX_TEMP;
9292
parts[i].temp=MAX_TEMP;
9393
sim->pv[y/CELL][x/CELL]+=80.0f;

src/simulation/elements/ELEC.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,14 @@ static int update(UPDATE_FUNC_ARGS)
126126
return 1;
127127
}
128128
break;
129+
case PT_PAPR:
130+
if (sim->rng.chance(1, 20))
131+
{
132+
int dcolour = parts[ID(r)].dcolour;
133+
sim->create_part(ID(r), x+rx, y+ry, PT_LCRY);
134+
parts[ID(r)].dcolour = dcolour;
135+
}
136+
break;
129137
case PT_NONE: //seems to speed up ELEC even if it isn't used
130138
break;
131139
default:

0 commit comments

Comments
 (0)