Skip to content

Commit

Permalink
Add player_speed and player_capabilities
Browse files Browse the repository at this point in the history
  • Loading branch information
FreeSlave committed May 21, 2024
1 parent 38ad0f5 commit 04a4267
Show file tree
Hide file tree
Showing 7 changed files with 219 additions and 2 deletions.
2 changes: 2 additions & 0 deletions cl_dll/hl/hl_weapons.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -799,6 +799,8 @@ void HUD_WeaponsPostThink( local_state_s *from, local_state_s *to, usercmd_t *cm
player.m_pActiveItem = g_pWpns[from->client.m_iId];
}

player.m_suppressedCapabilities = from->client.vuser2[0];

// Don't go firing anything if we have died.
// Or if we don't have a weapon model deployed
if( ( player.pev->deadflag != ( DEAD_DISCARDBODY + 1 ) ) &&
Expand Down
1 change: 1 addition & 0 deletions dlls/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1841,6 +1841,7 @@ void UpdateClientData( const struct edict_s *ent, int sendweapons, struct client
}
}
}
cd->vuser2.x = pl->m_suppressedCapabilities;
#endif
}

Expand Down
158 changes: 158 additions & 0 deletions dlls/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ TYPEDESCRIPTION CBasePlayer::m_playerSaveData[] =
DEFINE_ARRAY(CBasePlayer, m_timeBasedDmgModifiers, FIELD_CHARACTER, CDMG_TIMEBASED),
DEFINE_FIELD(CBasePlayer, m_settingsLoaded, FIELD_BOOLEAN),
DEFINE_FIELD(CBasePlayer, m_buddha, FIELD_BOOLEAN),
DEFINE_FIELD(CBasePlayer, m_suppressedCapabilities, FIELD_INTEGER),
DEFINE_FIELD(CBasePlayer, m_maxSpeedFraction, FIELD_FLOAT),

DEFINE_FIELD(CBasePlayer, m_loopedMp3, FIELD_STRING),

Expand Down Expand Up @@ -1724,6 +1726,9 @@ void CBasePlayer::PlayerUse( void )
if( !( ( pev->button | m_afButtonPressed | m_afButtonReleased) & IN_USE ) )
return;

if (FBitSet(m_suppressedCapabilities, PLAYER_SUPRESS_USE))
return;

// Hit Use on a train?
if( m_afButtonPressed & IN_USE )
{
Expand Down Expand Up @@ -2341,6 +2346,7 @@ void CBasePlayer::PreThink( void )
m_afButtonReleased = buttonsChanged & ( ~pev->button ); // The ones not down are "released"

g_pGameRules->PlayerThink( this );
pev->maxspeed = m_maxSpeedFraction * g_psv_maxspeed->value;

if( g_fGameOver )
return; // intermission or finale
Expand Down Expand Up @@ -3753,6 +3759,7 @@ int CBasePlayer::Restore( CRestore &restore )
g_engfuncs.pfnSetPhysicsKeyValue( edict(), "slj", "0" );
}

SetPhysicsKeyValues();
RenewItems();

#if CLIENT_WEAPONS
Expand All @@ -3769,6 +3776,26 @@ int CBasePlayer::Restore( CRestore &restore )
return status;
}

void CBasePlayer::SetPhysicsKeyValues()
{
if( FBitSet(m_suppressedCapabilities, PLAYER_SUPRESS_JUMP) )
{
g_engfuncs.pfnSetPhysicsKeyValue( edict(), "noj", "1" );
}
else
{
g_engfuncs.pfnSetPhysicsKeyValue( edict(), "noj", "0" );
}
if( FBitSet(m_suppressedCapabilities, PLAYER_SUPRESS_DUCK) )
{
pev->iuser3 = 1;
}
else
{
pev->iuser3 = 0;
}
}

