Skip to content

Commit

Permalink
Weapon Carry Limit
Browse files Browse the repository at this point in the history
Use g_weaponCarryLimit <max carry>
-1 = no limit
Number includes the starting weapons, but if you put less than 2 you'll still spawn with your weapons.
  • Loading branch information
themuffinator committed Jan 5, 2021
1 parent 6b42bd5 commit 7dd197b
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 7 deletions.
4 changes: 3 additions & 1 deletion code/cgame/cg_local.h
Original file line number Diff line number Diff line change
Expand Up @@ -1103,7 +1103,9 @@ typedef struct {
int teamChatMsgTimes[TEAMCHAT_HEIGHT];
int teamChatPos;
int teamLastChatPos;

//levelup
int weaponCarryLimit;
//-levelup
#ifdef MISSIONPACK
int cursorX;
int cursorY;
Expand Down
2 changes: 1 addition & 1 deletion code/cgame/cg_predict.c
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ static void CG_TouchItem( centity_t *cent ) {
return;
}

if ( !BG_CanItemBeGrabbed( cgs.gametype, cgs.dmflags, &cent->currentState, &cg.predictedPlayerState ) ) {
if ( !BG_CanItemBeGrabbed( cgs.gametype, cgs.dmflags, cgs.weaponCarryLimit, &cent->currentState, &cg.predictedPlayerState ) ) {
return; // can't hold it
}

Expand Down
2 changes: 2 additions & 0 deletions code/cgame/cg_servercmds.c
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ void CG_ParseServerinfo( void ) {
Com_sprintf( cgs.mapname, sizeof( cgs.mapname ), "maps/%s.bsp", mapname );
Q_strncpyz( cgs.redTeam, Info_ValueForKey( info, "g_redTeam" ), sizeof(cgs.redTeam) );
Q_strncpyz( cgs.blueTeam, Info_ValueForKey( info, "g_blueTeam" ), sizeof(cgs.blueTeam) );

cgs.weaponCarryLimit = atoi( Info_ValueForKey( info, "g_weaponCarryLimit" ) );
}


Expand Down
22 changes: 21 additions & 1 deletion code/game/bg_misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1007,6 +1007,20 @@ qboolean BG_PlayerTouchesItem( playerState_t *ps, entityState_t *item, int atTim
}


/*
================
CountNumWeaponsHeld
================
*/
int CountNumWeaponsHeld( int weapBits, int ignoreNum ) {
int i, count = 0;

for ( i = 0; i < WP_NUM_WEAPONS; i++ ) {
if ( weapBits & (1 << i) && i != ignoreNum ) count++;
}
return count;
}


/*
================
Expand All @@ -1016,7 +1030,7 @@ Returns false if the item should not be picked up.
This needs to be the same for client side prediction and server use.
================
*/
qboolean BG_CanItemBeGrabbed( int gametype, int dmFlags, const entityState_t *ent, const playerState_t *ps ) {
qboolean BG_CanItemBeGrabbed( int gametype, int dmFlags, int weaponCarryLimit, const entityState_t *ent, const playerState_t *ps ) {
gitem_t *item;
#ifdef MISSIONPACK
int upperBound;
Expand All @@ -1030,9 +1044,15 @@ qboolean BG_CanItemBeGrabbed( int gametype, int dmFlags, const entityState_t *en

switch( item->giType ) {
case IT_WEAPON:
// can't pickup weapons already held in weapons stay mode
if ( dmFlags & DF_WEAPONS_STAY ) {
if ( (ps->stats[STAT_WEAPONS] & (1 << item->giTag)) ) return qfalse;
}
// can't hold more than carry limit (if set) unless you already carry the weapon
if ( weaponCarryLimit > -1 ) {
if ( ps->stats[STAT_WEAPONS] & (1 << item->giTag) ) return qtrue;
if ( (CountNumWeaponsHeld( ps->stats[STAT_WEAPONS], -1 ) >= weaponCarryLimit) ) return qfalse;
}
return qtrue; // weapons are always picked up

case IT_AMMO:
Expand Down
2 changes: 1 addition & 1 deletion code/game/bg_public.h
Original file line number Diff line number Diff line change
Expand Up @@ -654,7 +654,7 @@ gitem_t *BG_FindItemForPowerup( powerup_t pw );
gitem_t *BG_FindItemForHoldable( holdable_t pw );
#define ITEM_INDEX(x) ((x)-bg_itemlist)

qboolean BG_CanItemBeGrabbed( int gametype, int dmFlags, const entityState_t *ent, const playerState_t *ps );
qboolean BG_CanItemBeGrabbed( int gametype, int dmFlags, int weaponCarryLimit, const entityState_t *ent, const playerState_t *ps );


// g_dmflags->integer flags
Expand Down
2 changes: 1 addition & 1 deletion code/game/g_items.c
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ void Touch_Item (gentity_t *ent, gentity_t *other, trace_t *trace) {
return; // dead people can't pickup

// the same pickup rules are used for client side and server side
if ( !BG_CanItemBeGrabbed( g_gametype.integer, g_dmflags.integer, &ent->s, &other->client->ps ) ) {
if ( !BG_CanItemBeGrabbed( g_gametype.integer, g_dmflags.integer, g_weaponCarryLimit.integer, &ent->s, &other->client->ps ) ) {
return;
}

Expand Down
5 changes: 4 additions & 1 deletion code/game/g_local.h
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,7 @@ void G_AddEvent( gentity_t *ent, int event, int eventParm );
void G_SetOrigin( gentity_t *ent, vec3_t origin );
void AddRemap(const char *oldShader, const char *newShader, float timeOffset);
const char *BuildShaderStateConfig( void );
int CountNumWeaponsHeld( int weapBits, int ignoreNum );

//
// g_combat.c
Expand Down Expand Up @@ -808,7 +809,9 @@ extern vmCvar_t g_enableDust;
extern vmCvar_t g_enableBreath;
extern vmCvar_t g_singlePlayer;
extern vmCvar_t g_proxMineTimeout;

//levelup
extern vmCvar_t g_weaponCarryLimit;
//-levelup
void trap_Print( const char *text );
void trap_Error( const char *text );
int trap_Milliseconds( void );
Expand Down
7 changes: 6 additions & 1 deletion code/game/g_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ vmCvar_t g_unlagged;
vmCvar_t pmove_fixed;
vmCvar_t pmove_msec;
vmCvar_t g_listEntity;
//levelup
vmCvar_t g_weaponCarryLimit;
//-levelup
#ifdef MISSIONPACK
vmCvar_t g_obeliskHealth;
vmCvar_t g_obeliskRegenPeriod;
Expand Down Expand Up @@ -144,7 +147,9 @@ static cvarTable_t gameCvarTable[] = {

{ &g_unlagged, "g_unlagged", "1", CVAR_SERVERINFO | CVAR_ARCHIVE, 0, qfalse },
{ &g_predictPVS, "g_predictPVS", "0", CVAR_ARCHIVE, 0, qfalse },

//levelup
{ &g_weaponCarryLimit, "g_weaponCarryLimit", "-1", CVAR_SERVERINFO, 0, qtrue },
//-levelup
#ifdef MISSIONPACK
{ &g_obeliskHealth, "g_obeliskHealth", "2500", 0, 0, qfalse },
{ &g_obeliskRegenPeriod, "g_obeliskRegenPeriod", "1", 0, 0, qfalse },
Expand Down

0 comments on commit 7dd197b

Please sign in to comment.