DM1 V1 — Creature AI Behavior

Status

RESOLVED for DM1 finish scope — movement, perception, reactions, and caster payloads gated

pass1066 gates the F0798/F0799 one-step movement selector. pass1067 gates F0790-F0796 perception, aggro transition, deterministic tick behavior, and champion target selection. pass1069 extends the creature-AI source-lock gate with reaction-event creation, projectile-hit search turning, and danger-on-square movement that stops attack behavior and returns the group to approach. Existing projectile/caster gates cover F0207/F0212 launch payloads, Vexirk alternate spell selection, Wizard Eye/Trolin-style spell palettes, and the C25/C26 BUG0_13-safe fallback.

Runtime creature-chain capture remains tracked separately under the Creature grouping/coordination and original-capture rows; it is not an unimplemented AI-rule gap.

Source-locked to: ReDMCSB WIP20210206 GROUP.C, DEFS.H Companion: src/dm1/dm1_v1_creature_ai_behavior_pc34_compat.c


1. Behavior State Machine

Creatures use a per-group Behavior enum (GROUP.C:1372–1378, DEFS.H):

Value Name Description
C0 BEHAVIOR_WANDER Move toward party if smelt; otherwise random dirs
C5 BEHAVIOR_FLEE Afraid — flees from square where party/danger was last seen
C6 BEHAVIOR_ATTACK Attack party; ranged casters line up shots; melee closes in
C7 BEHAVIOR_APPROACH Not in attack range — moves toward last known party position

Values C2–C4 (USELESS) are declared but never assigned (GROUP.C:329, 476 note BUG0_00).

Behavior is stored per-group (Group->Behavior), not per-creature, but individual creatures fire separate UPDATE_BEHAVIOR_CREATURE_N events (38–41) for per-creature attack timing (GROUP.C:2126–2127).


2. Behavior Transition Logic (GROUP.C F0209 GROUP_ProcessEvents29to41)

Wandering (C0) — lines 2100–2148

WANDER ├─ See party? (F0200_GetDistanceToVisibleParty > 0) │ ├─ In attack range? → BEHAVIOR_ATTACK (C6) │ └─ Not in range? → BEHAVIOR_APPROACH (C7) └─ No sight ├─ Smell party? (F0201 + smell range check) │ └─ Try primary dir → possible move → WANDER or same dir └─ No smell └─ Random direction walk (M004_RANDOM(4) + movement possible test)

Approach (C7) — lines 2236–2256

Attack (C6) — lines 2073–2134, 2376–2410

Flee (C5) — lines 2289–2308, 2336–2340


3. Event System

Timeline drives all behavior. Key events (DEFS.H:956–960):

Reaction events (GROUP.C F0209 C29..C31):

Events are accumulated even when Life is Frozen (BUG0_14 noted at GROUP.C:1982).


4. Creature Type Attributes

Creature attributes in Ranges struct (DEFS.H):

Creature properties from DATA.C creature tables:


5. Key Source Citations

Function File:Line Role
F0200_GROUP_GetDistanceToVisibleParty GROUP.C:1315 Line-of-sight distance to party
F0201_GROUP_GetSmelledPartyPrimaryDirectionOrdinal GROUP.C:1417 Smell-based direction
F0197_GROUP_IsViewPartyBlocked GROUP.C:1176 Wall/square blocks sight check
F0198_GROUP_IsSmellPartyBlocked GROUP.C:1214 Wall/square blocks smell check
F0207_GROUP_IsCreatureAttacking GROUP.C:1645 Melee/ranged attack resolution
F0193_GROUP_StealFromChampion GROUP.C:1013 Giggler steal behavior
F0209_GROUP_ProcessEvents29to41 GROUP.C:1837 Main behavior FSM
T0209094_FleeFromTarget GROUP.C:2290 Flee direction selection
MASK0x0080_IS_ATTACKING DEFS.H:606 Per-creature attacking bit
C0..C7BEHAVIOR* DEFS.H:1372–1378 Behavior enum