beyond-all-reason / spring

A powerful free cross-platform RTS game engine
https://beyond-all-reason.github.io/spring/
Other
182 stars 95 forks source link

prevent burst weapons firing outside their intended arc #1452

Closed marcushutchings closed 2 months ago

marcushutchings commented 3 months ago

Burst weapons will honour these settings on the weapon (in the unitDef):

maxAngleDif for units that allow weapons to fire independent of the unit's facing maxForwardAngleDif for units that lock their weapons towards the front of the unit

Fixes https://github.com/beyond-all-reason/spring/issues/1451

WatchTheFort commented 3 months ago

Why are two tags needed? Can't maxAngleDif be used for both, and the behaviour depends on whether or not the weapons are locked forward?

marcushutchings commented 2 months ago

Good question. The two tags have been in the engine for quite some time. They may be mergable.

sprunk commented 2 months ago

two tags

See #1449. This patch is doing the correct thing by following existing use though.

prevent burst weapons firing outside their intended arc

Looks good.

marcushutchings commented 2 months ago

Okay I have an alternative approach: I can make the burst weapons continue to unload the rest of their salvo in the direction of where the guns are currently facing if the target is out of arc. So as the unit turns the weapon to the next target, you'll see shots firing out as it turns.

Giving it a try, I think it does look better.

marcushutchings commented 2 months ago

Any objections if I switch this alternative method?

Though I suspect the request will be that the weapon be configured to do either.

sprunk commented 2 months ago

stopBurstWhenOutOfArc doesn't seem to do anything. The weapon always has the "stop burst" behaviour when targeting an out-of-arc unit and the "keep shooting at last valid position" when targeting an out-of-arc ground.

marcushutchings commented 2 months ago

stopBurstWhenOutOfArc doesn't seem to do anything. The weapon always has the "stop burst" behaviour when targeting an out-of-arc unit and the "keep shooting at last valid position" when targeting an out-of-arc ground.

How did you deduce that? I'm not sure what code you are looking at. I've tested this and I'm getting the expected behaviour.

sprunk commented 2 months ago

I'll produce a replay in about 10h.

sprunk commented 2 months ago

stopBurstWhenOutOfArc doesn't seem to do anything. The weapon always has the "stop burst" behaviour when targeting an out-of-arc unit and the "keep shooting at last valid position" when targeting an out-of-arc ground.

How did you deduce that? I'm not sure what code you are looking at. I've tested this and I'm getting the expected behaviour.

Looks like it partially works after all but not really. Here's a replay (zipped because github doesn't accept .sd.kfz) 2024-04-19_22-45-16-825_DeltaSiegeDry_105.1.1-2470-gb331036 HEAD.zip Select the turret spawned in the middle and pay attention to its manual attack orders. I make labels when appropriate tho.

If you keep the game version as-is:

sprunk commented 2 months ago

Here's another bad replay. 2024-04-19_23-34-01-293_DeltaSiegeDry_105.1.1-2470-gb331036 HEAD.zip

This time game version is https://github.com/ZeroK-RTS/Zero-K/commit/3b8fa0925b6772463b496bfd2b0e02cbb937de8e (note, not the same as previous replay)

marcushutchings commented 2 months ago

Thanks for making those replays I will take a closer look.

To be clear, we are only deciding what to do if a weapon is trying to fire outside its permitted arc. A couple of thoughts:

burst doesn't get stopped despite stopBurstWhenOutOfArc = true on ground target, it keeps firing at the previous spot.

So the turret is not rotating to a new target then (i.e. the turret hasn't picked a new target?) Then the point it is aiming at is going to be in its firing arc - so the shots will continue as expected. Sounds like you would also like this feature to consider stopping the burst once the target unit is dead (despite having selected no new target.)

when stopBurstWhenOutOfArc = false (you can change the .sdd and run the same replay) the burst correctly continues on a unit target but sometimes it randomly fires backwards.

That should only happen if the shot is permitted to fire in that direction. What are the aim constraint settings set on the weapon?

sprunk commented 2 months ago

burst doesn't get stopped despite stopBurstWhenOutOfArc = true on ground target, it keeps firing at the previous spot.

So the turret is not rotating to a new target then (i.e. the turret hasn't picked a new target?) Then the point it is aiming at is going to be in its firing arc - so the shots will continue as expected. Sounds like you would also like this feature to consider stopping the burst once the target unit is dead (despite having selected no new target.)

Yes, it continues firing the burst at the old target. It won't start another burst though. Note that what I did here was attack ground in arc and then, mid-burst, attack ground out of arc - no unit target involved.

If a unit target dies and the shooter does not pick up a new target then it should probably keep shooting at the target's last position which I believe may be how it works before this patch.

when stopBurstWhenOutOfArc = false (you can change the .sdd and run the same replay) the burst correctly continues on a unit target but sometimes it randomly fires backwards.

That should only happen if the shot is permitted to fire in that direction. What are the aim constraint settings set on the weapon?

180 degrees with maindir 0 0 1 which makes for a nice obvious hemisphere (pointing south because I'm spawning a building). And then in the replay it fires very obviously in the other direction.

marcushutchings commented 2 months ago

I can't get your replay to work properly. The Cerberus Turret refuses to shoot at anything. I'll try to replciate what you were doing.

marcushutchings commented 2 months ago

burst doesn't get stopped despite stopBurstWhenOutOfArc = true on ground target, it keeps firing at the previous spot.

I looked what is happening. Something is setting the currentTargetPos back to the previous point once every 10 frames. Is there a ZK script that tries to do something clever when the ground attack target is out of arc? This doesn't happen with BAR.

marcushutchings commented 2 months ago

Okay. The turret is firing the rest of the salvo at the previous position because it doesn't have a target - even though the unit has one. Somehow changing the aim point the way you did it didn't propagate down to the weapon - looks like it is because the new target isn't valid so the weapon didn't receive it.

marcushutchings commented 2 months ago

Adding a HaveTarget() check solves that behaviour. Though something else doesn't look right. I need to investigate that. UPDATE: okay, it was the 10 second reload time made it look like the Cerberus wasn't working - the numbers add up so it is fine.

marcushutchings commented 2 months ago

As a separate side note, I can see the turret being able to fire slightly outside its arc with stopBurstWhenOutOfArc = false because the turret model has rotated too far.

marcushutchings commented 2 months ago

I'm currently looking to taking all bug fix PRs into mainline. We will be testing further during integration testing, and I hope ZK will also be testing the next release candidate. Any objections if I pull this into the next release canddidate for integration testing?

sprunk commented 2 months ago

This is more of a behaviour change / feature than a bugfix but I don't mind.