Skip to content

[Gothic I] Implement Control Spell - #1077

Open
Abendlied wants to merge 12 commits into
Try:masterfrom
Abendlied:fix-g1-control-instance-guard
Open

Abendlied wants to merge 12 commits into
Try:masterfrom
Abendlied:fix-g1-control-instance-guard

Conversation

@Abendlied

@Abendlied Abendlied commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

Updated: Ready for review, please provide feedback!

This aims to include the missing Gothic I Control spell from issue #1061 Further references, where I also gathered learnings and information relevant for the implementation:
From 2024 #661, item 12.
Original tracking entry: #622, item 18.9.

Implemented

  • Control cast moves control from player over to target NPC
  • Control ends on pressing Return key
  • Control ends when controlled NPC dies (incl. fatal fall, drowning, killed)
  • Damage to the player (original caster) now is handled by the Control implementation
  • VFX works (large ray orb on target NPC, funnel-bridge links caster and target NPC during casting)
  • Cancelled cast cleans up spell state
  • Gothic I spell handling is guarded against treating INTTOSTRING as a transform instance
  • Player plays the concentration pose during Control. If the animation is rejected during the cast release, it is retried through the AI queue, for the Control caster only.
  • Control now ends cleanly when the player reacted to damage first. The player no longer stays in a script state, which looked like a camera trap.
  • Implemented Control distance thresholds: Control now ends when the controlled NPC is more than 4000 (=40m ingame) units from the player. Beyond 3500 (=35m ingame) units the screen pulses green as a warning.
  • The controlled NPC's inventory cannot be opened during Control.

Verification

Gothic I

Test Results

  • Partial Control cast: works as intended
  • Complete Control cast: works
  • Player (caster) plays and holds concentration pose for the time while an NPC is controlled.
  • Player leaves concentration pose when controlling the NPC ends (by NPC's death, pressing Return, attack on the player by another NPC or controlled NPC.

Ending Control by:

  • Enter
  • Controlled NPC's death caused by another NPC
  • Controlled NPC's death caused by drowning
  • Controlled NPC's death caused by a Monster
  • Controlled NPC's death caused by fatal fall damage
  • Player takes damage from another NPC
  • Controlled NPC's distance to player exceeds 4000 units
  • Controlled NPC's distance to player exceeds 3500 units but not 4000 units, triggering the green pulsing warning signal while Enter key is hit, leading to green pulse effect vanishing, control transfer back to player and player leaving concentration pose
  • Controlled NPC kills a monster (to be precise, last lethal hit done by controlled NPC)
  • Controlled NPC kills an NPC, e.g. using ranged or using melee kill finishing move

Control is not interrupted by:

  • Controlled NPC being knocked out by another NPC
  • Controlled NPC taking non-fatal fall damage
  • Controlled NPC taking damage from another NPC
  • Controlled NPC's distance to player exceeds 3500 units but not 4000 units, triggering the green pulsing warning signal (warning vanishes when reducing the distance again)

Inventory Access

  • The controlled NPC's inventory cannot be opened during Control using inventory keys
  • Chests and looting dead NPCs still work for controlled NPCs
  • Inventory key works again after pressing Enter key, ending the control

Regression Testing: Transformation

  • Tested the sequence: Transform to Orcdog → Control NPC → Transform to Orcdog → Control NPC, without any observed regression.

Known Gaps

  • Saving/loading while controlling an NPC
    • is not handled (vanilla behaviour unclear and I cannot test it).
    • problematic to leave unhandled because loading a savegame where an NPC is controlled is leading to the game starting with the target NPC stuck in the cam trap bug. Pressing Enter does not stop the Control spell. Game "thinks" NPC is the player now and is unaware of a Control spell being active, this is not saved between savegames. Game is locked at that point.
    • Please indicate if you expect a workaround/fix for that
  • Sleeping is prohibited while controlling an NPC
    • I THINK this is the original game design but cannot verify).
    • If someone is able to test this in the original game, please report back your observation
  • When attacking the player with a controlled NPC, the player draws a melee weapon but does not fight back. Only visible for some ticks, probably irrelevant.
    • Unclear what the vanilla behaviour is.
    • If someone is able to test this in the original game, please report back your observation
  • Controlled NPC attacking same-guild NPCs causes them not to fight back.
    Reactions of NPCs to a controlled NPC's attacks work in general ( flee, nearby guards attack controlled NPC). In some cases an attacked NPC neither fights back nor flees. Without knowing the original behaviour, we have no real requirement to meet. Will stay as a gap deliberately for now.

