Waldesfray
(Waldesfray)
September 5, 2016, 3:36pm
1023
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.
Thank you, the collision solution seems to be almost ideal one! But how could I make AI ignore its own faction (an allied factions) cities? These cities may stay unoccupied, but faction-allied by default.