Skip to content

fix: after the hero slept every NPC starts over at its routine for the new time - sleepers get up, chasers give up - #570

Open
BoroBongo wants to merge 10 commits into
developfrom
fix/npcs-start-over-after-sleep
Open

BoroBongo wants to merge 10 commits into
developfrom
fix/npcs-start-over-after-sleep

Conversation

@BoroBongo

Copy link
Copy Markdown
Contributor

What

After the hero sleeps (or Marvin sets the time), every living NPC starts over at its routine for the new time, the same way as after it was out of view: it goes to its routine spot with an empty action queue, no enemy and its weapon away. Visible NPCs reset one per frame; culled ones reset when they show up again.

Left out on purpose:

  • NPCs that are down (dead or knocked out). A magically frozen NPC does reset.
  • The hero's company: guides, followers, party members and summons.
  • The NPC the hero is talking to.
  • Time jumps while a world loads. G2's startup scripts set the time; the game clock no longer reports that as a jump.

This restores a fix that was lost when the experimental branch was split into PRs (26c60bf). AiHandler.ResetAfterTimeSkip was still in the code, but nothing called it.

Technical:

  • GameTimeService.SetTime raises GlobalEventDispatcher.GameTimeSkipped.
  • NpcService.ResetNpcsAfterTimeSkip recalculates the routines and queues the resets.
  • NpcRoutineService.RecalculateAllNpcRoutines is extracted from the minute tick.
  • New helpers: DialogModel.IsTalkingTo and NpcHelperService.IsHeroCompanion. The older copies of both checks move to them in NPC code cleanup after the 2026-11-25 fixes: split NpcService, one place per rule #568.

Why

In a playtest (G2 Khorinis), the NPCs kept sleeping after the hero slept until morning.

How to test manually

  • G2 Khorinis at night (Fellan sleeps 01:30-04:30): sleep in a bed until morning. Fellan gets up and goes to his planks; the log shows [TimeSkipReset] Time skipped - resetting N visible NPC(s).
  • G2 new game: the log shows [GameTime] ... not reported once during the world load, and there is no reset.
  • Sleep while a follower walks with you (G1 Mordrag's escort, or a summon). He stays with you.
  • Marvin set time while talking to an NPC. The dialog continues.
  • Sleep next to a dead and a knocked-out NPC. They stay as they are.
  • G1: a guard chasing the hero gives up after the hero sleeps.

Save/load

Nothing new is saved. A reset still pending for a culled NPC is lost on load; after a load every NPC starts at its routine anyway.

Known gaps / follow-ups

🤖 Generated with Claude Code

BoroBongo and others added 10 commits November 25, 2026 21:07
…e new time - sleepers get up, chasers give up (lost in the split of 26c60bf)

Wld_SetTime (PC_Sleep, Nadja, a world's startup) and Marvin's "set time" only moved the clock: visible NPCs kept
their state until it ended by itself, so the sleepers slept on through the morning. GameTimeService.SetTime now raises
GameTimeSkipped; NpcService recalculates every routine and resets each living NPC like after culling
(AiHandler.ResetAfterTimeSkip - it was still there, nobody called it): visible ones one per frame, culled ones when
they show up. Dead and knocked out NPCs stay.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…me jump of the world's startup no longer leaves stale marks

G2's STARTUP_* scripts call Wld_SetTime while the world loads: every NPC got a time-skip mark, an NPC's first build
never used it up, and at the first real sleep the marked visible NPCs were skipped - Lobart's farmers slept on. A
time jump while the world loads is ignored now (logged once), never built NPCs are not marked (they start fresh),
a first build drops the mark, and visible NPCs are always queued (once). The log counts visible and culled NPCs.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… the time-skip reset no longer teleports them to a waypoint

The reset after a time jump sends an NPC to its routine waypoint like after culling. NPCs in a guide/follow state
(ZS_GuidePC/ZS_FollowPC, ZS_Guide_Player/ZS_Follow_Player), party members (AIV_PARTYMEMBER, e.g. Mordrag leading
the hero) and the hero's summons (AIV_MM_PARTYMEMBER) are kept now; the log counts them.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…time - the time-skip reset leaves him out

A time jump during a dialog (Marvin's "set time"; sleeping opens no dialog) reset the dialog partner like after
culling: empty AI queue, teleport to his routine waypoint, while the dialog was still open.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…skip reset uses the shared "is down" rule

The reset skipped every NPC with BS_UNCONSCIOUS, which ZS_MagicFreeze also sets. It now uses IsDown(): dead or
knocked out, not frozen.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…pt the down, the hero's company and his dialog partner

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…alkingTo, used by the time-skip reset

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…eService doesn't raise GameTimeSkipped then, the NPC reset drops its own loading flag

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…Companion (escort, party member, summon), used by the time-skip reset

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…s, the routine change PR stacked on it doesn't end their activities then

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@BoroBongo

Copy link
Copy Markdown
Contributor Author

Review (architecture-reviewer + gothic-reviewer), two rounds

Round 1 (9d34048). Gothic: fix before merge. Architecture: fits with concerns. Everything was fixed in this PR:

  • Stale reset marks. G2's startup Wld_SetTime marked every NPC, and later sleeps skipped them. Fixed in three steps: a jump while a world loads isn't reported, unbuilt NPCs are skipped, and a mark is removed on the NPC's first build.
  • Hero's company. Followers, guides, party members and summons are no longer teleported.
  • Dialog partner. The NPC the hero is talking to is left alone.
  • Down check. Uses IsDown(), so a frozen NPC does reset.
  • ADR. Added.

Round 2 (66c90a7). Gothic: OK to merge. Architecture: fits with concerns. Fixed:

Follow-ups: #568 (split NpcService, move the old copies to the new helpers).

Editor check (G2 Khorinis, slot 6):

  • Time set to 07:05: [TimeSkipReset] resetting 59 visible NPC(s), and Fellan got up and went to his planks.
  • No exceptions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant