feat: give the player embodied hunger, energy, and starvation death

This commit is contained in:
2026-08-08 23:38:50 +02:00
parent 21b2eb06da
commit 9678526c5a
11 changed files with 488 additions and 65 deletions
+35 -1
View File
@@ -37,7 +37,7 @@ func _physics_process(delta: float) -> void:
var direction := (right * input.x + forward * -input.y).normalized()
var target_velocity := direction * move_speed
var target_velocity := direction * move_speed * _needs_speed_factor()
velocity.x = move_toward(velocity.x, target_velocity.x, acceleration * delta)
velocity.z = move_toward(velocity.z, target_velocity.z, acceleration * delta)
@@ -373,11 +373,45 @@ func _execute_pantry_interaction(context: PlayerInteractionResult) -> void:
var food_before := _get_pantry_food()
simulation_manager.eat_food(stomach_capacity_for_food)
var consumed := food_before - _get_pantry_food()
var player_hunger := _get_player_hunger()
if consumed > 0.0 and player_hunger > 0.0:
simulation_manager.player_eat(consumed)
interaction_feedback.emit(
"Ate from the pantry", "%.0f village food consumed." % consumed, consumed > 0.0
)
func _get_player_hunger() -> float:
if simulation_manager == null or not simulation_manager.has_method("get_player_state"):
return 0.0
var state: PlayerStateRecord = simulation_manager.get_player_state()
return state.get_hunger() if state != null else 0.0
func is_starving() -> bool:
if simulation_manager == null or not simulation_manager.has_method("get_player_state"):
return false
var state: PlayerStateRecord = simulation_manager.get_player_state()
return state.is_starving() if state != null else false
func _needs_speed_factor() -> float:
if simulation_manager == null or not simulation_manager.has_method("get_player_state"):
return 1.0
var state: PlayerStateRecord = simulation_manager.get_player_state()
if state == null or state.is_dead():
return 0.0
var factor := 1.0
if state.is_starving():
factor *= 0.5
var energy := state.get_energy()
if energy < 20.0:
factor *= 0.6
elif energy < 45.0:
factor *= 0.8
return factor
func _get_animal_feed_cost() -> float:
var definition := SimulationDefinitions.get_action(SimulationIds.ACTION_FEED_ANIMAL)
return definition.completion_cost_amount if definition != null else 1.0