Skip to content

Random Maps

PH77SER edited this page May 7, 2024 · 2 revisions

the random map generation code is BASED on this https://github.com/GarnetKane99/RandomWalkerAlgo_YT

in essence, you have a data structure called Grid, which can be ONE_ONE, TWO_ONE, TWO_TWO, CONTROL_ROOM and EMPTY

  1. generate an empty MapWidth x MapHeight grid, datatype Grid. fill it with Grid.EMPTY
  2. spawn some "walkers" in the middle, and let them walk from the middle, and wherever they walk, they turn Grid.EMPTY into Grid.ONE_ONE. this represents a ROOM SPACE for now, not neccesarily a 1x1 room.
  3. randomly pick a point in this until you hit a Grid.ONE_ONE, and turn it into Grid.CONTROL_ROOM. cuz only one spawns
  4. run through every tile in the grid. if it's ONE_ONE check it's neighbors to see if you can spawn a 2x2 room. roll the chance to get a 2x2 room, and if successful, change the tiles to Grid.TWO_TWO and run DrawTwoByTwo().
  5. similar logic for 2x1 vertical, and 2x1 horizontal rooms, and DrawTwoByOneVertical()/Horizontal()
  6. run through the entire grid again. if we land on a ONE_ONE room, draw it. (note: drawing means spawning all the assets in it so they're in the actual unity scene). (note: in the running of the Draw commands, we also spawn navmeshes on the whole map corresponding to each room)
  7. bake the navmesh so we have one big area where AI can walk on
  8. run PostMapGenFunction. this will generate doors so they do not interfere with A.I. pathfinding and also run PostmapGenScript for anything else.

Clone this wiki locally