feat: deliver emergent Jajce commitments
This commit is contained in:
@@ -4,6 +4,21 @@ signal event_recorded(event: EconomicEventRecord)
|
||||
|
||||
const DEFAULT_RATE_WINDOW_TICKS := 200
|
||||
const DEFAULT_TICKS_PER_DAY := 200.0
|
||||
const FACT_RESERVED_FIELDS := [
|
||||
"schema_version",
|
||||
"event_id",
|
||||
"event_type",
|
||||
"tick",
|
||||
"actor_id",
|
||||
"source_id",
|
||||
"destination_id",
|
||||
"item_id",
|
||||
"amount",
|
||||
"action_name",
|
||||
"action_id",
|
||||
"required_amount",
|
||||
"world_position",
|
||||
]
|
||||
|
||||
var events: Array[EconomicEventRecord] = []
|
||||
var next_event_id := 0
|
||||
@@ -69,6 +84,48 @@ func record_narrative(
|
||||
return event
|
||||
|
||||
|
||||
func record_fact(
|
||||
tick: int,
|
||||
event_type: StringName,
|
||||
actor_id: int,
|
||||
source_id: StringName = &"",
|
||||
destination_id: StringName = &"",
|
||||
fact_payload: Dictionary = {},
|
||||
world_position: Vector3 = Vector3.ZERO
|
||||
) -> EconomicEventRecord:
|
||||
if tick < 0 or event_type.is_empty():
|
||||
return null
|
||||
var event := EconomicEventRecord.create_narrative(
|
||||
next_event_id, event_type, tick, actor_id, source_id, "", world_position
|
||||
)
|
||||
event.data["destination_id"] = String(destination_id)
|
||||
var payload_keys: Array = fact_payload.keys()
|
||||
payload_keys.sort_custom(
|
||||
func(first: Variant, second: Variant) -> bool: return str(first) < str(second)
|
||||
)
|
||||
var normalized_keys := {}
|
||||
for raw_key in payload_keys:
|
||||
if not raw_key is String and not raw_key is StringName:
|
||||
return null
|
||||
var key := String(raw_key)
|
||||
if key.is_empty() or key in FACT_RESERVED_FIELDS or normalized_keys.has(key):
|
||||
return null
|
||||
normalized_keys[key] = true
|
||||
event.data[key] = fact_payload[raw_key]
|
||||
var normalized := EconomicEventRecord.from_dictionary(event.to_dictionary())
|
||||
if normalized == null:
|
||||
return null
|
||||
if (
|
||||
WorldEventRecord.from_economic_event(
|
||||
normalized, SimulationIds.WORLD_CORE, SimulationIds.LOCATION_JAJCE
|
||||
)
|
||||
== null
|
||||
):
|
||||
return null
|
||||
_append(normalized)
|
||||
return normalized
|
||||
|
||||
|
||||
func get_for_actor(actor_id: int, max_count: int = 8) -> Array[EconomicEventRecord]:
|
||||
var results: Array[EconomicEventRecord] = []
|
||||
var event_ids: Array = _event_ids_by_actor.get(actor_id, [])
|
||||
|
||||
Reference in New Issue
Block a user