Skip to content

Commit

Permalink
add 556 ammo
Browse files Browse the repository at this point in the history
for custom map weapons and op4 weapons in the distant future. Also adjust how ammo counter is displayed when exceeding the max the client can see.
  • Loading branch information
wootguy committed Jan 5, 2025
1 parent 7a44991 commit 2506246
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 4 deletions.
1 change: 1 addition & 0 deletions dlls/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,7 @@ set(AMMO_HDR
)
set(AMMO_SRC
weapon/CBasePlayerAmmo.cpp
weapon/CAmmo556.cpp
weapon/CCrossbowAmmo.cpp
weapon/CGaussAmmo.cpp
weapon/CGlockAmmo.cpp
Expand Down
1 change: 1 addition & 0 deletions dlls/game/skill.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ skill_cvar_t skill_cvars[] = {
DECL_SKILL_CVAR(sk_ammo_max_argrenades, CVAR_TYPE_ITEM),
DECL_SKILL_CVAR(sk_ammo_max_spores, CVAR_TYPE_ITEM),
DECL_SKILL_CVAR(sk_ammo_max_medkit, CVAR_TYPE_ITEM),
DECL_SKILL_CVAR(sk_ammo_max_556, CVAR_TYPE_ITEM),

// World weapons
DECL_SKILL_CVAR(sk_12mm_bullet, CVAR_TYPE_DAMAGE),
Expand Down
1 change: 1 addition & 0 deletions dlls/game/skill.h
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ struct skilldata_t
float sk_ammo_max_argrenades;
float sk_ammo_max_spores;
float sk_ammo_max_medkit;
float sk_ammo_max_556;

// World weapons
float sk_12mm_bullet;
Expand Down
10 changes: 9 additions & 1 deletion dlls/player/CBasePlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4435,10 +4435,18 @@ void CBasePlayer::SendAmmoUpdate(void)
ASSERT( m_rgAmmo[i] >= 0 );
ASSERT( m_rgAmmo[i] < 255 );

uint8_t ammoVal = m_rgAmmo[i];

// can't update max ammo counter without a client update
// this will at least show the client that ammo is being spent
if (m_rgAmmo[i] > 255) {
ammoVal = 250 + (m_rgAmmo[i] % 6);
}

// send "Ammo" update message
MESSAGE_BEGIN( MSG_ONE, gmsgAmmoX, NULL, pev );
WRITE_BYTE( i );
WRITE_BYTE( V_max( V_min( m_rgAmmo[i], 254 ), 0 ) ); // clamp the value to one byte
WRITE_BYTE(ammoVal);
MESSAGE_END();
}
}
Expand Down
30 changes: 30 additions & 0 deletions dlls/weapon/CAmmo556.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#include "CBasePlayerAmmo.h"
#include "skill.h"

class CAmmo556 : public CBasePlayerAmmo
{
void Spawn( void )
{
Precache( );
//SET_MODEL_MERGED(ENT(pev), "models/w_saw_clip.mdl", MERGE_MDL_W_CHAINAMMO);
SET_MODEL(ENT(pev), "models/w_saw_clip.mdl");
CBasePlayerAmmo::Spawn( );
}
void Precache( void )
{
//PRECACHE_REPLACEMENT_MODEL("models/w_saw_clip.mdl");
PRECACHE_MODEL ("models/w_saw_clip.mdl");
PRECACHE_SOUND("items/9mmclip1.wav");
}
BOOL AddAmmo( CBaseEntity *pOther )
{
int bResult = (pOther->GiveAmmo(AMMO_556_GIVE, "556", gSkillData.sk_ammo_max_556) != -1);
if (bResult)
{
EMIT_SOUND(ENT(pev), CHAN_ITEM, "items/9mmclip1.wav", 1, ATTN_NORM);
}
return bResult;
}
};

LINK_ENTITY_TO_CLASS( ammo_556, CAmmo556)
3 changes: 1 addition & 2 deletions dlls/weapon/CMP5AmmoBox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,4 @@ class CMP5AmmoBox : public CBasePlayerAmmo
}
};

LINK_ENTITY_TO_CLASS( ammo_9mmbox, CMP5AmmoBox)
LINK_ENTITY_TO_CLASS( ammo_556, CMP5AmmoBox)
LINK_ENTITY_TO_CLASS( ammo_9mmbox, CMP5AmmoBox)
1 change: 1 addition & 0 deletions dlls/weapon/ammo.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#define AMMO_357BOX_GIVE PYTHON_MAX_CLIP
#define AMMO_MP5CLIP_GIVE MP5_MAX_CLIP
#define AMMO_CHAINBOX_GIVE 200
#define AMMO_556_GIVE 50
#define AMMO_M203BOX_GIVE 2
#define AMMO_BUCKSHOTBOX_GIVE 12
#define AMMO_CROSSBOWCLIP_GIVE CROSSBOW_MAX_CLIP
Expand Down
2 changes: 1 addition & 1 deletion sevenkewp

0 comments on commit 2506246

Please sign in to comment.