Thanks! Happy to help!
I’m not exactly sure what you need the range array for. It is just used for temporarily storing what tiles are in range of a unit.
The simplest way to get a city to change faction when a unit moves into it is to use collision. Enable collision for your units (but make sure their collision do not block PathTrace and RangeTrace) and add a trigger volume to your cities in the middle of their tile. In the city blueprint you can get any colliding actors, cast them to Unit_Parent, get their faction and alter the faction of the city.
AI is a bit more tricky. In ATBTT_AI_Controller after pathfinding but before finding if there are any units in range you could get all actors of your city blueprint class, loop through them and use the vector to index function in BP_GridManager to convert their locations to indexes on the grid. You then check if that index in the CanMoveTo array in BP_GridManager is higher than 0 (meaning the current unit can move to it) and that the Pawn Array at that index is empty. If so you should set that tile index as the unit’s target and move it there using the same nodes in the AI controller used for directing the unit towards an enemy unit.
This is one possible solution, at least. I hope my explanation was understandable and that I understood your question correctly.
I have two functions called Make Tile Passable and Make Tile Impassable that should be useful to you. You should first get references to all the tiles you want to modify and loop over them, using Make Tile Passable for each. This should hopefully do the trick. To get the appropriate tiles you could possibly use the Get Indexes in Range function, though you could end up making surrounding tiles passable that you want to be impassable if you’re not careful.
Hmm, that’s not good. This might have been an oversight on my part. I will look into it when I have access to my home computer.
This is an error I have seen a few times, but it should not happen without you changing something. It is caused by the AI searching for player units to attack and one of the functions for finding targets returning false (or 0), causing the unit to move to index 0. Have you made any modifications to ATBTT_AI_Controller?