Skip to content

Commit

Permalink
Weapons Stay
Browse files Browse the repository at this point in the history
Use dmflags & 4
  • Loading branch information
themuffinator committed Jan 5, 2021
1 parent 3023780 commit 6b42bd5
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 15 deletions.
19 changes: 11 additions & 8 deletions 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, &cent->currentState, &cg.predictedPlayerState ) ) {
if ( !BG_CanItemBeGrabbed( cgs.gametype, cgs.dmflags, &cent->currentState, &cg.predictedPlayerState ) ) {
return; // can't hold it
}

Expand Down Expand Up @@ -526,15 +526,18 @@ static void CG_TouchItem( centity_t *cent ) {
// perform prediction
CG_PickupPrediction( cent, item );

// remove it from the frame so it won't be drawn
cent->currentState.eFlags |= EF_NODRAW;
// non-dropped weapons never removed during weapons stay mode
if ( !(item->giType == IT_WEAPON && cgs.dmflags & DF_WEAPONS_STAY && !(cent->currentState.modelindex2 == 1)) ) {
// remove it from the frame so it won't be drawn
cent->currentState.eFlags |= EF_NODRAW;

// don't touch it again this prediction
cent->miscTime = cg.time;
// don't touch it again this prediction
cent->miscTime = cg.time;

// delay next potential pickup for some time
cent->delaySpawn = cg.time + ( cg.meanPing > 0 ? cg.meanPing * 2 + 100 : 333 );
cent->delaySpawnPlayed = qfalse;
// delay next potential pickup for some time
cent->delaySpawn = cg.time + (cg.meanPing > 0 ? cg.meanPing * 2 + 100 : 333);
cent->delaySpawnPlayed = qfalse;
}

// if it's a weapon, give them some predicted ammo so the autoswitch will work
if ( item->giType == IT_WEAPON ) {
Expand Down
5 changes: 4 additions & 1 deletion code/game/bg_misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1016,7 +1016,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, const entityState_t *ent, const playerState_t *ps ) {
qboolean BG_CanItemBeGrabbed( int gametype, int dmFlags, const entityState_t *ent, const playerState_t *ps ) {
gitem_t *item;
#ifdef MISSIONPACK
int upperBound;
Expand All @@ -1030,6 +1030,9 @@ qboolean BG_CanItemBeGrabbed( int gametype, const entityState_t *ent, const play

switch( item->giType ) {
case IT_WEAPON:
if ( dmFlags & DF_WEAPONS_STAY ) {
if ( (ps->stats[STAT_WEAPONS] & (1 << item->giTag)) ) return qfalse;
}
return qtrue; // weapons are always picked up

case IT_AMMO:
Expand Down
10 changes: 6 additions & 4 deletions code/game/bg_public.h
Original file line number Diff line number Diff line change
Expand Up @@ -654,13 +654,15 @@ 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, const entityState_t *ent, const playerState_t *ps );
qboolean BG_CanItemBeGrabbed( int gametype, int dmFlags, const entityState_t *ent, const playerState_t *ps );


// g_dmflags->integer flags
#define DF_NO_FALLING 8
#define DF_FIXED_FOV 16
#define DF_NO_FOOTSTEPS 32
#define DF_WEAPONS_STAY 0x00000004
#define DF_NO_FALLING 0x00000008
#define DF_FIXED_FOV 0x00000010
#define DF_NO_FOOTSTEPS 0x00000020
#define DF_ALL (DF_WEAPONS_STAY|DF_NO_FALLING|DF_FIXED_FOV|DF_NO_FOOTSTEPS)

// content masks
#define MASK_ALL (-1)
Expand Down
17 changes: 15 additions & 2 deletions code/game/g_items.c
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ static int Pickup_Weapon( gentity_t *ent, gentity_t *other ) {
}

// dropped items and teamplay weapons always have full ammo
if ( ! (ent->flags & FL_DROPPED_ITEM) && g_gametype.integer != GT_TEAM ) {
if ( !(g_dmflags.integer & DF_WEAPONS_STAY) && ! (ent->flags & FL_DROPPED_ITEM) && g_gametype.integer != GT_TEAM ) {
// respawning rules
// drop the quantity if the already have over the minimum
if ( other->client->ps.ammo[ ent->item->giTag ] < quantity ) {
Expand Down 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, &ent->s, &other->client->ps ) ) {
if ( !BG_CanItemBeGrabbed( g_gametype.integer, g_dmflags.integer, &ent->s, &other->client->ps ) ) {
return;
}

Expand All @@ -492,6 +492,19 @@ void Touch_Item (gentity_t *ent, gentity_t *other, trace_t *trace) {
switch( ent->item->giType ) {
case IT_WEAPON:
respawn = Pickup_Weapon(ent, other);

// never 'pickup' weapons if weapons stay, only if weapon was dropped
if ( g_dmflags.integer & DF_WEAPONS_STAY ) {
if ( !(ent->flags & FL_DROPPED_ITEM) ) {
// play the normal pickup sound
if ( predict ) {
G_AddPredictableEvent( other, EV_ITEM_PICKUP, ent->s.modelindex );
} else {
G_AddEvent( other, EV_ITEM_PICKUP, ent->s.modelindex );
}
return;
}
}
break;
case IT_AMMO:
respawn = Pickup_Ammo(ent, other);
Expand Down

0 comments on commit 6b42bd5

Please sign in to comment.