--- 1. Handle each path-able|obstructing area as polygon.
Obstructing is everything where the height-difference is too extreme for a unit to walk across.
. Obstructing map
. 1 Path-able area (the rectangle you play on)
. 1.1 Obstacle 1
. 1.1.1 Path-able area within obstacle 1 (where you can build LLTs on the middle hills)
. 1.2 Obstacle 2
. 1.3 ...
Obstructing|Path-able is alternating in each hierarchy level of the tree structure.
--- 2. Detect areas: (simplified example)
A passage is at the shortest distance between 2 obstacles in the same tree-level.
For obstacles forming a bay, it is a bit more difficult.
Perhaps you have to check the distance of each node in the polygon to others depending on the sum of angles between these nodes.
But that is not the important part as it rarely changes enough for the performance to be a concern.
--- 3. Pathing:
Now you have areas, separated by passages, containing artificial obstacles (buildings, etc) which have small areas between them.
Units prefer passages which are 2x their size, so that they can evade another unit going the opposite direction …
… for a group of units, either take their group's radius or 2x the biggest unit's size if it is larger.
If a passage has 1/2 size, the unit may take a 10% longer way. if it has 1/3 of the groups radius, they may take 20% longer ways to avoid it if possible …
… it will not be noticed as a passage by units which too large to fit trough. Also groups which have such units and others which fit through the passage may want to avoid it for the sake of their formation.
Within these areas there are no obstacles, except units.
Units just have to register/unregister at map squares to check for collision with each nearby-map-square's units.
--- 4. The improvement:
If units don't align to a 0°, 45°, 90°, 135°, 180°, ... angles, but just move, platoons|groups moving at the same speed (slowest unit) remain their formation.
Units won't go into enemy towers anymore because they align to 45°-steps instead of following the line between origin and destination.
It's also a lot cheaper to calculate pathes:
- Possible? Only if the path-able origin and destination is the same tree-item.
- ETA? You can go from area to area to your destination and if you need to go around obstacles, you can get a list of passages they touch to speed up calculations.
I would like feedback how I can improve my post to make more peoples able to understand this post.