Advertisement
Guest User

custom.cpp

a guest
Nov 28th, 2023
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 22.04 KB | Gaming | 0 0
  1. /***
  2. *
  3. *   Copyright (c) 1996-2001, Valve LLC. All rights reserved.
  4. *  
  5. *   This product contains software technology licensed from Id
  6. *   Software, Inc. ("Id Technology").  Id Technology (c) 1996 Id Software, Inc.
  7. *   All Rights Reserved.
  8. *
  9. *   This source code contains proprietary and confidential information of
  10. *   Valve LLC and its suppliers.  Access to this code is restricted to
  11. *   persons who have executed a written SDK license with Valve.  Any access,
  12. *   use or distribution of this code by or to any unlicensed person is illegal.
  13. *
  14. ****/
  15. //=========================================================
  16. // monster template
  17. //=========================================================
  18. // UNDONE: Holster weapon?
  19.  
  20. #include    "extdll.h"
  21. #include    "util.h"
  22. #include    "cbase.h"
  23. #include    "monsters.h"
  24. #include    "talkmonster.h"
  25. #include    "schedule.h"
  26. #include    "defaultai.h"
  27. #include    "scripted.h"
  28. #include    "weapons.h"
  29. #include    "soundent.h"
  30.  
  31. //=========================================================
  32. // Monster's Anim Events Go Here
  33. //=========================================================
  34. // first flag is custom dying for scripted sequences?
  35. #define     CUSTOM_AE_DRAW      ( 2 )
  36. #define     CUSTOM_AE_SHOOT     ( 3 )
  37. #define     CUSTOM_AE_HOLSTER   ( 4 )
  38.  
  39. #define CUSTOM_BODY_GUNHOLSTERED    0
  40. #define CUSTOM_BODY_GUNDRAWN        1
  41. #define CUSTOM_BODY_GUNGONE         2
  42.  
  43. class CCustom : public CTalkMonster
  44. {
  45. public:
  46.     void Spawn( void );
  47.     void Precache( void );
  48.     void SetYawSpeed( void );
  49.     int  ISoundMask( void );
  50.     void CustomFirePistol( void );
  51.     void AlertSound( void );
  52.     int  Classify ( void );
  53.     void HandleAnimEvent( MonsterEvent_t *pEvent );
  54.    
  55.     void RunTask( Task_t *pTask );
  56.     void StartTask( Task_t *pTask );
  57.     virtual int ObjectCaps( void ) { return CTalkMonster :: ObjectCaps() | FCAP_IMPULSE_USE; }
  58.     int TakeDamage( entvars_t* pevInflictor, entvars_t* pevAttacker, float flDamage, int bitsDamageType);
  59.     BOOL CheckRangeAttack1 ( float flDot, float flDist );
  60.    
  61.     void DeclineFollowing( void );
  62.  
  63.     // Override these to set behavior
  64.     Schedule_t *GetScheduleOfType ( int Type );
  65.     Schedule_t *GetSchedule ( void );
  66.     MONSTERSTATE GetIdealState ( void );
  67.  
  68.     void DeathSound( void );
  69.     void PainSound( void );
  70.    
  71.     void TalkInit( void );
  72.  
  73.     void TraceAttack( entvars_t *pevAttacker, float flDamage, Vector vecDir, TraceResult *ptr, int bitsDamageType);
  74.     void Killed( entvars_t *pevAttacker, int iGib );
  75.    
  76.     virtual int     Save( CSave &save );
  77.     virtual int     Restore( CRestore &restore );
  78.     static  TYPEDESCRIPTION m_SaveData[];
  79.  
  80.     BOOL    m_fGunDrawn;
  81.     float   m_painTime;
  82.     float   m_checkAttackTime;
  83.     BOOL    m_lastAttackCheck;
  84.  
  85.     // UNDONE: What is this for?  It isn't used?
  86.     float   m_flPlayerDamage;// how much pain has the player inflicted on me?
  87.  
  88.     CUSTOM_SCHEDULES;
  89. };
  90.  
  91. LINK_ENTITY_TO_CLASS( monster_custom, CCustom );
  92.  
  93. TYPEDESCRIPTION CCustom::m_SaveData[] =
  94. {
  95.     DEFINE_FIELD( CCustom, m_fGunDrawn, FIELD_BOOLEAN ),
  96.     DEFINE_FIELD( CCustom, m_painTime, FIELD_TIME ),
  97.     DEFINE_FIELD( CCustom, m_checkAttackTime, FIELD_TIME ),
  98.     DEFINE_FIELD( CCustom, m_lastAttackCheck, FIELD_BOOLEAN ),
  99.     DEFINE_FIELD( CCustom, m_flPlayerDamage, FIELD_FLOAT ),
  100. };
  101.  
  102. IMPLEMENT_SAVERESTORE( CCustom, CTalkMonster );
  103.  
  104. //=========================================================
  105. // AI Schedules Specific to this monster
  106. //=========================================================
  107. Task_t  tlBaFollow[] =
  108. {
  109.     { TASK_MOVE_TO_TARGET_RANGE,(float)128      }// Move within 128 of target ent (client)
  110.     { TASK_SET_SCHEDULE,        (float)SCHED_TARGET_FACE },
  111. };
  112.  
  113. Schedule_t  slBaFollow[] =
  114. {
  115.     {
  116.         tlBaFollow,
  117.         ARRAYSIZE ( tlBaFollow ),
  118.         bits_COND_NEW_ENEMY     |
  119.         bits_COND_LIGHT_DAMAGE  |
  120.         bits_COND_HEAVY_DAMAGE  |
  121.         bits_COND_HEAR_SOUND |
  122.         bits_COND_PROVOKED,
  123.         bits_SOUND_DANGER,
  124.         "Follow"
  125.     },
  126. };
  127.  
  128. //=========================================================
  129. // CustomDraw- much better looking draw schedule for when
  130. // custom knows who he's gonna attack.
  131. //=========================================================
  132. Task_t  tlCustomEnemyDraw[] =
  133. {
  134.     { TASK_STOP_MOVING,                 0               },
  135.     { TASK_FACE_ENEMY,                  0               },
  136.     { TASK_PLAY_SEQUENCE_FACE_ENEMY,    (float) ACT_ARM },
  137. };
  138.  
  139. Schedule_t slCustomEnemyDraw[] =
  140. {
  141.     {
  142.         tlCustomEnemyDraw,
  143.         ARRAYSIZE ( tlCustomEnemyDraw ),
  144.         0,
  145.         0,
  146.         "Custom Enemy Draw"
  147.     }
  148. };
  149.  
  150. Task_t  tlBaFaceTarget[] =
  151. {
  152.     { TASK_SET_ACTIVITY,        (float)ACT_IDLE },
  153.     { TASK_FACE_TARGET,         (float)0        },
  154.     { TASK_SET_ACTIVITY,        (float)ACT_IDLE },
  155.     { TASK_SET_SCHEDULE,        (float)SCHED_TARGET_CHASE },
  156. };
  157.  
  158. Schedule_t  slBaFaceTarget[] =
  159. {
  160.     {
  161.         tlBaFaceTarget,
  162.         ARRAYSIZE ( tlBaFaceTarget ),
  163.         bits_COND_CLIENT_PUSH   |
  164.         bits_COND_NEW_ENEMY     |
  165.         bits_COND_LIGHT_DAMAGE  |
  166.         bits_COND_HEAVY_DAMAGE  |
  167.         bits_COND_HEAR_SOUND |
  168.         bits_COND_PROVOKED,
  169.         bits_SOUND_DANGER,
  170.         "FaceTarget"
  171.     },
  172. };
  173.  
  174.  
  175. Task_t  tlIdleBaStand[] =
  176. {
  177.     { TASK_STOP_MOVING,         0               },
  178.     { TASK_SET_ACTIVITY,        (float)ACT_IDLE },
  179.     { TASK_WAIT,                (float)2        }, // repick IDLESTAND every two seconds.
  180.     { TASK_TLK_HEADRESET,       (float)0        }, // reset head position
  181. };
  182.  
  183. Schedule_t  slIdleBaStand[] =
  184. {
  185.     {
  186.         tlIdleBaStand,
  187.         ARRAYSIZE ( tlIdleBaStand ),
  188.         bits_COND_NEW_ENEMY     |
  189.         bits_COND_LIGHT_DAMAGE  |
  190.         bits_COND_HEAVY_DAMAGE  |
  191.         bits_COND_HEAR_SOUND    |
  192.         bits_COND_SMELL         |
  193.         bits_COND_PROVOKED,
  194.  
  195.         bits_SOUND_COMBAT       |// sound flags - change these, and you'll break the talking code.
  196.         //bits_SOUND_PLAYER     |
  197.         //bits_SOUND_WORLD      |
  198.        
  199.         bits_SOUND_DANGER       |
  200.         bits_SOUND_MEAT         |// scents
  201.         bits_SOUND_CARCASS      |
  202.         bits_SOUND_GARBAGE,
  203.         "IdleStand"
  204.     },
  205. };
  206.  
  207. DEFINE_CUSTOM_SCHEDULES( CCustom )
  208. {
  209.     slBaFollow,
  210.     slCustomEnemyDraw,
  211.     slBaFaceTarget,
  212.     slIdleBaStand,
  213. };
  214.  
  215.  
  216. IMPLEMENT_CUSTOM_SCHEDULES( CCustom, CTalkMonster );
  217.  
  218. void CCustom :: StartTask( Task_t *pTask )
  219. {
  220.     CTalkMonster::StartTask( pTask );  
  221. }
  222.  
  223. void CCustom :: RunTask( Task_t *pTask )
  224. {
  225.     switch ( pTask->iTask )
  226.     {
  227.     case TASK_RANGE_ATTACK1:
  228.         if (m_hEnemy != NULL && (m_hEnemy->IsPlayer()))
  229.         {
  230.             pev->framerate = 1.5;
  231.         }
  232.         CTalkMonster::RunTask( pTask );
  233.         break;
  234.     default:
  235.         CTalkMonster::RunTask( pTask );
  236.         break;
  237.     }
  238. }
  239.  
  240.  
  241.  
  242.  
  243. //=========================================================
  244. // ISoundMask - returns a bit mask indicating which types
  245. // of sounds this monster regards.
  246. //=========================================================
  247. int CCustom :: ISoundMask ( void)
  248. {
  249.     return  bits_SOUND_WORLD    |
  250.             bits_SOUND_COMBAT   |
  251.             bits_SOUND_CARCASS  |
  252.             bits_SOUND_MEAT     |
  253.             bits_SOUND_GARBAGE  |
  254.             bits_SOUND_DANGER   |
  255.             bits_SOUND_PLAYER;
  256. }
  257.  
  258. //=========================================================
  259. // Classify - indicates this monster's place in the
  260. // relationship table.
  261. //=========================================================
  262. int CCustom :: Classify ( void )
  263. {
  264.     return  CLASS_PLAYER_ALLY;
  265. }
  266.  
  267. //=========================================================
  268. // ALertSound - custom says "Freeze!"
  269. //=========================================================
  270. void CCustom :: AlertSound( void )
  271. {
  272.     if ( m_hEnemy != NULL )
  273.     {
  274.         if ( FOkToSpeak() )
  275.         {
  276.             PlaySentence( "BA_ATTACK", RANDOM_FLOAT(2.8, 3.2), VOL_NORM, ATTN_IDLE );
  277.         }
  278.     }
  279.  
  280. }
  281. //=========================================================
  282. // SetYawSpeed - allows each sequence to have a different
  283. // turn rate associated with it.
  284. //=========================================================
  285. void CCustom :: SetYawSpeed ( void )
  286. {
  287.     int ys;
  288.  
  289.     ys = 0;
  290.  
  291.     switch ( m_Activity )
  292.     {
  293.     case ACT_IDLE:     
  294.         ys = 70;
  295.         break;
  296.     case ACT_WALK:
  297.         ys = 70;
  298.         break;
  299.     case ACT_RUN:
  300.         ys = 90;
  301.         break;
  302.     default:
  303.         ys = 70;
  304.         break;
  305.     }
  306.  
  307.     pev->yaw_speed = ys;
  308. }
  309.  
  310.  
  311. //=========================================================
  312. // CheckRangeAttack1
  313. //=========================================================
  314. BOOL CCustom :: CheckRangeAttack1 ( float flDot, float flDist )
  315. {
  316.     if ( flDist <= 1024 && flDot >= 0.5 )
  317.     {
  318.         if ( gpGlobals->time > m_checkAttackTime )
  319.         {
  320.             TraceResult tr;
  321.            
  322.             Vector shootOrigin = pev->origin + Vector( 0, 0, 55 );
  323.             CBaseEntity *pEnemy = m_hEnemy;
  324.             Vector shootTarget = ( (pEnemy->BodyTarget( shootOrigin ) - pEnemy->pev->origin) + m_vecEnemyLKP );
  325.             UTIL_TraceLine( shootOrigin, shootTarget, dont_ignore_monsters, ENT(pev), &tr );
  326.             m_checkAttackTime = gpGlobals->time + 1;
  327.             if ( tr.flFraction == 1.0 || (tr.pHit != NULL && CBaseEntity::Instance(tr.pHit) == pEnemy) )
  328.                 m_lastAttackCheck = TRUE;
  329.             else
  330.                 m_lastAttackCheck = FALSE;
  331.             m_checkAttackTime = gpGlobals->time + 1.5;
  332.         }
  333.         return m_lastAttackCheck;
  334.     }
  335.     return FALSE;
  336. }
  337.  
  338.  
  339. //=========================================================
  340. // CustomFirePistol - shoots one round from the pistol at
  341. // the enemy custom is facing.
  342. //=========================================================
  343. void CCustom :: CustomFirePistol ( void )
  344. {
  345.     Vector vecShootOrigin;
  346.  
  347.     UTIL_MakeVectors(pev->angles);
  348.     vecShootOrigin = pev->origin + Vector( 0, 0, 55 );
  349.     Vector vecShootDir = ShootAtEnemy( vecShootOrigin );
  350.  
  351.     Vector angDir = UTIL_VecToAngles( vecShootDir );
  352.     SetBlending( 0, angDir.x );
  353.     pev->effects = EF_MUZZLEFLASH;
  354.  
  355.     FireBullets(1, vecShootOrigin, vecShootDir, VECTOR_CONE_2DEGREES, 1024, BULLET_MONSTER_9MM );
  356.    
  357.     int pitchShift = RANDOM_LONG( 0, 20 );
  358.    
  359.     // Only shift about half the time
  360.     if ( pitchShift > 10 )
  361.         pitchShift = 0;
  362.     else
  363.         pitchShift -= 5;
  364.     EMIT_SOUND_DYN( ENT(pev), CHAN_WEAPON, "custom/ba_attack2.wav", 1, ATTN_NORM, 0, 100 + pitchShift );
  365.  
  366.     CSoundEnt::InsertSound ( bits_SOUND_COMBAT, pev->origin, 384, 0.3 );
  367.  
  368.     // UNDONE: Reload?
  369.     m_cAmmoLoaded--;// take away a bullet!
  370. }
  371.        
  372. //=========================================================
  373. // HandleAnimEvent - catches the monster-specific messages
  374. // that occur when tagged animation frames are played.
  375. //
  376. // Returns number of events handled, 0 if none.
  377. //=========================================================
  378. void CCustom :: HandleAnimEvent( MonsterEvent_t *pEvent )
  379. {
  380.     switch( pEvent->event )
  381.     {
  382.     case CUSTOM_AE_SHOOT:
  383.         CustomFirePistol();
  384.         break;
  385.  
  386.     case CUSTOM_AE_DRAW:
  387.         // custom's bodygroup switches here so he can pull gun from holster
  388.         pev->body = CUSTOM_BODY_GUNDRAWN;
  389.         m_fGunDrawn = TRUE;
  390.         break;
  391.  
  392.     case CUSTOM_AE_HOLSTER:
  393.         // change bodygroup to replace gun in holster
  394.         pev->body = CUSTOM_BODY_GUNHOLSTERED;
  395.         m_fGunDrawn = FALSE;
  396.         break;
  397.  
  398.     default:
  399.         CTalkMonster::HandleAnimEvent( pEvent );
  400.     }
  401. }
  402.  
  403. //=========================================================
  404. // Spawn
  405. //=========================================================
  406. void CCustom :: Spawn()
  407. {
  408.     Precache( );
  409.  
  410.     SET_MODEL(ENT(pev), "models/custom.mdl");
  411.     UTIL_SetSize(pev, VEC_HUMAN_HULL_MIN, VEC_HUMAN_HULL_MAX);
  412.  
  413.     pev->solid          = SOLID_SLIDEBOX;
  414.     pev->movetype       = MOVETYPE_STEP;
  415.     m_bloodColor        = BLOOD_COLOR_RED;
  416.     pev->health         = gSkillData.customHealth;
  417.     pev->view_ofs       = Vector ( 0, 0, 50 );// position of the eyes relative to monster's origin.
  418.     m_flFieldOfView     = VIEW_FIELD_WIDE; // NOTE: we need a wide field of view so npc will notice player and say hello
  419.     m_MonsterState      = MONSTERSTATE_NONE;
  420.  
  421.     pev->body           = 0; // gun in holster
  422.     m_fGunDrawn         = FALSE;
  423.  
  424.     m_afCapability      = bits_CAP_HEAR | bits_CAP_TURN_HEAD | bits_CAP_DOORS_GROUP;
  425.  
  426.     MonsterInit();
  427.     SetUse( &CCustom::FollowerUse );
  428. }
  429.  
  430. //=========================================================
  431. // Precache - precaches all resources this monster needs
  432. //=========================================================
  433. void CCustom :: Precache()
  434. {
  435.     PRECACHE_MODEL("models/custom.mdl");
  436.  
  437.     PRECACHE_SOUND("custom/ba_attack1.wav" );
  438.     PRECACHE_SOUND("custom/ba_attack2.wav" );
  439.  
  440.     PRECACHE_SOUND("custom/ba_pain1.wav");
  441.     PRECACHE_SOUND("custom/ba_pain2.wav");
  442.     PRECACHE_SOUND("custom/ba_pain3.wav");
  443.  
  444.     PRECACHE_SOUND("custom/ba_die1.wav");
  445.     PRECACHE_SOUND("custom/ba_die2.wav");
  446.     PRECACHE_SOUND("custom/ba_die3.wav");
  447.    
  448.     // every new custom must call this, otherwise
  449.     // when a level is loaded, nobody will talk (time is reset to 0)
  450.     TalkInit();
  451.     CTalkMonster::Precache();
  452. }  
  453.  
  454. // Init talk data
  455. void CCustom :: TalkInit()
  456. {
  457.    
  458.     CTalkMonster::TalkInit();
  459.  
  460.     // scientists speach group names (group names are in sentences.txt)
  461.  
  462.     m_szGrp[TLK_ANSWER]  =  "BA_ANSWER";
  463.     m_szGrp[TLK_QUESTION] = "BA_QUESTION";
  464.     m_szGrp[TLK_IDLE] =     "BA_IDLE";
  465.     m_szGrp[TLK_STARE] =        "BA_STARE";
  466.     m_szGrp[TLK_USE] =      "BA_OK";
  467.     m_szGrp[TLK_UNUSE] =    "BA_WAIT";
  468.     m_szGrp[TLK_STOP] =     "BA_STOP";
  469.  
  470.     m_szGrp[TLK_NOSHOOT] =  "BA_SCARED";
  471.     m_szGrp[TLK_HELLO] =    "BA_HELLO";
  472.  
  473.     m_szGrp[TLK_PLHURT1] =  "!BA_CUREA";
  474.     m_szGrp[TLK_PLHURT2] =  "!BA_CUREB";
  475.     m_szGrp[TLK_PLHURT3] =  "!BA_CUREC";
  476.  
  477.     m_szGrp[TLK_PHELLO] =   NULL;   //"BA_PHELLO";      // UNDONE
  478.     m_szGrp[TLK_PIDLE] =    NULL;   //"BA_PIDLE";           // UNDONE
  479.     m_szGrp[TLK_PQUESTION] = "BA_PQUEST";       // UNDONE
  480.  
  481.     m_szGrp[TLK_SMELL] =    "BA_SMELL";
  482.    
  483.     m_szGrp[TLK_WOUND] =    "BA_WOUND";
  484.     m_szGrp[TLK_MORTAL] =   "BA_MORTAL";
  485.  
  486.     // get voice for head - just one custom voice for now
  487.     m_voicePitch = 100;
  488. }
  489.  
  490.  
  491. static BOOL IsFacing( entvars_t *pevTest, const Vector &reference )
  492. {
  493.     Vector vecDir = (reference - pevTest->origin);
  494.     vecDir.z = 0;
  495.     vecDir = vecDir.Normalize();
  496.     Vector forward, angle;
  497.     angle = pevTest->v_angle;
  498.     angle.x = 0;
  499.     UTIL_MakeVectorsPrivate( angle, forward, NULL, NULL );
  500.     // He's facing me, he meant it
  501.     if ( DotProduct( forward, vecDir ) > 0.96 ) // +/- 15 degrees or so
  502.     {
  503.         return TRUE;
  504.     }
  505.     return FALSE;
  506. }
  507.  
  508.  
  509. int CCustom :: TakeDamage( entvars_t* pevInflictor, entvars_t* pevAttacker, float flDamage, int bitsDamageType)
  510. {
  511.     // make sure friends talk about it if player hurts talkmonsters...
  512.     int ret = CTalkMonster::TakeDamage(pevInflictor, pevAttacker, flDamage, bitsDamageType);
  513.     if ( !IsAlive() || pev->deadflag == DEAD_DYING )
  514.         return ret;
  515.  
  516.     if ( m_MonsterState != MONSTERSTATE_PRONE && (pevAttacker->flags & FL_CLIENT) )
  517.     {
  518.         m_flPlayerDamage += flDamage;
  519.  
  520.         // This is a heurstic to determine if the player intended to harm me
  521.         // If I have an enemy, we can't establish intent (may just be crossfire)
  522.         if ( m_hEnemy == NULL )
  523.         {
  524.             // If the player was facing directly at me, or I'm already suspicious, get mad
  525.             if ( (m_afMemory & bits_MEMORY_SUSPICIOUS) || IsFacing( pevAttacker, pev->origin ) )
  526.             {
  527.                 // Alright, now I'm pissed!
  528.                 PlaySentence( "BA_MAD", 4, VOL_NORM, ATTN_NORM );
  529.  
  530.                 Remember( bits_MEMORY_PROVOKED );
  531.                 StopFollowing( TRUE );
  532.             }
  533.             else
  534.             {
  535.                 // Hey, be careful with that
  536.                 PlaySentence( "BA_SHOT", 4, VOL_NORM, ATTN_NORM );
  537.                 Remember( bits_MEMORY_SUSPICIOUS );
  538.             }
  539.         }
  540.         else if ( !(m_hEnemy->IsPlayer()) && pev->deadflag == DEAD_NO )
  541.         {
  542.             PlaySentence( "BA_SHOT", 4, VOL_NORM, ATTN_NORM );
  543.         }
  544.     }
  545.  
  546.     return ret;
  547. }
  548.  
  549.    
  550. //=========================================================
  551. // PainSound
  552. //=========================================================
  553. void CCustom :: PainSound ( void )
  554. {
  555.     if (gpGlobals->time < m_painTime)
  556.         return;
  557.    
  558.     m_painTime = gpGlobals->time + RANDOM_FLOAT(0.5, 0.75);
  559.  
  560.     switch (RANDOM_LONG(0,2))
  561.     {
  562.     case 0: EMIT_SOUND_DYN( ENT(pev), CHAN_VOICE, "custom/ba_pain1.wav", 1, ATTN_NORM, 0, GetVoicePitch()); break;
  563.     case 1: EMIT_SOUND_DYN( ENT(pev), CHAN_VOICE, "custom/ba_pain2.wav", 1, ATTN_NORM, 0, GetVoicePitch()); break;
  564.     case 2: EMIT_SOUND_DYN( ENT(pev), CHAN_VOICE, "custom/ba_pain3.wav", 1, ATTN_NORM, 0, GetVoicePitch()); break;
  565.     }
  566. }
  567.  
  568. //=========================================================
  569. // DeathSound
  570. //=========================================================
  571. void CCustom :: DeathSound ( void )
  572. {
  573.     switch (RANDOM_LONG(0,2))
  574.     {
  575.     case 0: EMIT_SOUND_DYN( ENT(pev), CHAN_VOICE, "custom/ba_die1.wav", 1, ATTN_NORM, 0, GetVoicePitch()); break;
  576.     case 1: EMIT_SOUND_DYN( ENT(pev), CHAN_VOICE, "custom/ba_die2.wav", 1, ATTN_NORM, 0, GetVoicePitch()); break;
  577.     case 2: EMIT_SOUND_DYN( ENT(pev), CHAN_VOICE, "custom/ba_die3.wav", 1, ATTN_NORM, 0, GetVoicePitch()); break;
  578.     }
  579. }
  580.  
  581.  
  582. void CCustom::TraceAttack( entvars_t *pevAttacker, float flDamage, Vector vecDir, TraceResult *ptr, int bitsDamageType)
  583. {
  584.     switch( ptr->iHitgroup)
  585.     {
  586.     case HITGROUP_CHEST:
  587.     case HITGROUP_STOMACH:
  588.         if (bitsDamageType & (DMG_BULLET | DMG_SLASH | DMG_BLAST))
  589.         {
  590.             flDamage = flDamage / 2;
  591.         }
  592.         break;
  593.     case 10:
  594.         if (bitsDamageType & (DMG_BULLET | DMG_SLASH | DMG_CLUB))
  595.         {
  596.             flDamage -= 20;
  597.             if (flDamage <= 0)
  598.             {
  599.                 UTIL_Ricochet( ptr->vecEndPos, 1.0 );
  600.                 flDamage = 0.01;
  601.             }
  602.         }
  603.         // always a head shot
  604.         ptr->iHitgroup = HITGROUP_HEAD;
  605.         break;
  606.     }
  607.  
  608.     CTalkMonster::TraceAttack( pevAttacker, flDamage, vecDir, ptr, bitsDamageType );
  609. }
  610.  
  611.  
  612. void CCustom::Killed( entvars_t *pevAttacker, int iGib )
  613. {
  614.     if ( pev->body < CUSTOM_BODY_GUNGONE )
  615.     {// drop the gun!
  616.         Vector vecGunPos;
  617.         Vector vecGunAngles;
  618.  
  619.         pev->body = CUSTOM_BODY_GUNGONE;
  620.  
  621.         GetAttachment( 0, vecGunPos, vecGunAngles );
  622.        
  623.         CBaseEntity *pGun = DropItem( "weapon_9mmhandgun", vecGunPos, vecGunAngles );
  624.     }
  625.  
  626.     SetUse( NULL );
  627.     CTalkMonster::Killed( pevAttacker, iGib );
  628. }
  629.  
  630. //=========================================================
  631. // AI Schedules Specific to this monster
  632. //=========================================================
  633.  
  634. Schedule_t* CCustom :: GetScheduleOfType ( int Type )
  635. {
  636.     Schedule_t *psched;
  637.  
  638.     switch( Type )
  639.     {
  640.     case SCHED_ARM_WEAPON:
  641.         if ( m_hEnemy != NULL )
  642.         {
  643.             // face enemy, then draw.
  644.             return slCustomEnemyDraw;
  645.         }
  646.         break;
  647.  
  648.     // Hook these to make a looping schedule
  649.     case SCHED_TARGET_FACE:
  650.         // call base class default so that custom will talk
  651.         // when 'used'
  652.         psched = CTalkMonster::GetScheduleOfType(Type);
  653.  
  654.         if (psched == slIdleStand)
  655.             return slBaFaceTarget;  // override this for different target face behavior
  656.         else
  657.             return psched;
  658.  
  659.     case SCHED_TARGET_CHASE:
  660.         return slBaFollow;
  661.  
  662.     case SCHED_IDLE_STAND:
  663.         // call base class default so that scientist will talk
  664.         // when standing during idle
  665.         psched = CTalkMonster::GetScheduleOfType(Type);
  666.  
  667.         if (psched == slIdleStand)
  668.         {
  669.             // just look straight ahead.
  670.             return slIdleBaStand;
  671.         }
  672.         else
  673.             return psched; 
  674.     }
  675.  
  676.     return CTalkMonster::GetScheduleOfType( Type );
  677. }
  678.  
  679. //=========================================================
  680. // GetSchedule - Decides which type of schedule best suits
  681. // the monster's current state and conditions. Then calls
  682. // monster's member function to get a pointer to a schedule
  683. // of the proper type.
  684. //=========================================================
  685. Schedule_t *CCustom :: GetSchedule ( void )
  686. {
  687.     if ( HasConditions( bits_COND_HEAR_SOUND ) )
  688.     {
  689.         CSound *pSound;
  690.         pSound = PBestSound();
  691.  
  692.         ASSERT( pSound != NULL );
  693.         if ( pSound && (pSound->m_iType & bits_SOUND_DANGER) )
  694.             return GetScheduleOfType( SCHED_TAKE_COVER_FROM_BEST_SOUND );
  695.     }
  696.     if ( HasConditions( bits_COND_ENEMY_DEAD ) && FOkToSpeak() )
  697.     {
  698.         PlaySentence( "BA_KILL", 4, VOL_NORM, ATTN_NORM );
  699.     }
  700.  
  701.     switch( m_MonsterState )
  702.     {
  703.     case MONSTERSTATE_COMBAT:
  704.         {
  705. // dead enemy
  706.             if ( HasConditions( bits_COND_ENEMY_DEAD ) )
  707.             {
  708.                 // call base class, all code to handle dead enemies is centralized there.
  709.                 return CBaseMonster :: GetSchedule();
  710.             }
  711.  
  712.             // always act surprized with a new enemy
  713.             if ( HasConditions( bits_COND_NEW_ENEMY ) && HasConditions( bits_COND_LIGHT_DAMAGE) )
  714.                 return GetScheduleOfType( SCHED_SMALL_FLINCH );
  715.                
  716.             // wait for one schedule to draw gun
  717.             if (!m_fGunDrawn )
  718.                 return GetScheduleOfType( SCHED_ARM_WEAPON );
  719.  
  720.             if ( HasConditions( bits_COND_HEAVY_DAMAGE ) )
  721.                 return GetScheduleOfType( SCHED_TAKE_COVER_FROM_ENEMY );
  722.         }
  723.         break;
  724.  
  725.     case MONSTERSTATE_ALERT:   
  726.     case MONSTERSTATE_IDLE:
  727.         if ( HasConditions(bits_COND_LIGHT_DAMAGE | bits_COND_HEAVY_DAMAGE))
  728.         {
  729.             // flinch if hurt
  730.             return GetScheduleOfType( SCHED_SMALL_FLINCH );
  731.         }
  732.  
  733.         if ( m_hEnemy == NULL && IsFollowing() )
  734.         {
  735.             if ( !m_hTargetEnt->IsAlive() )
  736.             {
  737.                 // UNDONE: Comment about the recently dead player here?
  738.                 StopFollowing( FALSE );
  739.                 break;
  740.             }
  741.             else
  742.             {
  743.                 if ( HasConditions( bits_COND_CLIENT_PUSH ) )
  744.                 {
  745.                     return GetScheduleOfType( SCHED_MOVE_AWAY_FOLLOW );
  746.                 }
  747.                 return GetScheduleOfType( SCHED_TARGET_FACE );
  748.             }
  749.         }
  750.  
  751.         if ( HasConditions( bits_COND_CLIENT_PUSH ) )
  752.         {
  753.             return GetScheduleOfType( SCHED_MOVE_AWAY );
  754.         }
  755.  
  756.         // try to say something about smells
  757.         TrySmellTalk();
  758.         break;
  759.     }
  760.    
  761.     return CTalkMonster::GetSchedule();
  762. }
  763.  
  764. MONSTERSTATE CCustom :: GetIdealState ( void )
  765. {
  766.     return CTalkMonster::GetIdealState();
  767. }
  768.  
  769.  
  770.  
  771. void CCustom::DeclineFollowing( void )
  772. {
  773.     PlaySentence( "BA_POK", 2, VOL_NORM, ATTN_NORM );
  774. }
  775.  
  776.  
  777.  
  778.  
  779.  
  780. //=========================================================
  781. // DEAD CUSTOM PROP
  782. //
  783. // Designer selects a pose in worldcraft, 0 through num_poses-1
  784. // this value is added to what is selected as the 'first dead pose'
  785. // among the monster's normal animations. All dead poses must
  786. // appear sequentially in the model file. Be sure and set
  787. // the m_iFirstPose properly!
  788. //
  789. //=========================================================
  790. class CDeadCustom : public CBaseMonster
  791. {
  792. public:
  793.     void Spawn( void );
  794.     int Classify ( void ) { return  CLASS_PLAYER_ALLY; }
  795.  
  796.     void KeyValue( KeyValueData *pkvd );
  797.  
  798.     int m_iPose;// which sequence to display    -- temporary, don't need to save
  799.     static char *m_szPoses[3];
  800. };
  801.  
  802. char *CDeadCustom::m_szPoses[] = { "lying_on_back", "lying_on_side", "lying_on_stomach" };
  803.  
  804. void CDeadCustom::KeyValue( KeyValueData *pkvd )
  805. {
  806.     if (FStrEq(pkvd->szKeyName, "pose"))
  807.     {
  808.         m_iPose = atoi(pkvd->szValue);
  809.         pkvd->fHandled = TRUE;
  810.     }
  811.     else
  812.         CBaseMonster::KeyValue( pkvd );
  813. }
  814.  
  815. LINK_ENTITY_TO_CLASS( monster_custom_dead, CDeadCustom );
  816.  
  817. //=========================================================
  818. // ********** DeadCustom SPAWN **********
  819. //=========================================================
  820. void CDeadCustom :: Spawn( )
  821. {
  822.     PRECACHE_MODEL("models/custom.mdl");
  823.     SET_MODEL(ENT(pev), "models/custom.mdl");
  824.  
  825.     pev->effects        = 0;
  826.     pev->yaw_speed      = 8;
  827.     pev->sequence       = 0;
  828.     m_bloodColor        = BLOOD_COLOR_RED;
  829.  
  830.     pev->sequence = LookupSequence( m_szPoses[m_iPose] );
  831.     if (pev->sequence == -1)
  832.     {
  833.         ALERT ( at_console, "Dead custom with bad pose\n" );
  834.     }
  835.     // Corpses have less health
  836.     pev->health         = 8;//gSkillData.customHealth;
  837.  
  838.     MonsterInitDead();
  839. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement