Pular para o conteúdo principal

Hunger, sleep and death

Sleep by the clock​

NPCSleepHelper.isSleepPeriod answers whether this NPC's sleep window is open:

Float hour = currentHour(world);
if (hour == null) return false;
boolean night = hour < DAY_START_HOUR || hour >= NIGHT_START_HOUR;
return isNightWatch(npc) ? !night : night;

The night boundary reuses the same split InteractionManager already used for night-time greetings, so dialogue and routine never disagree about the time.

When the time resource cannot be read, it returns false — degrading to exhaustion-only behaviour rather than trapping the village in bed.

Guards (Profession.GUARD) run the inverted shift. Their energy drains and refills normally, just on the opposite schedule, which is why no special rule for zero energy was needed.

Food classification​

Map<InteractionType, String> interactions = item.getInteractions();
String id = interactions.get(InteractionType.Secondary);
// Root_Secondary_Consume_Food_T1..T3

The tier arrives free as a raw-versus-cooked signal: raw meat, ingredients and crops inherit T1 from their templates; anything cooked declares T2 or T3.

scoreFor ranks tier → taste → distance. Tier dominates deliberately: a hated pie beats a beloved slab of raw beef, which is the behaviour a village sim wants.

Thresholds and pacing​

HungerBehaviour
< 70Idle NPCs start FINDING_FOOD (RoutineSleepHelpers.handleIdle)
< 25Any NPC drops its task and goes to eat (RoutineAISystem interrupt)
<= 5tickStarvation keeps it IDLE, sad and crying

From 100, the first search happens after roughly 4h10, and the interrupt after ~10h25. Both values scale with hungerDecayMultiplier in simtale-config.json (1.0 = original pacing, 10.0 ≈ 25 minutes to the first search, 0 = frozen).

Where food comes from​

NPCHungerHelper scans ChestRegistry.CHESTS within 24 blocks and keeps only chests HouseManager.canOpenChest allows:

  • a private chest owned by the NPC's house;
  • an explicitly shared chest (/simtale chestshare);
  • a village-global chest: inside a village, owned by no house.

The last rule is derived live by ChestRegistry.isVillageGlobal; it is not persisted. Move the chest into a house and it becomes private again. This is also how homeless NPCs (guards, miners) get food.

The key is an enum

getInteractions() returns Map<InteractionType, String>, not Map<String, String>. Using get("Secondary") compiles and classifies every item as inedible.

Starvation​

Hunger is not lethal, by design. Aging and disease will own death; a third cause competing with them would make all three harder to reason about.

NPCHungerHelper.tickStarvation breaks a starving NPC out of whatever it was doing, sets SAD and plays the crying animation. What it costs the NPC is its usefulness, not its life — job, hobby and social life stop until someone feeds it.

Three families of task are excluded from the interruption:

ExcludedWhy
FINDING_FOOD, MOVING_TO_FOOD, EATINGOtherwise it finds a chest and is pulled back to IDLE before reaching it
The five sleep tasksYanking a sleeping NPC to IDLE leaves the sleeping flag orphaned
DYING, DEAD, REAPINGDying is not a task to interrupt

O fluxo DYING → DEAD → REAPING está totalmente integrado ao sistema de vida (Health) nativo da engine. Sempre que um NPC chega a 0 HP — por dano de combate, dano de queda, ou pelo /simtale forcekill — o RoutineAISystem intercepta isso e o joga no fluxo de morte, evitando que a entidade fique vagando quebrada num estado "quase-morto".

Removed system

Earlier versions of this page documented a Needs.starvationDamage counter that killed at 200 accumulated damage. Needs.java was removed in the migration to native EntityStats, and the leftover hunger <= 0 → DYING trigger — which killed instantly, the opposite of the intent — went with it, along with the now-unreferenced STARVATION_DAMAGE, STARVATION_INTERVAL_TICKS and LETHAL_STARVATION_DAMAGE.

Feeding by hand​

InteractionManager.tryFeed runs before the normal gift rules. At 70 hunger or below, edible gifts are eaten on the spot: hunger and health restored by tier, larger affinity gain.

It uses the same NPCFoodHelper as the chest routine, so a player cannot force-feed something the NPC would refuse on her own.

Persistence​

Needs live in the entity's EntityStatMap, but SimTale keeps its own snapshot in SimNPCData.needs and writes it on every saveNPC. On load, NeedsHelper.restoreSavedNeeds applies the snapshot only when all five live needs are still at the asset default (100) — the signature of a stat map the engine reset. If the engine restored real values, those win.

Detached-component save paths (commands and lifecycle helpers) reuse the snapshot already loaded rather than overwriting it with 100.

Forced feeding​

/simtale forceeat zeroes hunger, backdates the search cooldown so the chest scan runs immediately, and keeps forcedByDebug set while the NPC is in FINDING_FOOD / MOVING_TO_FOOD / EATING. The night sleep interrupt therefore cannot pull her into bed before she reaches the chest.

Constants​

See Balancing for the full table.