Changing const_snipertarget does not stop snipers already locked on

Started by planetfall, August 31, 2014, 02:40:53 PM

Previous topic - Next topic

planetfall

Yay, snipers again!!

Basically what the title says. I have some cores that are only supposed to be vulnerable when they are off screen, and when they move into view they become immune. However, if a sniper begins shooting one of these cores, and then it moves onto the screen, it sometimes continues to shoot repeatedly even though the target's CONST_SNIPERTARGET is false. It also triggers other effects while visible, so I'm certain that the snipertarget is set. However, if that sniper is moved, it stops shooting at the core, and new snipers that move into range also don't shoot it.

Edit: example save attached

Edit 2: this only seems to happen when the core is standing still, ie in the example save if you pan the screen rather than let the enemies move into the screen.
Pretty sure I'm supposed to be banned, someone might want to get on that.

Quote from: GoodMorning on December 01, 2016, 05:58:30 PM"Build a ladder to the moon" is simple as a sentence, but actually doing it is not.

Grayzzur

It's probably something along the lines of once a sniper has a target, it doesn't check those details until the target is dead or out of range.

You might try forcing it out of range for at least one frame to make the sniper look for another target when you switch to invulnerable. The SetTargetOffsetX/Y commands could do the trick without actually having to move the core itself. It's not documented in the Wiki yet, but I recall Virgil mentioning it once. http://knucklecracker.com/forums/index.php?topic=15387.0 Though, I don't know if the snipers do their range check based on that offset, or off the core itself with the offset just being a visual effects adjustment.
"Fate. It protects fools, little children, and ships named 'Enterprise.'" -William T. Riker

knucracker

There are a lot of things going on in this case actually.  Inspecting my code for crpltowers, snipers, etc.  It looks like the way sniperTarget was designed to work was mostly for on-map items.  Setting sniperTarget on a CRPLTower attempts to set an entry in what is called the crplTowerMap.  This is a giant array the size of the map and is used for spatial hashing.  This array is how snipers quickly scan for nearby targets without having to iterate over all possible target units.

Now, additionally a CRPLTower will also remember a boolean indicating it is in the sniperTarget state.  As a CRPLTower moves around, it unsets and sets itself in the spatial hash array (As it moves from cell to cell).  Naturally, when it is off the map it doesn't do this.

The sniper looks for a target if it currently doesn't have one, if it's current target is out of range, doesn't have a sniperTarget attribute, etc.  So that part looks fine.  However when it looks for a target the routine to find one doesn't actually check the sniperTarget boolean... it just looks at the spatial hash array.

Lastly, all range checks should obey the target offset.

So possible ways to skirt issue are the target offset as Grayzzur mentioned... or setting the sniperTarget attribute to false again (perhaps setting it to true then false in the same frame) as soon as the tower moves back onto the map.