0
\$\begingroup\$

I'm working on a fog-of-war system for a tile-based strategy game (e.g. Civilization), and I need to store which parts of the map have been revealed so the game can be saved/loaded properly. The revealed areas can be irregular shapes, obviously, as the player explores different parts of the map at a time.

The most obvious way to do this would be to have a bool isRevealed variable on each Tile object in the data model, but the terrains are being generated procedurally as-needed and not saved on a per-tile basis. Another option would be to store a giant list of Vector2 coordinates (as in "they've revealed {0,0} and {0,1} and {1,0} and {1,1} and..."), but that's super-inefficient for large maps.

Much better would be to store a list of Rects (as in "they've revealed {0,0,50,40} and {0,40,20,20} and..."). That would cut down massively on the amount of data stored, while still communicating the same info. Some of the straggler tiles around the edges would end up being 1x1 rects, but the main body of the explored area could be one giant Rect instead of an endless list of individual tiles.

I just can't figure out how to take a List(Vector2) and turn it into a List(Rect) like that, wrapping the points described into a set of bounds while leaving undiscovered areas out.

Is there a system for this? Some Unity "Bounds(Vector2)" method or something? It would be easy enough to find the single bounds of ALL the tiles, but that would end up including unexplored areas too. I need a List(Rect) which covers all relevant tiles, while excluding unexplored areas.

\$\endgroup\$
1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.