From 290868e88101b6638d6ec5f4dbb5a23c81e4d962 Mon Sep 17 00:00:00 2001 From: wootguy Date: Thu, 3 Oct 2024 14:57:21 -0700 Subject: [PATCH] fixes/tweaks - player drowning noises while dead - weapons/ammo not usable - permanent shock effects on nihilanth - less flinching for some monster melee attacks - compiler warnings - wrong assist player --- dlls/CBasePlayer.cpp | 6 +++-- dlls/cbase.h | 4 +++ dlls/item/CItem.cpp | 4 --- dlls/monster/CNihilanth.cpp | 2 ++ dlls/monster/defaultai.cpp | 2 +- dlls/multiplay_gamerules.cpp | 2 +- dlls/triggers/CTriggerChangeSky.cpp | 1 - dlls/util.cpp | 2 -- dlls/weapon/CBasePlayerAmmo.cpp | 32 +++++++++++++++++++++-- dlls/weapon/CBasePlayerAmmo.h | 2 ++ dlls/weapon/CBasePlayerItem.cpp | 39 ++++++++++++++++++++++++++--- dlls/weapon/CBasePlayerItem.h | 3 +++ dlls/weapon/CWeaponBox.cpp | 8 ++++++ dlls/weapon/CWeaponBox.h | 2 ++ 14 files changed, 92 insertions(+), 17 deletions(-) diff --git a/dlls/CBasePlayer.cpp b/dlls/CBasePlayer.cpp index b42e3a54..154bbd29 100644 --- a/dlls/CBasePlayer.cpp +++ b/dlls/CBasePlayer.cpp @@ -1385,7 +1385,7 @@ void CBasePlayer::WaterMove() // make bubbles air = (int)(pev->air_finished - gpGlobals->time); - if (!RANDOM_LONG(0,0x1f) && RANDOM_LONG(0,AIRTIME-1) >= air) + if (!RANDOM_LONG(0,0x1f) && RANDOM_LONG(0,AIRTIME-1) >= air && IsAlive()) { switch (RANDOM_LONG(0,3)) { @@ -1990,7 +1990,8 @@ void CBasePlayer::UpdateStatusBar() FakePlayerInfo fakePlayerInfo; fakePlayerInfo.enabled = false; - static char fakeNameBuffer[128]; + fakePlayerInfo.color = DEFAULT_TEAM_COLOR; + fakePlayerInfo.name = "\\no name\\"; std::string name; @@ -2179,6 +2180,7 @@ void CBasePlayer::UpdateStatusBar() MESSAGE_END(); tempNameActive = 1; + memset(m_tempName, 0, SBAR_STRING_SIZE); strncpy(m_tempName, fakePlayerInfo.name, SBAR_STRING_SIZE); m_tempName[SBAR_STRING_SIZE - 1] = 0; m_tempTeam = fakePlayerInfo.color; diff --git a/dlls/cbase.h b/dlls/cbase.h index 3b9cb5e1..52a82f83 100644 --- a/dlls/cbase.h +++ b/dlls/cbase.h @@ -725,6 +725,10 @@ class EXPORT CBaseToggle : public CBaseAnimating #define WATERLEVEL_WAIST 2 #define WATERLEVEL_HEAD 3 +#define SF_ITEM_TOUCH_ONLY 128 // Pick this item up only by touching it. +#define SF_ITEM_USE_ONLY 256 // Pick this item up only by using it ('USE' key). +#define SF_ITEM_USE_WITHOUT_LOS 512 // Player can pick up this item even when it's not within his line of sight. + class CBaseMonster; class CCineMonster; class CSound; diff --git a/dlls/item/CItem.cpp b/dlls/item/CItem.cpp index 93a443d1..eae28b0f 100644 --- a/dlls/item/CItem.cpp +++ b/dlls/item/CItem.cpp @@ -5,10 +5,6 @@ #include "CItem.h" #include "gamerules.h" -#define SF_ITEM_TOUCH_ONLY 128 // Pick this item up only by touching it. -#define SF_ITEM_USE_ONLY 256 // Pick this item up only by using it ('USE' key). -#define SF_ITEM_USE_WITHOUT_LOS 512 // Player can pick up this item even when it's not within his line of sight. - void CItem::Spawn(void) { UTIL_SetOrigin(pev, pev->origin); diff --git a/dlls/monster/CNihilanth.cpp b/dlls/monster/CNihilanth.cpp index f675630c..b2f4e123 100644 --- a/dlls/monster/CNihilanth.cpp +++ b/dlls/monster/CNihilanth.cpp @@ -435,6 +435,7 @@ void CNihilanth :: DyingThink( void ) pev->nextthink = gpGlobals->time + 0.1; DispatchAnimEvents( ); StudioFrameAdvance( ); + UpdateShockEffect(); if (pev->deadflag == DEAD_NO) { @@ -857,6 +858,7 @@ void CNihilanth :: HuntThink( void ) pev->nextthink = gpGlobals->time + 0.1; DispatchAnimEvents( ); StudioFrameAdvance( ); + UpdateShockEffect(); ShootBalls( ); diff --git a/dlls/monster/defaultai.cpp b/dlls/monster/defaultai.cpp index ffd4652d..5fdea223 100644 --- a/dlls/monster/defaultai.cpp +++ b/dlls/monster/defaultai.cpp @@ -559,7 +559,7 @@ Schedule_t slSecondaryMeleeAttack[] = ARRAYSIZE ( tlSecondaryMeleeAttack1 ), bits_COND_NEW_ENEMY | bits_COND_ENEMY_DEAD | - bits_COND_LIGHT_DAMAGE | + //bits_COND_LIGHT_DAMAGE | // TODO: may want to selectively disable this per monster bits_COND_HEAVY_DAMAGE | bits_COND_ENEMY_OCCLUDED, 0, diff --git a/dlls/multiplay_gamerules.cpp b/dlls/multiplay_gamerules.cpp index e8a7bb7f..1f98f923 100644 --- a/dlls/multiplay_gamerules.cpp +++ b/dlls/multiplay_gamerules.cpp @@ -822,7 +822,7 @@ void CHalfLifeMultiplay::DeathNotice( CBaseMonster *pVictim, entvars_t *pKiller, if (info.userid && info.userid != attackerId) { attackerCount++; if (!otherAttacker) { - CBasePlayer* plr = UTIL_PlayerByIndex(info.userid); + CBasePlayer* plr = UTIL_PlayerByUserId(info.userid); if (plr) otherAttacker = plr->DisplayName(); } diff --git a/dlls/triggers/CTriggerChangeSky.cpp b/dlls/triggers/CTriggerChangeSky.cpp index d1a9883a..7c6f28db 100644 --- a/dlls/triggers/CTriggerChangeSky.cpp +++ b/dlls/triggers/CTriggerChangeSky.cpp @@ -40,7 +40,6 @@ void CTriggerChangeSky::Spawn(void) // using a bsp because it isn't affected by world lighting and renders everywhere SET_MODEL(ENT(pev), UTIL_VarArgs(SKYBOX_MODEL_PATH "/%s.bsp", STRING(m_skyname))); - edict_t* world = ENT(0); if (CVAR_GET_FLOAT("sv_zmax") < SKYBOX_MIN_ZMAX) { ALERT(at_console, "trigger_changesky: increased sv_zmax to %d for skybox rendering\n", SKYBOX_MIN_ZMAX); CVAR_SET_FLOAT("sv_zmax", SKYBOX_MIN_ZMAX); diff --git a/dlls/util.cpp b/dlls/util.cpp index d5b48c03..fea35ab5 100644 --- a/dlls/util.cpp +++ b/dlls/util.cpp @@ -669,8 +669,6 @@ CBasePlayer* UTIL_PlayerByIndex( int playerIndex ) CBasePlayer* UTIL_PlayerByUserId(int userid) { - CBasePlayer* pPlayer = NULL; - if (userid > 0) { for (int i = 1; i <= gpGlobals->maxClients; i++) diff --git a/dlls/weapon/CBasePlayerAmmo.cpp b/dlls/weapon/CBasePlayerAmmo.cpp index 8a0acffe..71af2e48 100644 --- a/dlls/weapon/CBasePlayerAmmo.cpp +++ b/dlls/weapon/CBasePlayerAmmo.cpp @@ -16,7 +16,11 @@ void CBasePlayerAmmo::Spawn(void) UTIL_SetSize(pev, Vector(-16, -16, 0), Vector(16, 16, 16)); UTIL_SetOrigin(pev, pev->origin); - SetTouch(&CBasePlayerAmmo::DefaultTouch); + if (!(pev->spawnflags & SF_ITEM_USE_ONLY)) + SetTouch(&CBasePlayerAmmo::DefaultTouch); + + if (!(pev->spawnflags & SF_ITEM_TOUCH_ONLY)) + SetUse(&CBasePlayerAmmo::DefaultUse); } void CBasePlayerAmmo::KeyValue(KeyValueData* pkvd) @@ -53,7 +57,11 @@ void CBasePlayerAmmo::Materialize(void) pev->effects |= EF_MUZZLEFLASH; } - SetTouch(&CBasePlayerAmmo::DefaultTouch); + if (!(pev->spawnflags & SF_ITEM_USE_ONLY)) + SetTouch(&CBasePlayerAmmo::DefaultTouch); + + if (!(pev->spawnflags & SF_ITEM_TOUCH_ONLY)) + SetUse(&CBasePlayerAmmo::DefaultUse); } void CBasePlayerAmmo::DefaultTouch(CBaseEntity* pOther) @@ -84,3 +92,23 @@ void CBasePlayerAmmo::DefaultTouch(CBaseEntity* pOther) pev->nextthink = gpGlobals->time + .1; } } + +void CBasePlayerAmmo::DefaultUse(CBaseEntity* pActivator, CBaseEntity* pCaller, USE_TYPE useType, float value) +{ + if (pCaller && pCaller->IsPlayer()) { + + if (!(pev->spawnflags & SF_ITEM_USE_WITHOUT_LOS)) { + TraceResult tr; + TRACE_LINE(pCaller->pev->origin + pCaller->pev->view_ofs, pev->origin, dont_ignore_monsters, pCaller->edict(), &tr); + + bool hitItemSurface = tr.pHit && tr.pHit != edict(); + bool enteredItemBox = boxesIntersect(pev->absmin, pev->absmax, tr.vecEndPos, tr.vecEndPos); + if (!hitItemSurface && !enteredItemBox) { + ALERT(at_console, "Can't use item not in LOS\n"); + return; + } + } + + DefaultTouch(pCaller); + } +} \ No newline at end of file diff --git a/dlls/weapon/CBasePlayerAmmo.h b/dlls/weapon/CBasePlayerAmmo.h index 291d1016..a9a1c89f 100644 --- a/dlls/weapon/CBasePlayerAmmo.h +++ b/dlls/weapon/CBasePlayerAmmo.h @@ -10,7 +10,9 @@ class EXPORT CBasePlayerAmmo : public CBaseEntity virtual void Spawn( void ); void KeyValue(KeyValueData* pkvd); void DefaultTouch( CBaseEntity *pOther ); // default weapon touch + void DefaultUse(CBaseEntity* pActivator, CBaseEntity* pCaller, USE_TYPE useType, float value); virtual BOOL AddAmmo( CBaseEntity *pOther ) { return TRUE; }; + virtual int ObjectCaps(void) { return FCAP_ACROSS_TRANSITION | FCAP_IMPULSE_USE; } CBaseEntity* Respawn( void ); void Materialize( void ); diff --git a/dlls/weapon/CBasePlayerItem.cpp b/dlls/weapon/CBasePlayerItem.cpp index f4cd0635..cdacf97c 100644 --- a/dlls/weapon/CBasePlayerItem.cpp +++ b/dlls/weapon/CBasePlayerItem.cpp @@ -51,8 +51,11 @@ void CBasePlayerItem::FallInit(void) UTIL_SetOrigin(pev, pev->origin); UTIL_SetSize(pev, Vector(0, 0, 0), Vector(0, 0, 0));//pointsize until it lands on the ground. - SetTouch(&CBasePlayerItem::DefaultTouch); - SetThink(&CBasePlayerItem::FallThink); + if (!(pev->spawnflags & SF_ITEM_USE_ONLY)) + SetTouch(&CBasePlayerItem::DefaultTouch); + + if (!(pev->spawnflags & SF_ITEM_TOUCH_ONLY)) + SetUse(&CBasePlayerItem::DefaultUse); pev->nextthink = gpGlobals->time + 0.1; } @@ -87,6 +90,7 @@ void CBasePlayerItem::FallThink(void) else if (!m_hPlayer) { SetThink(NULL); + SetUse(NULL); } } @@ -106,8 +110,12 @@ void CBasePlayerItem::Materialize(void) pev->solid = SOLID_TRIGGER; UTIL_SetOrigin(pev, pev->origin);// link into world. - SetTouch(&CBasePlayerItem::DefaultTouch); - SetThink(NULL); + + if (!(pev->spawnflags & SF_ITEM_USE_ONLY)) + SetTouch(&CBasePlayerItem::DefaultTouch); + + if (!(pev->spawnflags & SF_ITEM_TOUCH_ONLY)) + SetUse(&CBasePlayerItem::DefaultUse); } @@ -238,6 +246,7 @@ int CBasePlayerItem::AddToPlayer(CBasePlayer* pPlayer) void CBasePlayerItem::Drop(void) { SetTouch(NULL); + SetUse(NULL); SetThink(&CBasePlayerItem::SUB_Remove); pev->nextthink = gpGlobals->time + .1; } @@ -245,6 +254,7 @@ void CBasePlayerItem::Drop(void) void CBasePlayerItem::Kill(void) { SetTouch(NULL); + SetUse(NULL); SetThink(&CBasePlayerItem::SUB_Remove); pev->nextthink = gpGlobals->time + .1; } @@ -270,4 +280,25 @@ void CBasePlayerItem::AttachToPlayer(CBasePlayer* pPlayer) pev->owner = pPlayer->edict(); pev->nextthink = gpGlobals->time + .1; SetTouch(NULL); + SetUse(NULL); } + +void CBasePlayerItem::DefaultUse(CBaseEntity* pActivator, CBaseEntity* pCaller, USE_TYPE useType, float value) +{ + if (pCaller && pCaller->IsPlayer()) { + + if (!(pev->spawnflags & SF_ITEM_USE_WITHOUT_LOS)) { + TraceResult tr; + TRACE_LINE(pCaller->pev->origin + pCaller->pev->view_ofs, pev->origin, dont_ignore_monsters, pCaller->edict(), &tr); + + bool hitItemSurface = tr.pHit && tr.pHit != edict(); + bool enteredItemBox = boxesIntersect(pev->absmin, pev->absmax, tr.vecEndPos, tr.vecEndPos); + if (!hitItemSurface && !enteredItemBox) { + ALERT(at_console, "Can't use item not in LOS\n"); + return; + } + } + + DefaultTouch(pCaller); + } +} \ No newline at end of file diff --git a/dlls/weapon/CBasePlayerItem.h b/dlls/weapon/CBasePlayerItem.h index a59d8baf..9e36c716 100644 --- a/dlls/weapon/CBasePlayerItem.h +++ b/dlls/weapon/CBasePlayerItem.h @@ -12,6 +12,8 @@ class EXPORT CBasePlayerItem : public CBaseAnimating virtual int Save( CSave &save ); virtual int Restore( CRestore &restore ); + + virtual int ObjectCaps(void) { return FCAP_ACROSS_TRANSITION | FCAP_IMPULSE_USE; } static TYPEDESCRIPTION m_SaveData[]; @@ -19,6 +21,7 @@ class EXPORT CBasePlayerItem : public CBaseAnimating virtual int AddDuplicate( CBasePlayerItem *pItem ) { return FALSE; } // return TRUE if you want your duplicate removed from world void DestroyItem( void ); void DefaultTouch( CBaseEntity *pOther ); // default weapon touch + void DefaultUse(CBaseEntity* pActivator, CBaseEntity* pCaller, USE_TYPE useType, float value); void FallThink ( void );// when an item is first spawned, this think is run to determine when the object has hit the ground. void Materialize( void );// make a weapon visible and tangible void AttemptToMaterialize( void ); // the weapon desires to become visible and tangible, if the game rules allow for it diff --git a/dlls/weapon/CWeaponBox.cpp b/dlls/weapon/CWeaponBox.cpp index 46b39e75..fcec4785 100644 --- a/dlls/weapon/CWeaponBox.cpp +++ b/dlls/weapon/CWeaponBox.cpp @@ -183,9 +183,17 @@ void CWeaponBox::Touch(CBaseEntity* pOther) EMIT_SOUND(pOther->edict(), CHAN_ITEM, hadWeapon ? "items/gunpickup2.wav" : "items/9mmclip1.wav", 1, ATTN_NORM); SetTouch(NULL); + SetUse(NULL); UTIL_Remove(this); } +void CWeaponBox::Use(CBaseEntity* pActivator, CBaseEntity* pCaller, USE_TYPE useType, float value) +{ + if (pCaller && pCaller->IsPlayer()) { + Touch(pCaller); + } +} + //========================================================= // CWeaponBox - PackWeapon: Add this weapon to the box //========================================================= diff --git a/dlls/weapon/CWeaponBox.h b/dlls/weapon/CWeaponBox.h index aa2268ab..c9e32898 100644 --- a/dlls/weapon/CWeaponBox.h +++ b/dlls/weapon/CWeaponBox.h @@ -9,10 +9,12 @@ class CWeaponBox : public CBaseEntity void Precache( void ); void Spawn( void ); void Touch( CBaseEntity *pOther ); + void Use(CBaseEntity* pActivator, CBaseEntity* pCaller, USE_TYPE useType, float value); void KeyValue( KeyValueData *pkvd ); BOOL IsEmpty( void ); int GiveAmmo( int iCount, const char *szName, int iMax, int *pIndex = NULL ); void SetObjectCollisionBox( void ); + virtual int ObjectCaps(void) { return FCAP_ACROSS_TRANSITION | FCAP_IMPULSE_USE; } public: void EXPORT Kill ( void );