feat: add missing wood opportunities
This commit is contained in:
+59
-8
@@ -37,6 +37,8 @@ func _ready() -> void:
|
||||
simulation_manager.opportunity_opened.connect(_on_opportunity_opened)
|
||||
if simulation_manager.has_signal("opportunity_resolved"):
|
||||
simulation_manager.opportunity_resolved.connect(_on_opportunity_resolved)
|
||||
if simulation_manager.has_signal("opportunity_invalidated"):
|
||||
simulation_manager.opportunity_invalidated.connect(_on_opportunity_invalidated)
|
||||
|
||||
if "village" in simulation_manager:
|
||||
_on_village_changed(simulation_manager.village)
|
||||
@@ -158,6 +160,11 @@ func _on_opportunity_resolved(
|
||||
_refresh_npc_inspector()
|
||||
|
||||
|
||||
func _on_opportunity_invalidated(_opportunity: RefCounted) -> void:
|
||||
_refresh_village_display()
|
||||
_refresh_npc_inspector()
|
||||
|
||||
|
||||
func _refresh_village_display() -> void:
|
||||
if simulation_manager != null and "village" in simulation_manager:
|
||||
_on_village_changed(simulation_manager.village)
|
||||
@@ -256,10 +263,15 @@ func _build_active_opportunity_display() -> String:
|
||||
return ""
|
||||
var interested_name := _get_npc_name(opportunity.get_interested_npc_id())
|
||||
var resource_name := String(opportunity.get_resource_id()).capitalize()
|
||||
var current_amount := 0.0
|
||||
var pantry: StorageStateRecord = simulation_manager.get_pantry()
|
||||
if pantry != null:
|
||||
current_amount = pantry.get_amount(opportunity.get_resource_id())
|
||||
var current_amount := _get_opportunity_current_amount(opportunity)
|
||||
if opportunity.get_opportunity_type() == SimulationIds.OPPORTUNITY_SUPPLY_MISSING_WOOD:
|
||||
var action_name := _get_opportunity_action_name(opportunity)
|
||||
return (
|
||||
"\n\nVillage need\n"
|
||||
+ "◆ Supply wood for blocked work\n"
|
||||
+ "%s could not finish %s\n" % [interested_name, action_name]
|
||||
+ "%s %.0f / %.0f" % [resource_name, current_amount, opportunity.get_target_amount()]
|
||||
)
|
||||
return (
|
||||
"\n\nVillage need\n"
|
||||
+ "◆ Restock the empty pantry\n"
|
||||
@@ -276,10 +288,16 @@ func _build_npc_opportunity_display(npc: SimNPC) -> String:
|
||||
return ""
|
||||
var resource_name := String(opportunity.get_resource_id()).capitalize()
|
||||
if opportunity.get_status() == OpportunityStateRecord.STATUS_OPEN:
|
||||
var pantry: StorageStateRecord = simulation_manager.get_pantry()
|
||||
var current_amount := 0.0
|
||||
if pantry != null:
|
||||
current_amount = pantry.get_amount(opportunity.get_resource_id())
|
||||
var current_amount := _get_opportunity_current_amount(opportunity)
|
||||
if opportunity.get_opportunity_type() == SimulationIds.OPPORTUNITY_SUPPLY_MISSING_WOOD:
|
||||
return (
|
||||
"Open village need\n"
|
||||
+ "◆ Find wood for %s\n" % _get_opportunity_action_name(opportunity)
|
||||
+ (
|
||||
"%s %.0f / %.0f\n\n"
|
||||
% [resource_name, current_amount, opportunity.get_target_amount()]
|
||||
)
|
||||
)
|
||||
return (
|
||||
"Open village need\n"
|
||||
+ "◆ Restock the empty pantry\n"
|
||||
@@ -288,6 +306,16 @@ func _build_npc_opportunity_display(npc: SimNPC) -> String:
|
||||
% [resource_name, current_amount, opportunity.get_target_amount()]
|
||||
)
|
||||
)
|
||||
if opportunity.get_status() == OpportunityStateRecord.STATUS_INVALIDATED:
|
||||
var reason := (
|
||||
"The interested villager died"
|
||||
if (
|
||||
opportunity.get_invalidation_reason()
|
||||
== SimulationIds.OPPORTUNITY_INVALIDATED_INTERESTED_DIED
|
||||
)
|
||||
else "The evidence became stale"
|
||||
)
|
||||
return "Closed village need\n◆ %s\n\n" % reason
|
||||
if opportunity.get_status() != OpportunityStateRecord.STATUS_RESOLVED:
|
||||
return ""
|
||||
var resolution_event: EconomicEventRecord = simulation_manager.get_opportunity_resolution_event(
|
||||
@@ -297,6 +325,12 @@ func _build_npc_opportunity_display(npc: SimNPC) -> String:
|
||||
if resolution_event != null:
|
||||
var actor_id := int(resolution_event.data["actor_id"])
|
||||
actor_name = "Player" if actor_id < 0 else _get_npc_name(actor_id)
|
||||
if opportunity.get_opportunity_type() == SimulationIds.OPPORTUNITY_SUPPLY_MISSING_WOOD:
|
||||
return (
|
||||
"Resolved village need\n"
|
||||
+ "◆ %s supplied the woodpile\n" % actor_name
|
||||
+ "%s target %.0f\n\n" % [resource_name, opportunity.get_target_amount()]
|
||||
)
|
||||
return (
|
||||
"Resolved village need\n"
|
||||
+ "◆ %s restocked the pantry\n" % actor_name
|
||||
@@ -304,6 +338,23 @@ func _build_npc_opportunity_display(npc: SimNPC) -> String:
|
||||
)
|
||||
|
||||
|
||||
func _get_opportunity_current_amount(opportunity: OpportunityStateRecord) -> float:
|
||||
var storage: StorageStateRecord
|
||||
match opportunity.get_target_id():
|
||||
SimulationIds.STORAGE_VILLAGE_PANTRY:
|
||||
storage = simulation_manager.get_pantry()
|
||||
SimulationIds.STORAGE_VILLAGE_WOODPILE:
|
||||
storage = simulation_manager.get_woodpile()
|
||||
return storage.get_amount(opportunity.get_resource_id()) if storage != null else 0.0
|
||||
|
||||
|
||||
func _get_opportunity_action_name(opportunity: OpportunityStateRecord) -> String:
|
||||
var trigger: EconomicEventRecord = simulation_manager.get_opportunity_trigger_event(opportunity)
|
||||
if trigger == null:
|
||||
return "work"
|
||||
return _get_action_name(StringName(trigger.data.get("action_id", &"")))
|
||||
|
||||
|
||||
func _get_npc_name(npc_id: int) -> String:
|
||||
for npc in simulation_manager.npcs:
|
||||
if npc.id == npc_id:
|
||||
|
||||
Reference in New Issue
Block a user