Currently the developers are putting their own money into JC2-MP to keep the servers online.

Please take a few seconds of your time and disable your AdBlock plugin for our website.

Ad revenue is not going to developers, it is used purely for covering our hosting costs.

 

You are also free to donate, which removes all ads from our website!

Patch 0.3 was just released! Full changelog here: https://t.co/4A50m6IKen

2 years ago

Advertisement
October 15, 2019, 09:19:03 am

Author Topic: Random Maze Generator  (Read 2140 times)

SinisterRectus

  • JC2-MP Betatester
  • Sr. Member
  • *****
  • Posts: 451
    • View Profile
Random Maze Generator
« on: February 01, 2016, 04:19:31 pm »
I threw this together a few months ago and haven't worked on it since. It's not a finished product, but I think it's still pretty interesting, so I decided to share it here.

Random Maze Generator









This module includes scripts for randomly generating an interactive maze.

Mazes are generated by creating an instance of a Maze class on the server. This uses a WorldNetworkObject to sync mazes across clients with a few settings:

- Seed: Client-side assets are populated according to this number
- Position: Where the maze is located in the game world
- Size: Side-length of a maze in meters. Must be a power of 2 >= step.
- Step: Side-length of a cell in meters. Must be a power of 2 <= size.
- Height: How tall the walls of the maze are. Must be a power of 2 >= 2.

An example Maze is generated on ModuleLoad in the MazeManager script with position = (0, 201, 0), size = 128, step= 16, and height = 16.

In the client MazeManager script, whether ceilings are constructed can be toggled with the self.ceilings boolean.

As far as maze construction goes, a square grid is first created, and then a random path is carved through it using a depth-first search algorithm. Openings are also created at the northwest and southeast cells. The maze is then populated by various client entities.

A brick wall is placed where ever there is no open connection to a neighboring cell. This object is 4 meters long and 2 meters high, and what causes the power of 2 limitations in the maze settings.

Torches, complete with static object, fire effect, and light effect, are placed at every corner of the maze.

Floors and ceilings (if enabled) are added. A slight offset is used to prevent Z-fighting. Due to the finite size of the object used, if the step size is < 8, then only one object is required. If the step size is >= 8, then multiple objects are used per cell, depending upon the actual size of the cell.

If the step (cell size) is >= 8 and the maze height is >= 8, then large pillar objects and rubble fires are randomly placed throughout the maze. The fires do damage players who enter them.

If the step (cell size) is >= 8, then pickups are placed in all dead-ends. When contacted, the pickups are destroyed and a sound effect is played. They are not synced, though. This is one of the very next things that needs to be worked on.

After the maze is generated, all objects are spawned. These are buffered in order to prevent weird behavior such as invisible client effects or crashes. No more than 1 pickup, 1 rubble fire, 1 torch, and 1000 additional static objects are spawned per tick.

Let me know if you have any questions, suggestions, or comments about this.

Download From GitHub Here
« Last Edit: February 01, 2016, 09:37:06 pm by SinisterRectus »

Dev_34

  • Full Member
  • ***
  • Posts: 158
    • View Profile
Re: Random Maze Generator
« Reply #1 on: February 01, 2016, 09:26:49 pm »
This script is pretty awesome and I'll definitely be using this logic in some way. Thanks!  :)