feat: add physical animal care delivery

This commit is contained in:
Rijad Zuzo
2026-07-31 00:19:41 +02:00
parent 7d410d8193
commit ead75fca68
25 changed files with 1469 additions and 191 deletions
+18 -1
View File
@@ -98,6 +98,21 @@ static func from_dictionary(record_data: Dictionary) -> NPCStateRecord:
return null
if not record_data["inventory"] is Dictionary:
return null
var normalized_inventory := {}
for raw_item_id in record_data["inventory"]:
var item_id := str(raw_item_id)
var raw_amount = record_data["inventory"][raw_item_id]
if typeof(raw_amount) not in [TYPE_INT, TYPE_FLOAT]:
return null
var amount := float(raw_amount)
if (
item_id.is_empty()
or normalized_inventory.has(item_id)
or not is_finite(amount)
or amount < 0.0
):
return null
normalized_inventory[item_id] = amount
var profession_id := StringName(record_data["profession"])
if SimulationDefinitions.get_profession(profession_id) == null:
return null
@@ -110,7 +125,9 @@ static func from_dictionary(record_data: Dictionary) -> NPCStateRecord:
var last_action_id := StringName(record_data["last_task"])
if not last_action_id.is_empty() and SimulationDefinitions.get_action(last_action_id) == null:
return null
return NPCStateRecord.new(record_data)
var normalized := record_data.duplicate(true)
normalized["inventory"] = normalized_inventory
return NPCStateRecord.new(normalized)
static func _migrate_legacy(legacy_data: Dictionary, version: int) -> Dictionary:
+9 -1
View File
@@ -473,11 +473,19 @@ static func _is_valid_animal_feed_event(
var animal := (
animal_records_by_id.get(StringName(event.data["destination_id"])) as AnimalStateRecord
)
var source_id := StringName(event.data["source_id"])
var has_valid_source := source_id == SimulationIds.STORAGE_VILLAGE_PANTRY
if actor_id >= 0:
# Existing v11 saves contain direct pantry-to-animal NPC feed facts.
# New physical deliveries name the matching carried inventory instead.
has_valid_source = (
has_valid_source or source_id == SimulationIds.npc_inventory_id(actor_id)
)
return (
(actor_id == -1 or npc_ids.has(actor_id))
and int(event.data["tick"]) <= current_tick
and animal != null
and StringName(event.data["source_id"]) == SimulationIds.STORAGE_VILLAGE_PANTRY
and has_valid_source
and storage_records_by_id.has(SimulationIds.STORAGE_VILLAGE_PANTRY)
and StringName(event.data["item_id"]) == SimulationIds.RESOURCE_FOOD
and definition != null