Units garrisoned on a gate shouldn't interfere with the opening and closing of it, or for example block large units from passing through the gate. So let's disable block movement and block pathfinding for garrisoned units and ignore them when deciding whether we can open or close the gate.
Seems like we might want this for all turrets, see:
- This happens because we don't move visible-garrisoned units out of the world. This makes sense if these are somewhat independent, for example in the case of autonomous drones and so on.
- It should probably be a GarrisonHolder property whether garrisoning removes your "collision" or not.
Thus the correct way to fix this, imo, is to add a parameter to GarrisonHolder (and other components that have the same behaviour), instead of changing Gate. We may want buildings where visible garrison points are obstructions.
On the precise mechanism, calling the pathfinder seems reasonable enough.
Read this better, there's two things here. On the "remove obstruction" part, see above.
These units should indeed not be counted towards opening the gate. I think however your current method won't work: say we have two garrisoned gates very close to each other, I think they'll get counted. The distinctive criteria here is that garrisoned units cannot move, they're static. I'm not entirely sure that's easily transatable in code though, maybe we need to add a "CutMyLegsOff" to CmpUnitMotion like we have "moveOutOfWorld" for CmpPosition.
Ah right no I understand now.
More involved fix involving four things:
- Gates open for units blocking movement, not construction (my opinion is that this overall makes more sense too).
- Gates open only if units nearby 'can move', a new unitAI state
- UnitAI keeps track of whether it can move or not. Packing moves the entity to Immobile, garrisoning too.
- Garrison holders remove the obstruction of garrisoned entities (this is the incidental fix for #5151)
Also use the opportunity to use this "AbleToMove" function in UnitAI elsewhere.
Regarding my above comment - if we want buildings where visible obstruction points _are_ obstructions, we'll handle that then.
This correctly handles the case of two gates close to each other with visible garrison units inside each of them, unlike the previous patch.