Skip to content

Commit

Permalink
Add player_maxhealth and player_maxarmor features. Add maxhealth and …
Browse files Browse the repository at this point in the history
…maxarmor parameters in the map config. Add parameters for game_player_settings
  • Loading branch information
FreeSlave committed May 22, 2024
1 parent 04a4267 commit 5b424cc
Show file tree
Hide file tree
Showing 19 changed files with 192 additions and 35 deletions.
6 changes: 5 additions & 1 deletion cl_dll/battery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ DECLARE_MESSAGE( m_Battery, Battery )
int CHudBattery::Init( void )
{
m_iBat = 0;
m_iMaxBat = 100;
m_fFade = 0;
m_iFlags = 0;

Expand Down Expand Up @@ -56,6 +57,7 @@ int CHudBattery::MsgFunc_Battery( const char *pszName, int iSize, void *pbuf )

BEGIN_READ( pbuf, iSize );
int x = READ_SHORT();
m_iMaxBat = READ_SHORT();

if( x != m_iBat )
{
Expand Down Expand Up @@ -122,7 +124,9 @@ int CHudBattery::Draw( float flTime )
}

x += ( m_prc1->right - m_prc1->left );
x = gHUD.DrawHudNumber( x, y, DHN_3DIGITS | DHN_DRAWZERO, m_iBat, r, g, b );

const int digitFlag = m_iBat >= 1000 ? DHN_4DIGITS : DHN_3DIGITS;
x = gHUD.DrawHudNumber( x, y, digitFlag | DHN_DRAWZERO, m_iBat, r, g, b );

return 1;
}
10 changes: 6 additions & 4 deletions cl_dll/health.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ int CHudHealth::Init( void )
HOOK_MESSAGE( Health );
HOOK_MESSAGE( Damage );
m_iHealth = 100;
m_iMaxHealth = 100;
m_fFade = 0;
m_iFlags = 0;
m_bitsDamage = 0;
Expand Down Expand Up @@ -98,7 +99,8 @@ int CHudHealth::MsgFunc_Health( const char *pszName, int iSize, void *pbuf )
{
// TODO: update local health data
BEGIN_READ( pbuf, iSize );
int x = READ_BYTE();
int x = READ_SHORT();
m_iMaxHealth = READ_SHORT();

m_iFlags |= HUD_ACTIVE;

Expand All @@ -108,7 +110,6 @@ int CHudHealth::MsgFunc_Health( const char *pszName, int iSize, void *pbuf )
m_fFade = FADE_TIME;
m_iHealth = x;
}

return 1;
}

Expand Down Expand Up @@ -230,9 +231,10 @@ int CHudHealth::Draw( float flTime )

CHud::Renderer().SPR_DrawAdditive( gHUD.GetSprite( m_HUD_cross ), r, g, b, x, y, &gHUD.GetSpriteRect( m_HUD_cross ) );

x = CrossWidth + HealthWidth / 2;
x += CrossWidth;

x = gHUD.DrawHudNumber( x, y, DHN_3DIGITS | DHN_DRAWZERO, m_iHealth, r, g, b );
const int digitFlag = m_iHealth >= 1000 ? DHN_4DIGITS : DHN_3DIGITS;
x = gHUD.DrawHudNumber( x, y, digitFlag | DHN_DRAWZERO, m_iHealth, r, g, b );

x += HealthWidth / 2;

Expand Down
1 change: 1 addition & 0 deletions cl_dll/health.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ class CHudHealth : public CHudBase
int MsgFunc_Health( const char *pszName, int iSize, void *pbuf );
int MsgFunc_Damage( const char *pszName, int iSize, void *pbuf );
int m_iHealth;
int m_iMaxHealth;
int m_HUD_dmg_bio;
int m_HUD_cross;
float m_fAttackFront, m_fAttackRear, m_fAttackLeft, m_fAttackRight;
Expand Down
1 change: 1 addition & 0 deletions cl_dll/hud.h
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,7 @@ class CHudBattery : public CHudBase
wrect_t *m_prc1;
wrect_t *m_prc2;
int m_iBat;
int m_iMaxBat;
float m_fFade;
int m_iHeight; // width of the battery innards
};
Expand Down
5 changes: 5 additions & 0 deletions dlls/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ ModFeatures::ModFeatures()
memset(wall_puff3, 0, sizeof(StringBuf));
memset(wall_puff4, 0, sizeof(StringBuf));

