Who can see what is pretty important in a game. For the rendering, it indicates what is going to be drawn on the screen. For the AI, it influences the action to be taken.

I don’t have AI yet, but visibility is on the critical path to getting it working. It can be used for the rendering too, so I can kill two birds with one stone.

The key is the good old navigation zones that I built for pathfinding. The zones are connected by portals, so to calculate visibility I just have to trace through zones recursively until I can’t see any more portals. This provides a tree structure that can be used to determine visibility of anything from the root position: e.g. a map square or an object.

The map looks a lot nicer with fog-of-war turned on.

Advertisements