Skip to content

Commit

Permalink
Add support for adding 64 weapons
Browse files Browse the repository at this point in the history
Resolves #98
  • Loading branch information
SamVanheer committed Dec 2, 2021
1 parent ffe7362 commit c633af8
Show file tree
Hide file tree
Showing 23 changed files with 135 additions and 34 deletions.
8 changes: 4 additions & 4 deletions cl_dll/ammo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ void CHudAmmo::Think()

if (p && WEAPON_NONE != p->iId)
{
if ((gHUD.m_iWeaponBits & (1 << p->iId)) != 0)
if (gHUD.HasWeapon(p->iId))
gWR.PickupWeapon(p);
else
gWR.DropWeapon(p);
Expand Down Expand Up @@ -424,10 +424,10 @@ void WeaponsResource::SelectSlot(int iSlot, bool fAdvance, int iDirection)
if (gHUD.m_fPlayerDead || (gHUD.m_iHideHUDDisplay & (HIDEHUD_WEAPONS | HIDEHUD_ALL)) != 0)
return;

if ((gHUD.m_iWeaponBits & (1 << (WEAPON_SUIT))) == 0)
if (!gHUD.HasSuit())
return;

if ((gHUD.m_iWeaponBits & ~(1 << (WEAPON_SUIT))) == 0)
if (!gHUD.HasAnyWeapons())
return;

WEAPON* p = NULL;
Expand Down Expand Up @@ -829,7 +829,7 @@ bool CHudAmmo::Draw(float flTime)
int a, x, y, r, g, b;
int AmmoWidth;

if ((gHUD.m_iWeaponBits & (1 << (WEAPON_SUIT))) == 0)
if (!gHUD.HasSuit())
return true;

if ((gHUD.m_iHideHUDDisplay & (HIDEHUD_WEAPONS | HIDEHUD_ALL)) != 0)
Expand Down
2 changes: 1 addition & 1 deletion cl_dll/ammohistory.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class WeaponsResource
}

///// WEAPON /////
int iOldWeaponBits;
std::uint64_t iOldWeaponBits;

WEAPON* GetWeapon(int iId) { return &rgWeapons[iId]; }
void AddWeapon(WEAPON* wp)
Expand Down
2 changes: 1 addition & 1 deletion cl_dll/battery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ bool CHudBattery::Draw(float flTime)

UnpackRGB(r, g, b, RGB_YELLOWISH);

if ((gHUD.m_iWeaponBits & (1 << (WEAPON_SUIT))) == 0)
if (!gHUD.HasSuit())
return true;

// Has health changed? Flash the health #
Expand Down
2 changes: 1 addition & 1 deletion cl_dll/flashlight.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ bool CHudFlashlight::Draw(float flTime)
int r, g, b, x, y, a;
Rect rc;

if ((gHUD.m_iWeaponBits & (1 << (WEAPON_SUIT))) == 0)
if (!gHUD.HasSuit())
return true;

if (m_fOn)
Expand Down
2 changes: 1 addition & 1 deletion cl_dll/health.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ bool CHudHealth::Draw(float flTime)
ScaleColors(r, g, b, a);

// Only draw health if we have the suit.
if ((gHUD.m_iWeaponBits & (1 << (WEAPON_SUIT))) != 0)
if (gHUD.HasSuit())
{
HealthWidth = gHUD.GetSpriteRect(gHUD.m_HUD_number_0).right - gHUD.GetSpriteRect(gHUD.m_HUD_number_0).left;
int CrossWidth = gHUD.GetSpriteRect(m_HUD_cross).right - gHUD.GetSpriteRect(m_HUD_cross).left;
Expand Down
6 changes: 6 additions & 0 deletions cl_dll/hud.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,11 @@ int __MsgFunc_Concuss(const char* pszName, int iSize, void* pbuf)
return static_cast<int>(gHUD.MsgFunc_Concuss(pszName, iSize, pbuf));
}

int __MsgFunc_Weapons(const char* pszName, int iSize, void* pbuf)
{
return static_cast<int>(gHUD.MsgFunc_Weapons(pszName, iSize, pbuf));
}