void CBasePlayer::SelectItem( const char *pstr )
{
if( !pstr )
Expand Down Expand Up @@ -6128,6 +6155,137 @@ IMPLEMENT_SAVERESTORE( CPlayerHasWeapon, CPointEntity )

LINK_ENTITY_TO_CLASS( player_hasweapon, CPlayerHasWeapon )


enum
{
PLAYER_ABILITY_DISABLE = -1,
PLAYER_ABILITY_NOCHANGE = 0,
PLAYER_ABILITY_ENABLE = 1,
PLAYER_ABILITY_TOGGLE = 2,
PLAYER_ABILITY_COPYINPUT = 3,
};

class CPlayerCapabilities : public CPointEntity
{
public:
void Use( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value )
{
CBasePlayer* pPlayer = g_pGameRules->EffectivePlayer(pActivator);
if (!pPlayer)
return;
ConfigurePlayerCapability(pPlayer, PLAYER_SUPRESS_ATTACK, m_attackCapability, useType);
ConfigurePlayerCapability(pPlayer, PLAYER_SUPRESS_JUMP, m_jumpCapability, useType);
ConfigurePlayerCapability(pPlayer, PLAYER_SUPRESS_DUCK, m_duckCapability, useType);
ConfigurePlayerCapability(pPlayer, PLAYER_SUPRESS_USE, m_useCapability, useType);

pPlayer->SetPhysicsKeyValues();
}

void KeyValue( KeyValueData *pkvd )
{
if( FStrEq( pkvd->szKeyName, "attack_capability" ) )
{
m_attackCapability = atoi( pkvd->szValue );
pkvd->fHandled = TRUE;
}
else if( FStrEq( pkvd->szKeyName, "jump_capability" ) )
{
m_jumpCapability = atoi( pkvd->szValue );
pkvd->fHandled = TRUE;
}
else if( FStrEq( pkvd->szKeyName, "duck_capability" ) )
{
m_duckCapability = atoi( pkvd->szValue );
pkvd->fHandled = TRUE;
}
else if( FStrEq( pkvd->szKeyName, "use_capability" ) )
{
m_useCapability = atoi( pkvd->szValue );
pkvd->fHandled = TRUE;
}
else
CPointEntity::KeyValue(pkvd);
}

virtual int Save( CSave &save );
virtual int Restore( CRestore &restore );
static TYPEDESCRIPTION m_SaveData[];

private:
void ConfigurePlayerCapability(CBasePlayer* pPlayer, int suppressCapability, short setting, USE_TYPE useType)
{
if (setting == PLAYER_ABILITY_COPYINPUT)
{
if (useType == USE_OFF)
setting = PLAYER_ABILITY_DISABLE;
else if (useType == USE_ON)
setting = PLAYER_ABILITY_ENABLE;
else
setting = PLAYER_ABILITY_TOGGLE;
}

if (setting == PLAYER_ABILITY_DISABLE)
{
SetBits(pPlayer->m_suppressedCapabilities, suppressCapability);
}
else if (setting == PLAYER_ABILITY_ENABLE)
{
ClearBits(pPlayer->m_suppressedCapabilities, suppressCapability);
}
else if (setting == PLAYER_ABILITY_TOGGLE)
{
if (FBitSet(pPlayer->m_suppressedCapabilities, suppressCapability))
ClearBits(pPlayer->m_suppressedCapabilities, suppressCapability);
else
SetBits(pPlayer->m_suppressedCapabilities, suppressCapability);
}
}

short m_attackCapability;
short m_jumpCapability;
short m_duckCapability;
short m_useCapability;
};

LINK_ENTITY_TO_CLASS( player_capabilities, CPlayerCapabilities )

TYPEDESCRIPTION CPlayerCapabilities::m_SaveData[] =
{
DEFINE_FIELD( CPlayerCapabilities, m_attackCapability, FIELD_SHORT ),
DEFINE_FIELD( CPlayerCapabilities, m_jumpCapability, FIELD_SHORT ),
DEFINE_FIELD( CPlayerCapabilities, m_duckCapability, FIELD_SHORT ),
DEFINE_FIELD( CPlayerCapabilities, m_useCapability, FIELD_SHORT ),
};

IMPLEMENT_SAVERESTORE( CPlayerCapabilities, CPointEntity )

class CPlayerSpeed : public CPointEntity
{
public:
void Use( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value )
{
CBasePlayer* pPlayer = g_pGameRules->EffectivePlayer(pActivator);
if (!pPlayer)
return;

pPlayer->m_maxSpeedFraction = pev->health;
}

void KeyValue( KeyValueData *pkvd )
{
if( FStrEq( pkvd->szKeyName, "maxspeed" ) )
{
// pev->maxspeed is not saved by default. Use some other float variable
pev->health = atof( pkvd->szValue );
pkvd->fHandled = TRUE;
}
else
CPointEntity::KeyValue(pkvd);
}
};

LINK_ENTITY_TO_CLASS( player_speed, CPlayerSpeed )

#define SF_PLAYER_LOAD_SAVED_FREEZE 1
#define SF_PLAYER_LOAD_SAVED_WEAPONSTRIP 2
#define SF_PLAYER_LOAD_SAVED_RETURN_TO_MENU 128
Expand Down
9 changes: 9 additions & 0 deletions dlls/player.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,11 @@ enum sbar_data
#define ARMOR_RATIO 0.2 // Armor Takes 80% of the damage
#define ARMOR_BONUS 0.5 // Each Point of Armor is work 1/x points of health

#define PLAYER_SUPRESS_ATTACK (1<<0)
#define PLAYER_SUPRESS_JUMP (1<<1)
#define PLAYER_SUPRESS_DUCK (1<<2)
#define PLAYER_SUPRESS_USE (1<<5)

class CBasePlayer : public CBaseMonster
{
public:
Expand Down Expand Up @@ -251,6 +256,7 @@ class CBasePlayer : public CBaseMonster

virtual int Save( CSave &save );
virtual int Restore( CRestore &restore );
void SetPhysicsKeyValues();
void RenewItems(void);
void PackDeadPlayerItems( void );
void RemoveAllItems( int stripFlags );
Expand Down Expand Up @@ -474,6 +480,9 @@ class CBasePlayer : public CBaseMonster
short m_iSatchelControl;
short m_iPreferNewGrenadePhysics;

int m_suppressedCapabilities;
float m_maxSpeedFraction;

void SetLoopedMp3(string_t loopedMp3);
string_t m_loopedMp3;
};
Expand Down
6 changes: 4 additions & 2 deletions dlls/weapons_shared.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ void CBasePlayerWeapon::ItemPostFrame( void )
m_fFireOnEmpty = TRUE;
}

