feat: derive capable opportunity helpers
This commit is contained in:
@@ -806,23 +806,32 @@ func get_active_opportunity() -> OpportunityStateRecord:
|
||||
return opportunity_system.get_open_opportunity()
|
||||
|
||||
|
||||
func get_active_opportunity_helper() -> OpportunityHelperResult:
|
||||
var active := get_active_opportunity()
|
||||
if active == null:
|
||||
return null
|
||||
return opportunity_system.find_capable_helper(
|
||||
active,
|
||||
economy.get_storage(active.get_target_id()),
|
||||
npcs,
|
||||
event_knowledge_system,
|
||||
relationship_system,
|
||||
resource_states
|
||||
)
|
||||
|
||||
|
||||
func get_latest_opportunity_for_npc(npc_id: int) -> OpportunityStateRecord:
|
||||
return opportunity_system.get_latest_for_npc(npc_id)
|
||||
|
||||
|
||||
func get_opportunity_trigger_event(opportunity: OpportunityStateRecord) -> EconomicEventRecord:
|
||||
if opportunity == null:
|
||||
return null
|
||||
return event_log.get_by_id(opportunity.get_trigger_event_id())
|
||||
var event_id := opportunity.get_trigger_event_id() if opportunity != null else -1
|
||||
return event_log.get_by_id(event_id)
|
||||
|
||||
|
||||
func get_opportunity_resolution_event(opportunity: OpportunityStateRecord) -> EconomicEventRecord:
|
||||
if (
|
||||
opportunity == null
|
||||
or opportunity.get_resolution_event_id() == OpportunityStateRecord.NO_EVENT_ID
|
||||
):
|
||||
return null
|
||||
return event_log.get_by_id(opportunity.get_resolution_event_id())
|
||||
var event_id := opportunity.get_resolution_event_id() if opportunity != null else -1
|
||||
return event_log.get_by_id(event_id)
|
||||
|
||||
|
||||
func npc_knows_event(npc_id: int, event_id: int) -> bool:
|
||||
@@ -1106,7 +1115,6 @@ func create_state_record() -> SimulationStateRecord:
|
||||
wander_streams.append(
|
||||
{"npc_id": int(npc_id), "seed": str(source.seed), "state": str(source.state)}
|
||||
)
|
||||
|
||||
record.simulation = {
|
||||
"seed": simulation_seed,
|
||||
"tick_interval": tick_interval,
|
||||
@@ -1121,7 +1129,6 @@ func create_state_record() -> SimulationStateRecord:
|
||||
record.village = VillageStateRecord.capture(village)
|
||||
for npc in npcs:
|
||||
record.npcs.append(NPCStateRecord.capture(npc))
|
||||
|
||||
var sorted_resource_ids: Array = resource_states.keys()
|
||||
sorted_resource_ids.sort()
|
||||
for resource_id in sorted_resource_ids:
|
||||
@@ -1158,7 +1165,6 @@ func restore_state_from_json(json_text: String) -> bool:
|
||||
func restore_state(record: SimulationStateRecord) -> bool:
|
||||
if record == null:
|
||||
return false
|
||||
|
||||
simulation_seed = int(record.simulation["seed"])
|
||||
tick_interval = float(record.simulation["tick_interval"])
|
||||
tick_count = int(record.simulation["tick_count"])
|
||||
@@ -1171,7 +1177,6 @@ func restore_state(record: SimulationStateRecord) -> bool:
|
||||
economy.restore_storage(record.storages)
|
||||
event_log.restore(record.economic_events, int(record.simulation["next_event_id"]))
|
||||
latest_decisions.clear()
|
||||
|
||||
npcs.clear()
|
||||
for npc_record in record.npcs:
|
||||
npcs.append(npc_record.restore(debug_logs))
|
||||
@@ -1179,7 +1184,6 @@ func restore_state(record: SimulationStateRecord) -> bool:
|
||||
event_knowledge_system.restore(record.event_knowledge)
|
||||
opportunity_system.restore(record.opportunities, int(record.simulation["next_opportunity_id"]))
|
||||
_maintain_event_knowledge(tick_count % get_knowledge_review_interval() == 0)
|
||||
|
||||
wander_random_sources.clear()
|
||||
var wander_streams: Array = record.simulation["wander_random_streams"]
|
||||
for stream_data in wander_streams:
|
||||
@@ -1187,12 +1191,10 @@ func restore_state(record: SimulationStateRecord) -> bool:
|
||||
source.seed = String(stream_data["seed"]).to_int()
|
||||
source.state = String(stream_data["state"]).to_int()
|
||||
wander_random_sources[int(stream_data["npc_id"])] = source
|
||||
|
||||
resource_states.clear()
|
||||
for resource_record in record.resources:
|
||||
resource_states[resource_record.get_node_id()] = resource_record
|
||||
register_loaded_resource_nodes()
|
||||
|
||||
village_changed.emit(village)
|
||||
state_restored.emit()
|
||||
return true
|
||||
|
||||
Reference in New Issue
Block a user