RaRa_LevelGenerationSystem - robblofield/Tomebound-Docs GitHub Wiki

RaRa Level Generation System – Overview Documentation

1. RaRa_LevelEnums.cs

Responsibilities:

  • Holds shared enums for consistent classification of levels and districts.
  • Enums:
    • District: Midday, Dusk, Midnight, Dawn
    • LevelType: Plaza, Battleground, Gauntlet, Observatory, Treasury, Merchant, Boss

2. RaRa_LevelComponentProfile.cs (Sub-ScriptableObject)

Responsibilities:

  • Defines data for a single level component (room/section).
  • Fields:
    • LevelType levelComponentType β†’ Type of the level component.
    • GameObject levelComponentPrefab β†’ Prefab to instantiate for this component.
    • bool IsSingleUseOnly β†’ Whether this component can only be spawned once (narrative/special rooms).

3. RaRa_LevelGenerationProfile.cs (Main Pool ScriptableObject)

Responsibilities:

  • A pool of level component profiles for a given combination of district + level type.
  • Fields:
    • District district β†’ Which district this pool applies to.
    • LevelType levelType β†’ Which type of levels this pool contains.
    • List<RaRa_LevelComponentProfile> levelGenerationPool β†’ All components eligible for spawning.

4. RaRa_NoFlyList.cs

Responsibilities:

  • A runtime pool tracking single-use-only components that can’t be spawned again this session.
  • Key Methods:
    • AddToNoFlyList(RaRa_LevelComponentProfile profile)
    • IsInNoFlyList(RaRa_LevelComponentProfile profile)
    • ClearNoFlyList()

5. RaRa_LevelGenerationSystem.cs (Runtime MonoBehaviour)

Responsibilities:

  • The runtime procedural generation system.

  • Key Features Implemented:

    1. Queue Generation:
      • Generates a list (generatedQueue) of components to spawn.
      • Randomly selects components from the pool.
      • Skips single-use components already in the No-Fly List.
      • Adds single-use components to the No-Fly List once queued.
    2. Spawning Logic:
      • Instantiates prefabs in order along the X-axis, offset by 5m each.
      • Organizes spawned prefabs under an optional spawnParent.
      • Tracks spawned prefabs for clearing.
  • Key Methods:

    • GenerateLevelQueue() β†’ Builds the queue.
    • SpawnGeneratedQueue() β†’ Instantiates prefabs at runtime.
    • ClearSpawnedPrefabs() β†’ Destroys all spawned prefabs.
    • GetGeneratedQueue() β†’ Returns the current queue.

6. Editor Tools

  • Custom Inspectors for:
    • RaRa_LevelGenerationProfile β†’ Enum dropdowns, warnings for mismatched types.
    • RaRa_LevelGenerationSystem β†’ Buttons for:
      • Generate Level Queue
      • Spawn Generated Queue
      • Clear Spawned Prefabs
      • Clear No-Fly List

Remaining Features / To-Do List

1. Room Rarity System

  • Initial Rarity: Each component profile gets a rarity weight (e.g., Common, Rare, Epic, or just a float/int weight).
  • Repeat Rarity Modifier: After being spawned once, a component’s chance to be picked decreases further (stacks for each repeat).

2. Doorway & Room Connectivity

  • Each prefab can have up to 4 doorway spawn points.
  • Spawn 1–4 active doorways randomly for each room.
  • Mark certain rooms as through-rooms or dead ends programmatically (dead ends keep only 1 doorway active).

3. Rune Gate & Rune Blocks System

  • One room in the queue will be marked as Rune Gate Room:
    • When spawned, finds the Rune Gate component in its prefab and activates it.
  • Other rooms:
    • Have ~20 possible rune block spawn points.
    • Randomly activate a certain number of rune block spawns.
    • Communicate with the existing Rune Gate system to:
      • Assign runes to the blocks.
      • Prime the Rune Gate to expect those specific rune combinations.

4. Doorway Connectivity Graph

  • Procedurally connect doorways:
    • Either randomly or via a more intelligent graph-based system.
    • Ensure:
      • A valid loop exists (all rooms are accessible via at least 1 continuous path).
      • Dead ends are respected (F -> G example).
      • No isolated/unreachable rooms.

5. Misc. Polish / Future Systems

  • Rotation/Position Variation for room placement.
  • Grid / NavMesh Based Placement instead of simple X-axis offset.
  • Debug Visualization Tools (gizmos for doorway connections).
  • Save/Load Seeds for deterministic level generation.

Next Step Proposal

  1. Implement the Room Rarity System first (weights + repeat modifiers).
  2. Move into Doorway Connectivity & Through-Room Logic (larger procedural system).
  3. Then integrate the Rune Gate & Rune Blocks system.