LSNS: formatting changes, change if statements to switch

This commit is contained in:
jacob1 2019-08-10 17:22:46 -04:00
parent 25b7021f2a
commit 0ec50951f7

View File

@ -47,19 +47,19 @@ Element_LSNS::Element_LSNS()
//#TPT-Directive ElementHeader Element_LSNS static int update(UPDATE_FUNC_ARGS)
int Element_LSNS::update(UPDATE_FUNC_ARGS)
{
int r, rx, ry, rt, rd = parts[i].tmp2;
int rd = parts[i].tmp2;
if (rd > 25) parts[i].tmp2 = rd = 25;
if (parts[i].life)
{
parts[i].life = 0;
for (rx = -2; rx < 3; rx++)
for (ry = -2; ry < 3; ry++)
for (int rx = -2; rx <= 2; rx++)
for (int ry = -2; ry <= 2; ry++)
if (BOUNDS_CHECK && (rx || ry))
{
r = pmap[y + ry][x + rx];
int r = pmap[y + ry][x + rx];
if (!r)
continue;
rt = TYP(r);
int rt = TYP(r);
if (sim->parts_avg(i, ID(r), PT_INSL) != PT_INSL)
{
if ((sim->elements[rt].Properties&PROP_CONDUCTS) && !(rt == PT_WATR || rt == PT_SLTW || rt == PT_NTCT || rt == PT_PTCT || rt == PT_INWR) && parts[ID(r)].life == 0)
@ -72,48 +72,50 @@ int Element_LSNS::update(UPDATE_FUNC_ARGS)
}
}
bool setFilt = false;
bool Setnewlife = false;
int partlife = 0;
int Newlife = 0;
for (rx = -rd; rx < rd + 1; rx++)
for (ry = -rd; ry < rd + 1; ry++)
bool doSerialization = false;
bool doDeserialization = false;
int life = 0;
for (int rx = -rd; rx < rd + 1; rx++)
for (int ry = -rd; ry < rd + 1; ry++)
if (x + rx >= 0 && y + ry >= 0 && x + rx < XRES && y + ry < YRES && (rx || ry))
{
r = pmap[y + ry][x + rx];
int r = pmap[y + ry][x + rx];
if (!r)
r = sim->photons[y + ry][x + rx];
if (!r)
continue;
if (parts[i].tmp == 1 && TYP(r) != PT_LSNS && TYP(r) != PT_FILT && parts[ID(r)].life >= 0)
switch (parts[i].tmp)
{
setFilt = true;
partlife = parts[ID(r)].life;
}
if (parts[i].tmp == 3 && TYP(r) == PT_FILT)
{
Setnewlife = true;
Newlife = parts[ID(r)].ctype;
}
if ((parts[i].tmp != 1) && (parts[i].tmp != 2) && (parts[i].tmp != 3))
{
if (parts[ID(r)].life > parts[i].temp - 273.15)
case 1:
// .life serialization into FILT
if (TYP(r) != PT_LSNS && TYP(r) != PT_FILT && parts[ID(r)].life >= 0)
{
parts[i].life = 1;
doSerialization = true;
life = parts[ID(r)].life;
}
}
//Invert mode.
if (parts[i].tmp == 2)
{
if (parts[ID(r)].life > parts[i].temp - 273.15)
parts[i].life = 0;
else
break;
case 3:
// .life deserialization
if (TYP(r) == PT_FILT)
{
doDeserialization = true;
life = parts[ID(r)].ctype;
}
break;
case 2:
// Invert mode
if (TYP(r) != PT_METL && parts[ID(r)].life <= parts[i].temp - 273.15)
parts[i].life = 1;
break;
default:
// Normal mode
if (TYP(r) != PT_METL && parts[ID(r)].life > parts[i].temp - 273.15)
parts[i].life = 1;
break;
}
}
int nx, ny;
for (int rx = -1; rx <= 1; rx++)
for (int ry = -1; ry <= 1; ry++)
if (BOUNDS_CHECK && (rx || ry))
@ -121,14 +123,14 @@ int Element_LSNS::update(UPDATE_FUNC_ARGS)
int r = pmap[y + ry][x + rx];
if (!r)
continue;
nx = x + rx;
ny = y + ry;
//.life serialization.
if (setFilt)
int nx = x + rx;
int ny = y + ry;
// .life serialization.
if (doSerialization)
{
while (TYP(r) == PT_FILT)
{
parts[ID(r)].ctype = 0x10000000 + partlife;
parts[ID(r)].ctype = 0x10000000 + life;
nx += rx;
ny += ry;
if (nx < 0 || ny < 0 || nx >= XRES || ny >= YRES)
@ -136,20 +138,18 @@ int Element_LSNS::update(UPDATE_FUNC_ARGS)
r = pmap[ny][nx];
}
}
//.life deserialization.
if (Setnewlife)
// .life deserialization.
if (doDeserialization)
{
if (TYP(r) != PT_FILT)
{
parts[ID(r)].life = Newlife - 0x10000000;
parts[ID(r)].life = life - 0x10000000;
break;
}
}
}
return 0;
}
Element_LSNS::~Element_LSNS() {}
Element_LSNS::~Element_LSNS() {}