Nuclide
Software Development Kit for id Technology
NSMonster.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
17var bool autocvar_ai_enable = true;
18var bool autocvar_ai_debugLogic = false;
19void
20_NSMonster_Log(string className, string functionName, float edictNum, string warnMessage)
21{
22 if (autocvar_g_logTimestamps)
23 printf("^9%f ^5%s (%d) ^7: %s\n", time, functionName, edictNum, warnMessage);
24 else
25 printf("^5%s (%d) ^7: %s\n", functionName, edictNum, warnMessage);
26}
27#define NSMonsterLog(...) if (autocvar_ai_debugLogic == true) _NSMonster_Log(classname, __FUNC__, num_for_edict(this), sprintf(__VA_ARGS__))
28
34typedef enumflags
35{
36 MONFL_CHANGED_ORIGIN_X,
37 MONFL_CHANGED_ORIGIN_Y,
38 MONFL_CHANGED_ORIGIN_Z,
39 MONFL_CHANGED_ANGLES_X,
40 MONFL_CHANGED_ANGLES_Y,
41 MONFL_CHANGED_ANGLES_Z,
42 MONFL_CHANGED_MODELINDEX,
43 MONFL_CHANGED_SIZE,
44 MONFL_CHANGED_FLAGS,
45 MONFL_CHANGED_SOLID,
46 MONFL_CHANGED_FRAME,
47 MONFL_CHANGED_SKINHEALTH,
48 MONFL_CHANGED_MOVETYPE,
49 MONFL_CHANGED_EFFECTS,
50 MONFL_CHANGED_BODY,
51 MONFL_CHANGED_SCALE,
52 MONFL_CHANGED_VELOCITY,
53 MONFL_CHANGED_RENDERCOLOR,
54 MONFL_CHANGED_RENDERAMT,
55 MONFL_CHANGED_RENDERMODE,
56 MONFL_CHANGED_HEADYAW
57} nsmonster_changed_t;
58
59
61typedef enumflags
62{
63 MSF_WAITTILLSEEN,
64 MSF_GAG,
65 MSF_MONSTERCLIP,
66 MSF_RESERVED1,
67 MSF_PRISONER,
68 MSF_RESERVED2,
69 MSF_IGNOREPLAYER,
70 MSF_WAITFORSCRIPT,
71 MSF_RESERVED3,
72 MSF_FADECORPSE,
73 MSF_MULTIPLAYER,
74 MSF_FALLING,
75 MSF_HORDE
76} monsterFlag_t;
77
79typedef enumflags
80{
81 SMSF_WAITTILLSEEN,
82 SMSF_GAG,
83 SMSF_FALLTOGROUND,
84 SMSF_DROPHEALTHKIT,
85 SMSF_EFFICIENT,
86 SMSF_RESERVED1,
87 SMSF_RESERVED2,
88 SMSF_WAITFORSCRIPT,
89 SMSF_LONGVISIBILITY,
90 SMSF_FADECORPSE,
91 SMSF_THINKOUTPVS,
92 SMSF_TEMPLATE,
93 SMSF_ALTCOLLISION,
94 SMSF_NODROPWEAPONS,
95 SMSF_IGNOREPLAYERPUSH
96} sourceMonsterFlag_t;
97
99typedef enum
100{
101 MONSTER_IDLE,
102 MONSTER_ALERT,
103 MONSTER_FOLLOWING,
104 MONSTER_CHASING,
105 MONSTER_AIMING,
106 MONSTER_DEAD,
107 MONSTER_GIBBED
108} monsterState_t;
109
111typedef enum
112{
113 SEQUENCESTATE_NONE,
114 SEQUENCESTATE_IDLE,
115 SEQUENCESTATE_ACTIVE,
116 SEQUENCESTATE_ENDING
117} sequenceState_t;
118
120typedef enum
121{
122 MAL_FRIEND,
123 MAL_ENEMY,
124 MAL_ALIEN,
125 MAL_ROGUE,
126 MAL_NEUTRAL
127} allianceState_t;
128
130typedef enum
131{
132 MOVESTATE_IDLE,
133 MOVESTATE_WALK,
134 MOVESTATE_RUN
135} movementState_t;
136
141typedef enum
142{
143 MTRIG_NONE,
144 MTRIG_SEEPLAYER_ANGRY,
145 MTRIG_PAIN,
146 MTRIG_HALFHEALTH,
147 MTRIG_DEATH,
148 MTRIG_SQUADMEMBERDEAD,
149 MTRIG_SQUADLEADERDEAD,
150 MTRIG_HEARNOISE,
151 MTRIG_HEARENEMYPLAYER,
152 MTRIG_HEARWEAPONS,
153 MTRIG_SEEPLAYER,
154 MTRIG_SEEPLAYER_RELAXED,
155} triggerCondition_t;
156
157/* FIXME: I'd like to move this into NSMonster, but our current IsFriend()
158 * check is currently only checking on a .takedamage basis. */
159.int m_iAlliance;
160
243{
244public:
245 void NSMonster(void);
246
247#ifdef SERVER
248 /* overrides */
249 virtual void Save(float);
250 virtual void Restore(string,string);
251 virtual void EvaluateEntity(void);
252 virtual float SendEntity(entity,float);
253 virtual void Touch(entity);
254 //virtual void Hide(void);
255 virtual void Spawned(void);
256 virtual void Respawn(void);
257 virtual void Input(entity,string,string);
258 virtual void Pain(entity, entity, int, vector, vector, int);
259 virtual void Death(entity, entity, int, vector, vector, int);
260 virtual void Physics(void);
261 virtual void Gib(int, vector);
262 virtual void Sound(string);
263 virtual void SpawnKey(string,string);
264
267 virtual void RunAI(void);
269 virtual void IdleNoise(void);
271 virtual void FallNoise(void);
273 virtual void AlertNoise(void);
274
276 virtual bool IsAlive(void);
278 virtual bool IsFriend(int);
280 virtual void HasBeenKilled(void);
282 virtual void HasBeenHit(void);
283 /* Overridable: Called when the monster was gibbed. */
284 virtual void HasBeenGibbed(void);
285 /* Overridable: Called when the monster has been alerted to threat. */
286 virtual void HasBeenAlerted(void);
287
288 /* see/hear subsystem */
290 virtual void SeeThink(void);
292 virtual float SeeFOV(void);
293
295 virtual void AlertNearby(void);
296
297 /* movement */
299 virtual float GetWalkSpeed(void);
301 virtual float GetChaseSpeed(void);
303 virtual float GetRunSpeed(void);
305 virtual float GetYawSpeed(void);
306
307 /* attack system */
309 virtual void AttackDraw(void);
311 virtual void AttackHolster(void);
313 virtual void AttackThink(void);
315 virtual int AttackMelee(void);
317 virtual int AttackRanged(void);
318 nonvirtual void PerformAttack(string);
319
321 virtual float MeleeMaxDistance(void);
322
325 virtual bool MeleeCondition(void);
326
328 nonvirtual bool IsValidEnemy(entity);
330 virtual bool IsOnRoute(void);
331
332 /* sequences */
334 virtual void FreeState(void);
336 virtual void FreeStateMoved(void);
338 virtual void FreeStateDead(void);
340 virtual void RouteEnded(void);
342 virtual void WalkRoute(void);
343
344 /* callbacks */
346 virtual void SeenPlayer(NSActor);
348 virtual void SeenEnemy(NSActor);
350 virtual void SeenFriend(NSActor);
351
353 nonvirtual int GetSequenceState(void);
355 nonvirtual bool InSequence(void);
356
357 /* animation cycles */
359 virtual int AnimIdle(void);
361 virtual int AnimWalk(void);
363 virtual int AnimRun(void);
365 virtual void AnimPlay(float);
367 virtual void AnimationUpdate(void);
369 nonvirtual bool InAnimation(void);
370 nonvirtual void AnimReset(void);
371
372 /* states */
374 virtual void StateChanged(monsterState_t,monsterState_t);
376 nonvirtual void SetState(monsterState_t);
378 nonvirtual monsterState_t GetState(void);
379
380 /* TriggerTarget/Condition */
382 nonvirtual int GetTriggerCondition(void);
384 virtual void TriggerTargets(void);
385
386 virtual void Trigger(entity, triggermode_t);
387#endif
388
389 nonvirtual vector GetHeadAngles(void);
390
391#ifdef CLIENT
392
394 virtual void customphysics(void);
395 virtual float predraw(void);
396 virtual void ReceiveEntity(float,float);
397#endif
398
399private:
400
401 vector v_angle_net;
402
403#ifdef CLIENT
404 nonvirtual void _RenderDebugViewCone();
405#endif
406
407 PREDICTED_FLOAT(m_flHeadYaw)
408 PREDICTED_FLOAT_N(subblendfrac)
409 PREDICTED_FLOAT_N(bonecontrol1)
410
411#ifdef SERVER
412 entity m_eLookAt;
413 entity m_ssLast;
414 vector oldnet_velocity;
415 float m_flPitch;
416 int m_iFlags;
417 vector base_mins;
418 vector base_maxs;
419 float base_health;
420
421 /* sequences */
422 string m_strRouteEnded;
423 int m_iSequenceRemove;
424 int m_iSequenceState;
425 float m_flSequenceEnd;
426 float m_flSequenceSpeed;
427 vector m_vecSequenceAngle;
428 int m_iSequenceFlags;
429 movementState_t m_iMoveState;
430 string m_strSequenceKillTarget;
431
432 int m_iTriggerCondition;
433 string m_strTriggerTarget;
434
435 /* model events */
436 float m_flBaseTime;
437
438 /* attack/alliance system */
439 entity m_eEnemy;
440 float m_flAttackThink;
441 monsterState_t m_iMState;
442 monsterState_t m_iOldMState;
443 vector m_vecLKPos; /* last-known pos */
444
445 /* see/hear subsystem */
446 float m_flSeeTime;
447 /* animation cycles */
448 float m_flAnimTime;
449
450 /* timer for keeping track of the target */
451 float m_flTrackingTime;
452
453 PREDICTED_VECTOR_N(view_ofs)
454
455 /* caching variables, don't save these */
456 float m_actIdle;
457 bool m_bTurning;
458 float m_flIdleNext;
459 float _m_flMeleeAttempts;
460 float _m_flMeleeDelay;
461 float _m_flBurstCount;
462 bool _m_bShouldThrow;
463 bool _m_bStartDead;
464 float _m_flFrame;
465
466 /* save these please */
467 float _m_flReloadTracker;
468 bool m_bWeaponDrawn;
469
470 /* entityDef related */
471 float m_flEyeHeight;
472 string m_sndSight;
473 string m_sndIdle;
474 float m_flIdleMin;
475 float m_flIdleMax;
476 string m_sndFootstep;
477 string m_sndChatter;
478 string m_sndChatterCombat;
479 string m_sndPain;
480
481 string m_sndMeleeAttack;
482 string m_sndMeleeAttackHit;
483 string m_sndMeleeAttackMiss;
484
485 string m_sndDeath;
486 string m_sndThud;
487
488 /* attack definitions, if defined will fire projectiles */
489 string m_defSpecial1;
490 float m_flSpecial1Range;
491 string m_defSpecial2;
492 float m_flSpecial2Range;
493 string m_defRanged1;
494 float m_flRanged1Range;
495 string m_defRanged2;
496 float m_flRanged2Range;
497
498 /* ranged1 only */
499 int m_iNumProjectiles;
500 float m_flProjectileDelay;
501 float m_flProjectileSpread;
502
503 /* general */
504 float m_flAttackCone;
505 float m_flAttackAccuracy;
506
507 /* melee attack */
508 string m_defMelee;
509 float m_flMeleeRange;
510
511 string m_sndRangedAttack;
512 float m_flReloadCount;
513 float m_flReloadDelay;
514 string m_sndReload;
515 float m_flReserveAmmo;
516
517 string m_sndRangedAttack2;
518
519 bool m_bWeaponStartsDrawn;
520 string m_strBodyOnDraw;
521
522 float m_flWalkSpeed;
523 float m_flRunSpeed;
524
525 float m_flLeapDamage;
526 bool m_bLeapAttacked;
527 float m_flForceSequence;
528 float m_flSkin;
529 bool m_bGagged;
530 float m_flStopTime;
531 float m_flyOffset;
532 bool m_usesNav;
533 bool m_fireFromHead;
534
535 nonvirtual void _LerpTurnToEnemy(void);
536 nonvirtual void _LerpTurnToPos(vector);
537 nonvirtual void _LerpTurnToYaw(vector);
538 virtual void _Alerted(void);
539 nonvirtual void _ChaseAfterSpawn(void);
540#endif
541};
542
543#ifdef CLIENT
544string Sentences_GetSamples(string);
545string Sentences_ProcessSample(string);
546#endif
547
548#ifdef SERVER
549void NSMonster_AlertEnemyAlliance(vector pos, float radius, int alliance);
550entity NSMonster_FindClosestPlayer(entity);
551#endif
552
553.float baseframe2;
554.float baseframe1time;
555.float baseframe2time;
556.float baselerpfrac;
557.float bonecontrol1;
558.float bonecontrol2;
559.float bonecontrol3;
560.float bonecontrol4;
561.float bonecontrol5;
562.float subblendfrac;
563.float subblend2frac;
564.float basesubblendfrac;
565.float basesubblend2frac;
This entity class represents an object with choreographed/free-form movement.
Definition: NSNavAI.h:50
This entity class represents non-player characters.
Definition: NSMonster.h:243
virtual bool MeleeCondition(void)
Returns whether or not we should attempt a melee attack.
Definition: NSMonster.qc:560
virtual bool IsAlive(void)
Returns if they're considered alive.
Definition: NSMonster.qc:1525
virtual void TriggerTargets(void)
Call to trigger their targets manually.
Definition: NSMonster.qc:112
virtual void Save(float)
Handles saving a copy of this entity to a given filehandle.
Definition: NSMonster.qc:124
virtual void WalkRoute(void)
Internal use only.
Definition: NSMonster.qc:1326
virtual void HasBeenKilled(void)
Overridable: Called once, when the monster has died.
Definition: NSMonster.qc:1841
virtual void EvaluateEntity(void)
Run each tic after physics are run to determine if we need to send updates over the network.
Definition: NSMonster.qc:2292
virtual bool IsOnRoute(void)
Returns TRUE if the monster is currently on route to a position.
Definition: NSMonster.qc:650
virtual float GetChaseSpeed(void)
Overridable: Returns the chase speed in Quake units per second.
Definition: NSMonster.qc:793
nonvirtual bool InSequence(void)
Returns if they're currently in a scripted sequence.
Definition: NSMonster.qc:1583
virtual void Restore(string, string)
Similar to NSIO::SpawnKey but for save-game fields.
Definition: NSMonster.qc:209
virtual void AlertNoise(void)
Overridable: Called when this monster gets 'alerted' to something new.
Definition: NSMonster.qc:528
virtual void HasBeenGibbed(void)
Definition: NSMonster.qc:1847
virtual void Gib(int, vector)
Definition: NSMonster.qc:497
nonvirtual monsterState_t GetState(void)
Returns the current state of this NSMonster.
Definition: NSMonster.qc:1571
virtual float MeleeMaxDistance(void)
Overridable: Returns the distance in qu of what'll be a successfull melee attack.
Definition: NSMonster.qc:553
virtual void RouteEnded(void)
Internal use only.
Definition: NSMonster.qc:1301
virtual void FreeStateMoved(void)
Internal use only.
Definition: NSMonster.qc:1267
nonvirtual void AnimReset(void)
Definition: NSMonster.qc:479
nonvirtual vector GetHeadAngles(void)
Definition: NSMonster.qc:99
virtual void Trigger(entity, triggermode_t)
Called whenever we're legacy triggered by another object or function.
Definition: NSMonster.qc:2107
virtual void Touch(entity)
Called whenever we're touching another entity.
Definition: NSMonster.qc:1702
virtual float SeeFOV(void)
Overridable: Returns the field of view in degrees.
Definition: NSMonster.qc:566
nonvirtual int GetSequenceState(void)
Returns the type of sequence they're currently in.
Definition: NSMonster.qc:1577
nonvirtual void SetState(monsterState_t)
Sets the current state of this NSMonster.
Definition: NSMonster.qc:1560
virtual float GetWalkSpeed(void)
Overridable: Returns the walking speed in Quake units per second.
Definition: NSMonster.qc:787
virtual void FallNoise(void)
Overridable: Called when they start falling.
Definition: NSMonster.qc:509
virtual float predraw(void)
virtual bool IsFriend(int)
Returns whether they are allied with the type in question.
Definition: NSMonster.qc:538
nonvirtual bool IsValidEnemy(entity)
Returns TRUE if 'enemy' should be considered a valid target for killing.
Definition: NSMonster.qc:606
virtual void SeenEnemy(NSActor)
Called when an enemy is seen by the monster.
Definition: NSMonster.qc:674
virtual void HasBeenHit(void)
Overridable: Called every time the monster is hurt, while still alive.
Definition: NSMonster.qc:1749
virtual void Input(entity, string, string)
Called when we are being prompted by another object/function with an input message.
Definition: NSMonster.qc:2066
virtual void SeeThink(void)
Internal use only.
Definition: NSMonster.qc:684
virtual void ReceiveEntity(float, float)
Client: Handles network updates from the server for the associated entity.
virtual void Physics(void)
Definition: NSMonster.qc:1597
virtual void Death(entity, entity, int, vector, vector, int)
Called when the health is equal or below 0.
Definition: NSMonster.qc:1865
virtual void SeenFriend(NSActor)
Called when a friend is seen by the monster.
Definition: NSMonster.qc:679
virtual void Sound(string)
Definition: NSMonster.qc:491
nonvirtual void PerformAttack(string)
Definition: NSMonster.qc:1007
virtual void FreeState(void)
Internal use only.
Definition: NSMonster.qc:1210
virtual void AttackDraw(void)
Overridable: Called when they're drawing a weapon.
Definition: NSMonster.qc:1184
virtual void AnimPlay(float)
Call to play a single animation onto it, which cannot be interrupted by movement.
Definition: NSMonster.qc:472
virtual void Pain(entity, entity, int, vector, vector, int)
Called whenever the entity receives damage.
Definition: NSMonster.qc:1755
virtual float GetYawSpeed(void)
Overridable: Returns the turning speed in euler-angle units per second.
Definition: NSMonster.qc:805
virtual void FreeStateDead(void)
Internal use only.
Definition: NSMonster.qc:1282
virtual int AnimWalk(void)
DEPRECATED, Overridable: Called when we need to play a fresh walking framegroup.
Definition: NSMonster.qc:459
virtual float SendEntity(entity, float)
Called by the engine whenever we need to send a client an update about this entity.
Definition: NSMonster.qc:2337
virtual void StateChanged(monsterState_t, monsterState_t)
Called whenever the state of this NSMonster changes.
Definition: NSMonster.qc:1534
virtual void AttackHolster(void)
Overridable: Called when they're holstering a weapon.
Definition: NSMonster.qc:1202
virtual void SpawnKey(string, string)
This method handles entity key/value pairs on map load.
Definition: NSMonster.qc:2122
virtual void RunAI(void)
Internal use only.
Definition: NSMonster.qc:1589
virtual void Respawn(void)
Server: Called when the entity first spawns or when game-logic requests the entity to return to its o...
Definition: NSMonster.qc:1987
virtual float GetRunSpeed(void)
Overridable: Returns the running speed in Quake units per second.
Definition: NSMonster.qc:799
nonvirtual bool InAnimation(void)
Returns if we're currently in a forced animation sequence.
Definition: NSMonster.qc:485
virtual void AnimationUpdate(void)
Internal use only.
Definition: NSMonster.qc:1459
virtual void IdleNoise(void)
Overridable: Called after a while when they've got nothing to do.
Definition: NSMonster.qc:514
virtual int AttackMelee(void)
Overridable: Called when attempting to melee attack.
Definition: NSMonster.qc:944
virtual void customphysics(void)
overrides
nonvirtual int GetTriggerCondition(void)
Returns the condition under which they'll trigger their targets.
Definition: NSMonster.qc:106
void NSMonster(void)
Definition: NSMonster.qc:21
virtual void AlertNearby(void)
FIXME: Same as WarnAllies/StartleAllies? WTF?
Definition: NSMonster.qc:572
virtual void HasBeenAlerted(void)
Definition: NSMonster.qc:1853
virtual int AnimIdle(void)
DEPRECATED, Overridable: Called when we need to play a fresh idle framegroup.
Definition: NSMonster.qc:453
virtual void SeenPlayer(NSActor)
Called when a player is seen by the monster.
Definition: NSMonster.qc:669
virtual int AttackRanged(void)
Overridable: Called when attempting to attack from a distance.
Definition: NSMonster.qc:1017
virtual void AttackThink(void)
Overridable: Called when aiming their weapon.
Definition: NSMonster.qc:886
virtual int AnimRun(void)
DEPRECATED, Overridable: Called when we need to play a fresh running framegroup.
Definition: NSMonster.qc:465
virtual void Spawned(void)
Called when the entity is fulled initialized.
Definition: NSMonster.qc:1966
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:149