78 lines
1.5 KiB
GDScript
78 lines
1.5 KiB
GDScript
class_name SimNPC
|
|
extends RefCounted
|
|
|
|
var id: int
|
|
var npc_name: String
|
|
var profession: String
|
|
var hunger: float
|
|
var energy: float
|
|
var strength: float
|
|
var intelligence: float
|
|
var current_task: String = "idle"
|
|
var position: Vector3
|
|
|
|
func _init(
|
|
_id: int,
|
|
_npc_name: String,
|
|
_profession: String,
|
|
_strength: float,
|
|
_intelligence: float
|
|
) -> void:
|
|
id = _id
|
|
npc_name = _npc_name
|
|
profession = _profession
|
|
strength = _strength
|
|
intelligence = _intelligence
|
|
hunger = randf_range(20.0, 80.0)
|
|
energy = randf_range(40.0, 100.0)
|
|
|
|
position = Vector3(randf_range(-8.0, 8.0), 0.0, randf_range(-8.0, 8.0))
|
|
|
|
func simulate_tick(village: SimVillage) -> void:
|
|
hunger += 5.0 * village.food_modifier
|
|
energy -= 2.0
|
|
|
|
hunger = clamp(hunger, 0.0, 100.0)
|
|
energy = clamp(energy, 0.0, 100.0)
|
|
|
|
if hunger > 75.0:
|
|
if village.food > 0:
|
|
current_task = "eat"
|
|
hunger -= 25.0
|
|
else:
|
|
current_task = "gather_food"
|
|
return
|
|
|
|
if energy < 30.0:
|
|
current_task = "rest"
|
|
energy += 20.0
|
|
return
|
|
|
|
if village.food < 15.0:
|
|
current_task = "gather_food"
|
|
return
|
|
|
|
if village.wood < 10.0:
|
|
current_task = "gather_wood"
|
|
return
|
|
|
|
if village.safety < 40.0 and profession == "guard":
|
|
current_task = "patrol"
|
|
return
|
|
|
|
if village.knowledge < 10.0 and profession == "scholar":
|
|
current_task = "study"
|
|
return
|
|
|
|
match profession:
|
|
"farmer":
|
|
current_task = "gather_food"
|
|
"woodcutter":
|
|
current_task = "gather_wood"
|
|
"guard":
|
|
current_task = "patrol"
|
|
"scholar":
|
|
current_task = "study"
|
|
_:
|
|
current_task = "wander"
|