feat: define reusable animal archetypes
This commit is contained in:
@@ -29,6 +29,7 @@ var states: Dictionary = {}
|
||||
var economy: RefCounted
|
||||
var active_world_adapter: Node
|
||||
var current_tick := 0
|
||||
var _animal_catalog: AnimalCatalog
|
||||
|
||||
|
||||
func configure(economy_service: RefCounted, world_adapter: Node) -> void:
|
||||
@@ -36,6 +37,19 @@ func configure(economy_service: RefCounted, world_adapter: Node) -> void:
|
||||
active_world_adapter = world_adapter
|
||||
|
||||
|
||||
func configure_animal_catalog(catalog: AnimalCatalog) -> bool:
|
||||
if catalog == null or not catalog.rebuild().is_empty():
|
||||
return false
|
||||
_animal_catalog = catalog
|
||||
return true
|
||||
|
||||
|
||||
func get_animal_catalog() -> AnimalCatalog:
|
||||
if _animal_catalog == null:
|
||||
_animal_catalog = AnimalCatalog.create_core()
|
||||
return _animal_catalog
|
||||
|
||||
|
||||
func advance(simulation_tick: int) -> void:
|
||||
current_tick = simulation_tick
|
||||
var animal_ids: Array = states.keys()
|
||||
@@ -67,15 +81,23 @@ func register_node(node: AnimalNode) -> bool:
|
||||
push_error("AnimalCareSystem: Animal ID '%s' collides with a world target" % node.animal_id)
|
||||
return false
|
||||
var action_definition := SimulationDefinitions.get_action(SimulationIds.ACTION_FEED_ANIMAL)
|
||||
var animal_catalog := get_animal_catalog()
|
||||
var animal_definition := (
|
||||
animal_catalog.get_definition(node.animal_definition_id) if animal_catalog != null else null
|
||||
)
|
||||
if (
|
||||
action_definition == null
|
||||
or action_definition.target_type != SimulationIds.TARGET_ANIMAL
|
||||
or node.species_id != SimulationIds.SPECIES_GOAT
|
||||
or animal_definition == null
|
||||
or animal_definition.behavior_id != AnimalDefinition.BEHAVIOR_GRAZER_ROUTINE
|
||||
or animal_definition.species_id != node.species_id
|
||||
or not animal_definition.supports_action(SimulationIds.ACTION_FEED_ANIMAL)
|
||||
or not node.supports_action(SimulationIds.ACTION_FEED_ANIMAL)
|
||||
):
|
||||
push_error(
|
||||
(
|
||||
"AnimalCareSystem: AnimalNode '%s' has an invalid feed action or species '%s'"
|
||||
% [node.animal_id, node.species_id]
|
||||
"AnimalCareSystem: AnimalNode '%s' has invalid definition '%s' or species '%s'"
|
||||
% [node.animal_id, node.animal_definition_id, node.species_id]
|
||||
)
|
||||
)
|
||||
return false
|
||||
|
||||
Reference in New Issue
Block a user