Skip to content

Commit

Permalink
server alt fire swap handler refactoring and improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
Chomenor committed Apr 3, 2022
1 parent 5f71bc4 commit cffd029
Show file tree
Hide file tree
Showing 14 changed files with 250 additions and 46 deletions.
9 changes: 9 additions & 0 deletions build/msvc_2019/game.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -201,12 +201,16 @@
<ClInclude Include="..\..\code\game\botai.h" />
<ClInclude Include="..\..\code\game\botlib.h" />
<ClInclude Include="..\..\code\game\chars.h" />
<ClInclude Include="..\..\code\game\g_cvar_defs.h" />
<ClInclude Include="..\..\code\game\g_groups.h" />
<ClInclude Include="..\..\code\game\g_local.h" />
<ClInclude Include="..\..\code\game\g_public.h" />
<ClInclude Include="..\..\code\game\g_team.h" />
<ClInclude Include="..\..\code\game\inv.h" />
<ClInclude Include="..\..\code\game\match.h" />
<ClInclude Include="..\..\code\game\mods\g_mod_defs.h" />
<ClInclude Include="..\..\code\game\mods\g_mod_local.h" />
<ClInclude Include="..\..\code\game\mods\g_mod_public.h" />
<ClInclude Include="..\..\code\game\syn.h" />
</ItemGroup>
<ItemGroup>
Expand Down Expand Up @@ -249,6 +253,11 @@
<ClCompile Include="..\..\code\game\g_usable.c" />
<ClCompile Include="..\..\code\game\g_utils.c" />
<ClCompile Include="..\..\code\game\g_weapon.c" />
<ClCompile Include="..\..\code\game\mods\features\feature_altswap_handler.c" />
<ClCompile Include="..\..\code\game\mods\features\feature_player_move.c" />
<ClCompile Include="..\..\code\game\mods\g_mod_main.c" />
<ClCompile Include="..\..\code\game\mods\g_mod_stubs.c" />
<ClCompile Include="..\..\code\game\mods\g_mod_utils.c" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
Expand Down
33 changes: 33 additions & 0 deletions build/msvc_2019/game.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@
<Filter Include="game">
<UniqueIdentifier>{9F35977C-8B6C-980D-3459-7E10206F140F}</UniqueIdentifier>
</Filter>
<Filter Include="game\mods">
<UniqueIdentifier>{81BBD40A-ED25-8981-3664-3A27A20D67D6}</UniqueIdentifier>
</Filter>
<Filter Include="game\mods\features">
<UniqueIdentifier>{CF5F3109-BB43-F25E-24A4-ECB110A7DCE0}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\code\common\bg_local.h">
Expand Down Expand Up @@ -78,6 +84,9 @@
<ClInclude Include="..\..\code\game\chars.h">
<Filter>game</Filter>
</ClInclude>
<ClInclude Include="..\..\code\game\g_cvar_defs.h">
<Filter>game</Filter>
</ClInclude>
<ClInclude Include="..\..\code\game\g_groups.h">
<Filter>game</Filter>
</ClInclude>
Expand All @@ -96,6 +105,15 @@
<ClInclude Include="..\..\code\game\match.h">
<Filter>game</Filter>
</ClInclude>
<ClInclude Include="..\..\code\game\mods\g_mod_defs.h">
<Filter>game\mods</Filter>
</ClInclude>
<ClInclude Include="..\..\code\game\mods\g_mod_local.h">
<Filter>game\mods</Filter>
</ClInclude>
<ClInclude Include="..\..\code\game\mods\g_mod_public.h">
<Filter>game\mods</Filter>
</ClInclude>
<ClInclude Include="..\..\code\game\syn.h">
<Filter>game</Filter>
</ClInclude>
Expand Down Expand Up @@ -218,5 +236,20 @@
<ClCompile Include="..\..\code\game\g_weapon.c">
<Filter>game</Filter>
</ClCompile>
<ClCompile Include="..\..\code\game\mods\features\feature_altswap_handler.c">
<Filter>game\mods\features</Filter>
</ClCompile>
<ClCompile Include="..\..\code\game\mods\features\feature_player_move.c">
<Filter>game\mods\features</Filter>
</ClCompile>
<ClCompile Include="..\..\code\game\mods\g_mod_main.c">
<Filter>game\mods</Filter>
</ClCompile>
<ClCompile Include="..\..\code\game\mods\g_mod_stubs.c">
<Filter>game\mods</Filter>
</ClCompile>
<ClCompile Include="..\..\code\game\mods\g_mod_utils.c">
<Filter>game\mods</Filter>
</ClCompile>
</ItemGroup>
</Project>
1 change: 1 addition & 0 deletions build/qvm_build/build_game.bat
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ set src=game&set name=g_weapon&call :compile
set src=game\mods&set name=g_mod_main&call :compile
set src=game\mods&set name=g_mod_stubs&call :compile
set src=game\mods&set name=g_mod_utils&call :compile
set src=game\mods\features&set name=feature_altswap_handler&call :compile
set src=game\mods\features&set name=feature_player_move&call :compile
set src=common&set name=logging&call :compile
set src=common&set name=vm_extensions&call :compile
Expand Down
6 changes: 0 additions & 6 deletions code/game/g_active.c
Original file line number Diff line number Diff line change
Expand Up @@ -1593,12 +1593,6 @@ LOGFUNCTION_VOID( ModFNDefault_PmoveInit, ( int clientNum, pmove_t *pmove ), ( c
pmove->pointcontents = trap_PointContents;
pmove->debugLevel = g_debugMove.integer;
pmove->noFootsteps = ( g_dmflags.integer & DF_NO_FOOTSTEPS ) > 0;

if ( client->ps.weapon >= 1 && client->ps.weapon < WP_NUM_WEAPONS ) {
if ( client->sess.altSwapFlags & ( 1 << ( client->ps.weapon - 1 ) ) ) {
pmove->altFireMode = ALTMODE_SWAPPED;
}
}
}

/*
Expand Down
18 changes: 5 additions & 13 deletions code/game/g_cmds.c
Original file line number Diff line number Diff line change
Expand Up @@ -1643,17 +1643,6 @@ void Cmd_SetViewpos_f( gentity_t *ent ) {
TeleportPlayer( ent, origin, angles, TP_NORMAL );
}

/*
=================
Cmd_SetAltSwap_f
=================
*/
void Cmd_SetAltSwap_f( gentity_t *ent ) {
char buffer[MAX_TOKEN_CHARS];
trap_Argv( 1, buffer, sizeof( buffer ) );
ent->client->sess.altSwapFlags = atoi( buffer );
}


/*
=================
Expand All @@ -1672,6 +1661,11 @@ void ClientCommand( int clientNum ) {

trap_Argv( 0, cmd, sizeof( cmd ) );

// Check if any mods have special handling of this command
if ( modfn.ModClientCommand( clientNum, cmd ) ) {
return;
}

if (Q_stricmp (cmd, "say") == 0) {
Cmd_Say_f (ent, SAY_ALL, qfalse);
return;
Expand Down Expand Up @@ -1732,8 +1726,6 @@ void ClientCommand( int clientNum ) {
Cmd_GameCommand_f( ent );
else if (Q_stricmp (cmd, "setviewpos") == 0)
Cmd_SetViewpos_f( ent );
else if (Q_stricmp (cmd, "setaltswap") == 0)
Cmd_SetAltSwap_f( ent );
else
trap_SendServerCommand( clientNum, va("print \"unknown cmd %s\n\"", cmd ) );
}
2 changes: 0 additions & 2 deletions code/game/g_cvar_defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,5 +84,3 @@ CVAR_DEF( g_team_group_blue, "g_team_group_blue", "", CVAR_LATCH, qfalse ) // U
CVAR_DEF( g_random_skin_limit, "g_random_skin_limit", "4", CVAR_ARCHIVE, qfalse )
CVAR_DEF( g_noJoinTimeout, "g_noJoinTimeout", "120", CVAR_ARCHIVE, qfalse )
CVAR_DEF( g_classChangeDebounceTime, "g_classChangeDebounceTime", "180", CVAR_ARCHIVE, qfalse )

CVAR_DEF( g_altSwapSupport, "g_altSwapSupport", "1", CVAR_ARCHIVE, qfalse )
2 changes: 1 addition & 1 deletion code/game/g_local.h
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,6 @@ typedef struct {
spectatorState_t spectatorState;
int spectatorClient; // for chasecam and follow mode
int wins, losses; // tournament stats
int altSwapFlags; // for alt-fire swapping
} clientSession_t;

#define MAX_VOTE_COUNT 3
Expand Down Expand Up @@ -362,6 +361,7 @@ typedef struct {
// we changed gametype

qboolean restarted; // waiting for a map_restart to fire
qboolean hasRestarted; // whether any map_restart has been done since map was loaded

int numConnectedClients;
int numNonSpectatorClients; // includes connecting clients
Expand Down
19 changes: 1 addition & 18 deletions code/game/g_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -277,10 +277,6 @@ void G_UpdateModConfigInfo( void ) {

modfn.AddModConfigInfo( info );

if ( g_altSwapSupport.integer ) {
Info_SetValueForKey( info, "altSwapSupport", "1" );
}

if ( *info ) {
trap_SetConfigstring( CS_MOD_CONFIG, buffer );
} else {
Expand All @@ -289,17 +285,6 @@ void G_UpdateModConfigInfo( void ) {
}
}

/*
=================
G_UpdateModConfigCvar
Called when a cvar linked to a mod config value has changed.
=================
*/
static void G_UpdateModConfigCvar( trackedCvar_t *cv ) {
G_UpdateModConfigInfo();
}

/*
=================
G_UpdateNeedPass
Expand Down Expand Up @@ -399,9 +384,6 @@ static void G_RegisterCvars( void ) {

// configure g_needpass auto update
G_RegisterCvarCallback( &g_password, G_UpdateNeedPass, qtrue );

// handle mod config cvar changes
G_RegisterCvarCallback( &g_altSwapSupport, G_UpdateModConfigCvar, qfalse );
}

/*
Expand Down Expand Up @@ -476,6 +458,7 @@ void G_InitGame( int levelTime, int randomSeed, int restart ) {
level.time = levelTime;
level.startTime = levelTime;
level.restarted = restart;
level.hasRestarted = restart;

level.snd_fry = G_SoundIndex("sound/player/fry.wav"); // FIXME standing in lava / slime

Expand Down
10 changes: 4 additions & 6 deletions code/game/g_session.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,14 @@ void G_WriteClientSessionData( gclient_t *client ) {
const char *var;
info_string_t info;

s = va("%i %i %i %i %i %i %i %i",
s = va("%i %i %i %i %i %i %i",
client->sess.sessionTeam,
client->sess.sessionClass,
client->sess.spectatorTime,
client->sess.spectatorState,
client->sess.spectatorClient,
client->sess.wins,
client->sess.losses,
client->sess.altSwapFlags
client->sess.losses
);

var = va( "session%i", clientNum );
Expand Down Expand Up @@ -128,15 +127,14 @@ void G_ReadSessionData( gclient_t *client ) {
var = va( "session%i", clientNum );
trap_Cvar_VariableStringBuffer( var, s, sizeof(s) );

sscanf( s, "%i %i %i %i %i %i %i %i",
sscanf( s, "%i %i %i %i %i %i %i",
&client->sess.sessionTeam,
&client->sess.sessionClass,
&client->sess.spectatorTime,
&client->sess.spectatorState,
&client->sess.spectatorClient,
&client->sess.wins,
&client->sess.losses,
&client->sess.altSwapFlags
&client->sess.losses
);

// Call mod initialization
Expand Down
Loading

0 comments on commit cffd029

Please sign in to comment.