Discuss: non-vanilla NPC AI rules removed from the NPC AI port (split/16)

Abierto
#501 2 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
5/5
Tiempo estimado
Más de una semana
Aptitud para principiantes
25/100
Tipo de issue
Nueva funcionalidad
Claridad
Bastante claro
Estado de actividad
Activo
Stack tecnológico
csharp, unity
Área
backend, game-dev

Línea de trabajo

Read the issue’s descriptions of the six removed rules and inspect commit 3e652e84 on branch split/16-npc-ai alongside the removal commit. The discussion needs a decision about which rules, if any, should return and whether they should be optional or address a specific VR behavior; done means that scope is agreed.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

Why they were removed

During the review of PR #479 (branch split/16-npc-ai, the NPC AI port) the maintainer decided that the port should match vanilla Gothic (G1/G2) exactly. Six AI rules were our own additions, not what the Daedalus scripts or the original engine do - more like a mod than a remake. Each sat behind its own DeveloperConfig flag (all on in Production). The flags and the code behind them were removed, so the game now does what the scripts and the engine do.

This issue keeps what they did and how, so we can discuss whether any of them should come back (for example as an optional, mod-like setting).

Restoring: the last commit that still has the code is 3e652e84 on branch split/16-npc-ai. The removal is the commit "refactor: AI rules beyond the vanilla scripts are removed" right after it on the same branch. git show 3e652e84:<path> gives the old files; reverting the removal commit brings everything back at once.


1. EnableNpcArmedThreatDetection - NPCs react to an armed, fighting NPC nearby

What it did: an NPC in its routine (no target) that saw a non-hero NPC with a drawn weapon (not fists) who was actively fighting someone within 4 m went into ZS_AssessFighter, as if the hero had drawn a weapon next to it.