player_maxhealth = MAX_NORMAL_HEALTH;
player_maxarmor = MAX_NORMAL_BATTERY;

suit_light = SUIT_LIGHT_FLASHLIGHT;
suit_light_allow_both = false;
suit_sentences = true;
Expand Down Expand Up @@ -170,6 +173,8 @@ bool ModFeatures::SetValue(const char *key, const char *value)
}

KeyValueDefinition<int> integers[] = {
KEY_VALUE_DEF(player_maxhealth),
KEY_VALUE_DEF(player_maxarmor),
KEY_VALUE_DEF(scientist_random_heads),
};

Expand Down
13 changes: 13 additions & 0 deletions dlls/game.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@

extern void GameDLLInit( void );

#define MAX_NORMAL_HEALTH 100
#define MAX_NORMAL_BATTERY 100

struct ModFeatures
{
enum {
Expand Down Expand Up @@ -50,6 +53,13 @@ struct ModFeatures
void EnableMonster(const char* name);
bool IsMonsterEnabled(const char* name) const;

int MaxPlayerHealth() {
return player_maxhealth > 0 ? player_maxhealth : MAX_NORMAL_HEALTH;
}
int MaxPlayerArmor() {
return player_maxarmor > 0 ? player_maxarmor : MAX_NORMAL_BATTERY;
}

int suit_light;
bool suit_light_allow_both;
bool suit_sentences;
Expand All @@ -59,6 +69,9 @@ struct ModFeatures
bool satchels_pickable;
bool gauss_fidget;

int player_maxhealth;
int player_maxarmor;

bool alien_teleport_sound;
bool warpball_at_monster_center;

Expand Down
15 changes: 12 additions & 3 deletions dlls/gamerules.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -626,10 +626,19 @@ bool CGameRules::EquipPlayerFromMapConfig(CBasePlayer *pPlayer, const MapConfig
pPlayer->GiveNamedItem("weapon_medkit");
}
#endif
if (mapConfig.maxhealth > 0)
{
pPlayer->SetMaxHealth(mapConfig.maxhealth);
pPlayer->pev->health = pPlayer->pev->max_health;
}
if (mapConfig.maxarmor > 0)
{
pPlayer->SetMaxArmor(mapConfig.maxarmor);
}
if (mapConfig.startarmor > 0)
pPlayer->pev->armorvalue = Q_min(mapConfig.startarmor, MAX_NORMAL_BATTERY);
if (mapConfig.starthealth > 0 && mapConfig.starthealth < pPlayer->pev->max_health)
pPlayer->pev->health = mapConfig.starthealth;
pPlayer->SetArmor(mapConfig.startarmor);
if (mapConfig.starthealth > 0)
pPlayer->SetHealth(mapConfig.starthealth);

if (mapConfig.longjump)
{
Expand Down
4 changes: 2 additions & 2 deletions dlls/h_battery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ void CRechargeDecay::Use(CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE
CBasePlayer* pPlayer = static_cast<CBasePlayer*>(pCaller);

// if the player doesn't have the suit, or there is no juice left, make the deny noise
if( ( m_iJuice <= 0 ) || ( !pPlayer->HasSuit() ) || pPlayer->pev->armorvalue >= MAX_NORMAL_BATTERY )
if( ( m_iJuice <= 0 ) || ( !pPlayer->HasSuit() ) || pPlayer->pev->armorvalue >= pPlayer->MaxArmor() )
{
if( m_flSoundTime <= gpGlobals->time )
{
Expand Down Expand Up @@ -375,7 +375,7 @@ void CRechargeDecay::Use(CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE
}

// charge the player
if( pPlayer->pev->armorvalue < MAX_NORMAL_BATTERY )
if( pPlayer->pev->armorvalue < pPlayer->MaxArmor() )
{
if (m_triggerOnFirstUse)
{
Expand Down
6 changes: 3 additions & 3 deletions dlls/islave.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -220,10 +220,10 @@ void CChargeToken::Precache()

void CChargeToken::ArmorPieceTouch(CBaseEntity *pOther)
{
if (pOther->IsPlayer() && (static_cast<CBasePlayer*>(pOther))->HasSuit())
CBasePlayer* pPlayer = pOther->IsPlayer() ? static_cast<CBasePlayer*>(pOther) : nullptr;
if (pPlayer && pPlayer->HasSuit())
{
pOther->pev->armorvalue += pev->health;
pOther->pev->armorvalue = Q_min(pOther->pev->armorvalue, MAX_NORMAL_BATTERY);
pPlayer->TakeArmor(this, pev->health);
EMIT_SOUND_DYN( ENT( pOther->pev ), CHAN_ITEM, "items/suitchargeok1.wav", 1, ATTN_NORM, 0, 150 );
SetTouch(NULL);
SetThink(&CBaseEntity::SUB_Remove);
Expand Down
4 changes: 2 additions & 2 deletions dlls/items.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -587,7 +587,7 @@ class CItemBattery : public CItem
return FALSE;
}

if( ( pPlayer->pev->armorvalue < MAX_NORMAL_BATTERY ) && pPlayer->HasSuit() )
if( ( pPlayer->pev->armorvalue < pPlayer->MaxArmor() ) && pPlayer->HasSuit() )
{
pPlayer->TakeArmor(this, pev->health > 0 ? pev->health : DefaultCapacity());

Expand All @@ -603,7 +603,7 @@ class CItemBattery : public CItem
char szcharge[64];
// Suit reports new power level
// For some reason this wasn't working in release build -- round it.
pct = (int)( (float)( pPlayer->pev->armorvalue * 100.0f ) * ( 1.0f / MAX_NORMAL_BATTERY ) + 0.5f );
pct = (int)( (float)( pPlayer->pev->armorvalue * 100.0f ) * ( 1.0f / 100 ) + 0.5f );
pct = ( pct / 5 );
if( pct > 0 )
pct--;
Expand Down
9 changes: 9 additions & 0 deletions dlls/mapconfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ PickupEnt::PickupEnt(): entName(0), count(0) {}
MapConfig::MapConfig() :
pickupEntCount(0), ammoCount(0), cvarCount(0),
starthealth(0), startarmor(0),
maxhealth(0), maxarmor(0),
nomedkit(false), nosuit(false),
suitLogon(SuitNoLogon), suit_light(SUIT_LIGHT_DEFAULT), longjump(false),
valid(false)
Expand Down Expand Up @@ -135,6 +136,14 @@ bool ReadMapConfigFromText(MapConfig& mapConfig, byte* pMemFile, int fileSize)
{
mapConfig.starthealth = atoi(value);
}
else if (strcmp(key, "maxhealth") == 0)
{
mapConfig.maxhealth = atoi(value);
}
else if (strcmp(key, "maxarmor") == 0)
{
mapConfig.maxarmor = atoi(value);
}
else if (strncmp(key, "sv_", 3) == 0 || strncmp(key, "mp_", 3) == 0 || strncmp(key, "npc_", 4) == 0)
{
if (mapConfig.cvarCount < 32)
Expand Down
2 changes: 2 additions & 0 deletions dlls/mapconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ struct MapConfig

int starthealth;
int startarmor;
int maxhealth;
int maxarmor;

bool nomedkit; // for co-op

Expand Down
35 changes: 31 additions & 4 deletions dlls/maprules.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -965,6 +965,8 @@ class CGamePlayerSettings : public CRulePointEntity
int m_ammoCounts[MAX_AMMO_TYPES];
short m_suitLogon;
short m_suitLight;
BOOL m_allowOverheal;
BOOL m_allowOvercharge;
};

LINK_ENTITY_TO_CLASS( game_player_settings, CGamePlayerSettings )
Expand All @@ -974,6 +976,8 @@ TYPEDESCRIPTION CGamePlayerSettings::m_SaveData[] =
DEFINE_ARRAY( CGamePlayerSettings, m_ammoCounts, FIELD_INTEGER, MAX_AMMO_TYPES ),
DEFINE_FIELD( CGamePlayerSettings, m_suitLogon, FIELD_SHORT ),
DEFINE_FIELD( CGamePlayerSettings, m_suitLight, FIELD_SHORT ),
DEFINE_FIELD( CGamePlayerSettings, m_allowOverheal, FIELD_BOOLEAN ),
DEFINE_FIELD( CGamePlayerSettings, m_allowOvercharge, FIELD_BOOLEAN ),
};

IMPLEMENT_SAVERESTORE( CGamePlayerSettings, CRulePointEntity )
Expand Down Expand Up @@ -1002,6 +1006,21 @@ void CGamePlayerSettings::KeyValue(KeyValueData *pkvd)
m_suitLight = atoi(pkvd->szValue);
pkvd->fHandled = TRUE;
}
else if (FStrEq(pkvd->szKeyName, "max_armor"))
{
pev->armortype = atoi(pkvd->szValue);
pkvd->fHandled = TRUE;
}
else if (FStrEq(pkvd->szKeyName, "allow_overheal"))
{
m_allowOverheal = atoi(pkvd->szValue) != 0;
pkvd->fHandled = TRUE;
}
else if (FStrEq(pkvd->szKeyName, "allow_overcharge"))
{
m_allowOvercharge = atoi(pkvd->szValue) != 0;
pkvd->fHandled = TRUE;
}
else
CRulePointEntity::KeyValue(pkvd);
}
Expand All @@ -1013,13 +1032,21 @@ void CGamePlayerSettings::EquipPlayer(CBaseEntity *pPlayer)

CBasePlayer* player = (CBasePlayer*)pPlayer;

if (pev->health > 0 && pev->health <= player->pev->max_health)
if (pev->max_health > 0)
{
player->SetMaxHealth(pev->max_health, !m_allowOverheal);
}
if (pev->armortype > 0)
{
player->SetMaxArmor(pev->armortype, !m_allowOvercharge);
}
if (pev->health > 0)
{
player->pev->health = (int)pev->health;
player->SetHealth((int)pev->health, m_allowOverheal);
}
if (pev->armorvalue > 0 && pev->armorvalue <= MAX_NORMAL_BATTERY)
if (pev->armorvalue > 0)
{
player->pev->armorvalue = (int)pev->armorvalue;
player->SetArmor((int)pev->armorvalue, m_allowOvercharge);
}

if (pev->spawnflags & SF_PLAYER_SETTINGS_SUIT)
Expand Down
2 changes: 1 addition & 1 deletion dlls/multiplay_gamerules.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2127,7 +2127,7 @@ void CMultiplayBusters::PlayerGotWeapon( CBasePlayer *pPlayer, CBasePlayerWeapon
UTIL_ClientPrintAll( HUD_PRINTTALK, UTIL_VarArgs( "%s is busting!\n", STRING( pPlayer->pev->netname )));
SetPlayerModel( pPlayer, TRUE );
pPlayer->pev->health = pPlayer->pev->max_health;
pPlayer->pev->armorvalue = MAX_NORMAL_BATTERY;
pPlayer->pev->armorvalue = pPlayer->MaxArmor();
pPlayer->pev->renderfx = kRenderFxGlowShell;
pPlayer->pev->renderamt = 25;
pPlayer->pev->rendercolor = Vector( 0, 75, 250 );
Expand Down
Loading

0 comments on commit 5b424cc

Please sign in to comment.