fix: make C3 AI behavior policies explicit
This commit is contained in:
@@ -5,26 +5,63 @@ const PathfindingType = preload("res://scripts/domain/ai/pathfinding.gd")
|
||||
const MELEE_RANGE := 1
|
||||
|
||||
# C3 deliberately only selects movement and melee. Ranged attacks remain C4.
|
||||
# Every catalog behavior is listed deliberately. Unknown data must remain safe
|
||||
# and observable rather than inheriting an accidental aggressive fallback.
|
||||
static func decide(enemy: ActorState, player: ActorState, map: GridMapState, blocked_cells: Dictionary[Vector2i, bool] = {}) -> Dictionary:
|
||||
var behavior := enemy.ai_behavior
|
||||
if behavior == &"legacy":
|
||||
return _legacy_decide(enemy, player, map, blocked_cells)
|
||||
if behavior == &"passive" or behavior == &"defensive":
|
||||
return {"kind": &"idle"}
|
||||
var distance := _manhattan_distance(enemy.cell, player.cell)
|
||||
# Enemy data defines tactical detection distance. Pathfinding subsequently
|
||||
# handles occluders rather than treating a wall/door as a reason to forget a
|
||||
# target that is already within the enemy's vision range.
|
||||
if distance > enemy.vision_range:
|
||||
return {"kind": &"idle"}
|
||||
if behavior == &"ranged":
|
||||
if distance <= enemy.attack_range:
|
||||
match enemy.ai_behavior:
|
||||
&"legacy":
|
||||
return _legacy_decide(enemy, player, map, blocked_cells)
|
||||
&"passive", &"defensive":
|
||||
return {"kind": &"idle"}
|
||||
return _move_toward(enemy, player, map, blocked_cells)
|
||||
if distance == MELEE_RANGE:
|
||||
&"aggressive":
|
||||
return _aggressive_decide(enemy, player, map, blocked_cells)
|
||||
&"guard":
|
||||
return _guard_decide(enemy, player, map, blocked_cells)
|
||||
&"boss":
|
||||
return _boss_aggressive_decide(enemy, player, map, blocked_cells)
|
||||
&"ranged":
|
||||
return _ranged_decide(enemy, player, map, blocked_cells)
|
||||
_:
|
||||
return _unsupported_behavior_decision(enemy.ai_behavior)
|
||||
|
||||
# Enemy data defines tactical detection distance. Pathfinding subsequently
|
||||
# handles occluders rather than treating a wall/door as a reason to forget a
|
||||
# target that is already within the enemy's vision range.
|
||||
static func _aggressive_decide(enemy: ActorState, player: ActorState, map: GridMapState, blocked_cells: Dictionary[Vector2i, bool]) -> Dictionary:
|
||||
if not _can_see_player(enemy, player):
|
||||
return {"kind": &"idle"}
|
||||
if _manhattan_distance(enemy.cell, player.cell) == MELEE_RANGE:
|
||||
return {"kind": &"melee"}
|
||||
return _move_toward(enemy, player, map, blocked_cells)
|
||||
|
||||
# Guards hold their post until the player enters their data-backed vision, then
|
||||
# use the same close/approach engagement rules as an aggressive enemy.
|
||||
static func _guard_decide(enemy: ActorState, player: ActorState, map: GridMapState, blocked_cells: Dictionary[Vector2i, bool]) -> Dictionary:
|
||||
return _aggressive_decide(enemy, player, map, blocked_cells)
|
||||
|
||||
# Bosses intentionally use this named aggressive profile in C3. Boss-specific
|
||||
# abilities and phases remain future behavior work rather than an implicit
|
||||
# fallback through the generic branch.
|
||||
static func _boss_aggressive_decide(enemy: ActorState, player: ActorState, map: GridMapState, blocked_cells: Dictionary[Vector2i, bool]) -> Dictionary:
|
||||
return _aggressive_decide(enemy, player, map, blocked_cells)
|
||||
|
||||
static func _ranged_decide(enemy: ActorState, player: ActorState, map: GridMapState, blocked_cells: Dictionary[Vector2i, bool]) -> Dictionary:
|
||||
if not _can_see_player(enemy, player):
|
||||
return {"kind": &"idle"}
|
||||
if _manhattan_distance(enemy.cell, player.cell) <= enemy.attack_range:
|
||||
return {"kind": &"idle"}
|
||||
return _move_toward(enemy, player, map, blocked_cells)
|
||||
|
||||
static func _can_see_player(enemy: ActorState, player: ActorState) -> bool:
|
||||
return _manhattan_distance(enemy.cell, player.cell) <= enemy.vision_range
|
||||
|
||||
static func _unsupported_behavior_decision(behavior: StringName) -> Dictionary:
|
||||
return {
|
||||
"kind": &"idle",
|
||||
"diagnostic": &"unsupported_ai_behavior",
|
||||
"behavior": behavior,
|
||||
}
|
||||
|
||||
static func _legacy_decide(enemy: ActorState, player: ActorState, map: GridMapState, blocked_cells: Dictionary[Vector2i, bool]) -> Dictionary:
|
||||
var delta := player.cell - enemy.cell
|
||||
if _manhattan_distance(enemy.cell, player.cell) == MELEE_RANGE:
|
||||
|
||||
@@ -49,6 +49,17 @@ static func append_enemy_response(state: GameState, results: Array[TurnResult])
|
||||
if enemy == null or not enemy.is_alive():
|
||||
continue
|
||||
var decision: Dictionary = EnemyBehaviorsType.decide(enemy, state.player, state.map, occupied)
|
||||
if decision.has("diagnostic"):
|
||||
results.append(TurnResultType.new(
|
||||
enemy.id,
|
||||
&"enemy_behavior_unsupported",
|
||||
enemy.cell,
|
||||
enemy.cell,
|
||||
&"",
|
||||
0,
|
||||
"%s holds: unsupported AI behavior '%s'." % [_actor_label(enemy.id), decision.behavior],
|
||||
{"diagnostic": decision.diagnostic, "behavior": decision.behavior}
|
||||
))
|
||||
match decision.get("kind", &"idle"):
|
||||
&"melee":
|
||||
_append_combat_results(results, CombatEngineType.new().resolve_attack(enemy, state.player), enemy.cell, state.player.cell)
|
||||
|
||||
Reference in New Issue
Block a user