Skip to content

Commit

Permalink
fixes/tweaks
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
wootguy committed Oct 3, 2024
1 parent 981c49e commit 290868e
Show file tree
Hide file tree
Showing 14 changed files with 92 additions and 17 deletions.
6 changes: 4 additions & 2 deletions dlls/CBasePlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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))
{
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions dlls/cbase.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 0 additions & 4 deletions dlls/item/CItem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions dlls/monster/CNihilanth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,7 @@ void CNihilanth :: DyingThink( void )
pev->nextthink = gpGlobals->time + 0.1;
DispatchAnimEvents( );
StudioFrameAdvance( );
UpdateShockEffect();

if (pev->deadflag == DEAD_NO)
{
Expand Down Expand Up @@ -857,6 +858,7 @@ void CNihilanth :: HuntThink( void )
pev->nextthink = gpGlobals->time + 0.1;
DispatchAnimEvents( );
StudioFrameAdvance( );
UpdateShockEffect();

ShootBalls( );

Expand Down
2 changes: 1 addition & 1 deletion dlls/monster/defaultai.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion dlls/multiplay_gamerules.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
1 change: 0 additions & 1 deletion dlls/triggers/CTriggerChangeSky.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 0 additions & 2 deletions dlls/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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++)
Expand Down
32 changes: 30 additions & 2 deletions dlls/weapon/CBasePlayerAmmo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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);
}
}
2 changes: 2 additions & 0 deletions dlls/weapon/CBasePlayerAmmo.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down
39 changes: 35 additions & 4 deletions dlls/weapon/CBasePlayerItem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -87,6 +90,7 @@ void CBasePlayerItem::FallThink(void)
else if (!m_hPlayer)
{
SetThink(NULL);
SetUse(NULL);
}
}

Expand All @@ -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);

}

Expand Down Expand Up @@ -238,13 +246,15 @@ int CBasePlayerItem::AddToPlayer(CBasePlayer* pPlayer)
void CBasePlayerItem::Drop(void)
{
SetTouch(NULL);
SetUse(NULL);
SetThink(&CBasePlayerItem::SUB_Remove);
pev->nextthink = gpGlobals->time + .1;
}

void CBasePlayerItem::Kill(void)
{
SetTouch(NULL);
SetUse(NULL);
SetThink(&CBasePlayerItem::SUB_Remove);
pev->nextthink = gpGlobals->time + .1;
}
Expand All @@ -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);
}
}
3 changes: 3 additions & 0 deletions dlls/weapon/CBasePlayerItem.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,16 @@ 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[];

virtual int AddToPlayer( CBasePlayer *pPlayer ); // return TRUE if the item you want the item added to the player inventory
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
Expand Down
8 changes: 8 additions & 0 deletions dlls/weapon/CWeaponBox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
//=========================================================
Expand Down
2 changes: 2 additions & 0 deletions dlls/weapon/CWeaponBox.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down

0 comments on commit 290868e

Please sign in to comment.