From 0a907c5177ec72b69dcdc10a07fbf1b6973a2bac Mon Sep 17 00:00:00 2001 From: jacob1 Date: Mon, 28 Sep 2015 11:28:19 -0400 Subject: [PATCH] fix bug if the first space after the DRAY was empty, fix bug with DRAY's ctype sometimes not working --- src/simulation/elements/DRAY.cpp | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/src/simulation/elements/DRAY.cpp b/src/simulation/elements/DRAY.cpp index 2d5c6453c4..06cbef1a73 100644 --- a/src/simulation/elements/DRAY.cpp +++ b/src/simulation/elements/DRAY.cpp @@ -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) { 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 = sim->photons[yCurrent][xCurrent]; - foundParticle = isEnergy = true; + if (rr) + foundParticle = isEnergy = true; } else 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]; 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 + // 3. Stop when we are out of bounds if ((!copyLength && (rr&0xFF) == ctype && (ctype != PT_LIFE || parts[rr>>8].ctype == ctypeExtra)) || !(--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; 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 = sim->photons[yCurrent][xCurrent]&0xFF; else type = pmap[yCurrent][xCurrent]&0xFF; + // if sparked by PSCN, overwrite whatever is in the target location, instead of just ignoring it if (overwrite) { if (isEnergy) @@ -132,16 +142,17 @@ int Element_DRAY::update(UPDATE_FUNC_ARGS) 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); else if (type) p = sim->create_part(-1, xCopyTo, yCopyTo, type); else continue; + // if new particle was created successfully if (p >= 0) { - if (type == PT_SPRK) + if (type == PT_SPRK) // spark hack sim->part_change_type(p, xCopyTo, yCopyTo, PT_SPRK); if (isEnergy) parts[p] = parts[sim->photons[yCurrent][xCurrent]>>8];