• R/O
  • SSH

提交

標籤
無標籤

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

This is a fork of Zandronum Beta for Mac Os (Silicon and Intel)


Commit MetaInfo

修訂6cbfdc124b0578e0526c898990e28ac67ab3a84e (tree)
時間2022-10-10 05:35:32
作者Adam Kaminski <kaminskiadam9@gmai...>
CommiterAdam Kaminski

Log Message

Added "offlineonly" and "onlineonly" options to the game settings feature of the GAMEMODE lump. This allows some CVars to only be configured for offline or online games, or both.

Change Summary

差異

diff -r 9396eb2fe15d -r 6cbfdc124b05 docs/zandronum-history.txt
--- a/docs/zandronum-history.txt Sun Oct 09 15:28:27 2022 -0400
+++ b/docs/zandronum-history.txt Sun Oct 09 16:35:32 2022 -0400
@@ -34,6 +34,7 @@
3434 + - Added the CVar "cl_identifymonsters" which allows monsters to be identified with cl_identifytarget. [Kaminsky]
3535 + - Added the CCMD "rcon_logout" so that clients with RCON access may logout if they want to. This also changes the old behaviour where a client who already had RCON access could lose it if they resent the wrong password to the server. [Kaminsky]
3636 + - Added ACS function: "SetGameplaySetting", allowing modders to change gameplay-related CVars on the fly. [Kaminsky]
37++ - Added "offlineonly" and "onlineonly" options to the game settings feature of the GAMEMODE lump. This allows some CVars to only be configured for offline or online games, or both. [Kaminsky]
3738 - - Fixed: clients didn't initialize a sector's friction properly in some cases due to a superfluous check that wasn't removed earlier. [Kaminsky]
3839 - - Fixed: the server wouldn't initialize compatflags and compatflags2 properly if entered as command line parameters. [Kaminsky]
3940 - - Fixed: serverinfo CVars entered on the command line were restored in reverse order. [Kaminsky]
diff -r 9396eb2fe15d -r 6cbfdc124b05 src/gamemode.cpp
--- a/src/gamemode.cpp Sun Oct 09 15:28:27 2022 -0400
+++ b/src/gamemode.cpp Sun Oct 09 16:35:32 2022 -0400
@@ -143,6 +143,24 @@
143143 //*****************************************************************************
144144 // FUNCTIONS
145145
146+bool GAMEPLAYSETTING_s::IsOutOfScope( void )
147+{
148+ if ( Scope != GAMESCOPE_OFFLINEANDONLINE )
149+ {
150+ // [AK] "offlineonly" settings are not applied in online games.
151+ if (( Scope == GAMESCOPE_OFFLINEONLY ) && ( NETWORK_GetState( ) == NETSTATE_SERVER ))
152+ return true;
153+
154+ // [AK] "onlineonly" settings are not applied in offline games.
155+ if (( Scope == GAMESCOPE_ONLINEONLY ) && ( NETWORK_GetState( ) != NETSTATE_SERVER ))
156+ return true;
157+ }
158+
159+ return false;
160+}
161+
162+//*****************************************************************************
163+//
146164 void GAMEMODE_Tick( void )
147165 {
148166 static GAMESTATE_e oldState = GAMESTATE_UNSPECIFIED;
@@ -242,6 +260,7 @@
242260 //
243261 void GAMEMODE_ParseGameSettingBlock( FScanner &sc, const GAMEMODE_e GameMode, bool bLockCVars, bool bResetCVars )
244262 {
263+ GAMESCOPE_e Scope = GAMESCOPE_OFFLINEANDONLINE;
245264 sc.MustGetStringName( "{" );
246265
247266 // [AK] If this is the start of a "defaultgamesettings" or "defaultlockedgamesettings" block, empty the CVar
@@ -253,9 +272,34 @@
253272 g_GameModes[mode].GameplaySettings.Clear( );
254273 }
255274
256- while ( !sc.CheckString( "}" ))
275+ // [AK] Keep looping until we exited out of all blocks.
276+ while ( true )
257277 {
258278 sc.MustGetString( );
279+
280+ // [AK] "offlineonly" or "onlineonly" indicate the start of a new subblock and scope. CVars added into
281+ // either of these subblocks are only set in offline or online games respectively.
282+ if (( stricmp( sc.String, "offlineonly" ) == 0 ) || ( stricmp( sc.String, "onlineonly" ) == 0 ))
283+ {
284+ // [AK] Don't start a new subblock while in the middle of another subblock.
285+ if ( Scope != GAMESCOPE_OFFLINEANDONLINE )
286+ sc.ScriptError( "Tried to start a new \"%s\" subblock in the middle of an \"%s\" subblock.", sc.String, Scope == GAMESCOPE_OFFLINEONLY ? "offlineonly" : "onlineonly" );
287+
288+ Scope = ( stricmp( sc.String, "offlineonly" ) == 0 ) ? GAMESCOPE_OFFLINEONLY : GAMESCOPE_ONLINEONLY;
289+ sc.MustGetStringName( "{" );
290+ continue;
291+ }
292+ // [AK] This indicates the closing of a (sub)block.
293+ else if ( stricmp( sc.String, "}" ) == 0 )
294+ {
295+ // [AK] If we're not in an "offlineonly" or "onlineonly" subblock, then exit out of the game settings block entirely.
296+ if ( Scope == GAMESCOPE_OFFLINEANDONLINE )
297+ break;
298+
299+ Scope = GAMESCOPE_OFFLINEANDONLINE;
300+ continue;
301+ }
302+
259303 FBaseCVar *pCVar = FindCVar( sc.String, NULL );
260304
261305 // [AK] Make sure that this CVar exists.
@@ -327,20 +371,40 @@
327371 if (( GameMode == NUM_GAMEMODES ) || ( GameMode == static_cast<GAMEMODE_e>( mode )))
328372 {
329373 bool bPushToList = true;
374+ Setting.Scope = Scope;
330375
331376 // [AK] Check if this CVar is already in the list. We don't want to have multiple copies of the same CVar.
332377 for ( unsigned int i = 0; i < g_GameModes[GameMode].GameplaySettings.Size( ); i++ )
333378 {
334379 if ( g_GameModes[GameMode].GameplaySettings[i].pCVar == Setting.pCVar )
335380 {
336- // [AK] A locked CVar always replaces any unlocked copies of the same CVar that already exist.
337- // On the other hand, an unlocked CVar cannot replace any locked copies and will be discarded instead.
338- if (( g_GameModes[GameMode].GameplaySettings[i].bIsLocked ) && ( Setting.bIsLocked == false ))
339- bPushToList = false;
340- else
381+ // [AK] Check if these two CVars have the same scope (i.e. offline or online games only), or if the
382+ // new CVar that we're trying to add has no scope (i.e. works in both offline and online games).
383+ if (( g_GameModes[GameMode].GameplaySettings[i].Scope == Setting.Scope ) || ( Setting.Scope == GAMESCOPE_OFFLINEANDONLINE ))
384+ {
385+ // [AK] A locked CVar always replaces any unlocked copies of the same CVar that already exist.
386+ // On the other hand, an unlocked CVar cannot replace any locked copies.
387+ if (( g_GameModes[GameMode].GameplaySettings[i].bIsLocked ) && ( Setting.bIsLocked == false ))
388+ {
389+ // [AK] If the new/unlocked CVar has no scope, but the old/locked CVar is "offlineonly" or "onlineonly",
390+ // then change the new CVar's scope so that it's opposite to the old CVar's. The two CVars can then co-exist.
391+ // Otherwise, the new CVar must be discarded.
392+ if ( g_GameModes[GameMode].GameplaySettings[i].Scope != Setting.Scope )
393+ Setting.Scope = g_GameModes[GameMode].GameplaySettings[i].Scope != GAMESCOPE_OFFLINEONLY ? GAMESCOPE_OFFLINEONLY : GAMESCOPE_ONLINEONLY;
394+ else
395+ bPushToList = false;
396+
397+ break;
398+ }
399+
341400 g_GameModes[GameMode].GameplaySettings.Delete( i );
342-
343- break;
401+ }
402+ // [AK] If the old CVar has no scope, but the new CVar is "offlineonly" or "onlineonly", just change the old CVar's
403+ // scope so that it becomes opposite to the new CVar's. The two CVars can then co-exist.
404+ else if ( g_GameModes[GameMode].GameplaySettings[i].Scope == GAMESCOPE_OFFLINEANDONLINE )
405+ {
406+ g_GameModes[GameMode].GameplaySettings[i].Scope = Setting.Scope != GAMESCOPE_OFFLINEONLY ? GAMESCOPE_OFFLINEONLY : GAMESCOPE_ONLINEONLY;
407+ }
344408 }
345409 }
346410
@@ -1437,6 +1501,11 @@
14371501 if ( g_GameModes[g_CurrentGameMode].GameplaySettings[i].pCVar != pCVar )
14381502 continue;
14391503
1504+ // [AK] CVars that are "offlineonly" should only be set in offline games, and
1505+ // CVars that are "onlineonly" should only be set in online games.
1506+ if ( g_GameModes[g_CurrentGameMode].GameplaySettings[i].IsOutOfScope( ))
1507+ continue;
1508+
14401509 pSetting = &g_GameModes[g_CurrentGameMode].GameplaySettings[i];
14411510 break;
14421511 }
@@ -1472,7 +1541,12 @@
14721541
14731542 // [AK] If this CVar matches one that's locked on the list, then it's obviously locked.
14741543 if ( pCVar == g_GameModes[g_CurrentGameMode].GameplaySettings[i].pCVar )
1475- return true;
1544+ {
1545+ // [AK] CVars that are "offlineonly" are only locked in offline games, and if they're
1546+ // "onlineonly" then they're only locked in online games.
1547+ if ( g_GameModes[g_CurrentGameMode].GameplaySettings[i].IsOutOfScope( ) == false )
1548+ return true;
1549+ }
14761550 }
14771551
14781552 return false;
@@ -1490,8 +1564,9 @@
14901564 {
14911565 GAMEPLAYSETTING_s *const pSetting = &g_GameModes[g_CurrentGameMode].GameplaySettings[i];
14921566
1493- // [AK] Only reset unlocked CVars if we need to.
1494- if (( bLockedOnly ) && ( pSetting->bIsLocked == false ))
1567+ // [AK] Only reset unlocked CVars if we need to. Also, CVars that are "offlineonly" should only
1568+ // be reset in offline games, and CVars that are "onlineonly" should only be reset in online games.
1569+ if ((( bLockedOnly ) && ( pSetting->bIsLocked == false )) || ( pSetting->IsOutOfScope( )))
14951570 continue;
14961571
14971572 // [AK] Do we also want to reset this CVar to its default value?
diff -r 9396eb2fe15d -r 6cbfdc124b05 src/gamemode.h
--- a/src/gamemode.h Sun Oct 09 15:28:27 2022 -0400
+++ b/src/gamemode.h Sun Oct 09 16:35:32 2022 -0400
@@ -131,6 +131,14 @@
131131 } GAMELIMIT_e;
132132
133133 //*****************************************************************************
134+typedef enum
135+{
136+ GAMESCOPE_OFFLINEANDONLINE = 0,
137+ GAMESCOPE_OFFLINEONLY,
138+ GAMESCOPE_ONLINEONLY
139+} GAMESCOPE_e;
140+
141+//*****************************************************************************
134142 // STRUCTURES
135143
136144 typedef struct
@@ -151,6 +159,11 @@
151159 // [AK] The CVar is locked and cannot be changed from the console.
152160 bool bIsLocked;
153161
162+ // [AK] What kind of game (i.e. offline, online, or both) is the CVar's value applied.
163+ GAMESCOPE_e Scope;
164+
165+ bool IsOutOfScope( void );
166+
154167 } GAMEPLAYSETTING_s;
155168
156169 //*****************************************************************************