[SUPPORT] Advanced Turn Based Tile Toolkit

Ok, that might be true, but I was also not entirely correct in my suggestion. What I suggested will work in my next update, but not in the version currently on the marketplace. For now do this instead:

Hi there! Seems like you want to take the toolkit in an exciting direction. I’ve been toying around in my head with various stealth mechanics ever since I played Invisible Inc., so I can give you some suggestion. There is of course several ways to do this, and it might not be ideal for you depending on what you’re after, but it should hopefully be enough to get you started.

I would like to use a new grid sized array for stealth which at any time knows every tile on the grid which is watched over by an enemy. This way it can be quickly checked at any time and can even be used to display all such tiles to the player. Add a new integer array to BP_GridManager and resize it to the size of the grid at the end of the startup nodes in the event graph of BP_GridManager like so:

All indexes will have a value of 0 to begin with. This means that it is not watched over by any enemy. A value of 1 will mean it is watched by 1 enemy, 2 that it is watched by 2 and so on.

Next lets add a few variables to Unit_Parent. We will want a float that holds the field of view of a pawn (the number of degrees in front of it that it can see), an integer array that holds all indexes the AI can currently see, a boolean that determines if a unit is currently in stealth mode and an integer for the unit’s maximum sight range. Like so:

Now we will want to make a function for the AI that takes all indexes within its field of view and sight range and stores them in both AI sight array and Index AI sight array (on the unit itself). First we run Find Tiles In Range with range set to the sight range of the unit to get all potential visible tiles (with Max Z Difference set to whatever max height difference we want it to be able to look up and check visibility set to true to account for cover). Like so:

9zYXJ81.png

Then we run a custom function in BP_GridManager that checks all tiles outputted by the Find Tiles In Range function and sees if they are in the unit’s field of view. If they are we store them in our various arrays. Like so:
moRg48i.png

We will need to run this function for all enemy units at the start of the game so we know which tiles they can see initially. I do it at the end of the event graph of BP_GridManager like this:

At this point we have informed the AI sight array of all tiles visible to enemy units. Lets check out if it works by spawning tiles in sight range for all indexes in this array with a value greater then 0. Here is one way to test it in BP_GridManager:

Then place some enemy units in your game (make sure their sight range and field of view are resonably high. I used 90 and 6 for this example) and press “U”. Works like a charm for me:

Ok, so that is all well and good. But we need to make sure this updates when an enemy moves or rotates. This means we need to subtract one from the indexes in AI sight array we added one to previously so that they are back to neutral and then run our Insert Tiles In Sight Into Sight Array from the unit’s new location. Luckily we have stored all indexes we need to subtract in the Index AI Sight Array in each unit, making it easy to know which one we want to subtract. This is something we will want to run whenever the unit moves or rotates, both of which happen inside the event graph of Unit_Parent in ATBTT. Therefore I choose to make a new function for these two operations in Unit_Parent. Like so:

We only need to insert this function two places in the event graph of Unit_Parent since there are only two conditions in ATBTT that causes a unit to rotate or move. So insert the function these two places:


Ok, so now the AI Sight Array will update appropriately. We are still missing our stealth stuff, though. First lets make a very simple way for units to enter stealth. I added this tiny graph to ATBTT_PlayerController for testing. For a real game you would probably run this event from clicking some button in your UI:

Then while a unit is moving we want it to check for every tile it enters whether or not that tile is observed and if it does we want to disable stealth. I have added this to the event graph of Unit_Parent in a pretty lazy way (though one that works):

Now all we have left is to make the AI ignore units that are in stealth. I’ve added this by removing the indexes of any units with stealth from the arrays containing units found during Find Tiles In Range and Pathfinding in ATBTT_AIController:

Ok, I hope I remembered to include everything. This is by far the most time consuming answer I have given to a question. I usually cannot go into such detail since I struggle to get enough time to work on the toolkit as it is, but I intend to make a stealth game example in the future and this allowed me to test out some ideas I’ve had. This is not a complete solution and has some limitations. For instance I have not added a way for the AI to discover hidden units on their own turns. When a unit is hidded it stays hidden until it moves to a tile that is watched by an enemy. This might or might not be what you want, but if you want further I hope I’ve given you enough of a head start to begin experimenting yourself. Good luck!