Passability Map
It's a common problem in gaming and thus a wheel that has already been invented. How to figure out where you can walk on a map when some squares are impassable? Well, here's how Cultura does it and it's nothing fancy.
For each tile in the game there is an associated 32-bit integer which describes the passability. How to read this integer? It's a bit map. We can set various values. In general 0 means nothing is there and thus is definitely passable. We could set the first bit meaning there is water there... only units that can pass through water may go through it. And so each type of terrain can have an associated passability flag.
In Cultura, this passability map is only updated when you construct buildings (which likewise use the map to figure out if your placement is valid). Many parts of a building are passable (for example, a floor!) and some are not (for example a wall). Then there are doors.
The main rule is nothing can be smaller than 1x1. In that way there's no walls or doors smaller than 1x1 the pathfinding algorithm can simply look at a tile and state whether or not a unit can walk on it. Very simple.
So now all buildings are 4x4 structures, the outer is a wall, there's a door and the inner 2x2 area is walkable floor area. Hooray!
No comments:
Post a Comment