feat: let villagers witness and trust the player restock

This commit is contained in:
Rijad Zuzo
2026-08-10 23:36:47 +02:00
parent 9ed985d6a3
commit f72aa659d2
8 changed files with 296 additions and 26 deletions
+24 -8
View File
@@ -11,20 +11,25 @@ func observe_event(event: EconomicEventRecord, npcs: Array[SimNPC]) -> Array[Kno
var learned: Array[KnownEventStateRecord] = []
if not is_knowable_event(event):
return learned
var actor := _find_npc(int(event.data["actor_id"]), npcs)
if actor == null:
var actor_id := int(event.data["actor_id"])
var is_player_actor := actor_id == SimulationIds.PLAYER_ACTOR_ID
var actor := null if is_player_actor else _find_npc(actor_id, npcs)
if actor == null and not is_player_actor:
return learned
var event_id := int(event.data["event_id"])
var acquired_tick := int(event.data["tick"])
var actor_record := _remember(
actor.id, event_id, SimulationIds.KNOWLEDGE_ACQUISITION_PERFORMED, acquired_tick
)
if actor_record != null:
learned.append(actor_record)
if actor != null:
var actor_record := _remember(
actor.id, event_id, SimulationIds.KNOWLEDGE_ACQUISITION_PERFORMED, acquired_tick
)
if actor_record != null:
learned.append(actor_record)
var witness_radius_squared := WITNESS_RADIUS * WITNESS_RADIUS
var event_position := event.get_world_position()
for npc in npcs:
if npc.id == actor.id or npc.is_dead:
if npc.is_dead:
continue
if not is_player_actor and npc.id == actor.id:
continue
if npc.position.distance_squared_to(event_position) > witness_radius_squared:
continue
@@ -247,6 +252,17 @@ static func is_knowable_event(event: EconomicEventRecord) -> bool:
return false
if event_type == SimulationIds.EVENT_STORAGE_DEPOSITED:
return item_id == SimulationIds.RESOURCE_FOOD
if event_type == SimulationIds.EVENT_RESOURCE_EXTRACTED:
var player_actor_id := int(event.data["actor_id"])
if player_actor_id != SimulationIds.PLAYER_ACTOR_ID:
return false
return (
StringName(event.data["destination_id"])
in [
SimulationIds.STORAGE_VILLAGE_PANTRY,
SimulationIds.STORAGE_VILLAGE_WOODPILE,
]
)
if event_type != SimulationIds.EVENT_STORAGE_WITHDRAWN:
return false
var actor_id := int(event.data["actor_id"])