From bdc1f88b6fe2f0c154588243faed25ad7e9f6b51 Mon Sep 17 00:00:00 2001
From: Rijad Zuzo <rijad.zuzo@matriq.ch>
Date: Sat, 20 Jun 2026 18:55:09 +0200
Subject: [PATCH] feat: add user interaction with the task zones

---
 main.tscn                       | 14 ++++++++---
 player/player.gd                | 44 +++++++++++++++++++++++++++++++++
 project.godot                   |  2 +-
 simulation/SimulationManager.gd | 11 ++++++---
 4 files changed, 63 insertions(+), 8 deletions(-)

diff --git a/main.tscn b/main.tscn
index b73435d..867b7b4 100644
--- a/main.tscn
+++ b/main.tscn
@@ -75,10 +75,17 @@ skeleton = NodePath("../../..")
 transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.18380833, 0)
 shape = SubResource("BoxShape3D_lquwl")
 
-[node name="Player" type="CharacterBody3D" parent="." node_paths=PackedStringArray("camera_rig")]
+[node name="Player" type="CharacterBody3D" parent="." node_paths=PackedStringArray("camera_rig", "simulation_manager", "farm_zone", "forest_zone", "food_zone", "guard_zone", "study_zone")]
 transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.05, 0)
 script = ExtResource("1_h2yge")
 camera_rig = NodePath("../CameraRig")
+simulation_manager = NodePath("../SimulationManager")
+farm_zone = NodePath("../TaskZone/FarmZone")
+forest_zone = NodePath("../TaskZone/ForestZone")
+food_zone = NodePath("../TaskZone/FoodZone")
+guard_zone = NodePath("../TaskZone/GuardZone")
+study_zone = NodePath("../TaskZone/StudyZone")
+stomach_capacity_for_food = 10
 
 [node name="CollisionShape3D" type="CollisionShape3D" parent="Player"]
 transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.85, 0)
@@ -185,9 +192,10 @@ offset_bottom = 140.0
 [node name="MarginContainer" type="MarginContainer" parent="UI/VillagePanel"]
 layout_mode = 2
 theme_override_constants/margin_left = 12
-theme_override_constants/margin_top = 12
+theme_override_constants/margin_top = 4
 theme_override_constants/margin_right = 12
-theme_override_constants/margin_bottom = 12
+theme_override_constants/margin_bottom = 4
 
 [node name="VillageStatsLabel" type="Label" parent="UI/VillagePanel/MarginContainer"]
 layout_mode = 2
+theme_override_font_sizes/font_size = 10
diff --git a/player/player.gd b/player/player.gd
index d0f1f8d..f2c11eb 100644
--- a/player/player.gd
+++ b/player/player.gd
@@ -5,6 +5,17 @@ extends CharacterBody3D
 @export var rotation_speed := 12.0
 @export var camera_rig: Node3D
 
+@export var simulation_manager: Node
+
+@export var farm_zone: Marker3D
+@export var forest_zone: Marker3D
+@export var food_zone: Marker3D
+@export var guard_zone: Marker3D
+@export var study_zone: Marker3D
+
+@export var stomach_capacity_for_food := 5
+@export var interaction_range := 3.0
+
 func _physics_process(delta: float) -> void:
 	var input := Input.get_vector(
 		"move_left",
@@ -39,3 +50,36 @@ func _physics_process(delta: float) -> void:
 	if direction.length() > 0.01:
 		var target_angle := atan2(direction.x, direction.z)
 		rotation.y = lerp_angle(rotation.y, target_angle, rotation_speed * delta)
+
+
+func _unhandled_input(event: InputEvent) -> void:
+	# keep your camera mouse code here too
+	if event.is_action_pressed("interact"):
+		try_interact()
+		
+		
+func try_interact() -> void:
+	if simulation_manager == null:
+		return
+
+	if is_near(farm_zone):
+		simulation_manager.add_food(5.0)
+		print("Player gathered food for the village.")
+	elif is_near(forest_zone):
+		simulation_manager.add_wood(5.0)
+		print("Player gathered wood for the village.")
+	elif is_near(guard_zone):
+		simulation_manager.add_safety(3.0)
+		print("Player helped guard the village.")
+	elif is_near(study_zone):
+		simulation_manager.add_knowledge(2.0)
+		print("Player shared knowledge.")
+	elif is_near(food_zone):
+		simulation_manager.eat_food(stomach_capacity_for_food)
+		print("Player eating shit up.")
+		
+func is_near(zone: Marker3D) -> bool:
+	if zone == null:
+		return false
+	
+	return global_position.distance_to(zone.global_position) <= interaction_range
diff --git a/project.godot b/project.godot
index 8af93bf..3a4c829 100644
--- a/project.godot
+++ b/project.godot
@@ -37,7 +37,7 @@ move_right={
 "events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":68,"key_label":0,"unicode":100,"location":0,"echo":false,"script":null)
 ]
 }
-Interaction={
+interact={
 "deadzone": 0.2,
 "events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":69,"key_label":0,"unicode":101,"location":0,"echo":false,"script":null)
 ]
diff --git a/simulation/SimulationManager.gd b/simulation/SimulationManager.gd
index 38f12a0..5816c22 100644
--- a/simulation/SimulationManager.gd
+++ b/simulation/SimulationManager.gd
@@ -8,13 +8,12 @@ var village := SimVillage.new()
 const DEBUG_LOGS := true
 
 var npcs: Array[SimNPC] = []
-var tick_interval := 1.0
+var tick_interval := 1.2
 var tick_timer := 0.0
 var tick_count := 0
 
 var names := [
-	"Rafi", "Mira", "Adem", "Nura", "Sahin",
-	"Lejla", "Tarik", "Hana", "Idris", "Zejd"
+	"Amina", "Tarik", "Jasmin"
 ]
 
 var professions := [
@@ -38,7 +37,7 @@ func _process(delta: float) -> void:
 		simulate_tick()
 
 func generate_npcs() -> void:
-	for i in range(10):
+	for i in range(names.size()):
 		var npc := SimNPC.new(
 			i,
 			names[i],
@@ -78,6 +77,10 @@ func simulate_tick() -> void:
 		village_changed.emit(village)
 	if DEBUG_LOGS:
 		print(village.get_summary())
+
+func eat_food(amount: float) -> void:
+	village.food -= amount
+	village_changed.emit(village)
 		
 func add_food(amount: float) -> void:
 	village.food += amount
