Skip to content

Commit

Permalink
Starting Weapons
Browse files Browse the repository at this point in the history
g_startingWeapons <bitmask>
Sets weapon set players spawn with. Negative values add all available weapons in the map.
  • Loading branch information
themuffinator committed Jan 5, 2021
1 parent 7dd197b commit 81dc7d7
Show file tree
Hide file tree
Showing 11 changed files with 65 additions and 25 deletions.
4 changes: 2 additions & 2 deletions code/cgame/cg_draw.c
Original file line number Diff line number Diff line change
Expand Up @@ -637,9 +637,9 @@ static void CG_DrawStatusBar( void ) {
//
// ammo
//
if ( cent->currentState.weapon ) {
if ( cent->currentState.weapon > 0 ) {
value = ps->ammo[cent->currentState.weapon];
if ( value > -1 ) {
if ( value > -1 && cg.predictedPlayerState.weapon > 0 ) {
if ( cg.predictedPlayerState.weaponstate == WEAPON_FIRING
&& cg.predictedPlayerState.weaponTime > 100 ) {
// draw as dark grey when reloading
Expand Down
5 changes: 5 additions & 0 deletions code/cgame/cg_playerstate.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ void CG_CheckAmmo( void ) {

// see about how many seconds of ammo we have remaining
weapons = cg.snap->ps.stats[ STAT_WEAPONS ];

if ( !weapons ) {
cg.lowAmmoWarning = 0;
return;
}
total = 0;
for ( i = WP_MACHINEGUN ; i < WP_NUM_WEAPONS ; i++ ) {
if ( ! ( weapons & ( 1 << i ) ) ) {
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 @@ -326,7 +326,7 @@ static void CG_AddAmmo( int weapon, int count )
cg.predictedPlayerState.ammo[weapon] = -1;
} else {
cg.predictedPlayerState.ammo[weapon] += count;
if ( weapon >= WP_MACHINEGUN && weapon <= WP_BFG ) {
if ( weapon >= WP_MACHINEGUN && weapon < WP_GRAPPLING_HOOK ) {
if ( cg.predictedPlayerState.ammo[weapon] > AMMO_HARD_LIMIT ) {
cg.predictedPlayerState.ammo[weapon] = AMMO_HARD_LIMIT;
}
Expand Down
6 changes: 6 additions & 0 deletions code/cgame/cg_weapons.c
Original file line number Diff line number Diff line change
Expand Up @@ -1261,6 +1261,8 @@ void CG_AddPlayerWeapon( refEntity_t *parent, playerState_t *ps, centity_t *cent
ci = &cgs.clientinfo[ cent->currentState.clientNum ];
weaponNum = cent->currentState.weapon;

if ( weaponNum == WP_NONE ) return;

CG_RegisterWeapon( weaponNum );
weapon = &cg_weapons[weaponNum];

Expand Down Expand Up @@ -1477,6 +1479,8 @@ void CG_AddViewWeapon( playerState_t *ps ) {
fovOffset[2] = 0;
}

if ( ps->weapon == WP_NONE ) return;

cent = &cg.predictedPlayerEntity; // &cg_entities[cg.snap->ps.clientNum];
CG_RegisterWeapon( ps->weapon );
weapon = &cg_weapons[ ps->weapon ];
Expand Down Expand Up @@ -1567,6 +1571,8 @@ void CG_DrawWeaponSelect( void ) {
}
}

if ( !count ) return;

if ( weaponSelect < 3 ) {
x = 320 - count * 20;
y = cgs.screenYmax + 1 - 100; // - STATUSBAR_HEIGHT - 40
Expand Down
2 changes: 1 addition & 1 deletion code/game/ai_dmq3.c
Original file line number Diff line number Diff line change
Expand Up @@ -3673,7 +3673,7 @@ void BotCheckAttack(bot_state_t *bs) {
}

weapon = bs->cur_ps.weapon;
if ( weapon >= WP_MACHINEGUN && weapon <= WP_BFG && !bs->cur_ps.ammo[ weapon ] ) {
if ( weapon >= WP_MACHINEGUN && weapon < WP_GRAPPLING_HOOK && !bs->cur_ps.ammo[ weapon ] ) {
return;
}

Expand Down
10 changes: 5 additions & 5 deletions code/game/bg_pmove.c
Original file line number Diff line number Diff line change
Expand Up @@ -1462,7 +1462,7 @@ PM_BeginWeaponChange
===============
*/
static void PM_BeginWeaponChange( int weapon ) {
if ( weapon <= WP_NONE || weapon >= WP_NUM_WEAPONS ) {
if ( weapon < WP_NONE || weapon >= WP_NUM_WEAPONS ) {
return;
}

Expand Down Expand Up @@ -1515,7 +1515,7 @@ PM_TorsoAnimation
*/
static void PM_TorsoAnimation( void ) {
if ( pm->ps->weaponstate == WEAPON_READY ) {
if ( pm->ps->weapon == WP_GAUNTLET ) {
if ( pm->ps->weapon == WP_NONE || pm->ps->weapon == WP_GAUNTLET ) {
PM_ContinueTorsoAnim( TORSO_STAND2 );
} else {
PM_ContinueTorsoAnim( TORSO_STAND );
Expand Down Expand Up @@ -1595,7 +1595,7 @@ static void PM_Weapon( void ) {

if ( pm->ps->weaponstate == WEAPON_RAISING ) {
pm->ps->weaponstate = WEAPON_READY;
if ( pm->ps->weapon == WP_GAUNTLET ) {
if ( pm->ps->weapon == WP_NONE || pm->ps->weapon == WP_GAUNTLET ) {
PM_StartTorsoAnim( TORSO_STAND2 );
} else {
PM_StartTorsoAnim( TORSO_STAND );
Expand Down Expand Up @@ -1626,14 +1626,14 @@ static void PM_Weapon( void ) {
pm->ps->weaponstate = WEAPON_FIRING;

// check for out of ammo
if ( ! pm->ps->ammo[ pm->ps->weapon ] ) {
if ( pm->ps->weapon && ! pm->ps->ammo[ pm->ps->weapon ] ) {
PM_AddEvent( EV_NOAMMO );
pm->ps->weaponTime += 500;
return;
}

// take an ammo away if not infinite
if ( pm->ps->ammo[ pm->ps->weapon ] != -1 ) {
if ( pm->ps->weapon && pm->ps->ammo[ pm->ps->weapon ] != -1 ) {
pm->ps->ammo[ pm->ps->weapon ]--;
}

Expand Down
5 changes: 1 addition & 4 deletions code/game/g_arenas.c
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,7 @@ static gentity_t *SpawnModelOnVictoryPad( gentity_t *pad, vec3_t offset, gentity
body->s.groundEntityNum = ENTITYNUM_WORLD;
body->s.legsAnim = LEGS_IDLE;
body->s.torsoAnim = TORSO_STAND;
if( body->s.weapon == WP_NONE ) {
body->s.weapon = WP_MACHINEGUN;
}
if( body->s.weapon == WP_GAUNTLET) {
if ( body->s.weapon == WP_GAUNTLET ) {
body->s.torsoAnim = TORSO_STAND2;
}
body->s.event = 0;
Expand Down
46 changes: 36 additions & 10 deletions code/game/g_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -1086,16 +1086,36 @@ void ClientSpawn(gentity_t *ent) {

client->ps.clientNum = index;

client->ps.stats[STAT_WEAPONS] = ( 1 << WP_MACHINEGUN );
if ( g_gametype.integer == GT_TEAM ) {
client->ps.ammo[WP_MACHINEGUN] = 50;
} else {
client->ps.ammo[WP_MACHINEGUN] = 100;
}
if ( g_startingWeapons.integer ) {
for ( i = WP_GAUNTLET; i < WP_NUM_WEAPONS; i++ ) {
if ( g_startingWeapons.integer > 0 && g_startingWeapons.integer & (1 << i-1) )
client->ps.stats[STAT_WEAPONS] |= (1 << i);
else if ( g_startingWeapons.integer < 0 ) {
if ( abs( g_startingWeapons.integer ) & (1 << i - 1) )
client->ps.stats[STAT_WEAPONS] |= (1 << i);
else if ( level.mapWeapons & (1 << i) )
client->ps.stats[STAT_WEAPONS] |= (1 << i);
}
}

client->ps.stats[STAT_WEAPONS] |= ( 1 << WP_GAUNTLET );
client->ps.ammo[WP_GAUNTLET] = -1;
client->ps.ammo[WP_GRAPPLING_HOOK] = -1;
// give ammo for starting weapons
for ( i = WP_GAUNTLET; i < WP_NUM_WEAPONS; i++ ) {
if ( !(client->ps.stats[STAT_WEAPONS] & (1 << i)) ) continue;

if ( i == WP_SHOTGUN || i == WP_GRENADE_LAUNCHER || i == WP_ROCKET_LAUNCHER || i == WP_RAILGUN || i == WP_BFG ) {
client->ps.ammo[i] = 10;
} else if ( i == WP_GAUNTLET || i == WP_GRAPPLING_HOOK ) {
client->ps.ammo[i] = -1;
} else {
client->ps.ammo[i] = 50;
}
}
if ( client->ps.stats[STAT_WEAPONS] & (1 << WP_MACHINEGUN) ) {
if ( g_gametype.integer == GT_TEAM ) {
client->ps.ammo[i] = 50;
}
}
}

// health will count down towards max_health
ent->health = client->ps.stats[STAT_HEALTH] = client->ps.stats[STAT_MAX_HEALTH] + 25;
Expand All @@ -1114,7 +1134,13 @@ void ClientSpawn(gentity_t *ent) {
G_KillBox( ent );

// force the base weapon up
client->ps.weapon = WP_MACHINEGUN;
client->ps.weapon = 0;
for ( i = WP_NUM_WEAPONS - 1; i > 0; i-- ) {
if ( client->ps.stats[STAT_WEAPONS] & (1 << i) ) {
client->ps.weapon = i;
break;
}
}
client->ps.weaponstate = WEAPON_READY;

// don't allow full run speed for a bit
Expand Down
2 changes: 2 additions & 0 deletions code/game/g_items.c
Original file line number Diff line number Diff line change
Expand Up @@ -969,6 +969,8 @@ void G_SpawnItem( gentity_t *ent, gitem_t *item ) {
if ( item->giType == IT_POWERUP ) {
G_SoundIndex( "sound/items/poweruprespawn.wav" );
G_SpawnFloat( "noglobalsound", "0", &ent->speed);
} else if ( item->giType == IT_WEAPON ) {
level.mapWeapons |= (1 << item->giTag);
}

#ifdef MISSIONPACK
Expand Down
6 changes: 4 additions & 2 deletions code/game/g_local.h
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,9 @@ typedef struct {
int num_entities; // current number, <= MAX_GENTITIES

int warmupTime; // restart match at this time

//levelup
int mapWeapons;
//-levelup
fileHandle_t logFile;

// store latched cvars here that we want to get at often
Expand Down Expand Up @@ -521,7 +523,6 @@ 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 @@ -810,6 +811,7 @@ extern vmCvar_t g_enableBreath;
extern vmCvar_t g_singlePlayer;
extern vmCvar_t g_proxMineTimeout;
//levelup
extern vmCvar_t g_startingWeapons;
extern vmCvar_t g_weaponCarryLimit;
//-levelup
void trap_Print( const char *text );
Expand Down
2 changes: 2 additions & 0 deletions code/game/g_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ vmCvar_t pmove_fixed;
vmCvar_t pmove_msec;
vmCvar_t g_listEntity;
//levelup
vmCvar_t g_startingWeapons;
vmCvar_t g_weaponCarryLimit;
//-levelup
#ifdef MISSIONPACK
Expand Down Expand Up @@ -148,6 +149,7 @@ 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_startingWeapons, "g_startingWeapons", "3", 0, 0, qtrue },
{ &g_weaponCarryLimit, "g_weaponCarryLimit", "-1", CVAR_SERVERINFO, 0, qtrue },
//-levelup
#ifdef MISSIONPACK
Expand Down

0 comments on commit 81dc7d7

Please sign in to comment.