This question already has an answer here:
I am making an RTS game, and I implemented path finding with A*. My A* algorithm uses 8 directions and terminates early in the case of no path found (I use 50*the vector distance between the unit and the point as the limit to dequeueing the fringe). If there's no path then they will go to the nearest valid point to the destination. This problem arises because a structure is bigger than 1 tile
I am having trouble now with attacking a structure, right now I have it so that it checks each "tile" of the structure, and gets the distance between the unit and the structure "tile". Plus, it will see if theres a path from that tile to the unit, and if there is then the tile is put in a priority queue, where priority is min distance.
Here, this can be a lot of path finding calls for 1 unit using this, the number of calls is dependent on the x*y size of the structure. Here is a picture to illustrate (with the orange being the unit, red being barrier (that can potentially move) and the blue being the structure)
Here there will be 9 calls to path finder, 8 of them will fail almost immediately , 9 will produce the path from the unit in orange to the bottom right corner of the structure.
It can get much worse with an example like this:
Here there will be 6 path finding calls which could take a long time depending on the space between the unit and the structure. So there must be a better way to path to a closest available tile of a structure without calling path finder for each tile in the structure and I need help with that. How would I go about treating the entire blue region as the goal? My node only encompasses one tile, so would I need multiple destinations (so multiple f values)?