feat: add final floor victory and deep generation scale
This commit is contained in:
@@ -1,12 +1,13 @@
|
||||
class_name FloorGenerator
|
||||
extends RefCounted
|
||||
|
||||
const MAP_SIZE := Vector2i(80, 50)
|
||||
const ROOM_COUNT := 8
|
||||
const ROOM_MIN_SIZE := Vector2i(5, 4)
|
||||
const ROOM_MAX_SIZE := Vector2i(10, 8)
|
||||
const MAX_MAP_SIZE := Vector2i(700, 350)
|
||||
const MAX_ROOM_COUNT := 500
|
||||
const SHALLOW_ROOM_MIN_SIZE := Vector2i(5, 4)
|
||||
const SHALLOW_ROOM_MAX_SIZE := Vector2i(10, 8)
|
||||
const DEEP_ROOM_MIN_SIZE := Vector2i(4, 3)
|
||||
const DEEP_ROOM_MAX_SIZE := Vector2i(6, 5)
|
||||
const ROOM_PADDING := 2
|
||||
const ROOM_PLACEMENT_ATTEMPTS := 256
|
||||
const SHOP_ACTIVE_FROM_FLOOR := 3
|
||||
const BOSS_FLOOR_INTERVAL := 5
|
||||
const GUILD_ROOM_CHANCE := 0.35
|
||||
@@ -33,10 +34,33 @@ const RoomGraphType = preload("res://scripts/domain/world/room_graph.gd")
|
||||
const FloorPopulatorType = preload("res://scripts/domain/world/floor_populator.gd")
|
||||
const EconomyType = preload("res://scripts/domain/items/economy.gd")
|
||||
|
||||
# The profile deliberately caps the ASCII-inspired growth before maps become
|
||||
# impractical. It is also the sole sizing input to generation, making a seed
|
||||
# and floor number reproduce exactly the same layout.
|
||||
static func generation_profile(floor_number: int) -> Dictionary:
|
||||
if floor_number <= 1:
|
||||
return {
|
||||
"map_size": Vector2i(80, 50),
|
||||
"target_room_count": 8,
|
||||
"room_min_size": SHALLOW_ROOM_MIN_SIZE,
|
||||
"room_max_size": SHALLOW_ROOM_MAX_SIZE,
|
||||
}
|
||||
var normalized_floor := maxi(1, floor_number)
|
||||
return {
|
||||
"map_size": Vector2i(
|
||||
mini(MAX_MAP_SIZE.x, 180 + normalized_floor * 30),
|
||||
mini(MAX_MAP_SIZE.y, 90 + normalized_floor * 15)
|
||||
),
|
||||
"target_room_count": mini(MAX_ROOM_COUNT, 150 + normalized_floor * 20),
|
||||
"room_min_size": DEEP_ROOM_MIN_SIZE,
|
||||
"room_max_size": DEEP_ROOM_MAX_SIZE,
|
||||
}
|
||||
|
||||
static func generate(seed: String, floor_number: int, catalog: ContentCatalog) -> FloorState:
|
||||
var rng := DeterministicRngType.from_seed("%s-floor%d" % [seed, floor_number])
|
||||
var rooms := _place_rooms(rng)
|
||||
var map := GridMapStateType.new(MAP_SIZE, GridMapStateType.CellKind.WALL)
|
||||
var profile := generation_profile(floor_number)
|
||||
var rooms := _place_rooms(rng, profile)
|
||||
var map := GridMapStateType.new(profile["map_size"], GridMapStateType.CellKind.WALL)
|
||||
for room in rooms:
|
||||
_carve_room(map, room)
|
||||
|
||||
@@ -63,6 +87,7 @@ static func generate(seed: String, floor_number: int, catalog: ContentCatalog) -
|
||||
floor.entrance = _room_center(rooms[entrance_index].bounds)
|
||||
floor.exit = _room_center(rooms[exit_index].bounds)
|
||||
floor.map.set_cell(floor.exit, GridMapStateType.CellKind.STAIRS)
|
||||
floor.metadata["generation_profile"] = profile.duplicate(true)
|
||||
floor.metadata["room_graph"] = graph.to_dict()
|
||||
floor.metadata["tree_door_cells"] = tree_door_cells
|
||||
var colony_size := EconomyType.colony_size_for_floor(seed, floor_number)
|
||||
@@ -72,6 +97,28 @@ static func generate(seed: String, floor_number: int, catalog: ContentCatalog) -
|
||||
FloorPopulatorType.populate(floor, catalog, seed)
|
||||
return floor
|
||||
|
||||
# Grid slots provide a bounded, deterministic fallback-free layout. Their
|
||||
# spacing includes the existing room padding invariant, while sizes and room
|
||||
# contents still consume the seeded RNG.
|
||||
static func _place_rooms(rng: DeterministicRng, profile: Dictionary) -> Array[RoomState]:
|
||||
var map_size: Vector2i = profile["map_size"]
|
||||
var target_room_count := int(profile["target_room_count"])
|
||||
var room_min_size: Vector2i = profile["room_min_size"]
|
||||
var room_max_size: Vector2i = profile["room_max_size"]
|
||||
var slot_size := room_max_size + Vector2i.ONE * ROOM_PADDING * 2
|
||||
var columns := (map_size.x - 2) / slot_size.x
|
||||
var rows := (map_size.y - 2) / slot_size.y
|
||||
assert(target_room_count <= columns * rows, "Generation profile must fit its room lattice")
|
||||
var rooms: Array[RoomState] = []
|
||||
for room_index in range(target_room_count):
|
||||
var width := room_min_size.x + rng.next_int() % (room_max_size.x - room_min_size.x + 1)
|
||||
var height := room_min_size.y + rng.next_int() % (room_max_size.y - room_min_size.y + 1)
|
||||
var column := room_index % columns
|
||||
var row := room_index / columns
|
||||
var position := Vector2i(1 + column * slot_size.x, 1 + row * slot_size.y)
|
||||
rooms.append(RoomStateType.new(StringName("room_%03d" % room_index), Rect2i(position, Vector2i(width, height))))
|
||||
return rooms
|
||||
|
||||
# Beds must be installed before population so the occupancy-aware population
|
||||
# pass cannot place an NPC on a safe room's resting tile.
|
||||
static func _materialize_safe_room_beds(floor: FloorState) -> void:
|
||||
@@ -86,48 +133,6 @@ static func _materialize_safe_room_beds(floor: FloorState) -> void:
|
||||
bed_cells.append(bed_cell)
|
||||
floor.metadata["bed_cells"] = bed_cells
|
||||
|
||||
static func _place_rooms(rng: DeterministicRng) -> Array[RoomState]:
|
||||
var rooms: Array[RoomState] = []
|
||||
for room_index in range(ROOM_COUNT):
|
||||
var placed := false
|
||||
for _attempt in range(ROOM_PLACEMENT_ATTEMPTS):
|
||||
var bounds := _random_room_bounds(rng)
|
||||
if _has_required_padding(bounds, rooms):
|
||||
rooms.append(RoomStateType.new(StringName("room_%02d" % room_index), bounds))
|
||||
placed = true
|
||||
break
|
||||
if not placed:
|
||||
# The fixed 80x50 B2 map always supports this minimum-size fallback.
|
||||
# Never return a partial layout after exhausting random placement attempts.
|
||||
return _fallback_rooms()
|
||||
return rooms
|
||||
|
||||
static func _fallback_rooms() -> Array[RoomState]:
|
||||
var rooms: Array[RoomState] = []
|
||||
var positions := [
|
||||
Vector2i(3, 5), Vector2i(20, 5), Vector2i(37, 5), Vector2i(54, 5),
|
||||
Vector2i(3, 20), Vector2i(20, 20), Vector2i(37, 20), Vector2i(54, 20),
|
||||
]
|
||||
for room_index in range(ROOM_COUNT):
|
||||
rooms.append(RoomStateType.new(
|
||||
StringName("room_%02d" % room_index),
|
||||
Rect2i(positions[room_index], ROOM_MIN_SIZE)
|
||||
))
|
||||
return rooms
|
||||
|
||||
static func _random_room_bounds(rng: DeterministicRng) -> Rect2i:
|
||||
var width := ROOM_MIN_SIZE.x + rng.next_int() % (ROOM_MAX_SIZE.x - ROOM_MIN_SIZE.x + 1)
|
||||
var height := ROOM_MIN_SIZE.y + rng.next_int() % (ROOM_MAX_SIZE.y - ROOM_MIN_SIZE.y + 1)
|
||||
var x := 1 + rng.next_int() % (MAP_SIZE.x - width - 1)
|
||||
var y := 1 + rng.next_int() % (MAP_SIZE.y - height - 1)
|
||||
return Rect2i(x, y, width, height)
|
||||
|
||||
static func _has_required_padding(candidate: Rect2i, rooms: Array[RoomState]) -> bool:
|
||||
for room in rooms:
|
||||
if candidate.grow(ROOM_PADDING).intersects(room.bounds.grow(ROOM_PADDING)):
|
||||
return false
|
||||
return true
|
||||
|
||||
static func _carve_room(map: GridMapState, room: RoomState) -> void:
|
||||
for y in range(room.bounds.position.y, room.bounds.end.y):
|
||||
for x in range(room.bounds.position.x, room.bounds.end.x):
|
||||
|
||||
Reference in New Issue
Block a user