feat: enforce activity site capacity
This commit is contained in:
@@ -14,7 +14,7 @@ func resolve(
|
||||
npc, origin, definition, simulation_manager, active_world_adapter
|
||||
)
|
||||
SimulationIds.TARGET_ACTIVITY:
|
||||
return active_world_adapter.get_activity_target(npc.current_task, origin)
|
||||
return _resolve_activity(npc, origin, simulation_manager, active_world_adapter)
|
||||
SimulationIds.TARGET_FREE:
|
||||
return {
|
||||
"target_id": "", "position": origin + simulation_manager.get_wander_offset(npc.id)
|
||||
@@ -49,6 +49,36 @@ func _resolve_resource(
|
||||
return best
|
||||
|
||||
|
||||
func _resolve_activity(
|
||||
npc: SimNPC, origin: Vector3, simulation_manager: Node, active_world_adapter: Node
|
||||
) -> Dictionary:
|
||||
if not active_world_adapter.has_method("get_activity_candidates"):
|
||||
return active_world_adapter.get_activity_target(npc.current_task, origin)
|
||||
|
||||
var best: Dictionary = {}
|
||||
var best_distance := INF
|
||||
var candidates: Array[Dictionary] = active_world_adapter.get_activity_candidates(npc.current_task)
|
||||
for candidate in candidates:
|
||||
var target_id := StringName(candidate["target_id"])
|
||||
var capacity := maxi(int(candidate.get("capacity", 1)), 1)
|
||||
if (
|
||||
simulation_manager.has_method("get_activity_target_claim_count")
|
||||
and simulation_manager.get_activity_target_claim_count(target_id, npc.id) >= capacity
|
||||
):
|
||||
continue
|
||||
var position: Vector3 = candidate["position"]
|
||||
var distance := origin.distance_squared_to(position)
|
||||
if distance < best_distance:
|
||||
best_distance = distance
|
||||
best = candidate
|
||||
|
||||
if not best.is_empty():
|
||||
return best
|
||||
if not candidates.is_empty():
|
||||
return {}
|
||||
return active_world_adapter.get_activity_target(npc.current_task, origin)
|
||||
|
||||
|
||||
func score_resource_candidate(
|
||||
npc: SimNPC, origin: Vector3, position: Vector3, state: ResourceStateRecord
|
||||
) -> float:
|
||||
|
||||
Reference in New Issue
Block a user