Today I only cleaned and commented the FOV code. I also tested unit’s movement with a normal map. It works perfectly; and the fact that a unit can see through window tiles like in the original game is awesome. Time to do some research again for the next feature that I’m going to cover, and that is pathfinding.
What is pathfinding? To put it in simple words, it’s an algorithm which calculates the path from one position on the map to another, avoiding unpassable tiles (walls, closed doors… etc). It’s used for the computer AI and I have so many ideas how can I make it smart and configurable. For example, each computer unit, depending on the scenario, will have main objectives (patroling, guarding, attacking… etc). So, if a player eliminates a computer unit in the game, the other computer units are aware of this, and will automatically go to this position; but not if they have important main objectives, for example guarding another unit or something on other specific positions. All movements will use pathfinding, or how to get quickly from one position to another.
The most common algorithm that is used in games like this is called A* (A star). It’s fast, it can be configured, it supports moving in 4 or 8 directions, it takes also into account costs per move (how many AP’s do I need to get there) by analyzing surrounding tiles, which is very convenient because all of the tiles on the map have already the obstacles factor. There are also many tutorials, pseudo / source code how to implement this algorithm.
