I have a standard 2D grid that i use for pathfinding. I already use A* to find the path of my units when I want to move them around.
What I need to implement now is a preview of all possible destinations of the unit when it is selected.
I want to make this as optimized as possible, because it can be executed on very big maps and for multiple units.
I have something in mind but I wonder if there is better approach for this.
Here is my idea:
Get a list of all cells that are walkable in a square around my unit. The square will be from
Unit.X - Unit.Speedto
Unit.X + Unit.Speedfor X axis and
Unit.Y - Unit.Speedto
Unit.Y + Unit.Speedfor Y axis.
For each element in this list, execute A* search to see if it is possible to find a path.
By doing the search for only the cells that are within my unit range I should be able to do this on big maps.
Basically this is the same feature that we have in games like Heroes 3 and many other turn based games.
I was also wondering when it is a good idea to execute this pathfinding logic. When you select a unit (might result a spike) or when something moves on the map to update the list of all possible destinations of all units on the map.