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
17var bool autocvar_ai_enable = true;
18var bool autocvar_ai_debugLogic = false;
19void
20_ncMonster_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 ncMonsterLog(...) if (autocvar_ai_debugLogic == true) _ncMonster_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 ncMonster, but our current IsFriend()
158 * check is currently only checking on a .takedamage basis. */
159.int m_iAlliance;
160
274{
275public:
276 void ncMonster(void);
277
278#ifdef SERVER
279 /* overrides */
280 virtual void DebugDraw(void);
281 virtual void Save(float);
282 virtual void Restore(string,string);
283 virtual void EvaluateEntity(void);
284 virtual float SendEntity(entity,float);
285 virtual void Touch(entity);
286 //virtual void Hide(void);
287 virtual void Spawned(void);
288 virtual void Respawn(void);
289 virtual void Input(entity,string,string);
290 virtual void Pain(entity, entity, int, vector, vector, int);
291 virtual void Death(entity, entity, int, vector, vector, int);
292 virtual void Physics(void);
293 virtual void Gib(int, vector);
294 virtual void Sound(string);
295 virtual void SpawnKey(string,string);
296 virtual void HandleAnimEvent(float, int, string);
297
298 virtual void OnMapFinishedLoading(void);
299
302 virtual void RunAI(void);
304 virtual void IdleNoise(void);
306 virtual void FallNoise(void);
308 virtual void AlertNoise(void);
309
311 virtual bool IsAlive(void);
313 virtual bool IsFriend(int);
315 virtual void HasBeenKilled(void);
317 virtual void HasBeenHit(void);
318 /* Overridable: Called when the monster was gibbed. */
319 virtual void HasBeenGibbed(void);
320 /* Overridable: Called when the monster has been alerted to threat. */
321 virtual void HasBeenAlerted(void);
322
323 /* see/hear subsystem */
325 virtual void SeeThink(void);
327 virtual float SeeFOV(void);
328
330 virtual void AlertNearby(void);
331
332 /* movement */
334 virtual float GetWalkSpeed(void);
336 virtual float GetChaseSpeed(void);
338 virtual float GetRunSpeed(void);
340 virtual float GetYawSpeed(void);
341
342 /* attack system */
344 virtual void AttackDraw(void);
346 virtual void AttackHolster(void);
348 virtual void AttackThink(void);
350 virtual int AttackMelee(void);
352 virtual int AttackRanged(void);
353 nonvirtual void PerformAttack(string);
354
356 virtual float MeleeMaxDistance(void);
357
360 virtual bool MeleeCondition(void);
361
363 nonvirtual bool IsValidEnemy(entity);
365 virtual bool IsOnRoute(void);
367 virtual void RouteClear(void);
368
369 /* sequences */
371 virtual void ScriptedSequenceEnded(void);
373 virtual void ScriptedSequenceEnded_Moved(void);
375 virtual void ScriptedSequenceEnded_Dead(void);
377 virtual void RouteEnded(void);
379 virtual void WalkRoute(void);
380
381 /* callbacks */
383 virtual void SeenPlayer(ncActor);
385 virtual void SeenEnemy(ncActor);
387 virtual void SeenFriend(ncActor);
388
390 nonvirtual int GetSequenceState(void);
392 nonvirtual bool InScriptedSequence(void);
393
394 /* animation cycles */
396 virtual int AnimIdle(void);
398 virtual int AnimWalk(void);
400 virtual int AnimRun(void);
402 virtual void AnimPlay(float);
404 virtual void AnimationUpdate(void);
406 nonvirtual bool InForcedAnimation(void);
408 nonvirtual void AnimationRewind(void);
409
410 /* states */
412 virtual void StateChanged(monsterState_t,monsterState_t);
414 nonvirtual void SetState(monsterState_t);
416 nonvirtual monsterState_t GetState(void);
417
418 /* TriggerTarget/Condition */
420 nonvirtual int GetTriggerCondition(void);
422 virtual void TriggerTargets(void);
423
424 virtual void Trigger(entity, triggermode_t);
425 nonvirtual void AlertNearbyToSchedule(string scheduleType);
426 nonvirtual void AlertNearbyClassWithMindset(string scheduleType);
427 nonvirtual bool ShouldTurn(void);
428#endif
429
430 nonvirtual vector GetHeadAngles(void);
431
432 virtual void DebugDraw(void);
433
434#ifdef CLIENT
435
437 virtual void customphysics(void);
438 virtual float predraw(void);
439 virtual void ReceiveEntity(float,float);
440#endif
441
442private:
443
444 vector v_angle_net;
445
446#ifdef CLIENT
447 nonvirtual void _RenderDebugViewCone();
448#endif
449
450 NETWORKED_FLOAT(m_flHeadYaw)
451 NETWORKED_FLOAT_N(subblendfrac)
452 NETWORKED_FLOAT_N(bonecontrol1)
453
454#ifdef SERVER
455 entity m_eLookAt;
456 entity m_ssLast;
457 vector oldnet_velocity;
458 float m_sentencePitch;
459 int m_iFlags;
460 vector base_mins;
461 vector base_maxs;
462 float base_health;
463
464 /* I/O */
465 string m_outputOnDamaged;
466 string m_outputOnDeath;
467 string m_outputOnHalfHealth;
468 string m_outputOnHearPlayer;
469 string m_outputOnFoundEnemy;
470 string m_outputOnLostEnemy;
471 string m_outputOnLostEnemyLOS;
472 string m_outputOnFoundPlayer;
473 string m_outputOnLostPlayer;
474 string m_outputOnLostPlayerLOS;
475 string m_outputOnDamagedByPlayer;
476 string m_outputOnGreetPlayer;
477 bool m_bMetPlayer;
478
479 /* sequences */
480 string m_strRouteEnded;
481 int m_iSequenceRemove;
482 int m_iSequenceState;
483 float m_flSequenceEnd;
484 float m_flSequenceSpeed;
485 vector m_vecSequenceAngle;
486 int m_iSequenceFlags;
487 movementState_t m_iMoveState;
488 string m_strSequenceKillTarget;
489
490 int m_iTriggerCondition;
491 string m_strTriggerTarget;
492
493 /* model events */
494 float m_modelEventTime;
495
496 /* attack/alliance system */
497 entity m_eEnemy;
498 float m_flAttackThink;
499 monsterState_t m_iMState;
500 monsterState_t m_iOldMState;
501 vector m_vecLKPos; /* last-known pos */
502
503 /* see/hear subsystem */
504 float m_flSeeTime;
505 /* animation cycles */
506 float m_flAnimTime;
507
508 /* timer for keeping track of the target */
509 float m_flTrackingTime;
510
511 NETWORKED_VECTOR_N(view_ofs)
512
513 /* caching variables, don't save these */
514 float m_actIdle;
515 bool m_bTurning;
516 float m_flIdleNext;
517 float _m_flMeleeAttempts;
518 float _m_flMeleeDelay;
519 float _m_flBurstCount;
520 bool _m_bShouldThrow;
521 bool _m_bStartDead;
522 float _m_flFrame;
523
524 /* save these please */
525 float _m_flReloadTracker;
526 bool m_bWeaponDrawn;
527
528 /* entityDef related */
529 float m_flEyeHeight;
530 string m_sndSight;
531 string m_sndIdle;
532 float m_flIdleMin;
533 float m_flIdleMax;
534 string m_sndFootstep;
535 string m_sndChatter;
536 string m_sndChatterCombat;
537 string m_sndPain;
538
539 string m_sndMeleeAttack;
540 string m_sndMeleeAttackHit;
541 string m_sndMeleeAttackMiss;
542
543 string m_sndDeath;
544 string m_sndThud;
545
546 /* attack definitions, if defined will fire projectiles */
547 string m_defSpecial1;
548 float m_flSpecial1Range;
549 string m_defSpecial2;
550 float m_flSpecial2Range;
551 string m_defRanged1;
552 float m_flRanged1Range;
553 string m_defRanged2;
554 float m_flRanged2Range;
555
556 /* ranged1 only */
557 int m_iNumProjectiles;
558 float m_flProjectileDelay;
559 float m_flProjectileSpread;
560
561 /* general */
562 float m_flAttackCone;
563 float m_flAttackAccuracy;
564
565 /* melee attack */
566 string m_defMelee;
567 float m_flMeleeRange;
568
569 string m_sndRangedAttack;
570 float m_flReloadCount;
571 float m_flReloadDelay;
572 string m_sndReload;
573 float m_flReserveAmmo;
574
575 string m_sndRangedAttack2;
576
577 bool m_bWeaponStartsDrawn;
578 string m_strBodyOnDraw;
579
580 float m_flWalkSpeed;
581 float m_flRunSpeed;
582
583 float m_flLeapDamage;
584 bool m_bLeapAttacked;
585 float m_flForceSequence;
586 float m_flSkin;
587 bool m_bGagged;
588 float m_flStopTime;
589 float m_flyOffset;
590 bool m_usesNav;
591 bool m_fireFromHead;
592 bool m_bCanAttack;
593 bool m_freezeDuringPain;
594 bool m_flinchDuringMovement;
595
596 nonvirtual void _LerpTurnToPos(vector);
597 nonvirtual void _LerpTurnToYaw(float);
598 virtual void _Alerted(void);
599 nonvirtual void _ChaseAfterSpawn(void);
600#endif
601};
602
603#ifdef CLIENT
604string Sentences_GetSamples(string);
605string Sentences_ProcessSample(string);
606#endif
607
608#ifdef SERVER
609void ncMonster_AlertEnemyAlliance(vector pos, float radius, int alliance);
610entity ncMonster_FindClosestPlayer(entity);
611#endif
612
613.float baseframe2;
614.float baseframe1time;
615.float baseframe2time;
616.float baselerpfrac;
617.float bonecontrol1;
618.float bonecontrol2;
619.float bonecontrol3;
620.float bonecontrol4;
621.float bonecontrol5;
622.float subblendfrac;
623.float subblend2frac;
624.float basesubblendfrac;
625.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:274
virtual void AttackHolster(void)
Overridable: Called when they're holstering a weapon.
Definition: Monster.qc:1358
virtual void SeenPlayer(ncActor)
Called when a player is seen by the monster.
Definition: Monster.qc:806
virtual void Restore(string, string)
Similar to ncIO::SpawnKey() but for save-game fields.
Definition: Monster.qc:244
virtual void AlertNoise(void)
Overridable: Called when this monster gets 'alerted' to something new.
Definition: Monster.qc:577
virtual float GetRunSpeed(void)
Overridable: Returns the running speed in Quake units per second.
Definition: Monster.qc:982
nonvirtual void SetState(monsterState_t)
Sets the current state of this ncMonster.
Definition: Monster.qc:1682
virtual float GetWalkSpeed(void)
Overridable: Returns the walking speed in Quake units per second.
Definition: Monster.qc:970
virtual void Gib(int, vector)
Definition: Monster.qc:538
virtual void SeenFriend(ncActor)
Called when a friend is seen by the monster.
Definition: Monster.qc:816
virtual void DebugDraw(void)
virtual void IdleNoise(void)
Overridable: Called after a while when they've got nothing to do.
Definition: Monster.qc:563
virtual void Sound(string)
Definition: Monster.qc:532
virtual void HasBeenGibbed(void)
Definition: Monster.qc:2037
nonvirtual bool InForcedAnimation(void)
Returns if we're currently in a forced animation sequence.
Definition: Monster.qc:526
virtual float predraw(void)
virtual float GetYawSpeed(void)
Overridable: Returns the turning speed in euler-angle units per second.
Definition: Monster.qc:994
nonvirtual void AnimationRewind(void)
Starts the animation sequence from the beginning.
Definition: Monster.qc:520
virtual void StateChanged(monsterState_t, monsterState_t)
Called whenever the state of this ncMonster changes.
Definition: Monster.qc:1656
virtual void Pain(entity, entity, int, vector, vector, int)
Called whenever the entity receives damage.
Definition: Monster.qc:1914
virtual void AttackThink(void)
Overridable: Called when aiming their weapon.
Definition: Monster.qc:1054
virtual float SendEntity(entity, float)
Called by the engine whenever we need to send a client an update about this entity.
Definition: Monster.qc:2790
virtual bool IsAlive(void)
Returns if they're considered alive.
Definition: Monster.qc:1647
virtual void AttackDraw(void)
Overridable: Called when they're drawing a weapon.
Definition: Monster.qc:1340
virtual bool MeleeCondition(void)
Returns whether or not we should attempt a melee attack.
Definition: Monster.qc:612
virtual void ScriptedSequenceEnded(void)
Internal use only.
Definition: Monster.qc:1366
nonvirtual int GetSequenceState(void)
Returns the type of sequence they're currently in.
Definition: Monster.qc:1700
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:2196
virtual void Physics(void)
Definition: Monster.qc:1727
virtual int AnimIdle(void)
DEPRECATED, Overridable: Called when we need to play a fresh idle framegroup.
Definition: Monster.qc:494
virtual void Trigger(entity, triggermode_t)
Called whenever we're legacy triggered by another object or function.
Definition: Monster.qc:2518
virtual float GetChaseSpeed(void)
Overridable: Returns the chase speed in Quake units per second.
Definition: Monster.qc:976
nonvirtual bool IsValidEnemy(entity)
Returns TRUE if 'enemy' should be considered a valid target for killing.
Definition: Monster.qc:717
virtual void ScriptedSequenceEnded_Dead(void)
Internal use only.
Definition: Monster.qc:1441
virtual void AnimationUpdate(void)
Internal use only.
Definition: Monster.qc:1568
virtual bool IsOnRoute(void)
Returns TRUE if the monster is currently on route to a position.
Definition: Monster.qc:761
virtual void Save(float)
Handles saving a copy of this entity to a given filehandle.
Definition: Monster.qc:157
virtual void SpawnKey(string, string)
This method handles entity key/value pairs on map load.
Definition: Monster.qc:2533
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:1173
virtual void HandleAnimEvent(float, int, string)
Callback for any model event that gets triggered while playing a framegroup.
Definition: Monster.qc:1835
virtual float MeleeMaxDistance(void)
Overridable: Returns the distance in qu of what'll be a successfull melee attack.
Definition: Monster.qc:605
nonvirtual void PerformAttack(string)
Definition: Monster.qc:1163
virtual void RunAI(void)
Internal use only.
Definition: Monster.qc:1712
virtual void AnimPlay(float)
Call to play a single animation onto it, which cannot be interrupted by movement.
Definition: Monster.qc:513
nonvirtual void AlertNearbyClassWithMindset(string scheduleType)
Definition: Monster.qc:689
virtual int AttackMelee(void)
Overridable: Called when attempting to melee attack.
Definition: Monster.qc:1100
nonvirtual int GetTriggerCondition(void)
Returns the condition under which they'll trigger their targets.
Definition: Monster.qc:139
nonvirtual bool ShouldTurn(void)
Definition: Monster.qc:988
virtual void ScriptedSequenceEnded_Moved(void)
Internal use only.
Definition: Monster.qc:1426
virtual void WalkRoute(void)
Internal use only.
Definition: Monster.qc:1489
virtual void Touch(entity)
Called whenever we're touching another entity.
Definition: Monster.qc:1849
virtual void HasBeenHit(void)
Overridable: Called every time the monster is hurt, while still alive.
Definition: Monster.qc:1897
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:500
virtual void HasBeenAlerted(void)
Definition: Monster.qc:2043
nonvirtual void AlertNearbyToSchedule(string scheduleType)
Definition: Monster.qc:657
virtual void SeeThink(void)
Internal use only.
Definition: Monster.qc:821
nonvirtual monsterState_t GetState(void)
Returns the current state of this ncMonster.
Definition: Monster.qc:1694
virtual void Spawned(void)
Called when the entity is fulled initialized.
Definition: Monster.qc:2162
virtual void FallNoise(void)
Overridable: Called when they start falling.
Definition: Monster.qc:558
virtual void DebugDraw(void)
Definition: Monster.qc:114
virtual void OnMapFinishedLoading(void)
Overridable: Called when the level finished loading.
Definition: Monster.qc:2278
virtual float SeeFOV(void)
Overridable: Returns the field of view in degrees.
Definition: Monster.qc:618
virtual int AnimRun(void)
DEPRECATED, Overridable: Called when we need to play a fresh running framegroup.
Definition: Monster.qc:506
virtual void RouteClear(void)
Override.
Definition: Monster.qc:1903
virtual void HasBeenKilled(void)
Overridable: Called once, when the monster has died.
Definition: Monster.qc:2031
nonvirtual bool InScriptedSequence(void)
Returns if they're currently in a scripted sequence.
Definition: Monster.qc:1706
virtual bool IsFriend(int)
Returns whether they are allied with the type in question.
Definition: Monster.qc:587
virtual void Input(entity, string, string)
Called when we are being prompted by another object/function with an input message.
Definition: Monster.qc:2292
virtual void TriggerTargets(void)
Call to trigger their targets manually.
Definition: Monster.qc:145
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:2745
nonvirtual vector GetHeadAngles(void)
Definition: Monster.qc:132
virtual void Death(entity, entity, int, vector, vector, int)
Called when the health is equal or below 0.
Definition: Monster.qc:2055
virtual void customphysics(void)
overrides
virtual void RouteEnded(void)
Internal use only.
Definition: Monster.qc:1460
virtual void SeenEnemy(ncActor)
Called when an enemy is seen by the monster.
Definition: Monster.qc:811
virtual void AlertNearby(void)
FIXME: Same as WarnAllies/StartleAllies? WTF?
Definition: Monster.qc:624
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:154