feat: unify authored activity commands
This commit is contained in:
@@ -28,6 +28,23 @@ var _events_by_id: Dictionary = {}
|
||||
var _event_ids_by_actor: Dictionary = {}
|
||||
var _event_ids_by_type: Dictionary = {}
|
||||
var _event_ids_by_tick: Dictionary = {}
|
||||
var _world_id := SimulationIds.REGIONAL_WORLD_BOSNIA
|
||||
var _location_id := SimulationIds.REGIONAL_LOCATION_JAJCE
|
||||
|
||||
|
||||
func configure_scope(world_id: StringName, location_id: StringName) -> bool:
|
||||
if world_id.is_empty() or location_id.is_empty():
|
||||
return false
|
||||
if not events.is_empty():
|
||||
return world_id == _world_id and location_id == _location_id
|
||||
_world_id = world_id
|
||||
_location_id = location_id
|
||||
world_events = WorldEventStore.new()
|
||||
return true
|
||||
|
||||
|
||||
func get_scope() -> Dictionary:
|
||||
return {"world_id": _world_id, "location_id": _location_id}
|
||||
|
||||
|
||||
func record_economic(
|
||||
@@ -80,6 +97,14 @@ func record_narrative(
|
||||
item_id,
|
||||
required_amount
|
||||
)
|
||||
if event_type == SimulationIds.EVENT_TASK_BLOCKED:
|
||||
event.data["blocked_contract_kind"] = String(SimulationIds.BLOCKED_CONTRACT_ACTION_COST)
|
||||
event.data["world_id"] = String(_world_id)
|
||||
event.data["location_id"] = String(_location_id)
|
||||
var normalized := EconomicEventRecord.from_dictionary(event.to_dictionary())
|
||||
if normalized == null:
|
||||
return null
|
||||
event = normalized
|
||||
_append(event)
|
||||
return event
|
||||
|
||||
@@ -115,11 +140,105 @@ func record_fact(
|
||||
var normalized := EconomicEventRecord.from_dictionary(event.to_dictionary())
|
||||
if normalized == null:
|
||||
return null
|
||||
if WorldEventRecord.from_economic_event(normalized, _world_id, _location_id) == null:
|
||||
return null
|
||||
_append(normalized)
|
||||
return normalized
|
||||
|
||||
|
||||
func record_activity_completed(
|
||||
tick: int,
|
||||
actor_id: int,
|
||||
target_id: StringName,
|
||||
action_id: StringName,
|
||||
event_type_id: StringName,
|
||||
metric_id: StringName,
|
||||
metric_delta: float,
|
||||
world_position: Vector3 = Vector3.ZERO,
|
||||
cost_item_id: StringName = &"",
|
||||
cost_amount: float = 0.0
|
||||
) -> EconomicEventRecord:
|
||||
if (
|
||||
WorldEventRecord.from_economic_event(
|
||||
normalized, SimulationIds.WORLD_CORE, SimulationIds.LOCATION_JAJCE
|
||||
)
|
||||
== null
|
||||
tick < 0
|
||||
or actor_id < SimulationIds.PLAYER_ACTOR_ID
|
||||
or target_id.is_empty()
|
||||
or action_id.is_empty()
|
||||
or event_type_id.is_empty()
|
||||
or metric_id not in [&"safety", &"knowledge"]
|
||||
or not is_finite(metric_delta)
|
||||
or metric_delta <= 0.0
|
||||
or not world_position.is_finite()
|
||||
or not is_finite(cost_amount)
|
||||
or cost_amount < 0.0
|
||||
or (cost_item_id.is_empty() and cost_amount > 0.0)
|
||||
or (not cost_item_id.is_empty() and cost_amount <= 0.0)
|
||||
):
|
||||
return null
|
||||
var event := EconomicEventRecord.create_narrative(
|
||||
next_event_id,
|
||||
event_type_id,
|
||||
tick,
|
||||
actor_id,
|
||||
target_id,
|
||||
"",
|
||||
world_position,
|
||||
action_id,
|
||||
cost_item_id,
|
||||
cost_amount
|
||||
)
|
||||
event.data["metric_id"] = String(metric_id)
|
||||
event.data["metric_delta"] = metric_delta
|
||||
event.data["cost_item_id"] = String(cost_item_id)
|
||||
event.data["cost_amount"] = cost_amount
|
||||
event.data["target_kind"] = String(SimulationIds.TARGET_ACTIVITY)
|
||||
event.data["target_action_id"] = String(action_id)
|
||||
event.data["world_id"] = String(_world_id)
|
||||
event.data["location_id"] = String(_location_id)
|
||||
var normalized := EconomicEventRecord.from_dictionary(event.to_dictionary())
|
||||
if (
|
||||
normalized == null
|
||||
or (WorldEventRecord.from_economic_event(normalized, _world_id, _location_id) == null)
|
||||
):
|
||||
return null
|
||||
_append(normalized)
|
||||
return normalized
|
||||
|
||||
|
||||
func record_activity_blocked(
|
||||
tick: int,
|
||||
actor_id: int,
|
||||
target_id: StringName,
|
||||
action_id: StringName,
|
||||
action_display: String,
|
||||
world_position: Vector3,
|
||||
cost_storage_id: StringName,
|
||||
cost_item_id: StringName,
|
||||
cost_amount: float
|
||||
) -> EconomicEventRecord:
|
||||
var event := EconomicEventRecord.create_narrative(
|
||||
next_event_id,
|
||||
SimulationIds.EVENT_TASK_BLOCKED,
|
||||
tick,
|
||||
actor_id,
|
||||
cost_storage_id,
|
||||
action_display,
|
||||
world_position,
|
||||
action_id,
|
||||
cost_item_id,
|
||||
cost_amount
|
||||
)
|
||||
if target_id.is_empty():
|
||||
return null
|
||||
event.data["blocked_contract_kind"] = String(SimulationIds.BLOCKED_CONTRACT_ACTION_COST)
|
||||
event.data["world_id"] = String(_world_id)
|
||||
event.data["location_id"] = String(_location_id)
|
||||
event.data["activity_target_id"] = String(target_id)
|
||||
event.data["target_kind"] = String(SimulationIds.TARGET_ACTIVITY)
|
||||
event.data["target_action_id"] = String(action_id)
|
||||
var normalized := EconomicEventRecord.from_dictionary(event.to_dictionary())
|
||||
if (
|
||||
normalized == null
|
||||
or WorldEventRecord.from_economic_event(normalized, _world_id, _location_id) == null
|
||||
):
|
||||
return null
|
||||
_append(normalized)
|
||||
@@ -207,16 +326,27 @@ func get_consumption_rates(
|
||||
}
|
||||
|
||||
|
||||
func restore(restored_events: Array[EconomicEventRecord], restored_next_id: int) -> void:
|
||||
func restore(
|
||||
restored_events: Array[EconomicEventRecord],
|
||||
restored_next_id: int,
|
||||
restored_world_id: StringName = &"",
|
||||
restored_location_id: StringName = &""
|
||||
) -> bool:
|
||||
if restored_world_id.is_empty() != restored_location_id.is_empty():
|
||||
return false
|
||||
events.clear()
|
||||
_events_by_id.clear()
|
||||
_event_ids_by_actor.clear()
|
||||
_event_ids_by_type.clear()
|
||||
_event_ids_by_tick.clear()
|
||||
if not restored_world_id.is_empty():
|
||||
_world_id = restored_world_id
|
||||
_location_id = restored_location_id
|
||||
world_events = WorldEventStore.new()
|
||||
for event in restored_events:
|
||||
_index(event)
|
||||
next_event_id = restored_next_id
|
||||
return true
|
||||
|
||||
|
||||
func _append(event: EconomicEventRecord) -> void:
|
||||
@@ -236,7 +366,13 @@ func _index(event: EconomicEventRecord) -> void:
|
||||
_append_index(_event_ids_by_actor, int(event.data["actor_id"]), event_id)
|
||||
_append_index(_event_ids_by_type, StringName(event.data["event_type"]), event_id)
|
||||
_append_index(_event_ids_by_tick, int(event.data["tick"]), event_id)
|
||||
world_events.append_economic(event, SimulationIds.WORLD_CORE, SimulationIds.LOCATION_JAJCE)
|
||||
var event_world_id := StringName(event.data.get("world_id", _world_id))
|
||||
var event_location_id := StringName(event.data.get("location_id", _location_id))
|
||||
if event_world_id.is_empty():
|
||||
event_world_id = _world_id
|
||||
if event_location_id.is_empty():
|
||||
event_location_id = _location_id
|
||||
world_events.append_economic(event, event_world_id, event_location_id)
|
||||
|
||||
|
||||
static func _append_index(index: Dictionary, key: Variant, event_id: int) -> void:
|
||||
|
||||
Reference in New Issue
Block a user