int __MsgFunc_GameMode(const char* pszName, int iSize, void* pbuf)
{
return static_cast<int>(gHUD.MsgFunc_GameMode(pszName, iSize, pbuf));
Expand Down Expand Up @@ -284,6 +289,7 @@ void CHud::Init()
HOOK_MESSAGE(ViewMode);
HOOK_MESSAGE(SetFOV);
HOOK_MESSAGE(Concuss);
HOOK_MESSAGE(Weapons);

// TFFree CommandMenu
HOOK_COMMAND("+commandmenu", OpenCommandMenu);
Expand Down
18 changes: 17 additions & 1 deletion cl_dll/hud.h
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,21 @@ class CHud
int GetHudNumberWidth(int number, int width, int flags);
int DrawHudNumberReverse(int x, int y, int number, int flags, int r, int g, int b);

bool HasWeapon(int id) const
{
return (m_iWeaponBits & (1ULL << id)) != 0;
}

bool HasSuit() const
{
return HasWeapon(WEAPON_SUIT);
}

bool HasAnyWeapons() const
{
return (m_iWeaponBits & ~static_cast<std::uint64_t>(WEAPON_SUIT)) != 0;
}

private:
// the memory for these arrays are allocated in the first call to CHud::VidInit(), when the hud.txt and associated sprites are loaded.
// freed in ~CHud()
Expand Down Expand Up @@ -574,11 +589,12 @@ class CHud
void MsgFunc_ViewMode(const char* pszName, int iSize, void* pbuf);
bool MsgFunc_SetFOV(const char* pszName, int iSize, void* pbuf);
bool MsgFunc_Concuss(const char* pszName, int iSize, void* pbuf);
bool MsgFunc_Weapons(const char* pszName, int iSize, void* pbuf);

// Screen information
SCREENINFO m_scrinfo;

int m_iWeaponBits;
std::uint64_t m_iWeaponBits;
bool m_fPlayerDead;
bool m_iIntermission;

Expand Down
15 changes: 15 additions & 0 deletions cl_dll/hud_msg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ bool CHud::MsgFunc_ResetHUD(const char* pszName, int iSize, void* pbuf)
pList = pList->pNext;
}

//Reset weapon bits.
m_iWeaponBits = 0ULL;

// reset sensitivity
m_flMouseSensitivity = 0;

Expand Down Expand Up @@ -146,3 +149,15 @@ bool CHud::MsgFunc_Concuss(const char* pszName, int iSize, void* pbuf)
this->m_StatusIcons.DisableIcon("dmg_concuss");
return true;
}

bool CHud::MsgFunc_Weapons(const char* pszName, int iSize, void* pbuf)
{
BEGIN_READ(pbuf, iSize);

const std::uint64_t lowerBits = READ_LONG();
const std::uint64_t upperBits = READ_LONG();

m_iWeaponBits = lowerBits | (upperBits << 32ULL);

return true;
}
3 changes: 2 additions & 1 deletion cl_dll/hud_update.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ bool CHud::UpdateClientData(client_data_t* cdata, float time)
memcpy(m_vecAngles, cdata->viewangles, sizeof(Vector));

m_iKeyBits = CL_ButtonBits(false);
m_iWeaponBits = cdata->iWeaponBits;
//Handled in MsgFunc_Weapons now.
//m_iWeaponBits = cdata->iWeaponBits;

in_fov = cdata->fov;

Expand Down
2 changes: 2 additions & 0 deletions dlls/UserMessages.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,6 @@ void LinkUserMessages()

gmsgStatusText = REG_USER_MSG("StatusText", -1);
gmsgStatusValue = REG_USER_MSG("StatusValue", 3);

gmsgWeapons = REG_USER_MSG("Weapons", 8);
}
2 changes: 2 additions & 0 deletions dlls/UserMessages.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,6 @@ inline int gmsgTeamNames = 0;
inline int gmsgStatusText = 0;
inline int gmsgStatusValue = 0;

inline int gmsgWeapons = 0;

void LinkUserMessages();
7 changes: 6 additions & 1 deletion dlls/h_battery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "util.h"
#include "cbase.h"
#include "saverestore.h"
#include "player.h"
#include "skill.h"
#include "gamerules.h"