Gothic II / Gothic II NotR
Not verified

@Abendlied

Abendlied commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor Author

Approach for the concentration pose:
reject non-interruptible ... existing=T_CONSHOOT_2_STAND ... finished=0 interrupt=0 force=0. The player at this tick is still in cast release transition and Npc_PlayAni tries but fails. It tries only once and it is 5 ticks too early.

Queued AI_PlayAnim could be used, it puts the action back to the front of the queue and retries next tick (npc.cpp, the AI_PlayAnim case).
But it seems it is not really used often, this would be defacto a Control-only path. Also I have no idea about mod compatibility.
AI_PlayAnimBs is probably not good as it is equipped with a body state which is not given in the script.

A successful Control cast now hands the player over to the target NPC. Enter, the death of the target, or damage to the original caster hands control back. While casting, the target gets its ray ball and a ray funnel links it to the caster.

Known gaps: the caster does not play the concentration pose, there is no distance limit yet, the controlled NPC's inventory is not blocked, and saving during Control is not handled.
@Abendlied
Abendlied force-pushed the fix-g1-control-instance-guard branch from 000478a to c7dcfd0 Compare December 1, 2026 13:11
When Control is cast, ZS_PC_Controlling starts while the mage is still in the
cast release transition (T_CONSHOOT_2_STAND), which cannot be interrupted.
Npc_PlayAni tries once, gets rejected, and the concentration pose is never played.

If Npc_PlayAni fails for the Control caster, queue the animation as AI_PlayAnim.
The existing AI_PlayAnim case retries every tick until the animation is accepted.
Other NPCs and scripts are not affected.
If the controlled NPC attacks the player, the player reacts, draws a weapon and leaves
ZS_PC_Controlling. World::endControl only cleared the caster's state while it was in
ZS_PC_Controlling, so after pressing Enter the player stayed in a script state, and
PlayerControl ignores all movement input in such a state. The result looked like a
stuck camera.

Clear the caster's state and AI queue when it is in any script state.
@Abendlied

Abendlied commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor Author

Actually implemented:
Npc_PlayAni is rejected during the cast release transition. For the Control caster, the failed animation is queued as AI_PlayAnim, which already retries each tick.

Added tests to test list in the first comment.

While Control is active, check distance between player  and controlled NPC
every tick. There are two limit thresholds: Beyond 3500 units the screen pulses green
(screen blend, once per second),
beyond 4000 units Control ends instantly (same way as pressing Enter).
The warning is removed as soon as the distance is back below 3500 or Control ends.
@Abendlied

Copy link
Copy Markdown
Contributor Author

Added implementation for distance limit thresholds.

Green strength: the pulse peaks at about 43% opacity (alpha 110/255). If it is too weak or too strong, it can be tweaked by the last three digits 110 in "0 255 0 110".
The code measures from the player's body to the target's centre. I am not 100% sure if this is right but it somewhat matches vanilla.

Technically there is no proof this solution matches the original game behaviour but I have elaborated why I think we have a strong case still in this comment:
#1061 (comment)

While Control is active, the inventory key no longer opens the inventory of the
controlled NPC. Closing an open inventory, chests and looting dead NPCs are not
affected, matching vanilla behaviour. Without Control the behaviour is unchanged.
@Abendlied

Copy link
Copy Markdown
Contributor Author

While Control is active, the inventory keys no longer open the inventory of the
controlled NPC. Looting chests and dead NPCs are not affected.
Without Control the behaviour is unchanged.

The handler checks world ->isControlling() and does not open the inventory in this case.
PlayerControl::interact is not touched as we need looting to be allowed from the controlled NPC, see here why I think this is needed: #1061 (comment)

Closing braces, erase comments, declare World::tickControl with the other private methods.
Also remove dead leftover code caster->transformBack() call in World::endControl.
Kept "untidy" part because it matches with Pyrokinesis PR, to avoid trouble.
@Abendlied Abendlied changed the title [Gothic I] Fix Control Instance Guard [Gothic I] Implement Control Spell Dec 2, 2026
Killing (monster, NPC) with the controlled NPC now ends Control, as in the original game.
XP and level-ups stay with the controlled NPC, as in the original game as well.

Control ends two ticks after the kill instead of immediately, so the
victim's ZS_Dead still sees the controlled NPC as the player and credits
it. Knocking out a human does not end Control. Melee finishing kill move does.
@Abendlied
Abendlied marked this pull request as ready for review December 3, 2026 13:32
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