fix bug if the first space after the DRAY was empty, fix bug with DRAY's ctype sometimes not working

This commit is contained in:
jacob1
2015-09-28 11:28:19 -04:00
parent 93d6816740
commit 0a907c5177

View File

@@ -83,22 +83,30 @@ int Element_DRAY::update(UPDATE_FUNC_ARGS)
for (int xStep = rx*-1, yStep = ry*-1, xCurrent = x+xStep, yCurrent = y+yStep; ; xCurrent+=xStep, yCurrent+=yStep) for (int xStep = rx*-1, yStep = ry*-1, xCurrent = x+xStep, yCurrent = y+yStep; ; xCurrent+=xStep, yCurrent+=yStep)
{ {
int rr; 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) if (!foundParticle)
{ {
rr = pmap[yCurrent][xCurrent]; rr = pmap[yCurrent][xCurrent];
if (!rr) if (!rr)
{ {
rr = sim->photons[yCurrent][xCurrent]; rr = sim->photons[yCurrent][xCurrent];
foundParticle = isEnergy = true; if (rr)
foundParticle = isEnergy = true;
} }
else else
foundParticle = true; foundParticle = true;
} }
else if (isEnergy) // 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]; rr = sim->photons[yCurrent][xCurrent];
else else
rr = pmap[yCurrent][xCurrent]; 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
// 3. Stop when we are out of bounds
if ((!copyLength && (rr&0xFF) == ctype && (ctype != PT_LIFE || parts[rr>>8].ctype == ctypeExtra)) if ((!copyLength && (rr&0xFF) == ctype && (ctype != PT_LIFE || parts[rr>>8].ctype == ctypeExtra))
|| !(--partsRemaining && InBounds(xCurrent+xStep, yCurrent+yStep))) || !(--partsRemaining && InBounds(xCurrent+xStep, yCurrent+yStep)))
{ {
@@ -109,16 +117,18 @@ int Element_DRAY::update(UPDATE_FUNC_ARGS)
} }
} }
//now, actually copy the particles // now, actually copy the particles
partsRemaining = copyLength + 1; partsRemaining = copyLength + 1;
int type, p; 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) 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) if (isEnergy)
type = sim->photons[yCurrent][xCurrent]&0xFF; type = sim->photons[yCurrent][xCurrent]&0xFF;
else else
type = pmap[yCurrent][xCurrent]&0xFF; type = pmap[yCurrent][xCurrent]&0xFF;
// if sparked by PSCN, overwrite whatever is in the target location, instead of just ignoring it
if (overwrite) if (overwrite)
{ {
if (isEnergy) if (isEnergy)
@@ -132,16 +142,17 @@ int Element_DRAY::update(UPDATE_FUNC_ARGS)
sim->kill_part(pmap[yCopyTo][xCopyTo]>>8); sim->kill_part(pmap[yCopyTo][xCopyTo]>>8);
} }
} }
if (type == PT_SPRK) //hack if (type == PT_SPRK) // spark hack
p = sim->create_part(-1, xCopyTo, yCopyTo, PT_METL); p = sim->create_part(-1, xCopyTo, yCopyTo, PT_METL);
else if (type) else if (type)
p = sim->create_part(-1, xCopyTo, yCopyTo, type); p = sim->create_part(-1, xCopyTo, yCopyTo, type);
else else
continue; continue;
// if new particle was created successfully
if (p >= 0) if (p >= 0)
{ {
if (type == PT_SPRK) if (type == PT_SPRK) // spark hack
sim->part_change_type(p, xCopyTo, yCopyTo, PT_SPRK); sim->part_change_type(p, xCopyTo, yCopyTo, PT_SPRK);
if (isEnergy) if (isEnergy)
parts[p] = parts[sim->photons[yCurrent][xCurrent]>>8]; parts[p] = parts[sim->photons[yCurrent][xCurrent]>>8];