update scarcity
This commit is contained in:
+37
-13
@@ -439,15 +439,26 @@ func _start_game():
|
||||
|
||||
func _assign_random_spawn_positions():
|
||||
"""Assign random unique spawn positions to all players."""
|
||||
var spawn_locations = [
|
||||
Vector2i(0, 0), Vector2i(0, 1), Vector2i(0, 2), Vector2i(0, 3),
|
||||
Vector2i(0, 4), Vector2i(0, 5), Vector2i(0, 6), Vector2i(0, 7),
|
||||
Vector2i(0, 8), Vector2i(0, 9), Vector2i(0, 10), Vector2i(0, 11)
|
||||
]
|
||||
# Fetch all valid walkable positions from the generated map
|
||||
var valid_spawns = []
|
||||
var enhanced_gridmap = $EnhancedGridMap
|
||||
|
||||
if enhanced_gridmap:
|
||||
for x in range(enhanced_gridmap.columns):
|
||||
for z in range(enhanced_gridmap.rows):
|
||||
var ground = enhanced_gridmap.get_cell_item(Vector3i(x, 0, z))
|
||||
if ground == 0: # Walkable
|
||||
valid_spawns.append(Vector2i(x, z))
|
||||
|
||||
# Fallback if map generation failed or is empty
|
||||
if valid_spawns.size() < 12:
|
||||
print("Warning: Low spawn count! Adding defaults.")
|
||||
for i in range(12):
|
||||
if not Vector2i(0, i) in valid_spawns:
|
||||
valid_spawns.append(Vector2i(0, i))
|
||||
|
||||
# Shuffle spawn locations
|
||||
var shuffled_spawns = spawn_locations.duplicate()
|
||||
shuffled_spawns.shuffle()
|
||||
valid_spawns.shuffle()
|
||||
|
||||
# Get all players
|
||||
var all_players = get_tree().get_nodes_in_group("Players")
|
||||
@@ -455,9 +466,10 @@ func _assign_random_spawn_positions():
|
||||
# Assign positions
|
||||
var spawn_index = 0
|
||||
for player in all_players:
|
||||
if spawn_index >= shuffled_spawns.size():
|
||||
if spawn_index >= valid_spawns.size():
|
||||
print("Critical: Not enough spawn points for players!")
|
||||
break
|
||||
var spawn_pos = shuffled_spawns[spawn_index]
|
||||
var spawn_pos = valid_spawns[spawn_index]
|
||||
# Set position and sync to all clients
|
||||
player.current_position = spawn_pos
|
||||
player.position = player.grid_to_world(spawn_pos)
|
||||
@@ -900,13 +912,25 @@ func randomize_item_at_position(grid_position: Vector2i):
|
||||
var cell = Vector3i(grid_position.x, 1, grid_position.y)
|
||||
var current_item = enhanced_gridmap.get_cell_item(cell)
|
||||
|
||||
# If current item exists, replace it (scarcity aware)
|
||||
if current_item != -1:
|
||||
var rng = RandomNumberGenerator.new()
|
||||
rng.randomize()
|
||||
var new_item = rng.randi_range(7, 10)
|
||||
var scarcity_mgr = load("res://scripts/managers/scarcity_manager.gd")
|
||||
var new_item = 7
|
||||
|
||||
while new_item == current_item:
|
||||
if scarcity_mgr:
|
||||
new_item = scarcity_mgr.get_random_tile_id()
|
||||
# Try to ensure it changes, but respect scarcity
|
||||
var max_retries = 3
|
||||
while new_item == current_item and max_retries > 0:
|
||||
new_item = scarcity_mgr.get_random_tile_id()
|
||||
max_retries -= 1
|
||||
else:
|
||||
# Fallback
|
||||
var rng = RandomNumberGenerator.new()
|
||||
rng.randomize()
|
||||
new_item = rng.randi_range(7, 10)
|
||||
while new_item == current_item:
|
||||
new_item = rng.randi_range(7, 10)
|
||||
|
||||
sync_grid_item(cell.x, cell.y, cell.z, new_item)
|
||||
rpc("sync_grid_item", cell.x, cell.y, cell.z, new_item)
|
||||
|
||||
Reference in New Issue
Block a user