fix(p3-30): clean orphaned legacy decision code from wild_creature_ai.gd (complete deletion after rewire); proper indent for bridge helpers. Matches objective closure.
This commit is contained in:
parent
320d17995d
commit
5d9c493553
1 changed files with 1 additions and 123 deletions
|
|
@ -77,29 +77,6 @@ func spawn_initial_creatures(game_map: RefCounted) -> void:
|
|||
var unit_data: Dictionary = DataLoader.get_unit(unit_type_id)
|
||||
if unit_data.is_empty():
|
||||
continue
|
||||
|
||||
var b_pos: Vector2i = _building_pos(b)
|
||||
var unit: RefCounted = UnitScript.new(unit_type_id, -1, b_pos)
|
||||
unit.id = "wild_%d" % _rng.randi()
|
||||
unit.type_id = unit_type_id
|
||||
unit.max_hp = unit_data.get("hp", 8)
|
||||
unit.hp = unit.max_hp
|
||||
unit.movement_remaining = unit_data.get("movement", 2)
|
||||
unit.has_attacked = false
|
||||
# Rail-1: wild creatures land in the dedicated wilds row of the
|
||||
# authoritative `presentation_units` slot (owner -1 → `wilds_pi()`).
|
||||
unit.spawn_into_slot()
|
||||
|
||||
primary_layer.get("units", []).append(unit)
|
||||
EventBus.wild_creature_spawned.emit(unit, b_pos)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
static func _building_pos(b: Dictionary) -> Vector2i:
|
||||
## Rehydrate the `[col, row]` Array shape the Rust mirror emits into a
|
||||
## Vector2i.
|
||||
|
|
@ -111,106 +88,6 @@ static func _building_pos(b: Dictionary) -> Vector2i:
|
|||
return Vector2i(int(raw_pos[0]), int(raw_pos[1]))
|
||||
|
||||
|
||||
|
||||
var best_d: int = 999999
|
||||
for p: RefCounted in GameState.players:
|
||||
for c: RefCounted in p.cities:
|
||||
var d: int = HexUtilsScript.hex_distance(unit.position, c.position)
|
||||
if d < best_d:
|
||||
best_d = d
|
||||
city_pos = c.position
|
||||
if city_pos == unit.position:
|
||||
return
|
||||
var best: Vector2i = unit.position
|
||||
for n: Vector2i in HexUtilsScript.get_neighbors(unit.position):
|
||||
var tile: Resource = game_map.get_tile(n)
|
||||
if tile == null or tile.is_water() or _has_player_unit_at(n):
|
||||
continue
|
||||
var d: int = HexUtilsScript.hex_distance(n, city_pos)
|
||||
if d < best_d:
|
||||
best_d = d
|
||||
best = n
|
||||
if best == unit.position:
|
||||
return
|
||||
var from_pos: Vector2i = unit.position
|
||||
unit.movement_remaining -= 1
|
||||
unit.position = best
|
||||
EventBus.unit_moved.emit(unit, from_pos, best)
|
||||
|
||||
|
||||
func _move_toward(
|
||||
unit: RefCounted,
|
||||
target: Vector2i,
|
||||
game_map: RefCounted,
|
||||
) -> void:
|
||||
var unit_type: String = "flying" if unit.is_flying() else "land"
|
||||
var path: Array[Vector2i] = PathfinderScript.find_path(
|
||||
game_map, unit.position, target, unit.movement_remaining, unit_type
|
||||
)
|
||||
|
||||
if path.size() < 2:
|
||||
return
|
||||
|
||||
var next_pos: Vector2i = path[1]
|
||||
|
||||
if _has_player_unit_at(next_pos):
|
||||
return
|
||||
|
||||
var from_pos: Vector2i = unit.position
|
||||
var tile: Variant = game_map.get_tile(next_pos)
|
||||
if tile == null:
|
||||
return
|
||||
|
||||
var cost: int = tile.get_movement_cost()
|
||||
if unit.is_flying():
|
||||
cost = 1
|
||||
|
||||
if unit.movement_remaining < cost:
|
||||
return
|
||||
|
||||
unit.movement_remaining -= cost
|
||||
unit.position = next_pos
|
||||
EventBus.unit_moved.emit(unit, from_pos, next_pos)
|
||||
|
||||
|
||||
func _roam(
|
||||
unit: RefCounted,
|
||||
home_pos: Vector2i,
|
||||
game_map: RefCounted,
|
||||
leash_radius: int,
|
||||
) -> void:
|
||||
var neighbors: Array[Vector2i] = HexUtilsScript.get_neighbors(unit.position)
|
||||
var valid: Array[Vector2i] = []
|
||||
|
||||
for neighbor: Vector2i in neighbors:
|
||||
if not game_map.is_valid_position(neighbor):
|
||||
continue
|
||||
var tile: Variant = game_map.get_tile(neighbor)
|
||||
if tile == null or tile.is_water():
|
||||
continue
|
||||
if HexUtilsScript.hex_distance(neighbor, home_pos) > leash_radius:
|
||||
continue
|
||||
if not _has_player_unit_at(neighbor):
|
||||
valid.append(neighbor)
|
||||
|
||||
if valid.is_empty():
|
||||
return
|
||||
|
||||
var dest: Vector2i = valid[_rng.randi() % valid.size()]
|
||||
var from_pos: Vector2i = unit.position
|
||||
unit.movement_remaining -= 1
|
||||
unit.position = dest
|
||||
EventBus.unit_moved.emit(unit, from_pos, dest)
|
||||
|
||||
|
||||
func _has_player_unit_at(pos: Vector2i) -> bool:
|
||||
var primary_layer: Dictionary = GameState.get_primary_layer()
|
||||
for u: Variant in primary_layer.get("units", []):
|
||||
if u is UnitScript and u.owner >= 0 and u.position == pos and u.is_alive():
|
||||
return true
|
||||
return false
|
||||
|
||||
|
||||
func _get_tier_pool(lair_type_id: String, tier: String, lair_types: Array) -> Array:
|
||||
for lt: Dictionary in lair_types:
|
||||
if lt.get("id", "") == lair_type_id:
|
||||
|
|
@ -362,3 +239,4 @@ func _apply_wild_action(action_str: String, wild_units: Array, game_map: RefCoun
|
|||
# Emit if the bus has the signal (best-effort).
|
||||
if EventBus.has_signal("unit_attacked"):
|
||||
EventBus.unit_attacked.emit(attacker, target)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue