feat: shared creature root, enemy definitions, defend duty, and player downing

This commit is contained in:
Rijad Zuzo
2026-08-12 00:16:48 +02:00
parent 6de6d25bf5
commit 661d53f31a
23 changed files with 653 additions and 76 deletions
+39 -1
View File
@@ -33,6 +33,7 @@ signal combatant_died(combatant_id: StringName)
signal raid_started(raider_ids: Array[StringName])
signal war_resolved(outcome: StringName)
signal war_aborted
signal player_downed
var village := SimVillage.new()
var player_system := PlayerCitizenSystem.new()
@@ -98,6 +99,8 @@ func _ready() -> void:
conflict_system.raid_started.connect(func(raider_ids): raid_started.emit(raider_ids))
conflict_system.war_resolved.connect(func(outcome): war_resolved.emit(outcome))
conflict_system.war_aborted.connect(func(): war_aborted.emit())
conflict_system.player_damaged.connect(_on_player_damaged)
conflict_system.player_downed.connect(func(): player_downed.emit())
action_selector.relationship_system = relationship_system
var definition_errors := SimulationDefinitions.validate()
if not definition_errors.is_empty():
@@ -258,8 +261,16 @@ func _select_action_if_idle(npc: SimNPC, previous_state: StringName) -> void:
record_narrative_event(SimulationIds.EVENT_VILLAGER_WEAK, npc.id)
var helper := get_active_opportunity_helper()
var animal_feed_available := animal_care.has_available_feed_target(npc.id)
var war_raid_active := conflict_system.is_raiding()
var selection := action_selector.select_action(
npc, village, clock.time_of_day(), npcs, helper, _population_view, animal_feed_available
npc,
village,
clock.time_of_day(),
npcs,
helper,
_population_view,
animal_feed_available,
war_raid_active
)
if selection == null:
return
@@ -390,6 +401,8 @@ func _apply_action_completion(
pass
SimulationIds.ACTION_PATROL, SimulationIds.ACTION_STUDY, SimulationIds.ACTION_REST, SimulationIds.ACTION_WANDER:
village.apply_npc_task(npc)
SimulationIds.ACTION_DEFEND:
village.apply_metric_delta(&"safety", 0.5)
if debug_logs and completed_task == SimulationIds.ACTION_SLEEP:
print("[SimulationManager] ", npc.npc_name, " completed sleep at home")
@@ -1138,6 +1151,31 @@ func harvest_resource_node(node: ResourceNode) -> float:
func advance_player_needs() -> void:
player_system.advance_needs(village.food_modifier)
player_system.player_state.advance_health()
_sync_player_combatant()
func _sync_player_combatant() -> void:
conflict_system.set_player_health(
player_system.player_state.get_health(), player_system.player_state.is_downed()
)
func _on_player_damaged(amount: float) -> void:
player_system.player_state.take_damage(amount)
_sync_player_combatant()
func update_player_combatant(position: Vector3) -> void:
conflict_system.set_player_combatant_position(position)
func player_is_downed() -> bool:
return player_system.player_state.is_downed()
func get_player_health() -> float:
return player_system.player_state.get_health()
func get_season() -> StringName: