feat: add combat, wild wolves, factions, and tribe war motivation
This commit is contained in:
@@ -2,7 +2,7 @@ class_name SimulationStateRecord
|
||||
extends RefCounted
|
||||
|
||||
const SCHEMA_NAME := "the_steward.simulation"
|
||||
const SCHEMA_VERSION := 13
|
||||
const SCHEMA_VERSION := 14
|
||||
const LEGACY_SCHEMA_VERSION := 1
|
||||
const EVENT_LEGACY_SCHEMA_VERSION := 2
|
||||
const RELATIONSHIP_LEGACY_SCHEMA_VERSION := 3
|
||||
@@ -14,6 +14,7 @@ const ANIMAL_LEGACY_SCHEMA_VERSION := 9
|
||||
const ROUTINE_LEGACY_SCHEMA_VERSION := 10
|
||||
const PLAYER_RELATIONSHIP_SCHEMA_VERSION := 11
|
||||
const PLAYER_NEEDS_SCHEMA_VERSION := 12
|
||||
const CONFLICT_SCHEMA_VERSION := 13
|
||||
const PREVIOUS_SCHEMA_VERSION := 7
|
||||
|
||||
var simulation: Dictionary
|
||||
@@ -27,6 +28,8 @@ var relationships: Array[RelationshipStateRecord] = []
|
||||
var event_knowledge: Array[KnownEventStateRecord] = []
|
||||
var opportunities: Array[OpportunityStateRecord] = []
|
||||
var player: PlayerStateRecord
|
||||
var combatants: Array[CombatantStateRecord] = []
|
||||
var factions: Array[FactionStateRecord] = []
|
||||
|
||||
|
||||
func to_dictionary() -> Dictionary:
|
||||
@@ -55,6 +58,12 @@ func to_dictionary() -> Dictionary:
|
||||
var opportunity_data: Array[Dictionary] = []
|
||||
for opportunity_record in opportunities:
|
||||
opportunity_data.append(opportunity_record.to_dictionary())
|
||||
var combatant_data: Array[Dictionary] = []
|
||||
for combatant_record in combatants:
|
||||
combatant_data.append(combatant_record.to_dictionary())
|
||||
var faction_data: Array[Dictionary] = []
|
||||
for faction_record in factions:
|
||||
faction_data.append(faction_record.to_dictionary())
|
||||
|
||||
return {
|
||||
"schema": SCHEMA_NAME,
|
||||
@@ -69,7 +78,9 @@ func to_dictionary() -> Dictionary:
|
||||
"relationships": relationship_data,
|
||||
"event_knowledge": knowledge_data,
|
||||
"opportunities": opportunity_data,
|
||||
"player": player.to_dictionary()
|
||||
"player": player.to_dictionary(),
|
||||
"combatants": combatant_data,
|
||||
"factions": faction_data
|
||||
}
|
||||
|
||||
|
||||
@@ -103,6 +114,7 @@ static func from_dictionary(record_data: Dictionary) -> SimulationStateRecord:
|
||||
ROUTINE_LEGACY_SCHEMA_VERSION,
|
||||
PLAYER_RELATIONSHIP_SCHEMA_VERSION,
|
||||
PLAYER_NEEDS_SCHEMA_VERSION,
|
||||
CONFLICT_SCHEMA_VERSION,
|
||||
]
|
||||
):
|
||||
record_data = _migrate_legacy(record_data, version)
|
||||
@@ -123,6 +135,8 @@ static func from_dictionary(record_data: Dictionary) -> SimulationStateRecord:
|
||||
"event_knowledge",
|
||||
"opportunities",
|
||||
"player",
|
||||
"combatants",
|
||||
"factions",
|
||||
]
|
||||
)
|
||||
):
|
||||
@@ -212,6 +226,35 @@ static func from_dictionary(record_data: Dictionary) -> SimulationStateRecord:
|
||||
if player_record == null:
|
||||
return null
|
||||
record.player = player_record
|
||||
|
||||
var combatant_data = record_data["combatants"]
|
||||
var faction_data = record_data["factions"]
|
||||
if not combatant_data is Array or not faction_data is Array:
|
||||
return null
|
||||
var combatant_ids := {}
|
||||
for item in combatant_data:
|
||||
if not item is Dictionary:
|
||||
return null
|
||||
var combatant_record := CombatantStateRecord.from_dictionary(item)
|
||||
if combatant_record == null:
|
||||
return null
|
||||
var combatant_id := String(combatant_record.get_combatant_id())
|
||||
if combatant_ids.has(combatant_id):
|
||||
return null
|
||||
combatant_ids[combatant_id] = true
|
||||
record.combatants.append(combatant_record)
|
||||
var faction_ids := {}
|
||||
for item in faction_data:
|
||||
if not item is Dictionary:
|
||||
return null
|
||||
var faction_record := FactionStateRecord.from_dictionary(item)
|
||||
if faction_record == null:
|
||||
return null
|
||||
var faction_id := String(faction_record.get_faction_id())
|
||||
if faction_ids.has(faction_id):
|
||||
return null
|
||||
faction_ids[faction_id] = true
|
||||
record.factions.append(faction_record)
|
||||
var npc_ids := {}
|
||||
var npc_records_by_id := {}
|
||||
|
||||
@@ -227,6 +270,11 @@ static func from_dictionary(record_data: Dictionary) -> SimulationStateRecord:
|
||||
npc_ids[npc_id] = true
|
||||
npc_records_by_id[npc_id] = npc_record
|
||||
record.npcs.append(npc_record)
|
||||
for combatant_record in record.combatants:
|
||||
if combatant_record.get_kind() != SimulationIds.COMBATANT_KIND_NPC:
|
||||
continue
|
||||
if not npc_ids.has(combatant_record.get_npc_id()):
|
||||
return null
|
||||
|
||||
var resource_ids := {}
|
||||
var resource_records_by_id := {}
|
||||
@@ -802,6 +850,20 @@ static func _migrate_legacy(legacy_data: Dictionary, version: int) -> Dictionary
|
||||
migrated["schema_version"] = SCHEMA_VERSION
|
||||
if not migrated.has("player"):
|
||||
migrated["player"] = PlayerStateRecord.create_default().to_dictionary()
|
||||
if version < CONFLICT_SCHEMA_VERSION:
|
||||
migrated["combatants"] = []
|
||||
migrated["factions"] = [
|
||||
(
|
||||
FactionStateRecord
|
||||
. create(SimulationIds.FACTION_VILLAGE, "Village", 20.0, 0, 0.2, 0.8)
|
||||
. to_dictionary()
|
||||
),
|
||||
(
|
||||
FactionStateRecord
|
||||
. create(SimulationIds.FACTION_TRIBE, "Hill Tribe", 4.0, 4, 0.7, 0.7)
|
||||
. to_dictionary()
|
||||
),
|
||||
]
|
||||
if version <= ANIMAL_LEGACY_SCHEMA_VERSION:
|
||||
migrated["animals"] = []
|
||||
if version == LEGACY_SCHEMA_VERSION:
|
||||
@@ -864,6 +926,7 @@ static func _migrate_legacy(legacy_data: Dictionary, version: int) -> Dictionary
|
||||
ROUTINE_LEGACY_SCHEMA_VERSION,
|
||||
PLAYER_RELATIONSHIP_SCHEMA_VERSION,
|
||||
PLAYER_NEEDS_SCHEMA_VERSION,
|
||||
CONFLICT_SCHEMA_VERSION,
|
||||
]
|
||||
):
|
||||
migrated["opportunities"] = []
|
||||
|
||||
Reference in New Issue
Block a user