game.environment.villager_happiness

Manages the happiness level of the villagers.

Classes

VillagerHappinessSystem

Calculates and tracks the average happiness of island villagers.

Module Contents

class game.environment.villager_happiness.VillagerHappinessSystem(isometric_map, entity_manager, degradation_system)[source]

Calculates and tracks the average happiness of island villagers.

Happiness is composed of three parts:

  • Food happiness — rises with pig count up to an ideal range, then falls off as the population grows too large.

  • Environment happiness — average of ecosystem health (inverse of overall degradation) and current forest coverage.

  • Feast bonus — a temporary boost granted when an emergency feast reduces an over-populated pig herd; decays smoothly over time.

The two base components are recalculated once per second to avoid per-frame overhead. The feast bonus is updated every frame for smooth visual decay.

isometric_map[source]
entity_manager[source]
degradation_system[source]
food_happiness = 0.75[source]
environment_happiness = 0.75[source]
feast_happiness_bonus = 0.0[source]
feast_bonus_decay_rate = 0.1[source]
register_feast(pigs_slaughtered)[source]

Register that an emergency feast has taken place.

If the pig count before the feast exceeded HAPPINESS_IDEAL_PIG_MAX (i.e. the feast actually relieved overpopulation pressure), a one-off feast_happiness_bonus of 0.5 is granted. The bonus then decays each frame via update().

Parameters:

pigs_slaughtered (int) – Number of pigs removed by the feast. Added back to the current count to reconstruct the pre-feast population for the threshold check.

update(dt)[source]

Periodically recalculates base happiness and decays any active bonus.

get_average_happiness()[source]

Calculates and returns the current average happiness level (0.0 to 1.0). This is calculated on-demand to ensure the value is always current.