feat: define action completion costs
This commit is contained in:
@@ -182,9 +182,13 @@ func _choose_best_work_action(npc: SimNPC, village: SimVillage, all_npcs: Array)
|
||||
0.75
|
||||
)
|
||||
}
|
||||
if village.wood < 1.0:
|
||||
scores[SimulationIds.ACTION_PATROL] = UNAVAILABLE_ACTION_SCORE
|
||||
scores[SimulationIds.ACTION_STUDY] = UNAVAILABLE_ACTION_SCORE
|
||||
var rejections := {}
|
||||
for action_id in scores:
|
||||
var definition := SimulationDefinitions.get_action(action_id)
|
||||
var rejection := _get_cost_rejection(definition, village)
|
||||
if not rejection.is_empty():
|
||||
scores[action_id] = UNAVAILABLE_ACTION_SCORE
|
||||
rejections[action_id] = rejection
|
||||
for familiar_id in npc.familiarity:
|
||||
if not familiar_id is int:
|
||||
continue
|
||||
@@ -205,10 +209,32 @@ func _choose_best_work_action(npc: SimNPC, village: SimVillage, all_npcs: Array)
|
||||
best_action = action_id
|
||||
best_score = score
|
||||
return ActionSelectionResult.new(
|
||||
best_action, -1.0, "Highest current work utility", scores
|
||||
best_action, -1.0, "Highest current work utility", scores, rejections
|
||||
)
|
||||
|
||||
|
||||
func _get_cost_rejection(definition: ActionDefinition, village: SimVillage) -> String:
|
||||
if definition == null or not definition.has_completion_cost():
|
||||
return ""
|
||||
var available := _get_village_resource_amount(village, definition.completion_cost_resource_id)
|
||||
if available >= definition.completion_cost_amount:
|
||||
return ""
|
||||
return "Needs %.0f %s (%.1f available)" % [
|
||||
definition.completion_cost_amount,
|
||||
String(definition.completion_cost_resource_id).capitalize(),
|
||||
available,
|
||||
]
|
||||
|
||||
|
||||
func _get_village_resource_amount(village: SimVillage, resource_id: StringName) -> float:
|
||||
match resource_id:
|
||||
SimulationIds.RESOURCE_FOOD:
|
||||
return village.food
|
||||
SimulationIds.RESOURCE_WOOD:
|
||||
return village.wood
|
||||
return 0.0
|
||||
|
||||
|
||||
func _calculate_score(
|
||||
npc: SimNPC,
|
||||
action_id: StringName,
|
||||
|
||||
Reference in New Issue
Block a user