Indeed, that graph is about the biggest portion of the logic in the plugin so thats fairly manageable.
I’ve started working on an algorithm to do line of sight checking before flagging tiles as attackable (tile is within attack range, the red tiles). Until now I just computed a hollow diamond shape based on the minimum and maximum attack range, overlaid that over all reachable tiles and flagged the tiles within that shape as attackable. In the graph you can see that at the bottom: “Generate all attack offsets” generates the diamond shape and the loop below that marks the overlaid tiles as attackable + some extra stuff. I had already put a “HasLineOfSight” function that until now always returned true. This was so that users can implement it, since there are multiple ways to do line of sight on a grid. Its rather hard as well so I didn’t feel up for it.
But after thinking about it some I decided to do an implementation myself so that there is line of sight checking out of the box, since hey, I proclaimed you could make Advance Wars like games with this out of the box. So the way I’m going to do line of sight is using a line rastization algorithm from computer graphics: deciding which pixels to color for a line is actually the same as deciding which grid tiles to check for line of sight. I also want to take into account that when a line crosses exactly through a corner of a tile, a special check needs to be done. I’m not actually sure how tile based games usually handle this case, can line of sight pass through the corner of a blocking tile? Would like some thoughts on this. It will be easy to do either case, but I don’t know which one to put in as default. To illustrate the case I’m talking about:
I already implemented the line rasterizing algorithm in C++ using fractions! Here is an example output:
The ? marks show the corner cases. The reason I wanted to do fractions other than it being fancy is that I want to detect those corner cases consistently and not miss them due to rounding errors. I’m pretty proud I got that working, now the fun task of converting it to blueprint…