Remove leftover cooldown-related code from ARAY and DRAY

This commit is contained in:
Tamás Bálint Misius 2020-07-26 19:05:05 +02:00
parent 41254a2f95
commit 94353a9a3b
No known key found for this signature in database
GPG Key ID: 5B472A12F6ECA9F2
2 changed files with 220 additions and 217 deletions

View File

@ -31,7 +31,7 @@ void Element::Element_ARAY()
HeatConduct = 0;
Description = "Ray Emitter. Rays create points when they collide.";
Properties = TYPE_SOLID|PROP_LIFE_DEC;
Properties = TYPE_SOLID;
LowPressure = IPL;
LowPressureTransition = NT;
@ -47,164 +47,165 @@ void Element::Element_ARAY()
static int update(UPDATE_FUNC_ARGS)
{
if (!parts[i].life)
for (int rx = -1; rx <= 1; rx++)
{
for (int rx = -1; rx <= 1; rx++)
for (int ry = -1; ry <= 1; ry++)
if (BOUNDS_CHECK && (rx || ry))
for (int ry = -1; ry <= 1; ry++)
{
if (BOUNDS_CHECK && (rx || ry))
{
int r = pmap[y+ry][x+rx];
if (!r)
continue;
if (TYP(r) == PT_SPRK && parts[ID(r)].life == 3)
{
int r = pmap[y+ry][x+rx];
if (!r)
continue;
if (TYP(r) == PT_SPRK && parts[ID(r)].life == 3)
bool isBlackDeco = false;
int destroy = (parts[ID(r)].ctype==PT_PSCN) ? 1 : 0;
int nostop = (parts[ID(r)].ctype==PT_INST) ? 1 : 0;
int colored = 0, rt;
for (int docontinue = 1, nxx = 0, nyy = 0, nxi = rx*-1, nyi = ry*-1; docontinue; nyy+=nyi, nxx+=nxi)
{
bool isBlackDeco = false;
int destroy = (parts[ID(r)].ctype==PT_PSCN) ? 1 : 0;
int nostop = (parts[ID(r)].ctype==PT_INST) ? 1 : 0;
int colored = 0, rt;
for (int docontinue = 1, nxx = 0, nyy = 0, nxi = rx*-1, nyi = ry*-1; docontinue; nyy+=nyi, nxx+=nxi)
{
if (!(x+nxi+nxx<XRES && y+nyi+nyy<YRES && x+nxi+nxx >= 0 && y+nyi+nyy >= 0))
break;
if (!(x+nxi+nxx<XRES && y+nyi+nyy<YRES && x+nxi+nxx >= 0 && y+nyi+nyy >= 0))
break;
r = pmap[y+nyi+nyy][x+nxi+nxx];
rt = TYP(r);
r = ID(r);
if (!rt)
r = pmap[y+nyi+nyy][x+nxi+nxx];
rt = TYP(r);
r = ID(r);
if (!rt)
{
int nr = sim->create_part(-1, x+nxi+nxx, y+nyi+nyy, PT_BRAY);
if (nr != -1)
{
int nr = sim->create_part(-1, x+nxi+nxx, y+nyi+nyy, PT_BRAY);
if (nr != -1)
// if it came from PSCN
if (destroy)
{
// if it came from PSCN
if (destroy)
{
parts[nr].tmp = 2;
parts[nr].life = 2;
}
else
parts[nr].ctype = colored;
parts[nr].temp = parts[i].temp;
if (isBlackDeco)
parts[nr].dcolour = 0xFF000000;
parts[nr].tmp = 2;
parts[nr].life = 2;
}
else
parts[nr].ctype = colored;
parts[nr].temp = parts[i].temp;
if (isBlackDeco)
parts[nr].dcolour = 0xFF000000;
}
else if (!destroy)
}
else if (!destroy)
{
if (rt == PT_BRAY)
{
if (rt == PT_BRAY)
// cases for hitting different BRAY modes
switch(parts[r].tmp)
{
// cases for hitting different BRAY modes
switch(parts[r].tmp)
// normal white
case 0:
if (nyy != 0 || nxx !=0)
{
// normal white
case 0:
if (nyy != 0 || nxx !=0)
{
parts[r].life = 1020; // makes it last a while
parts[r].tmp = 1;
if (!parts[r].ctype) // and colors it if it isn't already
parts[r].ctype = colored;
}
// red bray or any other random tmp mode, stop
case 2:
default:
docontinue = 0;
break;
// long life, reset it
case 1:
parts[r].life = 1020;
//docontinue = 1;
break;
parts[r].life = 1020; // makes it last a while
parts[r].tmp = 1;
if (!parts[r].ctype) // and colors it if it isn't already
parts[r].ctype = colored;
}
if (isBlackDeco)
parts[r].dcolour = 0xFF000000;
// red bray or any other random tmp mode, stop
case 2:
default:
docontinue = 0;
break;
// long life, reset it
case 1:
parts[r].life = 1020;
//docontinue = 1;
break;
}
// get color if passed through FILT
else if (rt == PT_FILT)
if (isBlackDeco)
parts[r].dcolour = 0xFF000000;
}
// get color if passed through FILT
else if (rt == PT_FILT)
{
if (parts[r].tmp != 6)
{
if (parts[r].tmp != 6)
{
int Element_FILT_interactWavelengths(Particle* cpart, int origWl);
colored = Element_FILT_interactWavelengths(&parts[r], colored);
if (!colored)
break;
}
isBlackDeco = (parts[r].dcolour==0xFF000000);
parts[r].life = 4;
int Element_FILT_interactWavelengths(Particle* cpart, int origWl);
colored = Element_FILT_interactWavelengths(&parts[r], colored);
if (!colored)
break;
}
else if (rt == PT_STOR)
isBlackDeco = (parts[r].dcolour==0xFF000000);
parts[r].life = 4;
}
else if (rt == PT_STOR)
{
if (parts[r].tmp)
{
if (parts[r].tmp)
//Cause STOR to release
for (int ry1 = 1; ry1 >= -1; ry1--)
{
//Cause STOR to release
for (int ry1 = 1; ry1 >= -1; ry1--)
for (int rx1 = 0; rx1 >= -1 && rx1 <= 1; rx1 = -rx1 - rx1 + 1)
{
for (int rx1 = 0; rx1 >= -1 && rx1 <= 1; rx1 = -rx1 - rx1 + 1)
int np = sim->create_part(-1, x + nxi + nxx + rx1, y + nyi + nyy + ry1, TYP(parts[r].tmp));
if (np != -1)
{
int np = sim->create_part(-1, x + nxi + nxx + rx1, y + nyi + nyy + ry1, TYP(parts[r].tmp));
if (np != -1)
{
parts[np].temp = parts[r].temp;
parts[np].life = parts[r].tmp2;
parts[np].tmp = parts[r].pavg[0];
parts[np].ctype = parts[r].pavg[1];
parts[r].tmp = 0;
parts[r].life = 10;
break;
}
parts[np].temp = parts[r].temp;
parts[np].life = parts[r].tmp2;
parts[np].tmp = parts[r].pavg[0];
parts[np].ctype = parts[r].pavg[1];
parts[r].tmp = 0;
parts[r].life = 10;
break;
}
}
}
else
{
parts[r].life = 10;
}
// this if prevents BRAY from stopping on certain materials
}
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))
{
if (nyy!=0 || nxx!=0)
sim->create_part(-1, x+nxi+nxx, y+nyi+nyy, PT_SPRK);
if (!(nostop && parts[r].type==PT_SPRK && parts[r].ctype >= 0 && parts[r].ctype < PT_NUM && (sim->elements[parts[r].ctype].Properties&PROP_CONDUCTS)))
docontinue = 0;
else
docontinue = 1;
}
}
else if (destroy)
{
if (rt == PT_BRAY)
{
parts[r].tmp = 2;
parts[r].life = 1;
docontinue = 1;
if (isBlackDeco)
parts[r].dcolour = 0xFF000000;
//this if prevents red BRAY from stopping on certain materials
}
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))
{
if (rt == PT_STOR)
{
parts[r].tmp = 0;
parts[r].life = 0;
}
else if (rt == PT_FILT)
{
isBlackDeco = (parts[r].dcolour==0xFF000000);
parts[r].life = 2;
}
docontinue = 1;
}
else
{
docontinue = 0;
parts[r].life = 10;
}
// this if prevents BRAY from stopping on certain materials
}
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))
{
if (nyy!=0 || nxx!=0)
sim->create_part(-1, x+nxi+nxx, y+nyi+nyy, PT_SPRK);
if (!(nostop && parts[r].type==PT_SPRK && parts[r].ctype >= 0 && parts[r].ctype < PT_NUM && (sim->elements[parts[r].ctype].Properties&PROP_CONDUCTS)))
docontinue = 0;
else
docontinue = 1;
}
}
else if (destroy)
{
if (rt == PT_BRAY)
{
parts[r].tmp = 2;
parts[r].life = 1;
docontinue = 1;
if (isBlackDeco)
parts[r].dcolour = 0xFF000000;
//this if prevents red BRAY from stopping on certain materials
}
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))
{
if (rt == PT_STOR)
{
parts[r].tmp = 0;
parts[r].life = 0;
}
else if (rt == PT_FILT)
{
isBlackDeco = (parts[r].dcolour==0xFF000000);
parts[r].life = 2;
}
docontinue = 1;
}
else
{
docontinue = 0;
}
}
}
//parts[i].life = 4;
}
//parts[i].life = 4;
}
}
}
return 0;
}

View File

@ -31,7 +31,7 @@ void Element::Element_DRAY()
HeatConduct = 0;
Description = "Duplicator ray. Replicates a line of particles in front of it.";
Properties = TYPE_SOLID | PROP_LIFE_DEC;
Properties = TYPE_SOLID;
LowPressure = IPL;
LowPressureTransition = NT;
@ -62,111 +62,113 @@ static int update(UPDATE_FUNC_ARGS)
copyLength = parts[i].tmp = 0;
else if (copyLength > 0)
copySpaces++; //strange hack
if (!parts[i].life) // only fire when life is 0, but nothing sets the life right now
for (int rx = -1; rx <= 1; rx++)
{
for (int rx = -1; rx <= 1; rx++)
for (int ry = -1; ry <= 1; ry++)
if (BOUNDS_CHECK && (rx || ry))
for (int ry = -1; ry <= 1; ry++)
{
if (BOUNDS_CHECK && (rx || ry))
{
int r = pmap[y+ry][x+rx];
if (TYP(r) == PT_SPRK && parts[ID(r)].life == 3) //spark found, start creating
{
int r = pmap[y+ry][x+rx];
if (TYP(r) == PT_SPRK && parts[ID(r)].life == 3) //spark found, start creating
bool overwrite = parts[ID(r)].ctype == PT_PSCN;
int partsRemaining = copyLength, xCopyTo = -1, yCopyTo = -1; //positions where the line will start being copied at
int localCopyLength = copyLength;
if (parts[ID(r)].ctype == PT_INWR && rx && ry) // INWR doesn't spark from diagonals
continue;
//figure out where the copying will start/end
bool foundParticle = false;
bool isEnergy = false;
for (int xStep = rx*-1, yStep = ry*-1, xCurrent = x+xStep, yCurrent = y+yStep; ; xCurrent+=xStep, yCurrent+=yStep)
{
bool overwrite = parts[ID(r)].ctype == PT_PSCN;
int partsRemaining = copyLength, xCopyTo = -1, yCopyTo = -1; //positions where the line will start being copied at
int localCopyLength = copyLength;
if (parts[ID(r)].ctype == PT_INWR && rx && ry) // INWR doesn't spark from diagonals
continue;
//figure out where the copying will start/end
bool foundParticle = false;
bool isEnergy = false;
for (int xStep = rx*-1, yStep = ry*-1, xCurrent = x+xStep, yCurrent = y+yStep; ; xCurrent+=xStep, yCurrent+=yStep)
// Out of bounds, stop looking and don't copy anything
if (!sim->InBounds(xCurrent, yCurrent))
break;
int rr;
// haven't found a particle yet, keep looking for one
// the first particle it sees decides whether it will copy energy particles or not
if (!foundParticle)
{
// Out of bounds, stop looking and don't copy anything
if (!sim->InBounds(xCurrent, yCurrent))
break;
int rr;
// haven't found a particle yet, keep looking for one
// the first particle it sees decides whether it will copy energy particles or not
if (!foundParticle)
rr = pmap[yCurrent][xCurrent];
if (!rr)
{
rr = pmap[yCurrent][xCurrent];
if (!rr)
{
rr = sim->photons[yCurrent][xCurrent];
if (rr)
foundParticle = isEnergy = true;
}
else
foundParticle = true;
}
// now that it knows what kind of particle it is copying, do some extra stuff here so we can determine when to stop
if ((ctype && sim->elements[ctype].Properties&TYPE_ENERGY) || isEnergy)
rr = sim->photons[yCurrent][xCurrent];
if (rr)
foundParticle = isEnergy = true;
}
else
rr = pmap[yCurrent][xCurrent];
foundParticle = true;
}
// now that it knows what kind of particle it is copying, do some extra stuff here so we can determine when to stop
if ((ctype && sim->elements[ctype].Properties&TYPE_ENERGY) || isEnergy)
rr = sim->photons[yCurrent][xCurrent];
else
rr = pmap[yCurrent][xCurrent];
// Checks for when to stop:
// 1: if .tmp isn't set, and the element in this spot is the ctype, then stop
// 2: if .tmp is set, stop when the length limit reaches 0
if ((!localCopyLength && TYP(rr) == ctype && (ctype != PT_LIFE || parts[ID(rr)].ctype == ctypeExtra))
|| !--partsRemaining)
// Checks for when to stop:
// 1: if .tmp isn't set, and the element in this spot is the ctype, then stop
// 2: if .tmp is set, stop when the length limit reaches 0
if ((!localCopyLength && TYP(rr) == ctype && (ctype != PT_LIFE || parts[ID(rr)].ctype == ctypeExtra))
|| !--partsRemaining)
{
localCopyLength -= partsRemaining;
xCopyTo = xCurrent + xStep*copySpaces;
yCopyTo = yCurrent + yStep*copySpaces;
break;
}
}
// now, actually copy the particles
partsRemaining = localCopyLength + 1;
int type, p;
for (int xStep = rx*-1, yStep = ry*-1, xCurrent = x+xStep, yCurrent = y+yStep; InBounds(xCopyTo, yCopyTo) && --partsRemaining; xCurrent+=xStep, yCurrent+=yStep, xCopyTo+=xStep, yCopyTo+=yStep)
{
// get particle to copy
if (isEnergy)
type = TYP(sim->photons[yCurrent][xCurrent]);
else
type = TYP(pmap[yCurrent][xCurrent]);
// if sparked by PSCN, overwrite whatever is in the target location, instead of just ignoring it
if (overwrite)
{
if (isEnergy)
{
localCopyLength -= partsRemaining;
xCopyTo = xCurrent + xStep*copySpaces;
yCopyTo = yCurrent + yStep*copySpaces;
break;
if (sim->photons[yCopyTo][xCopyTo])
sim->kill_part(ID(sim->photons[yCopyTo][xCopyTo]));
}
else
{
if (pmap[yCopyTo][xCopyTo])
sim->kill_part(ID(pmap[yCopyTo][xCopyTo]));
}
}
if (type == PT_SPRK) // spark hack
p = sim->create_part(-1, xCopyTo, yCopyTo, PT_METL);
else if (type)
p = sim->create_part(-1, xCopyTo, yCopyTo, type);
else
continue;
// now, actually copy the particles
partsRemaining = localCopyLength + 1;
int type, p;
for (int xStep = rx*-1, yStep = ry*-1, xCurrent = x+xStep, yCurrent = y+yStep; InBounds(xCopyTo, yCopyTo) && --partsRemaining; xCurrent+=xStep, yCurrent+=yStep, xCopyTo+=xStep, yCopyTo+=yStep)
// if new particle was created successfully
if (p >= 0)
{
// get particle to copy
if (isEnergy)
type = TYP(sim->photons[yCurrent][xCurrent]);
else
type = TYP(pmap[yCurrent][xCurrent]);
// if sparked by PSCN, overwrite whatever is in the target location, instead of just ignoring it
if (overwrite)
{
if (isEnergy)
{
if (sim->photons[yCopyTo][xCopyTo])
sim->kill_part(ID(sim->photons[yCopyTo][xCopyTo]));
}
else
{
if (pmap[yCopyTo][xCopyTo])
sim->kill_part(ID(pmap[yCopyTo][xCopyTo]));
}
}
if (type == PT_SPRK) // spark hack
p = sim->create_part(-1, xCopyTo, yCopyTo, PT_METL);
else if (type)
p = sim->create_part(-1, xCopyTo, yCopyTo, type);
sim->part_change_type(p, xCopyTo, yCopyTo, PT_SPRK);
if (isEnergy)
parts[p] = parts[ID(sim->photons[yCurrent][xCurrent])];
else
continue;
// if new particle was created successfully
if (p >= 0)
{
if (type == PT_SPRK) // spark hack
sim->part_change_type(p, xCopyTo, yCopyTo, PT_SPRK);
if (isEnergy)
parts[p] = parts[ID(sim->photons[yCurrent][xCurrent])];
else
parts[p] = parts[ID(pmap[yCurrent][xCurrent])];
parts[p].x = xCopyTo;
parts[p].y = yCopyTo;
}
parts[p] = parts[ID(pmap[yCurrent][xCurrent])];
parts[p].x = xCopyTo;
parts[p].y = yCopyTo;
}
}
}
}
}
}
return 0;
}