Nuclide
Software Development Kit for id Technology (BETA)
Monster.h
1/*
2 * Copyright (c) 2016-2024 Vera Visions LLC.
3 *
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
13 * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
14 * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15*/
16
17#warning Integrate ai_relationship, ai_task, ai_schedule
18
19var bool autocvar_ai_enable = true;
20var bool autocvar_ai_debugLogic = false;
21void
22_ncMonster_Log(string className, string functionName, float edictNum, string warnMessage)
23{
24 if (autocvar_g_logTimestamps)
25 printf("^9%f ^5%s (%d) ^7: %s\n", time, functionName, edictNum, warnMessage);
26 else
27 printf("^5%s (%d) ^7: %s\n", functionName, edictNum, warnMessage);
28}
29#define ncMonsterLog(...) if (autocvar_ai_debugLogic == true) _ncMonster_Log(classname, __FUNC__, num_for_edict(this), sprintf(__VA_ARGS__))
30
36typedef enumflags
37{
38 MONFL_CHANGED_ORIGIN_X,
39 MONFL_CHANGED_ORIGIN_Y,
40 MONFL_CHANGED_ORIGIN_Z,
41 MONFL_CHANGED_ANGLES_X,
42 MONFL_CHANGED_ANGLES_Y,
43 MONFL_CHANGED_ANGLES_Z,
44 MONFL_CHANGED_MODELINDEX,
45 MONFL_CHANGED_SIZE,
46 MONFL_CHANGED_FLAGS,
47 MONFL_CHANGED_SOLID,
48 MONFL_CHANGED_FRAME,
49 MONFL_CHANGED_SKINHEALTH,
50 MONFL_CHANGED_MOVETYPE,
51 MONFL_CHANGED_EFFECTS,
52 MONFL_CHANGED_BODY,
53 MONFL_CHANGED_SCALE,
54 MONFL_CHANGED_VELOCITY,
55 MONFL_CHANGED_RENDERCOLOR,
56 MONFL_CHANGED_RENDERAMT,
57 MONFL_CHANGED_RENDERMODE,
58 MONFL_CHANGED_HEADYAW
59} nsmonster_changed_t;
60
61
63typedef enumflags
64{
65 MSF_WAITTILLSEEN,
66 MSF_GAG,
67 MSF_MONSTERCLIP,
68 MSF_RESERVED1,
69 MSF_PRISONER,
70 MSF_RESERVED2,
71 MSF_IGNOREPLAYER,
72 MSF_WAITFORSCRIPT,
73 MSF_RESERVED3,
74 MSF_FADECORPSE,
75 MSF_MULTIPLAYER,
76 MSF_FALLING,
77 MSF_HORDE
78} monsterFlag_t;
79
81typedef enumflags
82{
83 SMSF_WAITTILLSEEN,
84 SMSF_GAG,
85 SMSF_FALLTOGROUND,
86 SMSF_DROPHEALTHKIT,
87 SMSF_EFFICIENT,
88 SMSF_RESERVED1,
89 SMSF_RESERVED2,
90 SMSF_WAITFORSCRIPT,
91 SMSF_LONGVISIBILITY,
92 SMSF_FADECORPSE,
93 SMSF_THINKOUTPVS,
94 SMSF_TEMPLATE,
95 SMSF_ALTCOLLISION,
96 SMSF_NODROPWEAPONS,
97 SMSF_IGNOREPLAYERPUSH
98} sourceMonsterFlag_t;
99
101typedef enum
102{
103 MONSTER_IDLE,
104 MONSTER_ALERT,
105 MONSTER_FOLLOWING,
106 MONSTER_CHASING,
107 MONSTER_AIMING,
108 MONSTER_DEAD,
109 MONSTER_GIBBED
110} monsterState_t;
111
113typedef enum
114{
115 SEQUENCESTATE_NONE,
116 SEQUENCESTATE_IDLE,
117 SEQUENCESTATE_ACTIVE,
118 SEQUENCESTATE_ENDING
119} sequenceState_t;
120
122typedef enum
123{
124 MAL_FRIEND,
125 MAL_ENEMY,
126 MAL_ALIEN,
127 MAL_ROGUE,
128 MAL_NEUTRAL
129} allianceState_t;
130
132typedef enum
133{
134 MOVESTATE_IDLE,
135 MOVESTATE_WALK,
136 MOVESTATE_RUN
137} movementState_t;
138
143typedef enum
144{
145 MTRIG_NONE,
146 MTRIG_SEEPLAYER_ANGRY,
147 MTRIG_PAIN,
148 MTRIG_HALFHEALTH,
149 MTRIG_DEATH,
150 MTRIG_SQUADMEMBERDEAD,
151 MTRIG_SQUADLEADERDEAD,
152 MTRIG_HEARNOISE,
153 MTRIG_HEARENEMYPLAYER,
154 MTRIG_HEARWEAPONS,
155 MTRIG_SEEPLAYER,
156 MTRIG_SEEPLAYER_RELAXED,
157} triggerCondition_t;
158
159/* FIXME: I'd like to move this into ncMonster, but our current IsFriend()
160 * check is currently only checking on a .takedamage basis. */
161.int m_iAlliance;
162
276{
277public:
278 void ncMonster(void);
279
280#ifdef SERVER
281 /* overrides */
282 virtual void DebugDraw(void);
283 virtual void Save(float);
284 virtual void Restore(string,string);
285 virtual void EvaluateEntity(void);
286 virtual float SendEntity(entity,float);
287 virtual void Touch(entity);
288 //virtual void Hide(void);
289 virtual void Spawned(void);
290 virtual void Respawn(void);
291 virtual void Input(entity,string,string);
292 virtual void Pain(entity, entity, int, vector, vector, int);
293 virtual void Death(entity, entity, int, vector, vector, int);
294 virtual void Physics(void);
295 virtual void Gib(int, vector);
296 virtual void Sound(string);
297 virtual void SpawnKey(string,string);
298
301 virtual void RunAI(void);
303 virtual void IdleNoise(void);
305 virtual void FallNoise(void);
307 virtual void AlertNoise(void);
308
310 virtual bool IsAlive(void);
312 virtual bool IsFriend(int);
314 virtual void HasBeenKilled(void);
316 virtual void HasBeenHit(void);
317 /* Overridable: Called when the monster was gibbed. */
318 virtual void HasBeenGibbed(void);
319 /* Overridable: Called when the monster has been alerted to threat. */
320 virtual void HasBeenAlerted(void);
321
322 /* see/hear subsystem */
324 virtual void SeeThink(void);
326 virtual float SeeFOV(void);
327
329 virtual void AlertNearby(void);
330
331 /* movement */
333 virtual float GetWalkSpeed(void);
335 virtual float GetChaseSpeed(void);
337 virtual float GetRunSpeed(void);
339 virtual float GetYawSpeed(void);
340
341 /* attack system */
343 virtual void AttackDraw(void);
345 virtual void AttackHolster(void);
347 virtual void AttackThink(void);
349 virtual int AttackMelee(void);
351 virtual int AttackRanged(void);
352 nonvirtual void PerformAttack(string);
353
355 virtual float MeleeMaxDistance(void);
356
359 virtual bool MeleeCondition(void);
360
362 nonvirtual bool IsValidEnemy(entity);
364 virtual bool IsOnRoute(void);
366 virtual void RouteClear(void);
367
368 /* sequences */
370 virtual void ScriptedSequenceEnded(void);
372 virtual void ScriptedSequenceEnded_Moved(void);
374 virtual void ScriptedSequenceEnded_Dead(void);
376 virtual void RouteEnded(void);
378 virtual void WalkRoute(void);
379
380 /* callbacks */
382 virtual void SeenPlayer(ncActor);
384 virtual void SeenEnemy(ncActor);
386 virtual void SeenFriend(ncActor);
387
389 nonvirtual int GetSequenceState(void);
391 nonvirtual bool InScriptedSequence(void);
392
393 /* animation cycles */
395 virtual int AnimIdle(void);
397 virtual int AnimWalk(void);
399 virtual int AnimRun(void);
401 virtual void AnimPlay(float);
403 virtual void AnimationUpdate(void);
405 nonvirtual bool InForcedAnimation(void);
407 nonvirtual void AnimationRewind(void);
408
409 /* states */
411 virtual void StateChanged(monsterState_t,monsterState_t);
413 nonvirtual void SetState(monsterState_t);
415 nonvirtual monsterState_t GetState(void);
416
417 /* TriggerTarget/Condition */
419 nonvirtual int GetTriggerCondition(void);
421 virtual void TriggerTargets(void);
422
423 virtual void Trigger(entity, triggermode_t);
424 nonvirtual void AlertNearbyToSchedule(string scheduleType);
425 nonvirtual void AlertNearbyClassWithMindset(string scheduleType);
426 nonvirtual bool ShouldTurn(void);
427#endif
428
429 nonvirtual vector GetHeadAngles(void);
430
431 virtual void DebugDraw(void);
432
433#ifdef CLIENT
434
436 virtual void customphysics(void);
437 virtual float predraw(void);
438 virtual void ReceiveEntity(float,float);
439#endif
440
441private:
442
443 vector v_angle_net;
444
445#ifdef CLIENT
446 nonvirtual void _RenderDebugViewCone();
447#endif
448
449 PREDICTED_FLOAT(m_flHeadYaw)
450 PREDICTED_FLOAT_N(subblendfrac)
451 PREDICTED_FLOAT_N(bonecontrol1)
452
453#ifdef SERVER
454 entity m_eLookAt;
455 entity m_ssLast;
456 vector oldnet_velocity;
457 float m_sentencePitch;
458 int m_iFlags;
459 vector base_mins;
460 vector base_maxs;
461 float base_health;
462
463 /* I/O */
464 string m_outputOnDamaged;
465 string m_outputOnDeath;
466 string m_outputOnHalfHealth;
467 string m_outputOnHearPlayer;
468 string m_outputOnFoundEnemy;
469 string m_outputOnLostEnemy;
470 string m_outputOnLostEnemyLOS;
471 string m_outputOnFoundPlayer;
472 string m_outputOnLostPlayer;
473 string m_outputOnLostPlayerLOS;
474 string m_outputOnDamagedByPlayer;
475 string m_outputOnGreetPlayer;
476 bool m_bMetPlayer;
477
478 /* sequences */
479 string m_strRouteEnded;
480 int m_iSequenceRemove;
481 int m_iSequenceState;
482 float m_flSequenceEnd;
483 float m_flSequenceSpeed;
484 vector m_vecSequenceAngle;
485 int m_iSequenceFlags;
486 movementState_t m_iMoveState;
487 string m_strSequenceKillTarget;
488
489 int m_iTriggerCondition;
490 string m_strTriggerTarget;
491
492 /* model events */
493 float m_modelEventTime;
494
495 /* attack/alliance system */
496 entity m_eEnemy;
497 float m_flAttackThink;
498 monsterState_t m_iMState;
499 monsterState_t m_iOldMState;
500 vector m_vecLKPos; /* last-known pos */
501
502 /* see/hear subsystem */
503 float m_flSeeTime;
504 /* animation cycles */
505 float m_flAnimTime;
506
507 /* timer for keeping track of the target */
508 float m_flTrackingTime;
509
510 PREDICTED_VECTOR_N(view_ofs)
511
512 /* caching variables, don't save these */
513 float m_actIdle;
514 bool m_bTurning;
515 float m_flIdleNext;
516 float _m_flMeleeAttempts;
517 float _m_flMeleeDelay;
518 float _m_flBurstCount;
519 bool _m_bShouldThrow;
520 bool _m_bStartDead;
521 float _m_flFrame;
522
523 /* save these please */
524 float _m_flReloadTracker;
525 bool m_bWeaponDrawn;
526
527 /* entityDef related */
528 float m_flEyeHeight;
529 string m_sndSight;
530 string m_sndIdle;
531 float m_flIdleMin;
532 float m_flIdleMax;
533 string m_sndFootstep;
534 string m_sndChatter;
535 string m_sndChatterCombat;
536 string m_sndPain;
537
538 string m_sndMeleeAttack;
539 string m_sndMeleeAttackHit;
540 string m_sndMeleeAttackMiss;
541
542 string m_sndDeath;
543 string m_sndThud;
544
545 /* attack definitions, if defined will fire projectiles */
546 string m_defSpecial1;
547 float m_flSpecial1Range;
548 string m_defSpecial2;
549 float m_flSpecial2Range;
550 string m_defRanged1;
551 float m_flRanged1Range;
552 string m_defRanged2;
553 float m_flRanged2Range;
554
555 /* ranged1 only */
556 int m_iNumProjectiles;
557 float m_flProjectileDelay;
558 float m_flProjectileSpread;
559
560 /* general */
561 float m_flAttackCone;
562 float m_flAttackAccuracy;
563
564 /* melee attack */
565 string m_defMelee;
566 float m_flMeleeRange;
567
568 string m_sndRangedAttack;
569 float m_flReloadCount;
570 float m_flReloadDelay;
571 string m_sndReload;
572 float m_flReserveAmmo;
573
574 string m_sndRangedAttack2;
575
576 bool m_bWeaponStartsDrawn;
577 string m_strBodyOnDraw;
578
579 float m_flWalkSpeed;
580 float m_flRunSpeed;
581
582 float m_flLeapDamage;
583 bool m_bLeapAttacked;
584 float m_flForceSequence;
585 float m_flSkin;
586 bool m_bGagged;
587 float m_flStopTime;
588 float m_flyOffset;
589 bool m_usesNav;
590 bool m_fireFromHead;
591 bool m_pvsSleep;
592 bool m_bCanAttack;
593
594 nonvirtual void _LerpTurnToPos(vector);
595 nonvirtual void _LerpTurnToYaw(float);
596 virtual void _Alerted(void);
597 nonvirtual void _ChaseAfterSpawn(void);
598#endif
599};
600
601#ifdef CLIENT
602string Sentences_GetSamples(string);
603string Sentences_ProcessSample(string);
604#endif
605
606#ifdef SERVER
607void ncMonster_AlertEnemyAlliance(vector pos, float radius, int alliance);
608entity ncMonster_FindClosestPlayer(entity);
609#endif
610
611.float baseframe2;
612.float baseframe1time;
613.float baseframe2time;
614.float baselerpfrac;
615.float bonecontrol1;
616.float bonecontrol2;
617.float bonecontrol3;
618.float bonecontrol4;
619.float bonecontrol5;
620.float subblendfrac;
621.float subblend2frac;
622.float basesubblendfrac;
623.float basesubblend2frac;
This entity class represents an object with choreographed/free-form movement.
Definition: Actor.h:93
This entity class represents non-player characters.
Definition: Monster.h:276
virtual void AttackHolster(void)
Overridable: Called when they're holstering a weapon.
Definition: Monster.qc:1343
virtual void SeenPlayer(ncActor)
Called when a player is seen by the monster.
Definition: Monster.qc:791
virtual void Restore(string, string)
Similar to ncIO::SpawnKey() but for save-game fields.
Definition: Monster.qc:240
virtual void AlertNoise(void)
Overridable: Called when this monster gets 'alerted' to something new.
Definition: Monster.qc:562
virtual float GetRunSpeed(void)
Overridable: Returns the running speed in Quake units per second.
Definition: Monster.qc:967
nonvirtual void SetState(monsterState_t)
Sets the current state of this ncMonster.
Definition: Monster.qc:1667
virtual float GetWalkSpeed(void)
Overridable: Returns the walking speed in Quake units per second.
Definition: Monster.qc:955
virtual void Gib(int, vector)
Definition: Monster.qc:528
virtual void SeenFriend(ncActor)
Called when a friend is seen by the monster.
Definition: Monster.qc:801
virtual void DebugDraw(void)
virtual void IdleNoise(void)
Overridable: Called after a while when they've got nothing to do.
Definition: Monster.qc:548
virtual void Sound(string)
Definition: Monster.qc:522
virtual void HasBeenGibbed(void)
Definition: Monster.qc:2000
nonvirtual bool InForcedAnimation(void)
Returns if we're currently in a forced animation sequence.
Definition: Monster.qc:516
virtual float predraw(void)
virtual float GetYawSpeed(void)
Overridable: Returns the turning speed in euler-angle units per second.
Definition: Monster.qc:979
nonvirtual void AnimationRewind(void)
Starts the animation sequence from the beginning.
Definition: Monster.qc:510
virtual void StateChanged(monsterState_t, monsterState_t)
Called whenever the state of this ncMonster changes.
Definition: Monster.qc:1641
virtual void Pain(entity, entity, int, vector, vector, int)
Called whenever the entity receives damage.
Definition: Monster.qc:1885
virtual void AttackThink(void)
Overridable: Called when aiming their weapon.
Definition: Monster.qc:1039
virtual float SendEntity(entity, float)
Called by the engine whenever we need to send a client an update about this entity.
Definition: Monster.qc:2705
virtual bool IsAlive(void)
Returns if they're considered alive.
Definition: Monster.qc:1632
virtual void AttackDraw(void)
Overridable: Called when they're drawing a weapon.
Definition: Monster.qc:1325
virtual bool MeleeCondition(void)
Returns whether or not we should attempt a melee attack.
Definition: Monster.qc:597
virtual void ScriptedSequenceEnded(void)
Internal use only.
Definition: Monster.qc:1351
nonvirtual int GetSequenceState(void)
Returns the type of sequence they're currently in.
Definition: Monster.qc:1685
virtual void Respawn(void)
Server: Called when the entity first spawns or when game-logic requests the entity to return to its o...
Definition: Monster.qc:2154
virtual void Physics(void)
Definition: Monster.qc:1712
virtual int AnimIdle(void)
DEPRECATED, Overridable: Called when we need to play a fresh idle framegroup.
Definition: Monster.qc:484
virtual void Trigger(entity, triggermode_t)
Called whenever we're legacy triggered by another object or function.
Definition: Monster.qc:2439
virtual float GetChaseSpeed(void)
Overridable: Returns the chase speed in Quake units per second.
Definition: Monster.qc:961
nonvirtual bool IsValidEnemy(entity)
Returns TRUE if 'enemy' should be considered a valid target for killing.
Definition: Monster.qc:702
virtual void ScriptedSequenceEnded_Dead(void)
Internal use only.
Definition: Monster.qc:1426
virtual void AnimationUpdate(void)
Internal use only.
Definition: Monster.qc:1553
virtual bool IsOnRoute(void)
Returns TRUE if the monster is currently on route to a position.
Definition: Monster.qc:746
virtual void Save(float)
Handles saving a copy of this entity to a given filehandle.
Definition: Monster.qc:155
virtual void SpawnKey(string, string)
This method handles entity key/value pairs on map load.
Definition: Monster.qc:2454
virtual void ReceiveEntity(float, float)
Client: Handles network updates from the server for the associated entity.
virtual int AttackRanged(void)
Overridable: Called when attempting to attack from a distance.
Definition: Monster.qc:1158
virtual float MeleeMaxDistance(void)
Overridable: Returns the distance in qu of what'll be a successfull melee attack.
Definition: Monster.qc:590
nonvirtual void PerformAttack(string)
Definition: Monster.qc:1148
virtual void RunAI(void)
Internal use only.
Definition: Monster.qc:1697
virtual void AnimPlay(float)
Call to play a single animation onto it, which cannot be interrupted by movement.
Definition: Monster.qc:503
nonvirtual void AlertNearbyClassWithMindset(string scheduleType)
Definition: Monster.qc:674
virtual int AttackMelee(void)
Overridable: Called when attempting to melee attack.
Definition: Monster.qc:1085
nonvirtual int GetTriggerCondition(void)
Returns the condition under which they'll trigger their targets.
Definition: Monster.qc:137
nonvirtual bool ShouldTurn(void)
Definition: Monster.qc:973
virtual void ScriptedSequenceEnded_Moved(void)
Internal use only.
Definition: Monster.qc:1411
virtual void WalkRoute(void)
Internal use only.
Definition: Monster.qc:1474
virtual void Touch(entity)
Called whenever we're touching another entity.
Definition: Monster.qc:1820
virtual void HasBeenHit(void)
Overridable: Called every time the monster is hurt, while still alive.
Definition: Monster.qc:1868
void ncMonster(void)
Definition: Monster.qc:21
virtual int AnimWalk(void)
DEPRECATED, Overridable: Called when we need to play a fresh walking framegroup.
Definition: Monster.qc:490
virtual void HasBeenAlerted(void)
Definition: Monster.qc:2006
nonvirtual void AlertNearbyToSchedule(string scheduleType)
Definition: Monster.qc:642
virtual void SeeThink(void)
Internal use only.
Definition: Monster.qc:806
nonvirtual monsterState_t GetState(void)
Returns the current state of this ncMonster.
Definition: Monster.qc:1679
virtual void Spawned(void)
Called when the entity is fulled initialized.
Definition: Monster.qc:2120
virtual void FallNoise(void)
Overridable: Called when they start falling.
Definition: Monster.qc:543
virtual void DebugDraw(void)
Definition: Monster.qc:112
virtual float SeeFOV(void)
Overridable: Returns the field of view in degrees.
Definition: Monster.qc:603
virtual int AnimRun(void)
DEPRECATED, Overridable: Called when we need to play a fresh running framegroup.
Definition: Monster.qc:496
virtual void RouteClear(void)
Override.
Definition: Monster.qc:1874
virtual void HasBeenKilled(void)
Overridable: Called once, when the monster has died.
Definition: Monster.qc:1994
nonvirtual bool InScriptedSequence(void)
Returns if they're currently in a scripted sequence.
Definition: Monster.qc:1691
virtual bool IsFriend(int)
Returns whether they are allied with the type in question.
Definition: Monster.qc:572
virtual void Input(entity, string, string)
Called when we are being prompted by another object/function with an input message.
Definition: Monster.qc:2235
virtual void TriggerTargets(void)
Call to trigger their targets manually.
Definition: Monster.qc:143
virtual void EvaluateEntity(void)
Run each tic after physics are run to determine if we need to send updates over the network.
Definition: Monster.qc:2660
nonvirtual vector GetHeadAngles(void)
Definition: Monster.qc:130
virtual void Death(entity, entity, int, vector, vector, int)
Called when the health is equal or below 0.
Definition: Monster.qc:2018
virtual void customphysics(void)
overrides
virtual void RouteEnded(void)
Internal use only.
Definition: Monster.qc:1445
virtual void SeenEnemy(ncActor)
Called when an enemy is seen by the monster.
Definition: Monster.qc:796
virtual void AlertNearby(void)
FIXME: Same as WarnAllies/StartleAllies? WTF?
Definition: Monster.qc:609
typedef enumflags
Defines the valid alignment flags for text fields.
Definition: font.h:37
string Sentences_GetSamples(string)
Returns a string of sample for a given sentence.
Definition: sentences.qc:152