Permalink
Browse files

Make RFGL and RFRG a bit more realistic (#366)

* Make RFGL and RFRG a bit more realistic.

This means that they both more or less follow Gay-Lussac's law: T2 = T1 * P2 / P1. Simple heat transer mechanism, no playing around with .life, shared update function.

* Ditch weird pressure scale

* No /0 pls
  • Loading branch information...
LBPHacker authored and jacob1 committed Apr 23, 2017
1 parent 40972f9 commit 0fe596f741fb5184f61926eea9800973f2b434dc
Showing with 16 additions and 62 deletions.
  1. +4 −49 src/simulation/elements/RFGL.cpp
  2. +12 −13 src/simulation/elements/RFRG.cpp
@@ -27,66 +27,21 @@ Element_RFGL::Element_RFGL()
Weight = 10;
Temperature = R_TEMP + 273.15f;
HeatConduct = 0;
HeatConduct = 3;
Description = "Liquid refrigerant.";
Properties = TYPE_LIQUID|PROP_DEADLY;
LowPressure = IPL;
LowPressureTransition = NT;
LowPressure = 2;
LowPressureTransition = PT_RFRG;
HighPressure = IPH;
HighPressureTransition = NT;
LowTemperature = ITL;
LowTemperatureTransition = NT;
HighTemperature = ITH;
HighTemperatureTransition = NT;
Update = &Element_RFGL::update;
}
//#TPT-Directive ElementHeader Element_RFGL static int update(UPDATE_FUNC_ARGS)
int Element_RFGL::update(UPDATE_FUNC_ARGS)
{
float pressure = sim->pv[y/CELL][x/CELL];
if (pressure > parts[i].tmp)
parts[i].tmp = (int)pressure;
if (pressure > -1 && pressure < 15 && parts[i].life > 0)
parts[i].life --;
if (parts[i].temp >= 363.15f + (pressure * 6.0f))
sim->part_change_type(i, x, y, PT_RFRG);
int r, rx, ry;
for (rx=-1; rx<2; rx++)
for (ry=-1; ry<2; ry++)
if (BOUNDS_CHECK && (rx || ry))
{
r = pmap[y+ry][x+rx];
if (!r)
continue;
if ((r&0xFF) == PT_RFGL || (r&0xFF) == PT_RFRG)
{
float avgTemp = (parts[r>>8].temp + parts[i].temp) / 2;
parts[r>>8].temp = avgTemp;
parts[i].temp = avgTemp;
}
else
{
if (pressure > 20 && parts[i].temp > 273.15f + 2.0f - (pressure - 20.0f) && sim->elements[r&0xFF].HeatConduct)
{
parts[r>>8].temp = restrict_flt(parts[r>>8].temp + 80.0f, 0.0f, MAX_TEMP);
parts[i].temp = restrict_flt(parts[i].temp - 80.0f, 0.0f, MAX_TEMP);
}
else if (parts[i].life == 0 && parts[r>>8].temp > 273.15f - 50.0f - (parts[i].tmp - 20.0f) && sim->elements[r&0xFF].HeatConduct)
{
parts[r>>8].temp = restrict_flt(parts[r>>8].temp - 80.0f, 273.15f - 50.0f - (parts[i].tmp - 20.0f), MAX_TEMP);
parts[i].temp = restrict_flt(parts[i].temp + 80.0f, 0.0f, 383.15f);
}
}
}
return 0;
Update = &Element_RFRG::update;
}
Element_RFGL::~Element_RFGL() {}
@@ -28,14 +28,14 @@ Element_RFRG::Element_RFRG()
Temperature = R_TEMP + 273.15f;
HeatConduct = 3;
Description = "Refrigerant. Liquifies and transfers heat to other particles under pressure.";
Description = "Refrigerant. Heats up and liquifies under pressure.";
Properties = TYPE_GAS|PROP_DEADLY;
LowPressure = IPL;
LowPressureTransition = NT;
HighPressure = IPH;
HighPressureTransition = NT;
HighPressure = 2;
HighPressureTransition = PT_RFGL;
LowTemperature = ITL;
LowTemperatureTransition = NT;
HighTemperature = ITH;
@@ -47,16 +47,15 @@ Element_RFRG::Element_RFRG()
//#TPT-Directive ElementHeader Element_RFRG static int update(UPDATE_FUNC_ARGS)
int Element_RFRG::update(UPDATE_FUNC_ARGS)
{
if (sim->pv[y/CELL][x/CELL] > 15)
{
parts[i].temp += (sim->pv[y/CELL][x/CELL] - 15.0f) / 2.0f;
if (parts[i].temp >= 343.15f)
{
sim->part_change_type(i, x, y, PT_RFGL);
parts[i].life = 20;
}
}
float new_pressure = sim->pv[y/CELL][x/CELL];
float *old_pressure = (float *)&parts[i].tmp;
// * 0 bar seems to be pressure value -256 in TPT, see Air.cpp. Also, 1 bar seems to be pressure value 0.
// With those two values we can set up our pressure scale which states that ... the highest pressure
// we can achieve in TPT is 2 bar. That's not particularly realistic, but good enough for TPT.
parts[i].temp = restrict_flt(parts[i].temp * ((new_pressure + 257.f) / (*old_pressure + 257.f)), 0, MAX_TEMP);
*old_pressure = new_pressure;
return 0;
}

0 comments on commit 0fe596f

Please sign in to comment.