This is a fork of Zandronum Beta for Mac Os (Silicon and Intel)
修訂 | 6cbfdc124b0578e0526c898990e28ac67ab3a84e (tree) |
---|---|
時間 | 2022-10-10 05:35:32 |
作者 | Adam Kaminski <kaminskiadam9@gmai...> |
Commiter | Adam Kaminski |
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.
@@ -34,6 +34,7 @@ | ||
34 | 34 | + - Added the CVar "cl_identifymonsters" which allows monsters to be identified with cl_identifytarget. [Kaminsky] |
35 | 35 | + - 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] |
36 | 36 | + - 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] | |
37 | 38 | - - Fixed: clients didn't initialize a sector's friction properly in some cases due to a superfluous check that wasn't removed earlier. [Kaminsky] |
38 | 39 | - - Fixed: the server wouldn't initialize compatflags and compatflags2 properly if entered as command line parameters. [Kaminsky] |
39 | 40 | - - Fixed: serverinfo CVars entered on the command line were restored in reverse order. [Kaminsky] |
@@ -143,6 +143,24 @@ | ||
143 | 143 | //***************************************************************************** |
144 | 144 | // FUNCTIONS |
145 | 145 | |
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 | +// | |
146 | 164 | void GAMEMODE_Tick( void ) |
147 | 165 | { |
148 | 166 | static GAMESTATE_e oldState = GAMESTATE_UNSPECIFIED; |
@@ -242,6 +260,7 @@ | ||
242 | 260 | // |
243 | 261 | void GAMEMODE_ParseGameSettingBlock( FScanner &sc, const GAMEMODE_e GameMode, bool bLockCVars, bool bResetCVars ) |
244 | 262 | { |
263 | + GAMESCOPE_e Scope = GAMESCOPE_OFFLINEANDONLINE; | |
245 | 264 | sc.MustGetStringName( "{" ); |
246 | 265 | |
247 | 266 | // [AK] If this is the start of a "defaultgamesettings" or "defaultlockedgamesettings" block, empty the CVar |
@@ -253,9 +272,34 @@ | ||
253 | 272 | g_GameModes[mode].GameplaySettings.Clear( ); |
254 | 273 | } |
255 | 274 | |
256 | - while ( !sc.CheckString( "}" )) | |
275 | + // [AK] Keep looping until we exited out of all blocks. | |
276 | + while ( true ) | |
257 | 277 | { |
258 | 278 | 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 | + | |
259 | 303 | FBaseCVar *pCVar = FindCVar( sc.String, NULL ); |
260 | 304 | |
261 | 305 | // [AK] Make sure that this CVar exists. |
@@ -327,20 +371,40 @@ | ||
327 | 371 | if (( GameMode == NUM_GAMEMODES ) || ( GameMode == static_cast<GAMEMODE_e>( mode ))) |
328 | 372 | { |
329 | 373 | bool bPushToList = true; |
374 | + Setting.Scope = Scope; | |
330 | 375 | |
331 | 376 | // [AK] Check if this CVar is already in the list. We don't want to have multiple copies of the same CVar. |
332 | 377 | for ( unsigned int i = 0; i < g_GameModes[GameMode].GameplaySettings.Size( ); i++ ) |
333 | 378 | { |
334 | 379 | if ( g_GameModes[GameMode].GameplaySettings[i].pCVar == Setting.pCVar ) |
335 | 380 | { |
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 | + | |
341 | 400 | 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 | + } | |
344 | 408 | } |
345 | 409 | } |
346 | 410 |
@@ -1437,6 +1501,11 @@ | ||
1437 | 1501 | if ( g_GameModes[g_CurrentGameMode].GameplaySettings[i].pCVar != pCVar ) |
1438 | 1502 | continue; |
1439 | 1503 | |
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 | + | |
1440 | 1509 | pSetting = &g_GameModes[g_CurrentGameMode].GameplaySettings[i]; |
1441 | 1510 | break; |
1442 | 1511 | } |
@@ -1472,7 +1541,12 @@ | ||
1472 | 1541 | |
1473 | 1542 | // [AK] If this CVar matches one that's locked on the list, then it's obviously locked. |
1474 | 1543 | 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 | + } | |
1476 | 1550 | } |
1477 | 1551 | |
1478 | 1552 | return false; |
@@ -1490,8 +1564,9 @@ | ||
1490 | 1564 | { |
1491 | 1565 | GAMEPLAYSETTING_s *const pSetting = &g_GameModes[g_CurrentGameMode].GameplaySettings[i]; |
1492 | 1566 | |
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( ))) | |
1495 | 1570 | continue; |
1496 | 1571 | |
1497 | 1572 | // [AK] Do we also want to reset this CVar to its default value? |
@@ -131,6 +131,14 @@ | ||
131 | 131 | } GAMELIMIT_e; |
132 | 132 | |
133 | 133 | //***************************************************************************** |
134 | +typedef enum | |
135 | +{ | |
136 | + GAMESCOPE_OFFLINEANDONLINE = 0, | |
137 | + GAMESCOPE_OFFLINEONLY, | |
138 | + GAMESCOPE_ONLINEONLY | |
139 | +} GAMESCOPE_e; | |
140 | + | |
141 | +//***************************************************************************** | |
134 | 142 | // STRUCTURES |
135 | 143 | |
136 | 144 | typedef struct |
@@ -151,6 +159,11 @@ | ||
151 | 159 | // [AK] The CVar is locked and cannot be changed from the console. |
152 | 160 | bool bIsLocked; |
153 | 161 | |
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 | + | |
154 | 167 | } GAMEPLAYSETTING_s; |
155 | 168 | |
156 | 169 | //***************************************************************************** |