• R/O
  • SSH

zandronum-sandbox-stable: Commit


Commit MetaInfo

Revision8873b9831575691da9bcf174a5ce00d2d3505f01 (tree)
Time2022-02-10 01:43:18
AuthorAdam Kaminski <kaminskiadam9@gmai...>
CommiterAdam Kaminski

Log Message

Tentative cleanup of all gamemode CVars:
- Replaced the old duplicated, web entangled method of figuring out the game mode with a more clean and dynamic solution.
- Added a new property to the GAMEMODE lump to specify which CVar is used to enable a game mode.

Change Summary

Incremental Difference

diff -r 4f13149bed97 -r 8873b9831575 src/c_cvars.cpp
--- a/src/c_cvars.cpp Wed Feb 09 11:38:51 2022 -0500
+++ b/src/c_cvars.cpp Wed Feb 09 11:43:18 2022 -0500
@@ -178,6 +178,10 @@
178178
179179 Flags &= ~CVAR_ISDEFAULT;
180180
181+ // [AK] Check if this CVar enables a game mode and determine what the new game mode is.
182+ if ( Flags & CVAR_GAMEMODE )
183+ GAMEMODE_DetermineGameMode( this, false );
184+
181185 // [TP]
182186 if ( DMenu::CurrentMenu != NULL )
183187 DMenu::CurrentMenu->CVarChanged ( this );
@@ -227,8 +231,8 @@
227231
228232 if ( sv_cheats == false )
229233 {
230- // [AK] Don't change this CVar if it's locked in campaign mode.
231- if (( Flags & CVAR_CAMPAIGNLOCK ) && ( CAMPAIGN_InCampaign( )))
234+ // [AK] Don't change this CVar if it's locked, or used to change the game mode, in campaign mode.
235+ if (( Flags & ( CVAR_CAMPAIGNLOCK | CVAR_GAMEMODE )) && ( CAMPAIGN_InCampaign( )))
232236 {
233237 Printf( "%s cannot be changed during a campaign.\n", GetName( ));
234238 return;
diff -r 4f13149bed97 -r 8873b9831575 src/c_cvars.h
--- a/src/c_cvars.h Wed Feb 09 11:38:51 2022 -0500
+++ b/src/c_cvars.h Wed Feb 09 11:43:18 2022 -0500
@@ -84,8 +84,11 @@
8484 // synchronized to clients with RCON access.
8585 CVAR_SENSITIVESERVERSETTING = 1048576,
8686
87+ // [AK] This CVar is used to enable a game mode.
88+ CVAR_GAMEMODE = 2097152,
89+
8790 // [AK] The CVar is locked for a particular game mode and cannot be set from the console during play.
88- CVAR_GAMEMODELOCK = 2097152,
91+ CVAR_GAMEMODELOCK = 4194304,
8992 };
9093
9194 union UCVarValue
diff -r 4f13149bed97 -r 8873b9831575 src/cooperative.cpp
--- a/src/cooperative.cpp Wed Feb 09 11:38:51 2022 -0500
+++ b/src/cooperative.cpp Wed Feb 09 11:43:18 2022 -0500
@@ -299,80 +299,10 @@
299299 //*****************************************************************************
300300 // CONSOLE COMMANDS/VARIABLES
301301
302-// [BB] Since cooperative defaults to true and its default value sets deathmatch
303-// and teamgame to false, we have to initialize it last.
304-CUSTOM_CVAR( Bool, cooperative, true, CVAR_SERVERINFO | CVAR_LATCH | CVAR_CAMPAIGNLOCK | CVAR_NOINITCALL )
305-{
306- UCVarValue Val;
307-
308- if ( self == true )
309- {
310- Val.Bool = false;
311-
312- // Disable deathmatch and teamgame if we're playing cooperative.
313- if ( deathmatch != false )
314- deathmatch.ForceSet( Val, CVAR_Bool );
315- if ( teamgame != false )
316- teamgame.ForceSet( Val, CVAR_Bool );
317- }
318- else
319- {
320- Val.Bool = false;
321-
322- // Cooperative, so disable all related modes.
323- survival.ForceSet( Val, CVAR_Bool );
324- invasion.ForceSet( Val, CVAR_Bool );
325- }
326-
327- // Reset what the current game mode is.
328- GAMEMODE_DetermineGameMode( );
329-}
330-
331-//*****************************************************************************
332-//
333-CUSTOM_CVAR( Bool, survival, false, CVAR_SERVERINFO | CVAR_LATCH | CVAR_CAMPAIGNLOCK )
334-{
335- UCVarValue Val;
336-
337- if ( self == true )
338- {
339- Val.Bool = true;
340-
341- // Enable cooperative.
342- cooperative.ForceSet( Val, CVAR_Bool );
343-
344- Val.Bool = false;
345-
346- // Disable other modes.
347- invasion.ForceSet( Val, CVAR_Bool );
348- }
349-
350- // Reset what the current game mode is.
351- GAMEMODE_DetermineGameMode( );
352-}
353-
354-//*****************************************************************************
355-//
356-CUSTOM_CVAR( Bool, invasion, false, CVAR_SERVERINFO | CVAR_LATCH | CVAR_CAMPAIGNLOCK )
357-{
358- UCVarValue Val;
359-
360- if ( self == true )
361- {
362- Val.Bool = true;
363-
364- // Enable cooperative.
365- cooperative.ForceSet( Val, CVAR_Bool );
366-
367- Val.Bool = false;
368-
369- // Disable other modes.
370- survival.ForceSet( Val, CVAR_Bool );
371- }
372-
373- // Reset what the current game mode is.
374- GAMEMODE_DetermineGameMode( );
375-}
302+// [AK] Added CVAR_GAMEMODE.
303+CVAR( Bool, cooperative, true, CVAR_SERVERINFO | CVAR_LATCH | CVAR_GAMEMODE )
304+CVAR( Bool, survival, false, CVAR_SERVERINFO | CVAR_LATCH | CVAR_GAMEMODE )
305+CVAR( Bool, invasion, false, CVAR_SERVERINFO | CVAR_LATCH | CVAR_GAMEMODE )
376306
377307 //*****************************************************************************
378308 //*****************************************************************************
diff -r 4f13149bed97 -r 8873b9831575 src/d_main.cpp
--- a/src/d_main.cpp Wed Feb 09 11:38:51 2022 -0500
+++ b/src/d_main.cpp Wed Feb 09 11:43:18 2022 -0500
@@ -2935,9 +2935,6 @@
29352935 // Base systems have been inited; enable cvar callbacks
29362936 FBaseCVar::EnableCallbacks ();
29372937
2938- // [BB] Make sure that the callback of cooperative is first called after the ones of deathmatch and teamgame.
2939- cooperative.Callback();
2940-
29412938 // [RC] Start the G15 LCD module here.
29422939 G15_Construct ();
29432940
diff -r 4f13149bed97 -r 8873b9831575 src/deathmatch.cpp
--- a/src/deathmatch.cpp Wed Feb 09 11:38:51 2022 -0500
+++ b/src/deathmatch.cpp Wed Feb 09 11:43:18 2022 -0500
@@ -76,227 +76,15 @@
7676 //*****************************************************************************
7777 // CONSOLE COMMANDS/VARIABLES
7878
79-CUSTOM_CVAR( Bool, deathmatch, false, CVAR_SERVERINFO | CVAR_LATCH | CVAR_CAMPAIGNLOCK )
80-{
81- UCVarValue Val;
82-
83- if ( self == true )
84- {
85- Val.Bool = false;
86-
87- // Disable teamgame if we're playing deathmatch.
88- teamgame.ForceSet( Val, CVAR_Bool );
89-
90- // Disable cooperative if we're playing deathmatch.
91- cooperative.ForceSet( Val, CVAR_Bool );
92- }
93- else
94- {
95- Val.Bool = false;
96- // Deathmatch has been disabled, so disable all related modes.
97- teamplay.ForceSet( Val, CVAR_Bool );
98- duel.ForceSet( Val, CVAR_Bool );
99- terminator.ForceSet( Val, CVAR_Bool );
100- lastmanstanding.ForceSet( Val, CVAR_Bool );
101- teamlms.ForceSet( Val, CVAR_Bool );
102- possession.ForceSet( Val, CVAR_Bool );
103- teampossession.ForceSet( Val, CVAR_Bool );
104-
105- // If teamgame is also disabled, enable cooperative mode.
106- if ( teamgame == false )
107- {
108- Val.Bool = true;
109-
110- if ( cooperative != true )
111- cooperative.ForceSet( Val, CVAR_Bool );
112- }
113- }
114-
115- // Reset what the current game mode is.
116- GAMEMODE_DetermineGameMode( );
117-}
118-
119-//*****************************************************************************
120-//
121-CUSTOM_CVAR( Bool, teamplay, false, CVAR_SERVERINFO | CVAR_LATCH | CVAR_CAMPAIGNLOCK )
122-{
123- UCVarValue Val;
124-
125- if ( self == true )
126- {
127- Val.Bool = true;
128- // Enable deathmatch.
129- deathmatch.ForceSet( Val, CVAR_Bool );
130-
131- Val.Bool = false;
132- // Disable other modes.
133- duel.ForceSet( Val, CVAR_Bool );
134- terminator.ForceSet( Val, CVAR_Bool );
135- lastmanstanding.ForceSet( Val, CVAR_Bool );
136- teamlms.ForceSet( Val, CVAR_Bool );
137- possession.ForceSet( Val, CVAR_Bool );
138- teampossession.ForceSet( Val, CVAR_Bool );
139- }
140-
141- // Reset what the current game mode is.
142- GAMEMODE_DetermineGameMode( );
143-}
144-
145-//*****************************************************************************
146-//
147-CUSTOM_CVAR( Bool, duel, false, CVAR_SERVERINFO | CVAR_LATCH | CVAR_CAMPAIGNLOCK )
148-{
149- UCVarValue Val;
150-
151- if ( self == true )
152- {
153- Val.Bool = true;
154- // Enable deathmatch.
155- deathmatch.ForceSet( Val, CVAR_Bool );
156-
157- Val.Bool = false;
158- // Disable other modes.
159- teamplay.ForceSet( Val, CVAR_Bool );
160- terminator.ForceSet( Val, CVAR_Bool );
161- lastmanstanding.ForceSet( Val, CVAR_Bool );
162- teamlms.ForceSet( Val, CVAR_Bool );
163- possession.ForceSet( Val, CVAR_Bool );
164- teampossession.ForceSet( Val, CVAR_Bool );
165- }
166-
167- // Reset what the current game mode is.
168- GAMEMODE_DetermineGameMode( );
169-}
170-
171-//*****************************************************************************
172-//
173-CUSTOM_CVAR( Bool, terminator, false, CVAR_SERVERINFO | CVAR_LATCH | CVAR_CAMPAIGNLOCK )
174-{
175- UCVarValue Val;
176-
177- if ( self == true )
178- {
179- Val.Bool = true;
180- // Enable deathmatch.
181- deathmatch.ForceSet( Val, CVAR_Bool );
182-
183- Val.Bool = false;
184- // Disable other modes.
185- teamplay.ForceSet( Val, CVAR_Bool );
186- duel.ForceSet( Val, CVAR_Bool );
187- lastmanstanding.ForceSet( Val, CVAR_Bool );
188- teamlms.ForceSet( Val, CVAR_Bool );
189- possession.ForceSet( Val, CVAR_Bool );
190- teampossession.ForceSet( Val, CVAR_Bool );
191- }
192-
193- // Reset what the current game mode is.
194- GAMEMODE_DetermineGameMode( );
195-}
196-
197-//*****************************************************************************
198-//
199-CUSTOM_CVAR( Bool, lastmanstanding, false, CVAR_SERVERINFO | CVAR_LATCH | CVAR_CAMPAIGNLOCK )
200-{
201- UCVarValue Val;
202-
203- if ( self == true )
204- {
205- Val.Bool = true;
206- // Enable deathmatch.
207- deathmatch.ForceSet( Val, CVAR_Bool );
208-
209- Val.Bool = false;
210- // Disable other modes.
211- teamplay.ForceSet( Val, CVAR_Bool );
212- duel.ForceSet( Val, CVAR_Bool );
213- terminator.ForceSet( Val, CVAR_Bool );
214- teamlms.ForceSet( Val, CVAR_Bool );
215- possession.ForceSet( Val, CVAR_Bool );
216- teampossession.ForceSet( Val, CVAR_Bool );
217- }
218-
219- // Reset what the current game mode is.
220- GAMEMODE_DetermineGameMode( );
221-}
222-
223-//*****************************************************************************
224-//
225-CUSTOM_CVAR( Bool, teamlms, false, CVAR_SERVERINFO | CVAR_LATCH | CVAR_CAMPAIGNLOCK )
226-{
227- UCVarValue Val;
228-
229- if ( self == true )
230- {
231- Val.Bool = true;
232- // Enable deathmatch.
233- deathmatch.ForceSet( Val, CVAR_Bool );
234-
235- Val.Bool = false;
236- // Disable other modes.
237- teamplay.ForceSet( Val, CVAR_Bool );
238- duel.ForceSet( Val, CVAR_Bool );
239- terminator.ForceSet( Val, CVAR_Bool );
240- lastmanstanding.ForceSet( Val, CVAR_Bool );
241- possession.ForceSet( Val, CVAR_Bool );
242- teampossession.ForceSet( Val, CVAR_Bool );
243- }
244-
245- // Reset what the current game mode is.
246- GAMEMODE_DetermineGameMode( );
247-}
248-
249-//*****************************************************************************
250-//
251-CUSTOM_CVAR( Bool, possession, false, CVAR_SERVERINFO | CVAR_LATCH | CVAR_CAMPAIGNLOCK )
252-{
253- UCVarValue Val;
254-
255- if ( self == true )
256- {
257- Val.Bool = true;
258- // Enable deathmatch.
259- deathmatch.ForceSet( Val, CVAR_Bool );
260-
261- Val.Bool = false;
262- // Disable other modes.
263- teamplay.ForceSet( Val, CVAR_Bool );
264- duel.ForceSet( Val, CVAR_Bool );
265- terminator.ForceSet( Val, CVAR_Bool );
266- lastmanstanding.ForceSet( Val, CVAR_Bool );
267- teamlms.ForceSet( Val, CVAR_Bool );
268- teampossession.ForceSet( Val, CVAR_Bool );
269- }
270-
271- // Reset what the current game mode is.
272- GAMEMODE_DetermineGameMode( );
273-}
274-
275-//*****************************************************************************
276-//
277-CUSTOM_CVAR( Bool, teampossession, false, CVAR_SERVERINFO | CVAR_LATCH | CVAR_CAMPAIGNLOCK )
278-{
279- UCVarValue Val;
280-
281- if ( self == true )
282- {
283- Val.Bool = true;
284- // Enable deathmatch.
285- deathmatch.ForceSet( Val, CVAR_Bool );
286-
287- Val.Bool = false;
288- // Disable other modes.
289- teamplay.ForceSet( Val, CVAR_Bool );
290- duel.ForceSet( Val, CVAR_Bool );
291- terminator.ForceSet( Val, CVAR_Bool );
292- lastmanstanding.ForceSet( Val, CVAR_Bool );
293- teamlms.ForceSet( Val, CVAR_Bool );
294- possession.ForceSet( Val, CVAR_Bool );
295- }
296-
297- // Reset what the current game mode is.
298- GAMEMODE_DetermineGameMode( );
299-}
79+// [AK] Added CVAR_GAMEMODE.
80+CVAR( Bool, deathmatch, false, CVAR_SERVERINFO | CVAR_LATCH | CVAR_GAMEMODE )
81+CVAR( Bool, teamplay, false, CVAR_SERVERINFO | CVAR_LATCH | CVAR_GAMEMODE )
82+CVAR( Bool, duel, false, CVAR_SERVERINFO | CVAR_LATCH | CVAR_GAMEMODE )
83+CVAR( Bool, terminator, false, CVAR_SERVERINFO | CVAR_LATCH | CVAR_GAMEMODE )
84+CVAR( Bool, lastmanstanding, false, CVAR_SERVERINFO | CVAR_LATCH | CVAR_GAMEMODE )
85+CVAR( Bool, teamlms, false, CVAR_SERVERINFO | CVAR_LATCH | CVAR_GAMEMODE )
86+CVAR( Bool, possession, false, CVAR_SERVERINFO | CVAR_LATCH | CVAR_GAMEMODE )
87+CVAR( Bool, teampossession, false, CVAR_SERVERINFO | CVAR_LATCH | CVAR_GAMEMODE )
30088
30189 //*****************************************************************************
30290 //
diff -r 4f13149bed97 -r 8873b9831575 src/gamemode.cpp
--- a/src/gamemode.cpp Wed Feb 09 11:38:51 2022 -0500
+++ b/src/gamemode.cpp Wed Feb 09 11:43:18 2022 -0500
@@ -92,6 +92,13 @@
9292 // [AK] The result value of the current event being executed.
9393 static LONG g_lEventResult = 1;
9494
95+// [AK] Are we currently changing the game mode?
96+static bool g_bChangingGameMode = false;
97+
98+// [AK] A list of CVars changed during startup before the GAMEMODE lumps were parsed that we
99+// still need to call GAMEMODE_DetermineGameMode for.
100+static TArray<FBaseCVar *> g_PendingGameModeChanges;
101+
95102 // [BB] Implement the string table and the conversion functions for the GMF and GAMEMODE enums.
96103 #define GENERATE_ENUM_STRINGS // Start string generation
97104 #include "gamemode_enums.h"
@@ -211,6 +218,11 @@
211218 strncpy( g_GameModes[GameMode].szF1Texture, sc.String, 8 );
212219 g_GameModes[GameMode].szF1Texture[8] = 0;
213220 }
221+ else if (0 == stricmp (sc.String, "cvar"))
222+ {
223+ sc.MustGetString();
224+ g_GameModes[GameMode].CVarName = sc.String;
225+ }
214226 else if ((0 == stricmp (sc.String, "gamesettings")) || (0 == stricmp (sc.String, "lockedgamesettings")))
215227 {
216228 GAMEMODE_ParseGameSettingBlock( sc, GameMode, !stricmp( sc.String, "lockedgamesettings" ));
@@ -376,10 +388,60 @@
376388 I_Error( "Players have no way of earning kills, frags, points, or wins in \"%s\".", name.GetChars( ));
377389 else if (( ulFlags & ( ulFlags - 1 )) != 0 )
378390 I_Error( "There is more than one PLAYERSEARN flag enabled in \"%s\".", name.GetChars( ));
391+
392+ // [AK] If no CVar name was specified, throw an error message.
393+ if ( g_GameModes[i].CVarName.Len( ) == 0 )
394+ {
395+ I_Error( "No CVar specified for \"%s\".", name.GetChars( ));
396+ }
397+ else
398+ {
399+ FBaseCVar *pCVar = FindCVar( g_GameModes[i].CVarName, NULL );
400+
401+ // [AK] If this CVar doesn't exist, create a new one.
402+ if ( pCVar == NULL )
403+ {
404+ pCVar = C_CreateCVar( g_GameModes[i].CVarName, CVAR_Bool, CVAR_SERVERINFO | CVAR_LATCH | CVAR_GAMEMODE );
405+ }
406+ else
407+ {
408+ ulFlags = pCVar->GetFlags( ) & ( CVAR_SERVERINFO | CVAR_LATCH | CVAR_GAMEMODE );
409+
410+ // [AK] If this CVar already exists, make sure that it's valid.
411+ if (( pCVar->GetRealType( ) != CVAR_Bool ) || ( ulFlags != ( CVAR_SERVERINFO | CVAR_LATCH | CVAR_GAMEMODE )) || ( pCVar->GetFlags( ) & CVAR_ARCHIVE ))
412+ I_Error( "Invalid CVar \"%s\" used for \"%s\". It must be a latched, unarchived serverinfo CVar of boolean type.", pCVar->GetName( ), name.GetChars( ));
413+
414+ // [AK] Make sure that this CVar isn't already being used by another game mode.
415+ for ( unsigned int j = GAMEMODE_COOPERATIVE; j < NUM_GAMEMODES; j++ )
416+ {
417+ if (( i != j ) && ( g_GameModes[j].pCVar == pCVar ))
418+ I_Error( "\"%s\" is used for more than one game mode.", pCVar->GetName( ));
419+ }
420+
421+ FBoolCVar *pBoolCVar = static_cast<FBoolCVar *>( pCVar );
422+
423+ // [AK] The cooperative, deathmatch, and teamgame game modes must use their respective CVars!
424+ if ((( i == GAMEMODE_COOPERATIVE ) && ( pBoolCVar != &cooperative )) ||
425+ (( i == GAMEMODE_DEATHMATCH ) && ( pBoolCVar != &deathmatch )) ||
426+ (( i == GAMEMODE_TEAMGAME ) && ( pBoolCVar != &teamgame )))
427+ {
428+ I_Error( "\"%s\" must use the \"%s\" CVar!", name.GetChars( ), name.GetChars( ));
429+ }
430+ }
431+
432+ g_GameModes[i].pCVar = pCVar;
433+ }
379434 }
380435
381436 // Our default game mode is co-op.
382437 g_CurrentGameMode = GAMEMODE_COOPERATIVE;
438+
439+ // [AK] Process any pending game mode changes now.
440+ while ( g_PendingGameModeChanges.Size( ) > 0 )
441+ {
442+ GAMEMODE_DetermineGameMode( g_PendingGameModeChanges[0], true );
443+ g_PendingGameModeChanges.Delete( 0 );
444+ }
383445 }
384446
385447 //*****************************************************************************
@@ -472,39 +534,86 @@
472534
473535 //*****************************************************************************
474536 //
475-void GAMEMODE_DetermineGameMode( void )
537+void GAMEMODE_DetermineGameMode( FBaseCVar *pCVar, bool bForceExecution )
476538 {
477- g_CurrentGameMode = GAMEMODE_COOPERATIVE;
478- if ( survival )
479- g_CurrentGameMode = GAMEMODE_SURVIVAL;
480- if ( invasion )
481- g_CurrentGameMode = GAMEMODE_INVASION;
482- if ( deathmatch )
483- g_CurrentGameMode = GAMEMODE_DEATHMATCH;
484- if ( teamplay )
485- g_CurrentGameMode = GAMEMODE_TEAMPLAY;
486- if ( duel )
487- g_CurrentGameMode = GAMEMODE_DUEL;
488- if ( terminator )
489- g_CurrentGameMode = GAMEMODE_TERMINATOR;
490- if ( lastmanstanding )
491- g_CurrentGameMode = GAMEMODE_LASTMANSTANDING;
492- if ( teamlms )
493- g_CurrentGameMode = GAMEMODE_TEAMLMS;
494- if ( possession )
495- g_CurrentGameMode = GAMEMODE_POSSESSION;
496- if ( teampossession )
497- g_CurrentGameMode = GAMEMODE_TEAMPOSSESSION;
498- if ( teamgame )
499- g_CurrentGameMode = GAMEMODE_TEAMGAME;
500- if ( ctf )
501- g_CurrentGameMode = GAMEMODE_CTF;
502- if ( oneflagctf )
503- g_CurrentGameMode = GAMEMODE_ONEFLAGCTF;
504- if ( skulltag )
505- g_CurrentGameMode = GAMEMODE_SKULLTAG;
506- if ( domination )
507- g_CurrentGameMode = GAMEMODE_DOMINATION;
539+ UCVarValue Val;
540+
541+ // [AK] Don't do this if the CVar's invalid or if we're already changing the game mode.
542+ if (( pCVar == NULL ) || ( g_bChangingGameMode ))
543+ return;
544+
545+ // [AK] If we're in startup mode and the GAMEMODE lumps haven't been parsed yet, put this
546+ // CVar into a list which we'll process once the lumps are parsed.
547+ if (( gamestate == GS_STARTUP ) && ( bForceExecution == false ))
548+ {
549+ g_PendingGameModeChanges.Push( pCVar );
550+ return;
551+ }
552+
553+ FBoolCVar *pBoolCVar = static_cast<FBoolCVar *>( pCVar );
554+ ULONG ulCurrentFlags = g_GameModes[g_CurrentGameMode].ulFlags;
555+ const bool bEnable = pCVar->GetGenericRep( CVAR_Bool ).Bool;
556+
557+ g_bChangingGameMode = true;
558+ Val.Bool = false;
559+
560+ // [AK] Check if we're trying to change one of cooperative, deathmatch, and teamgame when
561+ // they're supposed to be enabled in the current game mode.
562+ if ((( pBoolCVar == &cooperative ) && ( ulCurrentFlags & GMF_COOPERATIVE )) ||
563+ (( pBoolCVar == &deathmatch ) && ( ulCurrentFlags & GMF_DEATHMATCH )) ||
564+ (( pBoolCVar == &teamgame ) && ( ulCurrentFlags & GMF_TEAMGAME )))
565+ {
566+ // [AK] Only do something if we're trying to disable them.
567+ if ( bEnable == false )
568+ {
569+ // [AK] Set the CVars of all game modes to false.
570+ for ( unsigned int i = GAMEMODE_COOPERATIVE; i < NUM_GAMEMODES; i++ )
571+ g_GameModes[i].pCVar->ForceSet( Val, CVAR_Bool );
572+
573+ // [AK] Change the current game mode to cooperative (default).
574+ Val.Bool = true;
575+ cooperative.ForceSet( Val, CVAR_Bool );
576+ g_CurrentGameMode = GAMEMODE_COOPERATIVE;
577+ }
578+ }
579+ else
580+ {
581+ for ( unsigned int i = GAMEMODE_COOPERATIVE; i < NUM_GAMEMODES; i++ )
582+ {
583+ // [AK] Don't execute this block if we disabled a CVar for a game mode that we're not playing.
584+ if (( g_GameModes[i].pCVar == pCVar ) && (( bEnable ) || ( i == g_CurrentGameMode )))
585+ {
586+ // [AK] Set cooperative, deathmatch, and teamgame to false first.
587+ cooperative.ForceSet( Val, CVAR_Bool );
588+ deathmatch.ForceSet( Val, CVAR_Bool );
589+ teamgame.ForceSet( Val, CVAR_Bool );
590+
591+ // [AK] Next, set the CVars of all other game modes to false.
592+ for ( unsigned int j = GAMEMODE_COOPERATIVE; j < NUM_GAMEMODES; j++ )
593+ {
594+ if (( i != j ) && ( g_GameModes[j].pCVar ))
595+ g_GameModes[j].pCVar->ForceSet( Val, CVAR_Bool );
596+ }
597+
598+ Val.Bool = true;
599+
600+ // [AK] Determine whether we should enable cooperative, deathmatch, or teamgame.
601+ if ( g_GameModes[i].ulFlags & GMF_COOPERATIVE )
602+ cooperative.ForceSet( Val, CVAR_Bool );
603+ else if ( g_GameModes[i].ulFlags & GMF_DEATHMATCH )
604+ deathmatch.ForceSet( Val, CVAR_Bool );
605+ else
606+ teamgame.ForceSet( Val, CVAR_Bool );
607+
608+ // [AK] Change to the new current game mode.
609+ g_CurrentGameMode = static_cast<GAMEMODE_e>( i );
610+ break;
611+ }
612+ }
613+ }
614+
615+ // [AK] We're done changing the game mode now.
616+ g_bChangingGameMode = false;
508617 }
509618
510619 //*****************************************************************************
@@ -1259,91 +1368,29 @@
12591368 //
12601369 void GAMEMODE_SetCurrentMode( GAMEMODE_e GameMode )
12611370 {
1262- UCVarValue Val;
1263- g_CurrentGameMode = GameMode;
1264-
1265- // [RC] Set all the CVars. We can't just use "= true;" because of the latched cvars.
1266- // (Hopefully Blzut's update will save us from this garbage.)
1371+ UCVarValue Val;
1372+ Val.Bool = false;
12671373
1268- Val.Bool = false;
1269- // [BB] Even though setting deathmatch and teamgame to false will set cooperative to true,
1270- // we need to set cooperative to false here first to clear survival and invasion.
1271- cooperative.ForceSet( Val, CVAR_Bool );
1272- deathmatch.ForceSet( Val, CVAR_Bool );
1273- teamgame.ForceSet( Val, CVAR_Bool );
1374+ // [AK] Don't do this if we're already changing the game mode.
1375+ if ( g_bChangingGameMode )
1376+ return;
1377+
1378+ g_bChangingGameMode = true;
1379+
1380+ // [AK] Set the CVars of all other game modes to false.
1381+ for ( unsigned int i = GAMEMODE_COOPERATIVE; i < NUM_GAMEMODES; i++ )
1382+ {
1383+ if ( static_cast<GAMEMODE_e>( i ) != GameMode )
1384+ g_GameModes[i].pCVar->ForceSet( Val, CVAR_Bool );
1385+ }
1386+
12741387 instagib.ForceSet( Val, CVAR_Bool );
12751388 buckshot.ForceSet( Val, CVAR_Bool );
12761389
1390+ // [AK] Set the CVar of the desired game mode to true.
1391+ g_bChangingGameMode = false;
12771392 Val.Bool = true;
1278- switch ( GameMode )
1279- {
1280- case GAMEMODE_COOPERATIVE:
1281-
1282- cooperative.ForceSet( Val, CVAR_Bool );
1283- break;
1284- case GAMEMODE_SURVIVAL:
1285-
1286- survival.ForceSet( Val, CVAR_Bool );
1287- break;
1288- case GAMEMODE_INVASION:
1289-
1290- invasion.ForceSet( Val, CVAR_Bool );
1291- break;
1292- case GAMEMODE_DEATHMATCH:
1293-
1294- deathmatch.ForceSet( Val, CVAR_Bool );
1295- break;
1296- case GAMEMODE_TEAMPLAY:
1297-
1298- teamplay.ForceSet( Val, CVAR_Bool );
1299- break;
1300- case GAMEMODE_DUEL:
1301-
1302- duel.ForceSet( Val, CVAR_Bool );
1303- break;
1304- case GAMEMODE_TERMINATOR:
1305-
1306- terminator.ForceSet( Val, CVAR_Bool );
1307- break;
1308- case GAMEMODE_LASTMANSTANDING:
1309-
1310- lastmanstanding.ForceSet( Val, CVAR_Bool );
1311- break;
1312- case GAMEMODE_TEAMLMS:
1313-
1314- teamlms.ForceSet( Val, CVAR_Bool );
1315- break;
1316- case GAMEMODE_POSSESSION:
1317-
1318- possession.ForceSet( Val, CVAR_Bool );
1319- break;
1320- case GAMEMODE_TEAMPOSSESSION:
1321-
1322- teampossession.ForceSet( Val, CVAR_Bool );
1323- break;
1324- case GAMEMODE_TEAMGAME:
1325-
1326- teamgame.ForceSet( Val, CVAR_Bool );
1327- break;
1328- case GAMEMODE_CTF:
1329-
1330- ctf.ForceSet( Val, CVAR_Bool );
1331- break;
1332- case GAMEMODE_ONEFLAGCTF:
1333-
1334- oneflagctf.ForceSet( Val, CVAR_Bool );
1335- break;
1336- case GAMEMODE_SKULLTAG:
1337-
1338- skulltag.ForceSet( Val, CVAR_Bool );
1339- break;
1340- case GAMEMODE_DOMINATION:
1341-
1342- domination.ForceSet( Val, CVAR_Bool );
1343- break;
1344- default:
1345- break;
1346- }
1393+ g_GameModes[GameMode].pCVar->ForceSet( Val, CVAR_Bool );
13471394 }
13481395
13491396 //*****************************************************************************
diff -r 4f13149bed97 -r 8873b9831575 src/gamemode.h
--- a/src/gamemode.h Wed Feb 09 11:38:51 2022 -0500
+++ b/src/gamemode.h Wed Feb 09 11:43:18 2022 -0500
@@ -164,6 +164,12 @@
164164 // this game mode.
165165 char szF1Texture[9];
166166
167+ // [AK] The name used to find the CVar that will enable this game mode.
168+ FString CVarName;
169+
170+ // [AK] The CVar used to enable this game mode.
171+ FBaseCVar *pCVar;
172+
167173 // [AK] All of the gameplay or compatibility flags we set for this game mode
168174 // (dmflags, compatflags, lmsallowedweapons, lmsspectatorsettings, etc.).
169175 LONG lFlagsets[NUM_FLAGSETS][3];
@@ -185,7 +191,7 @@
185191 char *GAMEMODE_GetF1Texture( GAMEMODE_e GameMode );
186192 int GAMEMODE_GetFlagsetMask( GAMEMODE_e GameMode, FIntCVar *Flagset, bool bLocked = false );
187193 int GAMEMODE_GetCurrentFlagsetMask( FIntCVar *Flagset, bool bLocked = false );
188-void GAMEMODE_DetermineGameMode( void );
194+void GAMEMODE_DetermineGameMode( FBaseCVar *pCVar, bool bForceExecution );
189195 bool GAMEMODE_IsGameInCountdown( void );
190196 bool GAMEMODE_IsGameInProgress( void );
191197 bool GAMEMODE_IsGameInResultSequence( void );
diff -r 4f13149bed97 -r 8873b9831575 src/team.cpp
--- a/src/team.cpp Wed Feb 09 11:38:51 2022 -0500
+++ b/src/team.cpp Wed Feb 09 11:43:18 2022 -0500
@@ -1924,134 +1924,12 @@
19241924 //*****************************************************************************
19251925 // CONSOLE COMMANDS/VARIABLES
19261926
1927-CUSTOM_CVAR( Bool, teamgame, false, CVAR_SERVERINFO | CVAR_LATCH | CVAR_CAMPAIGNLOCK )
1928-{
1929- UCVarValue Val;
1930-
1931- if ( self == true )
1932- {
1933- Val.Bool = false;
1934-
1935- // Disable deathmatch if we're setting a teamgame.
1936- deathmatch.ForceSet( Val, CVAR_Bool );
1937-
1938- // Disable cooperative if we're setting a teamgame.
1939- cooperative.ForceSet( Val, CVAR_Bool );
1940- }
1941- else
1942- {
1943- Val.Bool = false;
1944- // Teamgame has been disabled, so disable all related modes.
1945- ctf.ForceSet( Val, CVAR_Bool );
1946- oneflagctf.ForceSet( Val, CVAR_Bool );
1947- skulltag.ForceSet( Val, CVAR_Bool );
1948- domination.ForceSet( Val, CVAR_Bool );
1949-
1950- // If deathmatch is also disabled, enable cooperative mode.
1951- if ( deathmatch == false )
1952- {
1953- Val.Bool = true;
1954-
1955- if ( cooperative != true )
1956- cooperative.ForceSet( Val, CVAR_Bool );
1957- }
1958- }
1959-
1960- // Reset what the current game mode is.
1961- GAMEMODE_DetermineGameMode( );
1962-}
1963-
1964-//*****************************************************************************
1965-//
1966-CUSTOM_CVAR( Bool, ctf, false, CVAR_SERVERINFO | CVAR_LATCH | CVAR_CAMPAIGNLOCK )
1967-{
1968- UCVarValue Val;
1969-
1970- if ( self == true )
1971- {
1972- Val.Bool = true;
1973- // Enable teamgame if we're playing CTF.
1974- teamgame.ForceSet( Val, CVAR_Bool );
1975-
1976- Val.Bool = false;
1977- // Disable other modes.
1978- oneflagctf.ForceSet( Val, CVAR_Bool );
1979- skulltag.ForceSet( Val, CVAR_Bool );
1980- domination.ForceSet( Val, CVAR_Bool );
1981- }
1982-
1983- // Reset what the current game mode is.
1984- GAMEMODE_DetermineGameMode( );
1985-}
1986-
1987-//*****************************************************************************
1988-//
1989-CUSTOM_CVAR( Bool, oneflagctf, false, CVAR_SERVERINFO | CVAR_LATCH | CVAR_CAMPAIGNLOCK )
1990-{
1991- UCVarValue Val;
1992-
1993- if ( self == true )
1994- {
1995- Val.Bool = true;
1996- // Enable teamgame if we're playing CTF.
1997- teamgame.ForceSet( Val, CVAR_Bool );
1998-
1999- Val.Bool = false;
2000- // Disable other modes.
2001- ctf.ForceSet( Val, CVAR_Bool );
2002- skulltag.ForceSet( Val, CVAR_Bool );
2003- domination.ForceSet( Val, CVAR_Bool );
2004- }
2005-
2006- // Reset what the current game mode is.
2007- GAMEMODE_DetermineGameMode( );
2008-}
2009-
2010-//*****************************************************************************
2011-//
2012-CUSTOM_CVAR( Bool, skulltag, false, CVAR_SERVERINFO | CVAR_LATCH | CVAR_CAMPAIGNLOCK )
2013-{
2014- UCVarValue Val;
2015-
2016- if ( self == true )
2017- {
2018- Val.Bool = true;
2019- // Enable teamgame if we're playing CTF.
2020- teamgame.ForceSet( Val, CVAR_Bool );
2021-
2022- Val.Bool = false;
2023- // Disable other modes.
2024- ctf.ForceSet( Val, CVAR_Bool );
2025- oneflagctf.ForceSet( Val, CVAR_Bool );
2026- domination.ForceSet( Val, CVAR_Bool );
2027- }
2028-
2029- // Reset what the current game mode is.
2030- GAMEMODE_DetermineGameMode( );
2031-}
2032-
2033-//*****************************************************************************
2034-//
2035-CUSTOM_CVAR( Bool, domination, false, CVAR_SERVERINFO | CVAR_LATCH | CVAR_CAMPAIGNLOCK )
2036-{
2037- UCVarValue Val;
2038-
2039- if ( self == true )
2040- {
2041- Val.Bool = true;
2042- // Enable teamgame if we're playing CTF.
2043- teamgame.ForceSet( Val, CVAR_Bool );
2044-
2045- Val.Bool = false;
2046- // Disable other modes.
2047- ctf.ForceSet( Val, CVAR_Bool );
2048- oneflagctf.ForceSet( Val, CVAR_Bool );
2049- skulltag.ForceSet( Val, CVAR_Bool );
2050- }
2051-
2052- // Reset what the current game mode is.
2053- GAMEMODE_DetermineGameMode( );
2054-}
1927+// [AK] Added CVAR_GAMEMODE.
1928+CVAR( Bool, teamgame, false, CVAR_SERVERINFO | CVAR_LATCH | CVAR_GAMEMODE )
1929+CVAR( Bool, ctf, false, CVAR_SERVERINFO | CVAR_LATCH | CVAR_GAMEMODE )
1930+CVAR( Bool, oneflagctf, false, CVAR_SERVERINFO | CVAR_LATCH | CVAR_GAMEMODE )
1931+CVAR( Bool, skulltag, false, CVAR_SERVERINFO | CVAR_LATCH | CVAR_GAMEMODE )
1932+CVAR( Bool, domination, false, CVAR_SERVERINFO | CVAR_LATCH | CVAR_GAMEMODE )
20551933
20561934 //*****************************************************************************
20571935 //
diff -r 4f13149bed97 -r 8873b9831575 wadsrc/static/gamemode.txt
--- a/wadsrc/static/gamemode.txt Wed Feb 09 11:38:51 2022 -0500
+++ b/wadsrc/static/gamemode.txt Wed Feb 09 11:43:18 2022 -0500
@@ -12,6 +12,7 @@
1212 Name "Cooperative"
1313 ShortName "COOP"
1414 F1Texture "F1_COOP"
15+ CVar "cooperative"
1516 }
1617
1718 // Survival co-op
@@ -27,6 +28,7 @@
2728 Name "Survival"
2829 ShortName "SURV"
2930 F1Texture "F1_SCP"
31+ CVar "survival"
3032 }
3133
3234 // Invasion
@@ -41,6 +43,7 @@
4143 Name "Invasion"
4244 ShortName "INVAS"
4345 F1Texture "F1_INV"
46+ CVar "invasion"
4447 }
4548
4649 // Regular deathmatch
@@ -52,6 +55,7 @@
5255 Name "Deathmatch"
5356 ShortName "DM"
5457 F1Texture "F1_DM"
58+ CVar "deathmatch"
5559 }
5660
5761 // Teamplay DM
@@ -64,6 +68,7 @@
6468 Name "Team Deathmatch"
6569 ShortName "TDM"
6670 F1Texture "F1_TDM"
71+ CVar "teamplay"
6772 }
6873
6974 // Duel
@@ -77,6 +82,7 @@
7782 Name "Duel"
7883 ShortName "DUEL"
7984 F1Texture "F1_DUEL"
85+ CVar "duel"
8086 }
8187
8288 // Terminator DM
@@ -88,6 +94,7 @@
8894 Name "Terminator"
8995 ShortName "TERM"
9096 F1Texture "F1_TERM"
97+ CVar "terminator"
9198 }
9299
93100 // Last man standing
@@ -104,6 +111,7 @@
104111 Name "Last Man Standing"
105112 ShortName "LMS"
106113 F1Texture "F1_LMS"
114+ CVar "lastmanstanding"
107115 }
108116
109117 // Team LMS
@@ -121,6 +129,7 @@
121129 Name "Team Last Man Standing"
122130 ShortName "TLMS"
123131 F1Texture "F1_TLMS"
132+ CVar "teamlms"
124133 }
125134
126135 // Possession DM
@@ -134,6 +143,7 @@
134143 Name "Possession"
135144 ShortName "POSS"
136145 F1Texture "F1_POSS"
146+ CVar "possession"
137147 }
138148
139149 // Team possession
@@ -147,6 +157,7 @@
147157 Name "Team Possession"
148158 ShortName "TM POSS"
149159 F1Texture "F1_TPOSS"
160+ CVar "teampossession"
150161 }
151162
152163 // Regular teamgame
@@ -159,6 +170,7 @@
159170 Name "Team Game"
160171 ShortName "TM GAME"
161172 F1Texture "F1_TMGM"
173+ CVar "teamgame"
162174 }
163175
164176 // Capture the flag
@@ -173,6 +185,7 @@
173185 Name "Capture the Flag"
174186 ShortName "CTF"
175187 F1Texture "F1_CTF"
188+ CVar "ctf"
176189 }
177190
178191 // One flag CTF
@@ -187,6 +200,7 @@
187200 Name "1-Flag CTF"
188201 ShortName "1F-CTF"
189202 F1Texture "F1_1FCTF"
203+ CVar "oneflagctf"
190204 }
191205
192206 // Skulltag
@@ -200,6 +214,7 @@
200214 Name "Skulltag"
201215 ShortName "ST"
202216 F1Texture "F1_ST"
217+ CVar "skulltag"
203218 }
204219
205220 // Domination
@@ -212,4 +227,5 @@
212227 Name "Domination"
213228 ShortName "DOM"
214229 F1Texture "F1_DOM"
230+ CVar "domination"
215231 }
\ No newline at end of file
Show on old repository browser