update scarcity
This commit is contained in:
@@ -105,17 +105,52 @@ func validate_item_indices():
|
||||
func generate_grid(floor_index: int = -1):
|
||||
if floor_index == -1:
|
||||
clear()
|
||||
for y in range(floors):
|
||||
generate_floor(y)
|
||||
# Generate Floor 0 using Modular Generator
|
||||
var map_gen = load("res://scripts/generators/modular_map_generator.gd")
|
||||
if map_gen:
|
||||
var generator = map_gen.new()
|
||||
# Pick random shape
|
||||
var rng = RandomNumberGenerator.new()
|
||||
rng.randomize()
|
||||
var shape = rng.randi() % 4 # 0-3 (Rect, Islands, Maze, Rooms)
|
||||
generator.generate_map(self, columns, rows, shape)
|
||||
else:
|
||||
generate_floor(0)
|
||||
|
||||
# Generate upper floors (just Items, initially empty or randomized)
|
||||
for y in range(1, floors):
|
||||
# Just clear them initially or fill based on generator?
|
||||
# Usually Floor 1 is items on top of Floor 0.
|
||||
# Let's clean them first.
|
||||
clear_floor(y)
|
||||
|
||||
else:
|
||||
clear_floor(floor_index)
|
||||
generate_floor(floor_index)
|
||||
if floor_index == 0:
|
||||
var map_gen = load("res://scripts/generators/modular_map_generator.gd")
|
||||
if map_gen:
|
||||
var generator = map_gen.new()
|
||||
var rng = RandomNumberGenerator.new()
|
||||
rng.randomize()
|
||||
var shape = rng.randi() % 4
|
||||
generator.generate_map(self, columns, rows, shape)
|
||||
else:
|
||||
clear_floor(floor_index)
|
||||
generate_floor(floor_index)
|
||||
|
||||
update_grid_data()
|
||||
initialize_astar()
|
||||
update_astar_costs()
|
||||
|
||||
# After generating map, if we are auto-randomizing, we should randomize items (Floor 1)
|
||||
# ONLY on valid Floor 0 tiles.
|
||||
if auto_randomize:
|
||||
randomize_grid(1) # Floor 1 items
|
||||
|
||||
# Explicitly ensure Floor 0 is never randomized with items via standard randomize_grid
|
||||
# (randomize_grid(0) would overwrite the map with items)
|
||||
|
||||
func generate_floor(floor_index: int):
|
||||
# Fallback / Standard generation
|
||||
if not mesh_library:
|
||||
print("Error: No MeshLibrary assigned to GridMap")
|
||||
return
|
||||
@@ -124,12 +159,14 @@ func generate_floor(floor_index: int):
|
||||
|
||||
current_mesh_library = mesh_library
|
||||
var item_list = mesh_library.get_item_list()
|
||||
if item_list.size() < 5:
|
||||
print("Warning: MeshLibrary should have at least 5 items")
|
||||
|
||||
for x in range(columns):
|
||||
for z in range(rows):
|
||||
set_cell_item(Vector3i(x, floor_index, z), normal_items[0])
|
||||
if floor_index == 0:
|
||||
for x in range(columns):
|
||||
for z in range(rows):
|
||||
set_cell_item(Vector3i(x, floor_index, z), normal_items[0])
|
||||
else:
|
||||
# Upper floors start empty unless specified
|
||||
pass
|
||||
|
||||
# Grid operations
|
||||
func clear_floor(floor_index: int):
|
||||
@@ -198,15 +235,33 @@ func randomize_floor(floor_index: int):
|
||||
var rng = RandomNumberGenerator.new()
|
||||
rng.randomize()
|
||||
|
||||
var scarcity_mgr = null
|
||||
if floor_index == 1:
|
||||
scarcity_mgr = load("res://scripts/managers/scarcity_manager.gd")
|
||||
|
||||
for x in range(columns):
|
||||
for z in range(rows):
|
||||
var random_value = rng.randi() % 100
|
||||
var item_index
|
||||
if random_value < 80:
|
||||
item_index = normal_items[rng.randi() % normal_items.size()]
|
||||
# IMPORTANT: Only place items if Floor 0 has a walkable tile
|
||||
var floor_0_item = get_cell_item(Vector3i(x, 0, z))
|
||||
var is_ground = (floor_0_item == normal_items[0]) # Assuming 0 is ground
|
||||
|
||||
if not is_ground:
|
||||
set_cell_item(Vector3i(x, floor_index, z), -1) # Clear item if no ground
|
||||
continue
|
||||
|
||||
# If Floor 1 and ScarcityManager exists, use it
|
||||
if floor_index == 1 and scarcity_mgr:
|
||||
var item_index = scarcity_mgr.get_random_tile_id()
|
||||
set_cell_item(Vector3i(x, floor_index, z), item_index)
|
||||
else:
|
||||
item_index = non_walkable_items[rng.randi() % non_walkable_items.size()]
|
||||
set_cell_item(Vector3i(x, floor_index, z), item_index)
|
||||
# Default behavior
|
||||
var random_value = rng.randi() % 100
|
||||
var item_index
|
||||
if random_value < 80:
|
||||
item_index = normal_items[rng.randi() % normal_items.size()]
|
||||
else:
|
||||
item_index = non_walkable_items[rng.randi() % non_walkable_items.size()]
|
||||
set_cell_item(Vector3i(x, floor_index, z), item_index)
|
||||
|
||||
func randomize_grid_custom(randomize_states: Array, floor_index: int = -1):
|
||||
if not mesh_library:
|
||||
|
||||
Reference in New Issue
Block a user