﻿id	summary	reporter	owner	description	type	status	priority	milestone	component	resolution	keywords	cc	phab_field
6706	Unintended pack/unpack loop for catapults	Langbart		"So far **two** ways have been found to make a siege trapped in a pack/unpack loop.

== CASE NO1 - AURA MODIFICATION
This issue was reported by `dinuruian` in the forum for A26
- [https://wildfiregames.com/forum/topic/101749-siege-catapult-bug-packunpack-on-shooting-target/ siege catapult bug pack/unpack on shooting target] (15/Dec/22)


GIF/ scene of the replay provided by `dinuruian`, that shows the issue:
[[Image(siege_pack_unpack.gif, 600px, center)]]
[[Image(scene.png, 800px, center)]]

- see image below, the siege is able to reach the target, it gets a `10% range boost` from the hero `Demetrius I the Besieger`
- as it unpacks, everything looks good
- there is very brief period where the `maxRange` gets reset to 100, it packs up again
- while still packing the correct `maxRange` is shown

[[Image(hero_aura.png, 800px, center)]]


== CASE NO2 - PUSHING
==== to reproduce
- try to create a scene with lots of soldiers around catapults
- minimal replay attached (~4min)
  - attachment:commands.txt

[[Image(rec_scene.png, 600px, center)]]

===== Adding a debug message
- calculate the distance to the target, get the `maxRange` and watch for state changes, when the unit `Catapult` `packs/unpacks`
- by the time the unit is `unpacked`, it has been moved slightly behind its `maxRange`
 - it will `pack` up and attempts to find a new position, this can take a couple of times
{{{#!sh
0 A.D. (0.0.27) Main log (warnings and errors only)
WARNING: ""DistanceToTarget: 100.7005; MaxRange: 100; State: search new position""
WARNING: ""DistanceToTarget: 99.6598; MaxRange: 100; State: position found""
WARNING: ""DistanceToTarget: 99.6598; MaxRange: 100; State: unpacking""
WARNING: ""DistanceToTarget: 100.2639; MaxRange: 100; State: unpacking""
WARNING: ""DistanceToTarget: 100.2639; MaxRange: 100; State: out of range""
WARNING: ""DistanceToTarget: 100.2639; MaxRange: 100; State: packing""
WARNING: ""DistanceToTarget: 100.2639; MaxRange: 100; State: packing""
WARNING: ""DistanceToTarget: 100.2639; MaxRange: 100; State: search new position""
WARNING: ""DistanceToTarget: 99.9555; MaxRange: 100; State: position found""
WARNING: ""DistanceToTarget: 99.9555; MaxRange: 100; State: unpacking""
WARNING: ""DistanceToTarget: 100.0359; MaxRange: 100; State: unpacking""
WARNING: ""DistanceToTarget: 100.0359; MaxRange: 100; State: out of range""
}}}

==== reproducible
- issue can be noticed from A25 onwards

==== possible cause
- the issue might have been caused by the unit pushing changes
  - [25182]
  - [26245]
  - [26261]

==== expected behavior
- Once the siege units unpacks on a target, it should not pack up again

==== possible solutions
- **(A)** lowering the `StaticExtension` in [https://code.wildfiregames.com/source/0ad/browse/ps/trunk/binaries/data/mods/public/simulation/data/pathfinder.xml$17 simulation/data/pathfinder.xml] even more
{{{#!diff
--- a/binaries/data/mods/public/simulation/data/pathfinder.xml
+++ b/binaries/data/mods/public/simulation/data/pathfinder.xml
@@ -14,7 +14,7 @@
     <!-- Actual pushing radius for non-moving units is: -->
     <!-- Clearance * PushingRadius + StaticPushExtension -->
     <!-- This mostly controls the maximum unit density-->
-    <StaticExtension>0.5</StaticExtension>
+    <StaticExtension>0</StaticExtension>
 
     <!-- Actual pushing radius for moving units is: -->
     <!-- Clearance * PushingRadius + MovingPushExtension -->
}}}

- **(B)** when the catapult searches for a position on its target, the push changes are taken into account with a fixed value, e.g. (+/-2)

==== related
- issue about gatherers being pushed back on a berry bush
  - [[https://code.wildfiregames.com/D4461#190337|D4461]] (27/Jan/22)


"	defect	new	Should Have	Alpha 28	Core engine				
