feat: let opportunity helpers act autonomously
This commit is contained in:
@@ -18,7 +18,11 @@ var relationship_system: RefCounted
|
||||
|
||||
|
||||
func select_action(
|
||||
npc: SimNPC, village: SimVillage, time_of_day: float = 0.5, all_npcs: Array = []
|
||||
npc: SimNPC,
|
||||
village: SimVillage,
|
||||
time_of_day: float = 0.5,
|
||||
all_npcs: Array = [],
|
||||
opportunity_helper: OpportunityHelperResult = null
|
||||
) -> ActionSelectionResult:
|
||||
if npc.is_dead:
|
||||
return null
|
||||
@@ -98,6 +102,17 @@ func select_action(
|
||||
return ActionSelectionResult.new(
|
||||
SimulationIds.ACTION_GATHER_FOOD, -1.0, "Hungry; pantry is empty"
|
||||
)
|
||||
var is_opportunity_helper := _is_current_opportunity_helper(npc, opportunity_helper)
|
||||
if is_opportunity_helper and npc.energy < 25.0:
|
||||
return ActionSelectionResult.new(
|
||||
SimulationIds.ACTION_REST, -1.0, "Energy is low; resting before helping"
|
||||
)
|
||||
if is_opportunity_helper:
|
||||
return ActionSelectionResult.new(
|
||||
opportunity_helper.action_id,
|
||||
-1.0,
|
||||
"Responding to village need: %s" % opportunity_helper.reason
|
||||
)
|
||||
if npc.get_inventory_amount(SimulationIds.RESOURCE_FOOD) > 0.0:
|
||||
return ActionSelectionResult.new(
|
||||
SimulationIds.ACTION_DEPOSIT_FOOD, -1.0, "Carrying food for storage"
|
||||
@@ -131,6 +146,24 @@ func select_action(
|
||||
return _choose_best_work_action(npc, village)
|
||||
|
||||
|
||||
func _is_current_opportunity_helper(
|
||||
npc: SimNPC, opportunity_helper: OpportunityHelperResult
|
||||
) -> bool:
|
||||
return (
|
||||
opportunity_helper != null
|
||||
and opportunity_helper.helper_npc_id == npc.id
|
||||
and (
|
||||
opportunity_helper.action_id
|
||||
in [
|
||||
SimulationIds.ACTION_GATHER_FOOD,
|
||||
SimulationIds.ACTION_GATHER_WOOD,
|
||||
SimulationIds.ACTION_DEPOSIT_FOOD,
|
||||
SimulationIds.ACTION_DEPOSIT_WOOD,
|
||||
]
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
func _choose_best_work_action(npc: SimNPC, village: SimVillage) -> ActionSelectionResult:
|
||||
var scores := {
|
||||
SimulationIds.ACTION_GATHER_FOOD:
|
||||
|
||||
Reference in New Issue
Block a user