Vanilla: B_AssessFighter (PERC_ASSESSFIGHTER / PERC_DRAWWEAPON) returns at once for anyone but the player (!Npc_IsPlayer(other)), so NPC-vs-NPC fights with weapons go unnoticed by bystanders unless another perception (fight sound, others' damage) fires.

Implementation:

  • AiHandler.ExecuteActivePerceptions (perception tick): if (Properties.TargetNpc == null && Dev.EnableNpcArmedThreatDetection) _npcAiService.CheckForArmedNpcThreat(NpcInstance);
  • NpcAiService.CheckForArmedNpcThreat -> NpcTargetSelectionDomain.CheckForArmedNpcThreat(self): loop over awake NPCs (hero skipped - that is the scripts' job), candidate must be alive, FightMode not NoWeapon/Fist, TargetNpc != null, within 4 m, not Friendly, not same guild, not a party member, not self's summoner, and visible (ExtNpcCanSeeNpc). If self is not already in ZS_ASSESSFIGHTER: set EnemyNpc/TargetNpc to the candidate, set other and ExtAiStartState(self, ZS_AssessFighter).
2. EnableActiveAttackerRetarget - a fighting NPC turns to a second attacker

What it did: an NPC that already had a target (from a previous tick) and could not see that target any more switched to the closest NPC/monster within its senses range that was fighting it (had it as its own TargetNpc/EnemyNpc), sensed through walls too (hearing/smell). Example: Cavalorn or a wolf attacks a guard who is locked on the hero behind a wall.

Vanilla: combat states like ZS_Attack register no PERC_ASSESSENEMY, so an NPC in a fight stays on its target until the scripts change it (Npc_GetNextTarget in ZS_Attack_Loop, damage perceptions).

Implementation:

  • AiHandler.ExecuteActivePerceptions: a snapshot hadTargetBeforeThisTick = Properties.TargetNpc != null before UpdateEnemyNpc, then if (hadTargetBeforeThisTick && Dev.EnableActiveAttackerRetarget) _npcAiService.UpdateActiveAttackerTarget(NpcInstance);
  • NpcAiService.UpdateActiveAttackerTarget -> NpcTargetSelectionDomain.UpdateActiveAttackerTarget(self): keep the current target while it is alive and visible; otherwise scan the hero and awake NPCs for the closest one that targets self (not dead, not Friendly, not same guild, not a party member, not self's summoner, within senses range, CanSenseNpc(..., freeLOS: true)) and set it as EnemyNpc/TargetNpc.
3. EnableNpcHitRetaliation - an NPC hit by another NPC targets the attacker

What it did: when a non-hero NPC hit a living target, the target's TargetNpc/EnemyNpc were force-set to the attacker (wolves, monsters, companions became the active fight target), except Friendly attackers, same guild and party members (summons).

Vanilla: B_CombatReactToDamage switches the target only when the player is the attacker; other hits only go through the AssessDamage perception (B_AssessDamage / B_MM_ReactToDamage).

Implementation: DamagePerceptionDomain.BroadcastDamagePerceptions called TrySwitchTargetToAttacker(attacker, target, heroIndex) after the victim's ReactToDamage:

if (!Dev.EnableNpcHitRetaliation || attacker is hero || target dead || same guild ||
    IsPartyMember(attacker) || ExtGetAttitude(target, attacker) == Friendly) return;
target.Props.TargetNpc = attacker.Instance;
target.Props.EnemyNpc = attacker.Instance;
5. EnableGuardsAgainstBerzerk - guards knock out a berzerk NPC (G1)

What it did: whenever an NPC in ZS_Berzerk dealt a hit, every awake NPC within 15 m that C_NpcIsGuard accepted (and that was up, not the hero, not berzerk or in ZS_Attack itself) got the berzerker as EnemyNpc/TargetNpc, drew its weapon (AI_DrawWeapon) and started ZS_Attack. As the berzerker is not hostile to them, ZS_Attack_End only knocks it out.

Vanilla: G1 lets a berzerk NPC rage; guards only protect their charges from non-friends (B_AssessFightSound, "friendly fire" rule).

Implementation: DamagePerceptionDomain.CallGuardsAgainstBerzerk(attacker) at the start of BroadcastDamagePerceptions, with IsGuardCandidate and the range constant _guardsHelpRange = 15f. Needed DaedalusConst.ZsAttack and DaedalusConst.CNpcIsGuard (also removed). DamagePerceptionDomain.IsBerzerk stays - FightService still uses it.

6. EnableHeroSummonAttitude - NPCs see the hero's summons like the hero

What it did: between the hero's summon and a non-summon NPC, the attitude was the NPC's attitude towards the hero (temp, then permanent, then guild table): bandits and wolves fought the summon, Cavalorn or Xardas left it alone.

Vanilla: the guild table decides. In G2 B_InitMonsterAttitudes makes humans hostile to the GIL_SUMMONED_* guilds, so guards attack the hero's summons too.

Implementation: NpcHelperService.GetPersonAttitude, after the summoner/summon friendly rule:

if (Dev.EnableHeroSummonAttitude)
{
    if (IsHeroSummon(other) && self.SummonedBy == null && !IsHero(self)) return GetAttitudeTowardsHero(self);
    if (IsHeroSummon(self) && other.SummonedBy == null && !IsHero(other)) return GetAttitudeTowardsHero(other);
}

plus the private helpers IsHeroSummon and GetAttitudeTowardsHero. The rule that a summon and its own summoner are always friendly stays (it is unconditional and not part of this flag).

7. EnableProclaimFromAfar - the proclaiming NPC stops chasing within 12 m

What it did: an NPC in ZS_ProclaimAndPunish (G2, "Now wait...") chasing the hero cleared its AI queue and went to the state's End (the proclaim and the attack) once the hero was within 12 m; after HAI_TIME_PURSUIT seconds it cleared the queue so the loop could decide (back to routine). Added because a hero running away right after his attack was chased until caught (Lukis).

Vanilla: ZS_ProclaimAndPunish_Loop only runs again once its AI_GotoNpc is done, i.e. when the NPC reached the hero; then it checks PERC_DIST_DIALOG (5 m) and HAI_TIME_PURSUIT. (The engine-side stop of AI_GotoNpc after HAI_TIME_PURSUIT in GoToNpc is ungated and stays.)

Implementation: AiHandler.CheckProclaimChase(), called every tick in Update after ExecuteActivePerceptions; constants _proclaimState = "ZS_PROCLAIMANDPUNISH", _proclaimDistance = 12f, _defaultPursuitSeconds = 20f, and DaedalusConst.HaiTimePursuit (also removed):

if (!Dev.EnableProclaimFromAfar || loop state != Loop || queue empty and action finished || state != ZS_PROCLAIMANDPUNISH) return;
var isClose = distance(npc, hero) <= 12;
if (!isClose && StateTime <= HAI_TIME_PURSUIT) return;
_npcAiService.ExtNpcClearAiQueue(NpcInstance);
if (isClose) CurrentLoopState = LoopState.End;

(#4 EnableHeroChaseCooldown is not part of this removal - it is still being looked at.)


To discuss

Should any of these come back? If yes, as what: an optional, mod-like setting (off by default, the game stays vanilla), or a fix in a specific situation where vanilla behaviour looks broken in VR? Please say which rule and why.

🤖 Generated with Claude Code

Lenguaje dominante
C#
Estrellas
33
Forks
1
Merge medio
2 d 4 h
PR fusionados (30 d)
76

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de Gothic-Unity-Project/Gothic-Unity

Todos los issues de Gothic-Unity-Project/Gothic-Unity

Issues similares

Más issues de C#

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.