Expand Down Expand Up @@ -110,6 +111,8 @@ void CRecharge::Use(CBaseEntity* pActivator, CBaseEntity* pCaller, USE_TYPE useT
if (!FClassnameIs(pActivator->pev, "player"))
return;

auto player = static_cast<CBasePlayer*>(pActivator);

// if there is no juice left, turn it off
if (m_iJuice <= 0)
{
Expand All @@ -118,7 +121,7 @@ void CRecharge::Use(CBaseEntity* pActivator, CBaseEntity* pCaller, USE_TYPE useT
}

// if the player doesn't have the suit, or there is no juice left, make the deny noise
if ((m_iJuice <= 0) || (pActivator->pev->weapons & (1 << WEAPON_SUIT)) == 0)
if ((m_iJuice <= 0) || !player->HasSuit())
{
if (m_flSoundTime <= gpGlobals->time)
{
Expand All @@ -137,13 +140,15 @@ void CRecharge::Use(CBaseEntity* pActivator, CBaseEntity* pCaller, USE_TYPE useT
return;

// Make sure that we have a caller
//TODO: useless, it's accessed earlier on.
if (!pActivator)
return;

m_hActivator = pActivator;

//only recharge the player

//TODO: put this check at the top.
if (!m_hActivator->IsPlayer())
return;

Expand Down
2 changes: 1 addition & 1 deletion dlls/handgrenade.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ void CHandGrenade::Holster()
else
{
// no more grenades!
m_pPlayer->pev->weapons &= ~(1 << WEAPON_HANDGRENADE);
m_pPlayer->ClearWeaponBit(m_iId);
SetThink(&CHandGrenade::DestroyItem);
pev->nextthink = gpGlobals->time + 0.1;
}
Expand Down
6 changes: 4 additions & 2 deletions dlls/healthkit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,8 @@ void CWallHealth::Use(CBaseEntity* pActivator, CBaseEntity* pCaller, USE_TYPE us
if (!pActivator->IsPlayer())
return;

auto player = static_cast<CBasePlayer*>(pActivator);

// if there is no juice left, turn it off
if (m_iJuice <= 0)
{
Expand All @@ -193,7 +195,7 @@ void CWallHealth::Use(CBaseEntity* pActivator, CBaseEntity* pCaller, USE_TYPE us
}

// if the player doesn't have the suit, or there is no juice left, make the deny noise
if ((m_iJuice <= 0) || (pActivator->pev->weapons & (1 << WEAPON_SUIT)) == 0)
if ((m_iJuice <= 0) || !player->HasSuit())
{
if (m_flSoundTime <= gpGlobals->time)
{
Expand Down Expand Up @@ -226,7 +228,7 @@ void CWallHealth::Use(CBaseEntity* pActivator, CBaseEntity* pCaller, USE_TYPE us


// charge the player
if (pActivator->TakeHealth(1, DMG_GENERIC))
if (player->TakeHealth(1, DMG_GENERIC))
{
m_iJuice--;
}
Expand Down
8 changes: 4 additions & 4 deletions dlls/items.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,15 +182,15 @@ class CItemSuit : public CItem
}
bool MyTouch(CBasePlayer* pPlayer) override
{
if ((pPlayer->pev->weapons & (1 << WEAPON_SUIT)) != 0)
if (pPlayer->HasSuit())
return false;

if ((pev->spawnflags & SF_SUIT_SHORTLOGON) != 0)
EMIT_SOUND_SUIT(pPlayer->edict(), "!HEV_A0"); // short version of suit logon,
else
EMIT_SOUND_SUIT(pPlayer->edict(), "!HEV_AAx"); // long version of suit logon

pPlayer->pev->weapons |= (1 << WEAPON_SUIT);
pPlayer->SetHasSuit(true);
return true;
}
};
Expand Down Expand Up @@ -220,7 +220,7 @@ class CItemBattery : public CItem
}

if ((pPlayer->pev->armorvalue < MAX_NORMAL_BATTERY) &&
(pPlayer->pev->weapons & (1 << WEAPON_SUIT)) != 0)
pPlayer->HasSuit())
{
int pct;
char szcharge[64];
Expand Down Expand Up @@ -319,7 +319,7 @@ class CItemLongJump : public CItem
return false;
}

if ((pPlayer->pev->weapons & (1 << WEAPON_SUIT)) != 0)
if (pPlayer->HasSuit())
{
pPlayer->m_fLongJump = true; // player now has longjump module

Expand Down
2 changes: 1 addition & 1 deletion dlls/multiplay_gamerules.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,7 @@ void CHalfLifeMultiplay::PlayerSpawn(CBasePlayer* pPlayer)
const int originalAutoWepSwitch = pPlayer->m_iAutoWepSwitch;
pPlayer->m_iAutoWepSwitch = 1;

pPlayer->pev->weapons |= (1 << WEAPON_SUIT);
pPlayer->SetHasSuit(true);

addDefault = true;

Expand Down
32 changes: 23 additions & 9 deletions dlls/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ TYPEDESCRIPTION CBasePlayer::m_playerSaveData[] =
DEFINE_ARRAY(CBasePlayer, m_rgpPlayerItems, FIELD_CLASSPTR, MAX_ITEM_TYPES),
DEFINE_FIELD(CBasePlayer, m_pActiveItem, FIELD_CLASSPTR),
DEFINE_FIELD(CBasePlayer, m_pLastItem, FIELD_CLASSPTR),
DEFINE_FIELD(CBasePlayer, m_WeaponBits, FIELD_INT64),

DEFINE_ARRAY(CBasePlayer, m_rgAmmo, FIELD_INTEGER, MAX_AMMO_SLOTS),
DEFINE_FIELD(CBasePlayer, m_idrowndmg, FIELD_INTEGER),
Expand Down Expand Up @@ -738,10 +739,10 @@ void CBasePlayer::RemoveAllItems(bool removeSuit)
pev->viewmodel = 0;
pev->weaponmodel = 0;

if (removeSuit)
pev->weapons = 0;
else
pev->weapons &= ~WEAPON_ALLWEAPONS;
m_WeaponBits = 0ULL;

//Re-add suit bit if needed.
SetHasSuit(!removeSuit);

for (i = 0; i < MAX_AMMO_SLOTS; i++)
m_rgAmmo[i] = 0;
Expand Down Expand Up @@ -2185,7 +2186,7 @@ void CBasePlayer::CheckSuitUpdate()
int isearch = m_iSuitPlayNext;

// Ignore suit updates if no suit
if ((pev->weapons & (1 << WEAPON_SUIT)) == 0)
if (!HasSuit())
return;

// if in range of radiation source, ping geiger counter
Expand Down Expand Up @@ -2249,7 +2250,7 @@ void CBasePlayer::SetSuitUpdate(const char* name, bool fgroup, int iNoRepeatTime


// Ignore suit updates if no suit
if ((pev->weapons & (1 << WEAPON_SUIT)) == 0)
if (!HasSuit())
return;

if (g_pGameRules->IsMultiplayer())
Expand Down Expand Up @@ -3234,7 +3235,7 @@ void CBasePlayer::FlashlightTurnOn()
return;
}

if ((pev->weapons & (1 << WEAPON_SUIT)) != 0)
if (HasSuit())
{
EMIT_SOUND_DYN(ENT(pev), CHAN_WEAPON, SOUND_FLASHLIGHT_ON, 1.0, ATTN_NORM, 0, PITCH_NORM);
SetBits(pev->effects, EF_DIMLIGHT);
Expand Down Expand Up @@ -3891,6 +3892,19 @@ void CBasePlayer::UpdateClientData()
MESSAGE_END();
}

if (m_WeaponBits != m_ClientWeaponBits)
{
m_ClientWeaponBits = m_WeaponBits;

const int lowerBits = m_WeaponBits & 0xFFFFFFFF;
const int upperBits = (m_WeaponBits >> 32) & 0xFFFFFFFF;

MESSAGE_BEGIN(MSG_ONE, gmsgWeapons, nullptr, pev);
WRITE_LONG(lowerBits);
WRITE_LONG(upperBits);
MESSAGE_END();
}

if (0 != pev->dmg_take || 0 != pev->dmg_save || m_bitsHUDDamage != m_bitsDamageType)
{
// Comes from inside me if not set
Expand Down Expand Up @@ -4028,7 +4042,7 @@ void CBasePlayer::UpdateClientData()
WRITE_BYTE(II.iMaxAmmo2); // byte Max Ammo 2
WRITE_BYTE(II.iSlot); // byte bucket
WRITE_BYTE(II.iPosition); // byte bucket pos
WRITE_BYTE(II.iId); // byte id (bit index into pev->weapons)
WRITE_BYTE(II.iId); // byte id (bit index into m_WeaponBits)
WRITE_BYTE(II.iFlags); // byte Flags
MESSAGE_END();
}
Expand Down Expand Up @@ -4452,7 +4466,7 @@ void CBasePlayer::DropPlayerItem(char* pszItemName)

UTIL_MakeVectors(pev->angles);

pev->weapons &= ~(1 << pWeapon->m_iId); // take item off hud
ClearWeaponBit(pWeapon->m_iId); // take item off hud

CWeaponBox* pWeaponBox = (CWeaponBox*)CBaseEntity::Create("weaponbox", pev->origin + gpGlobals->v_forward * 10, pev->angles, edict());
pWeaponBox->pev->angles.x = 0;
Expand Down
Loading

0 comments on commit c633af8

Please sign in to comment.