style: apply gdformat formatting across the entire project

Auto-format all GDScript files using gdformat from gdtoolkit.
This is a baseline formatting pass to ensure consistent style:

- Normalizes indentation and spacing
- Wraps long lines to 100 characters
- Removes trailing whitespace
- Standardizes blank lines between functions

68 files reformatted, 8 files left unchanged (3rd-party addon files
with parse errors excluded).
This commit is contained in:
2026-07-05 23:06:23 +02:00
parent 28a2e42c41
commit 4463e524aa
69 changed files with 2253 additions and 1647 deletions
+161 -145
View File
@@ -1,10 +1,6 @@
extends Node
signal npc_task_changed(
npc: SimNPC,
old_task: StringName,
new_task: StringName
)
signal npc_task_changed(npc: SimNPC, old_task: StringName, new_task: StringName)
signal village_changed(village: SimVillage)
signal npc_died(npc: SimNPC)
signal npc_target_requested(npc: SimNPC)
@@ -32,9 +28,8 @@ var action_selector := ActionSelectionSystem.new()
var action_executor := ActionExecutionSystem.new()
var target_resolver := ActionTargetResolver.new()
var names := [
"Amina", "Tarik", "Jasmin"
]
var names := ["Amina", "Tarik", "Jasmin"]
func _ready() -> void:
add_to_group("simulation_manager")
@@ -53,20 +48,19 @@ func _ready() -> void:
call_deferred("register_loaded_resource_nodes")
if debug_logs:
print("--- Simulation started ---")
func _process(delta: float) -> void:
var ticks_due := clock.advance(delta)
for tick in ticks_due:
simulate_tick()
func generate_npcs() -> void:
var profession_ids := SimulationDefinitions.get_profession_ids()
for i in range(names.size()):
var npc_random := _create_random_source(i, 0)
var profession_index := npc_random.randi_range(
0,
profession_ids.size() - 1
)
var profession_index := npc_random.randi_range(0, profession_ids.size() - 1)
var npc := SimNPC.new(
i,
names[i],
@@ -80,21 +74,20 @@ func generate_npcs() -> void:
npcs.append(npc)
wander_random_sources[i] = _create_random_source(i, 1)
func _create_random_source(npc_id: int, stream_id: int) -> RandomNumberGenerator:
var source := RandomNumberGenerator.new()
source.seed = simulation_seed + (npc_id + 1) * 1000003 + stream_id * 7919
return source
func get_wander_offset(npc_id: int) -> Vector3:
var source: RandomNumberGenerator = wander_random_sources.get(npc_id)
if source == null:
source = _create_random_source(npc_id, 1)
wander_random_sources[npc_id] = source
return Vector3(
source.randf_range(-6.0, 6.0),
0.0,
source.randf_range(-6.0, 6.0)
)
return Vector3(source.randf_range(-6.0, 6.0), 0.0, source.randf_range(-6.0, 6.0))
func simulate_tick() -> void:
tick_count += 1
@@ -113,21 +106,12 @@ func simulate_tick() -> void:
action_executor.advance_npc(npc, village)
if (
not npc.is_dead
and old_state in [
SimNPC.TASK_STATE_IDLE,
SimNPC.TASK_STATE_COMPLETE
]
and npc.task_state in [
SimNPC.TASK_STATE_IDLE,
SimNPC.TASK_STATE_COMPLETE
]
and old_state in [SimNPC.TASK_STATE_IDLE, SimNPC.TASK_STATE_COMPLETE]
and npc.task_state in [SimNPC.TASK_STATE_IDLE, SimNPC.TASK_STATE_COMPLETE]
):
var selection := action_selector.select_action(npc, village)
if selection != null:
npc.set_task(
selection.action_id,
selection.duration_override
)
npc.set_task(selection.action_id, selection.duration_override)
if old_task != npc.current_task and old_target != &"":
release_npc_reservation(npc.id)
@@ -147,45 +131,36 @@ func simulate_tick() -> void:
if not was_complete and npc.task_complete and not npc.is_dead:
var completed_task := npc.current_task
var completed_definition := SimulationDefinitions.get_action(
completed_task
)
var completed_definition := SimulationDefinitions.get_action(completed_task)
if (
npc.target_id != &""
and completed_definition != null
and completed_definition.target_type == SimulationIds.TARGET_RESOURCE
):
var resource_state := get_resource_state(npc.target_id)
if (
resource_state != null
and resource_state.get_reserved_by() == npc.id
):
if resource_state != null and resource_state.get_reserved_by() == npc.id:
var extracted := resource_state.extract()
if extracted > 0:
if resource_state.get_resource_id() == SimulationIds.RESOURCE_FOOD:
npc.add_inventory(
SimulationIds.RESOURCE_FOOD,
extracted
)
npc.add_inventory(SimulationIds.RESOURCE_FOOD, extracted)
npc_inventory_changed.emit(
npc,
SimulationIds.RESOURCE_FOOD,
npc.get_inventory_amount(
SimulationIds.RESOURCE_FOOD
)
npc.get_inventory_amount(SimulationIds.RESOURCE_FOOD)
)
else:
village.apply_resource_delta(
resource_state.get_resource_id(),
extracted
resource_state.get_resource_id(), extracted
)
_record_economic_event(
SimulationIds.EVENT_RESOURCE_EXTRACTED,
npc.id,
resource_state.get_node_id(),
_npc_inventory_id(npc.id)
if resource_state.get_resource_id() == SimulationIds.RESOURCE_FOOD
else &"village",
(
_npc_inventory_id(npc.id)
if resource_state.get_resource_id() == SimulationIds.RESOURCE_FOOD
else &"village"
),
resource_state.get_resource_id(),
extracted
)
@@ -201,7 +176,13 @@ func simulate_tick() -> void:
resource_state.get_node_id()
)
elif debug_logs:
print("[SimulationManager] ", npc.npc_name, " could not complete ", completed_task, ": target reservation was invalid")
print(
"[SimulationManager] ",
npc.npc_name,
" could not complete ",
completed_task,
": target reservation was invalid"
)
release_npc_reservation(npc.id)
elif completed_task == SimulationIds.ACTION_DEPOSIT_FOOD:
deposit_npc_inventory(npc, SimulationIds.RESOURCE_FOOD)
@@ -209,13 +190,19 @@ func simulate_tick() -> void:
withdraw_to_npc(npc, SimulationIds.RESOURCE_FOOD, 1.0)
elif completed_task == SimulationIds.ACTION_EAT:
consume_npc_food(npc)
elif completed_task not in [
SimulationIds.ACTION_GATHER_FOOD,
SimulationIds.ACTION_GATHER_WOOD
]:
elif (
completed_task
not in [SimulationIds.ACTION_GATHER_FOOD, SimulationIds.ACTION_GATHER_WOOD]
):
village.apply_npc_task(npc)
elif debug_logs:
print("[SimulationManager] ", npc.npc_name, " could not complete ", completed_task, ": no resource target")
print(
"[SimulationManager] ",
npc.npc_name,
" could not complete ",
completed_task,
": no resource target"
)
village_was_changed = true
@@ -254,20 +241,29 @@ func simulate_tick() -> void:
)
if old_state != npc.task_state:
print("[SimulationManager] State changed: ", npc.npc_name, " ", old_state, " -> ", npc.task_state)
print(
"[SimulationManager] State changed: ",
npc.npc_name,
" ",
old_state,
" -> ",
npc.task_state
)
if village_was_changed:
village_changed.emit(village)
if debug_logs:
print(village.get_summary())
func set_npc_target_id(npc_id: int, target_id: StringName) -> void:
for npc in npcs:
if npc.id == npc_id:
npc.target_id = target_id
return
func release_npc_reservation(npc_id: int) -> void:
for npc in npcs:
if npc.id == npc_id:
@@ -278,6 +274,7 @@ func release_npc_reservation(npc_id: int) -> void:
npc.target_id = &""
return
func notify_npc_arrived(npc_id: int) -> void:
for npc in npcs:
if npc.id == npc_id:
@@ -285,9 +282,7 @@ func notify_npc_arrived(npc_id: int) -> void:
return
if npc.task_state == SimNPC.TASK_STATE_TRAVELING:
var definition := SimulationDefinitions.get_action(
npc.current_task
)
var definition := SimulationDefinitions.get_action(npc.current_task)
if (
npc.target_id != &""
and definition != null
@@ -300,7 +295,13 @@ func notify_npc_arrived(npc_id: int) -> void:
or resource_state.get_reserved_by() != npc.id
):
if debug_logs:
print("[SimulationManager] ", npc.npc_name, " arrived but target ", npc.target_id, " is unavailable, replanning")
print(
"[SimulationManager] ",
npc.npc_name,
" arrived but target ",
npc.target_id,
" is unavailable, replanning"
)
notify_npc_navigation_failed(npc.id)
return
@@ -308,9 +309,15 @@ func notify_npc_arrived(npc_id: int) -> void:
npc.start_working()
if debug_logs:
print("[SimulationManager] ", npc.npc_name, " arrived and started working on: ", npc.current_task)
print(
"[SimulationManager] ",
npc.npc_name,
" arrived and started working on: ",
npc.current_task
)
return
func notify_npc_navigation_failed(npc_id: int) -> void:
for npc in npcs:
if npc.id != npc_id:
@@ -326,12 +333,20 @@ func notify_npc_navigation_failed(npc_id: int) -> void:
npc_target_requested.emit(npc)
if debug_logs:
print("[SimulationManager] ", npc.npc_name, " could not navigate for ", failed_task, " and is trying a wander target")
print(
"[SimulationManager] ",
npc.npc_name,
" could not navigate for ",
failed_task,
" and is trying a wander target"
)
return
func notify_npc_target_unavailable(npc_id: int) -> void:
notify_npc_navigation_failed(npc_id)
func resolve_npc_target(npc_id: int, origin: Vector3) -> bool:
if active_world_adapter == null:
push_error("SimulationManager: active_world_adapter is missing")
@@ -341,12 +356,7 @@ func resolve_npc_target(npc_id: int, origin: Vector3) -> bool:
continue
if npc.is_dead or npc.task_state != SimNPC.TASK_STATE_TRAVELING:
return false
var result := target_resolver.resolve(
npc,
origin,
self,
active_world_adapter
)
var result := target_resolver.resolve(npc, origin, self, active_world_adapter)
if result.is_empty():
notify_npc_target_unavailable(npc.id)
return false
@@ -357,6 +367,7 @@ func resolve_npc_target(npc_id: int, origin: Vector3) -> bool:
return true
return false
func request_current_travel(npc_id: int) -> bool:
for npc in npcs:
if npc.id != npc_id:
@@ -370,6 +381,7 @@ func request_current_travel(npc_id: int) -> bool:
return true
return false
func synchronize_npc_position(npc_id: int, active_position: Vector3) -> bool:
for npc in npcs:
if npc.id == npc_id:
@@ -377,9 +389,11 @@ func synchronize_npc_position(npc_id: int, active_position: Vector3) -> bool:
return true
return false
func _npc_inventory_id(npc_id: int) -> StringName:
return StringName("npc_%d_inventory" % npc_id)
func _record_economic_event(
event_type: StringName,
actor_id: int,
@@ -391,35 +405,26 @@ func _record_economic_event(
if amount <= 0.0:
return
var event := EconomicEventRecord.create(
next_event_id,
event_type,
tick_count,
actor_id,
source_id,
destination_id,
item_id,
amount
next_event_id, event_type, tick_count, actor_id, source_id, destination_id, item_id, amount
)
next_event_id += 1
economic_events.append(event)
economic_event_recorded.emit(event)
func _initialize_storage() -> void:
if storage_states.has(SimulationIds.STORAGE_VILLAGE_PANTRY):
_sync_village_food()
return
storage_states[SimulationIds.STORAGE_VILLAGE_PANTRY] = (
StorageStateRecord.create(
SimulationIds.STORAGE_VILLAGE_PANTRY,
{String(SimulationIds.RESOURCE_FOOD): village.food}
)
)
storage_states[SimulationIds.STORAGE_VILLAGE_PANTRY] = (StorageStateRecord.create(
SimulationIds.STORAGE_VILLAGE_PANTRY, {String(SimulationIds.RESOURCE_FOOD): village.food}
))
_sync_village_food()
func get_pantry() -> StorageStateRecord:
return storage_states.get(
SimulationIds.STORAGE_VILLAGE_PANTRY
) as StorageStateRecord
return storage_states.get(SimulationIds.STORAGE_VILLAGE_PANTRY) as StorageStateRecord
func _sync_village_food() -> void:
var pantry := get_pantry()
@@ -428,6 +433,7 @@ func _sync_village_food() -> void:
village.update_modifiers()
village.update_priorities()
func deposit_npc_inventory(npc: SimNPC, item_id: StringName) -> float:
var available := npc.get_inventory_amount(item_id)
var deposited := get_pantry().deposit(item_id, available)
@@ -445,11 +451,8 @@ func deposit_npc_inventory(npc: SimNPC, item_id: StringName) -> float:
)
return deposited
func withdraw_to_npc(
npc: SimNPC,
item_id: StringName,
amount: float
) -> float:
func withdraw_to_npc(npc: SimNPC, item_id: StringName, amount: float) -> float:
var withdrawn := get_pantry().withdraw(item_id, amount)
npc.add_inventory(item_id, withdrawn)
_sync_village_food()
@@ -465,6 +468,7 @@ func withdraw_to_npc(
)
return withdrawn
func consume_npc_food(npc: SimNPC) -> bool:
if npc.remove_inventory(SimulationIds.RESOURCE_FOOD, 1.0) < 1.0:
npc.hunger = minf(npc.hunger + 5.0, 100.0)
@@ -474,9 +478,7 @@ func consume_npc_food(npc: SimNPC) -> bool:
npc.starvation_ticks = 0
npc.is_starving = npc.hunger >= 90.0
npc_inventory_changed.emit(
npc,
SimulationIds.RESOURCE_FOOD,
npc.get_inventory_amount(SimulationIds.RESOURCE_FOOD)
npc, SimulationIds.RESOURCE_FOOD, npc.get_inventory_amount(SimulationIds.RESOURCE_FOOD)
)
_record_economic_event(
SimulationIds.EVENT_ITEM_CONSUMED,
@@ -488,10 +490,12 @@ func consume_npc_food(npc: SimNPC) -> bool:
)
return true
func register_loaded_resource_nodes() -> void:
for node in ResourceNode.get_all():
register_resource_node(node)
func register_resource_node(node: ResourceNode) -> bool:
if node == null or node.node_id.is_empty():
return false
@@ -502,8 +506,10 @@ func register_resource_node(node: ResourceNode) -> bool:
or action_definition.resource_action_id != node.action_id
):
push_error(
"SimulationManager: ResourceNode '%s' has invalid action_id '%s'"
% [node.node_id, node.action_id]
(
"SimulationManager: ResourceNode '%s' has invalid action_id '%s'"
% [node.node_id, node.action_id]
)
)
return false
var resource_state := get_resource_state(node.node_id)
@@ -511,46 +517,40 @@ func register_resource_node(node: ResourceNode) -> bool:
resource_state = ResourceStateRecord.create_from_node(node)
resource_states[node.node_id] = resource_state
elif not resource_state.apply_definition(node):
push_error(
"SimulationManager: ResourceNode definition mismatch for '%s'"
% node.node_id
)
push_error("SimulationManager: ResourceNode definition mismatch for '%s'" % node.node_id)
return false
return node.bind_state(resource_state)
func get_resource_state(node_id: StringName) -> ResourceStateRecord:
return resource_states.get(node_id) as ResourceStateRecord
func reserve_resource(node_id: StringName, agent_id: int) -> bool:
var resource_state := get_resource_state(node_id)
return resource_state != null and resource_state.reserve(agent_id)
func release_resource(node_id: StringName, agent_id: int) -> void:
var resource_state := get_resource_state(node_id)
if resource_state != null:
resource_state.release(agent_id)
func find_resource_node_for_player(
from_position: Vector3,
max_distance: float
) -> ResourceNode:
func find_resource_node_for_player(from_position: Vector3, max_distance: float) -> ResourceNode:
var best: ResourceNode
var best_distance := max_distance * max_distance
for node in ResourceNode.get_all():
var resource_state := get_resource_state(node.node_id)
if (
resource_state == null
or not resource_state.can_player_use_resource()
):
if resource_state == null or not resource_state.can_player_use_resource():
continue
var distance := from_position.distance_squared_to(
node.interaction_point.global_position
)
var distance := from_position.distance_squared_to(node.interaction_point.global_position)
if distance <= best_distance:
best_distance = distance
best = node
return best
func harvest_resource_node(node: ResourceNode) -> float:
if node == null:
return 0.0
@@ -570,9 +570,11 @@ func harvest_resource_node(node: ResourceNode) -> float:
SimulationIds.EVENT_RESOURCE_EXTRACTED,
-1,
resource_state.get_node_id(),
SimulationIds.STORAGE_VILLAGE_PANTRY
if resource_state.get_resource_id() == SimulationIds.RESOURCE_FOOD
else &"village",
(
SimulationIds.STORAGE_VILLAGE_PANTRY
if resource_state.get_resource_id() == SimulationIds.RESOURCE_FOOD
else &"village"
),
resource_state.get_resource_id(),
extracted
)
@@ -590,11 +592,13 @@ func harvest_resource_node(node: ResourceNode) -> float:
return extracted
func eat_food(amount: float) -> void:
get_pantry().withdraw(SimulationIds.RESOURCE_FOOD, amount)
_sync_village_food()
village_changed.emit(village)
func add_food(amount: float) -> void:
if amount >= 0.0:
get_pantry().deposit(SimulationIds.RESOURCE_FOOD, amount)
@@ -603,18 +607,22 @@ func add_food(amount: float) -> void:
_sync_village_food()
village_changed.emit(village)
func add_wood(amount: float) -> void:
village.apply_resource_delta(&"wood", amount)
village_changed.emit(village)
func add_safety(amount: float) -> void:
village.apply_resource_delta(&"safety", amount)
village_changed.emit(village)
func add_knowledge(amount: float) -> void:
village.apply_resource_delta(&"knowledge", amount)
village_changed.emit(village)
func get_starving_count() -> int:
var count := 0
for npc in npcs:
@@ -622,37 +630,42 @@ func get_starving_count() -> int:
count += 1
return count
func get_state_snapshot() -> Dictionary:
var npc_snapshots: Array[Dictionary] = []
for npc in npcs:
npc_snapshots.append({
"id": npc.id,
"name": npc.npc_name,
"profession": npc.profession,
"hunger": npc.hunger,
"energy": npc.energy,
"strength": npc.strength,
"intelligence": npc.intelligence,
"task": npc.current_task,
"task_state": npc.task_state,
"task_duration": npc.task_duration,
"task_progress": npc.task_progress,
"target_id": String(npc.target_id),
"position": [npc.position.x, npc.position.y, npc.position.z],
"travel_target_position": [
npc.travel_target_position.x,
npc.travel_target_position.y,
npc.travel_target_position.z
],
"has_travel_target": npc.has_travel_target,
"starvation_ticks": npc.starvation_ticks,
"is_dead": npc.is_dead
})
npc_snapshots.append(
{
"id": npc.id,
"name": npc.npc_name,
"profession": npc.profession,
"hunger": npc.hunger,
"energy": npc.energy,
"strength": npc.strength,
"intelligence": npc.intelligence,
"task": npc.current_task,
"task_state": npc.task_state,
"task_duration": npc.task_duration,
"task_progress": npc.task_progress,
"target_id": String(npc.target_id),
"position": [npc.position.x, npc.position.y, npc.position.z],
"travel_target_position":
[
npc.travel_target_position.x,
npc.travel_target_position.y,
npc.travel_target_position.z
],
"has_travel_target": npc.has_travel_target,
"starvation_ticks": npc.starvation_ticks,
"is_dead": npc.is_dead
}
)
return {
"seed": simulation_seed,
"tick_count": tick_count,
"village": {
"village":
{
"food": village.food,
"wood": village.wood,
"safety": village.safety,
@@ -661,9 +674,11 @@ func get_state_snapshot() -> Dictionary:
"npcs": npc_snapshots
}
func get_state_checksum() -> String:
return create_state_record().to_json().sha256_text()
func create_state_record() -> SimulationStateRecord:
var record := SimulationStateRecord.new()
var wander_streams: Array[Dictionary] = []
@@ -671,11 +686,9 @@ func create_state_record() -> SimulationStateRecord:
sorted_npc_ids.sort()
for npc_id in sorted_npc_ids:
var source: RandomNumberGenerator = wander_random_sources[npc_id]
wander_streams.append({
"npc_id": int(npc_id),
"seed": str(source.seed),
"state": str(source.state)
})
wander_streams.append(
{"npc_id": int(npc_id), "seed": str(source.seed), "state": str(source.state)}
)
record.simulation = {
"seed": simulation_seed,
@@ -704,9 +717,11 @@ func create_state_record() -> SimulationStateRecord:
record.economic_events.append(event)
return record
func serialize_state() -> String:
return create_state_record().to_json()
func restore_state_from_json(json_text: String) -> bool:
var record := SimulationStateRecord.from_json(json_text)
if record == null:
@@ -714,6 +729,7 @@ func restore_state_from_json(json_text: String) -> bool:
return false
return restore_state(record)
func restore_state(record: SimulationStateRecord) -> bool:
if record == null:
return false