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
245{
246public:
247 void ncMonster(void);
248
249#ifdef SERVER
250 /* overrides */
251 virtual void DebugDraw(void);
252 virtual void Save(float);
253 virtual void Restore(string,string);
254 virtual void EvaluateEntity(void);
255 virtual float SendEntity(entity,float);
256 virtual void Touch(entity);
257 //virtual void Hide(void);
258 virtual void Spawned(void);
259 virtual void Respawn(void);
260 virtual void Input(entity,string,string);
261 virtual void Pain(entity, entity, int, vector, vector, int);
262 virtual void Death(entity, entity, int, vector, vector, int);
263 virtual void Physics(void);
264 virtual void Gib(int, vector);
265 virtual void Sound(string);
266 virtual void SpawnKey(string,string);
267
270 virtual void RunAI(void);
272 virtual void IdleNoise(void);
274 virtual void FallNoise(void);
276 virtual void AlertNoise(void);
277
279 virtual bool IsAlive(void);
281 virtual bool IsFriend(int);
283 virtual void HasBeenKilled(void);
285 virtual void HasBeenHit(void);
286 /* Overridable: Called when the monster was gibbed. */
287 virtual void HasBeenGibbed(void);
288 /* Overridable: Called when the monster has been alerted to threat. */
289 virtual void HasBeenAlerted(void);
290
291 /* see/hear subsystem */
293 virtual void SeeThink(void);
295 virtual float SeeFOV(void);
296
298 virtual void AlertNearby(void);
299
300 /* movement */
302 virtual float GetWalkSpeed(void);
304 virtual float GetChaseSpeed(void);
306 virtual float GetRunSpeed(void);
308 virtual float GetYawSpeed(void);
309
310 /* attack system */
312 virtual void AttackDraw(void);
314 virtual void AttackHolster(void);
316 virtual void AttackThink(void);
318 virtual int AttackMelee(void);
320 virtual int AttackRanged(void);
321 nonvirtual void PerformAttack(string);
322
324 virtual float MeleeMaxDistance(void);
325
328 virtual bool MeleeCondition(void);
329
331 nonvirtual bool IsValidEnemy(entity);
333 virtual bool IsOnRoute(void);
335 virtual void RouteClear(void);
336
337 /* sequences */
339 virtual void ScriptedSequenceEnded(void);
341 virtual void ScriptedSequenceEnded_Moved(void);
343 virtual void ScriptedSequenceEnded_Dead(void);
345 virtual void RouteEnded(void);
347 virtual void WalkRoute(void);
348
349 /* callbacks */
351 virtual void SeenPlayer(ncActor);
353 virtual void SeenEnemy(ncActor);
355 virtual void SeenFriend(ncActor);
356
358 nonvirtual int GetSequenceState(void);
360 nonvirtual bool InScriptedSequence(void);
361
362 /* animation cycles */
364 virtual int AnimIdle(void);
366 virtual int AnimWalk(void);
368 virtual int AnimRun(void);
370 virtual void AnimPlay(float);
372 virtual void AnimationUpdate(void);
374 nonvirtual bool InForcedAnimation(void);
376 nonvirtual void AnimationRewind(void);
377
378 /* states */
380 virtual void StateChanged(monsterState_t,monsterState_t);
382 nonvirtual void SetState(monsterState_t);
384 nonvirtual monsterState_t GetState(void);
385
386 /* TriggerTarget/Condition */
388 nonvirtual int GetTriggerCondition(void);
390 virtual void TriggerTargets(void);
391
392 virtual void Trigger(entity, triggermode_t);
393#endif
394
395 nonvirtual vector GetHeadAngles(void);
396
397#ifdef CLIENT
398
400 virtual void customphysics(void);
401 virtual float predraw(void);
402 virtual void ReceiveEntity(float,float);
403#endif
404
405private:
406
407 vector v_angle_net;
408
409#ifdef CLIENT
410 nonvirtual void _RenderDebugViewCone();
411#endif
412
413 PREDICTED_FLOAT(m_flHeadYaw)
414 PREDICTED_FLOAT_N(subblendfrac)
415 PREDICTED_FLOAT_N(bonecontrol1)
416
417#ifdef SERVER
418 entity m_eLookAt;
419 entity m_ssLast;
420 vector oldnet_velocity;
421 float m_flPitch;
422 int m_iFlags;
423 vector base_mins;
424 vector base_maxs;
425 float base_health;
426
427 /* I/O */
428 string m_outputOnDamaged;
429 string m_outputOnDeath;
430 string m_outputOnHalfHealth;
431 string m_outputOnHearPlayer;
432 string m_outputOnFoundEnemy;
433 string m_outputOnLostEnemy;
434 string m_outputOnLostEnemyLOS;
435 string m_outputOnFoundPlayer;
436 string m_outputOnLostPlayer;
437 string m_outputOnLostPlayerLOS;
438 string m_outputOnDamagedByPlayer;
439 string m_outputOnGreetPlayer;
440 bool m_bMetPlayer;
441
442 /* sequences */
443 string m_strRouteEnded;
444 int m_iSequenceRemove;
445 int m_iSequenceState;
446 float m_flSequenceEnd;
447 float m_flSequenceSpeed;
448 vector m_vecSequenceAngle;
449 int m_iSequenceFlags;
450 movementState_t m_iMoveState;
451 string m_strSequenceKillTarget;
452
453 int m_iTriggerCondition;
454 string m_strTriggerTarget;
455
456 /* model events */
457 float m_flBaseTime;
458
459 /* attack/alliance system */
460 entity m_eEnemy;
461 float m_flAttackThink;
462 monsterState_t m_iMState;
463 monsterState_t m_iOldMState;
464 vector m_vecLKPos; /* last-known pos */
465
466 /* see/hear subsystem */
467 float m_flSeeTime;
468 /* animation cycles */
469 float m_flAnimTime;
470
471 /* timer for keeping track of the target */
472 float m_flTrackingTime;
473
474 PREDICTED_VECTOR_N(view_ofs)
475
476 /* caching variables, don't save these */
477 float m_actIdle;
478 bool m_bTurning;
479 float m_flIdleNext;
480 float _m_flMeleeAttempts;
481 float _m_flMeleeDelay;
482 float _m_flBurstCount;
483 bool _m_bShouldThrow;
484 bool _m_bStartDead;
485 float _m_flFrame;
486
487 /* save these please */
488 float _m_flReloadTracker;
489 bool m_bWeaponDrawn;
490
491 /* entityDef related */
492 float m_flEyeHeight;
493 string m_sndSight;
494 string m_sndIdle;
495 float m_flIdleMin;
496 float m_flIdleMax;
497 string m_sndFootstep;
498 string m_sndChatter;
499 string m_sndChatterCombat;
500 string m_sndPain;
501
502 string m_sndMeleeAttack;
503 string m_sndMeleeAttackHit;
504 string m_sndMeleeAttackMiss;
505
506 string m_sndDeath;
507 string m_sndThud;
508
509 /* attack definitions, if defined will fire projectiles */
510 string m_defSpecial1;
511 float m_flSpecial1Range;
512 string m_defSpecial2;
513 float m_flSpecial2Range;
514 string m_defRanged1;
515 float m_flRanged1Range;
516 string m_defRanged2;
517 float m_flRanged2Range;
518
519 /* ranged1 only */
520 int m_iNumProjectiles;
521 float m_flProjectileDelay;
522 float m_flProjectileSpread;
523
524 /* general */
525 float m_flAttackCone;
526 float m_flAttackAccuracy;
527
528 /* melee attack */
529 string m_defMelee;
530 float m_flMeleeRange;
531
532 string m_sndRangedAttack;
533 float m_flReloadCount;
534 float m_flReloadDelay;
535 string m_sndReload;
536 float m_flReserveAmmo;
537
538 string m_sndRangedAttack2;
539
540 bool m_bWeaponStartsDrawn;
541 string m_strBodyOnDraw;
542
543 float m_flWalkSpeed;
544 float m_flRunSpeed;
545
546 float m_flLeapDamage;
547 bool m_bLeapAttacked;
548 float m_flForceSequence;
549 float m_flSkin;
550 bool m_bGagged;
551 float m_flStopTime;
552 float m_flyOffset;
553 bool m_usesNav;
554 bool m_fireFromHead;
555 bool m_pvsSleep;
556 bool m_bCanAttack;
557
558 nonvirtual void _LerpTurnToPos(vector);
559 nonvirtual void _LerpTurnToYaw(float);
560 virtual void _Alerted(void);
561 nonvirtual void _ChaseAfterSpawn(void);
562#endif
563};
564
565#ifdef CLIENT
566string Sentences_GetSamples(string);
567string Sentences_ProcessSample(string);
568#endif
569
570#ifdef SERVER
571void ncMonster_AlertEnemyAlliance(vector pos, float radius, int alliance);
572entity ncMonster_FindClosestPlayer(entity);
573#endif
574
575.float baseframe2;
576.float baseframe1time;
577.float baseframe2time;
578.float baselerpfrac;
579.float bonecontrol1;
580.float bonecontrol2;
581.float bonecontrol3;
582.float bonecontrol4;
583.float bonecontrol5;
584.float subblendfrac;
585.float subblend2frac;
586.float basesubblendfrac;
587.float basesubblend2frac;
This entity class represents an object with choreographed/free-form movement.
Definition: Actor.h:72
This entity class represents non-player characters.
Definition: Monster.h:245
virtual void AttackHolster(void)
Overridable: Called when they're holstering a weapon.
Definition: Monster.qc:1279
virtual void SeenPlayer(ncActor)
Called when a player is seen by the monster.
Definition: Monster.qc:738
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:903
nonvirtual void SetState(monsterState_t)
Sets the current state of this ncMonster.
Definition: Monster.qc:1603
virtual float GetWalkSpeed(void)
Overridable: Returns the walking speed in Quake units per second.
Definition: Monster.qc:891
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:748
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:1936
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:915
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:1577
virtual void Pain(entity, entity, int, vector, vector, int)
Called whenever the entity receives damage.
Definition: Monster.qc:1821
virtual void AttackThink(void)
Overridable: Called when aiming their weapon.
Definition: Monster.qc:975
virtual float SendEntity(entity, float)
Called by the engine whenever we need to send a client an update about this entity.
Definition: Monster.qc:2626
virtual bool IsAlive(void)
Returns if they're considered alive.
Definition: Monster.qc:1568
virtual void AttackDraw(void)
Overridable: Called when they're drawing a weapon.
Definition: Monster.qc:1261
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:1287
nonvirtual int GetSequenceState(void)
Returns the type of sequence they're currently in.
Definition: Monster.qc:1621
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:2091
virtual void Physics(void)
Definition: Monster.qc:1648
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:2360
virtual float GetChaseSpeed(void)
Overridable: Returns the chase speed in Quake units per second.
Definition: Monster.qc:897
nonvirtual bool IsValidEnemy(entity)
Returns TRUE if 'enemy' should be considered a valid target for killing.
Definition: Monster.qc:675
virtual void ScriptedSequenceEnded_Dead(void)
Internal use only.
Definition: Monster.qc:1362
virtual void AnimationUpdate(void)
Internal use only.
Definition: Monster.qc:1489
virtual bool IsOnRoute(void)
Returns TRUE if the monster is currently on route to a position.
Definition: Monster.qc:719
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:2375
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:1094
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:1084
virtual void RunAI(void)
Internal use only.
Definition: Monster.qc:1633
virtual void AnimPlay(float)
Call to play a single animation onto it, which cannot be interrupted by movement.
Definition: Monster.qc:503
virtual int AttackMelee(void)
Overridable: Called when attempting to melee attack.
Definition: Monster.qc:1021
nonvirtual int GetTriggerCondition(void)
Returns the condition under which they'll trigger their targets.
Definition: Monster.qc:137
virtual void ScriptedSequenceEnded_Moved(void)
Internal use only.
Definition: Monster.qc:1347
virtual void WalkRoute(void)
Internal use only.
Definition: Monster.qc:1410
virtual void Touch(entity)
Called whenever we're touching another entity.
Definition: Monster.qc:1756
virtual void HasBeenHit(void)
Overridable: Called every time the monster is hurt, while still alive.
Definition: Monster.qc:1804
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:1942
virtual void SeeThink(void)
Internal use only.
Definition: Monster.qc:753
nonvirtual monsterState_t GetState(void)
Returns the current state of this ncMonster.
Definition: Monster.qc:1615
virtual void Spawned(void)
Called when the entity is fulled initialized.
Definition: Monster.qc:2057
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:1810
virtual void HasBeenKilled(void)
Overridable: Called once, when the monster has died.
Definition: Monster.qc:1930
nonvirtual bool InScriptedSequence(void)
Returns if they're currently in a scripted sequence.
Definition: Monster.qc:1627
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:2173
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:2581
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:1954
virtual void customphysics(void)
overrides
virtual void RouteEnded(void)
Internal use only.
Definition: Monster.qc:1381
virtual void SeenEnemy(ncActor)
Called when an enemy is seen by the monster.
Definition: Monster.qc:743
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