tl;dr : my tests showed the current code getting 10- reaction shots on red's .Sav, mine getting 10+
checkReactionFire(unit)
- getSpottingUnits(vs unit)
- getReactor(spotters vs unit)
- loop, getReactionScore(spotters)
- if best score, reactor = spotter *
- else, initiative returns to unit.
* here is where i put in a check in an attempt to make sure the same spotter is not returned as the reactor twice in a row. But it now seems unnecessary, since iterating over the spotters-vector will never re-iterate over a single unit anyway. Thanks red.
So we get back to checkReactionFire(), passing in the best reactor. Here is the most suspect code:
if (reactor != unit) https:// ok, getReactor() returns unit only when no one bests the initiative
{
while (true)
{
if (!tryReactionSnap(reactor, unit)) https:// aggro, targetting, etc.
break; https:// but if that guy can't do it, why break???
https:// Maybe the next guy in the spotters-vector can...
reactor = getReactor(spotters, unit); https:// here.
result = true; https:// yes a reaction was successfully made
if (reactor == unit) https:// ok. if getReactor returns the unit itself, initiative has gone back to unit.
break; https:// -> break
}
}
btw, There seems to be redundancies between canMakeSnap() and tryReactionSnap() -- checking weapon & ammo, eg.
Will amend my code, and try to amend the 'reaction Update' commit.... oh and this is gonna require *playtesting* :p
ps. I just don't like it. I'd much rather see the spotters-vector getting iterated over in checkReactionFire(). Why? Because i believe checkReactionFire() gets called only once per tile (when unit gets to its next tile during movement) or once when it takes an action like shooting. But checkReactionFire() calls getReactor(), where the spotters-vector *is* iterated over, only if the previously-identified spotter succeeds in making a reaction shot.
it would seem to smooth things out to consolidate (refactor) what's there,
anyway, time to relax on an alienBase mission: 2 xcom down, 10 to go..
Pps. Am i the only guy who doesn't like "while(true)" loops ? <- hint hint