Good evening folks,

I had some trouble optimizing the calculation of terrain penalty and obstacles that affect maximum movement range as you select a unit, which forced me to think outside the box to find another method. I’ll try to explain it in a comprehensive fashion and in the simplest way possible. If you have any question, do not hesitate to use the comment section below.

In the video below, I tried two flawed methods before finding the appropriate way to approach the issue.

Version 1

Here, I tried displaying everything from the get-go, which created this sliding animation to display movement range.

I took the grid that a user with no terrain or obstacle penalty could walk (which is 5 max movement range in this case), then I looped in this array to make detect any squares with either an obstacle on them, or that would require more than 5 move range to reach. Since I have to draw a path and detect obstacles on every square (which is about 40 squares, in this case), the player could see the computer calculating. It would be even worse on a less powerful computer.

Version 2

Then, I thought that, maybe, if I displayed the tiles AFTER the calculation, it would be nearly seemless, but the fact that it takes about 0.5 second to calculate made it visible too. If the player had to deal with this on every unit movement, it would get frustrating. Then again, it could also be worse, depending on the player’s computer.

Final Version

After analyzing a Fire Emblem game, I noticed that before every turn, there is some music playing while ‘Player Phase’ is displayed. THIS is the moment when they calculate the movement penalty and store it in the memory. It would also explain why units can go through other allied units. Their new position isn’t taken into account until the next turn.

Afterwards, you just have to access to the variable to get the accessible tiles when you select the unit instead of calculating them on the spot.

If I decide to add a dancer/bard/refresher, I could also use the animation time to calculate the new movement range.

I’ll see you guys next time,

Coco