SecondaryAttack();
if (!FBitSet(m_pPlayer->m_suppressedCapabilities, PLAYER_SUPRESS_ATTACK))
SecondaryAttack();
m_pPlayer->pev->button &= ~IN_ATTACK2;
}
else if( ( m_pPlayer->pev->button & IN_ATTACK ) && CanAttack( m_flNextPrimaryAttack, gpGlobals->time, UseDecrement() ) )
Expand All @@ -120,7 +121,8 @@ void CBasePlayerWeapon::ItemPostFrame( void )
m_fFireOnEmpty = TRUE;
}

PrimaryAttack();
if (!FBitSet(m_pPlayer->m_suppressedCapabilities, PLAYER_SUPRESS_ATTACK))
PrimaryAttack();
}
else if( m_pPlayer->pev->button & IN_RELOAD && iMaxClip() != WEAPON_NOCLIP && !m_fInReload )
{
Expand Down
41 changes: 41 additions & 0 deletions fgd/halflife.fgd
Original file line number Diff line number Diff line change
Expand Up @@ -7158,6 +7158,42 @@
]
]

@PointClass base(Targetname) = player_capabilities : "Enable/disable certain player's capabilities"
[
attack_capability(choices) : "Attack capability" =
[
-1 : "Off"
0 : "No change"
1 : "On"
2 : "Toggle"
3 : "Copy use input"
]
jump_capability(choices) : "Jump capability" =
[
-1 : "Off"
0 : "No change"
1 : "On"
2 : "Toggle"
3 : "Copy use input"
]
duck_capability(choices) : "Duck capability" =
[
-1 : "Off"
0 : "No change"
1 : "On"
2 : "Toggle"
3 : "Copy use input"
]
use_capability(choices) : "Use capability" =
[
-1 : "Off"
0 : "No change"
1 : "On"
2 : "Toggle"
3 : "Copy use input"
]
]

@PointClass base(Targetname) color(72 96 128) = player_hasitem : "Check if player has a specific item"
[
item_type(choices) : "Item Type" : 0 =
Expand Down Expand Up @@ -7196,6 +7232,11 @@
]
]

@PointClass base(Targetname) = player_speed : "Configure player's speed"
[
maxspeed(string) : "Maxspeed multiplier [0=reset]" : 0
]

@PointClass base(Targetname) size(-16 -16 -16, 16 16 16) = player_weaponstrip : "Strips player's weapons and items"
[
spawnflags(Flags) =
Expand Down
4 changes: 4 additions & 0 deletions pm_shared/pm_shared.c
Original file line number Diff line number Diff line change
Expand Up @@ -2525,6 +2525,10 @@ void PM_Jump( void )
return;
}

// check if jump is disabled
if (atoi( pmove->PM_Info_ValueForKey( pmove->physinfo, "noj" ) ) == 1)
return;

if( pmove->flags & FL_FROZEN )
return;

Expand Down

0 comments on commit 04a4267

Please sign in to comment.