diff options
-rw-r--r-- | src/game/g_active.c | 2 | ||||
-rw-r--r-- | src/game/g_local.h | 9 | ||||
-rw-r--r-- | src/game/g_main.c | 134 | ||||
-rw-r--r-- | src/game/g_mover.c | 2 | ||||
-rw-r--r-- | src/game/g_spawn.c | 39 | ||||
-rw-r--r-- | src/game/g_trigger.c | 2 |
6 files changed, 81 insertions, 107 deletions
diff --git a/src/game/g_active.c b/src/game/g_active.c index fa18c30c..d7e73b20 100644 --- a/src/game/g_active.c +++ b/src/game/g_active.c @@ -1347,7 +1347,7 @@ void ClientThink_real( gentity_t *ent ) client->lastPoisonTime + ALIEN_POISON_TIME < level.time ) client->ps.stats[ STAT_STATE ] &= ~SS_POISONED; - client->ps.gravity = level.gravity; + client->ps.gravity = g_gravity.value; if( BG_InventoryContainsUpgrade( UP_MEDKIT, client->ps.stats ) && BG_UpgradeIsActive( UP_MEDKIT, client->ps.stats ) ) diff --git a/src/game/g_local.h b/src/game/g_local.h index d7f5890a..691e932a 100644 --- a/src/game/g_local.h +++ b/src/game/g_local.h @@ -627,15 +627,6 @@ typedef struct gentity_t *markedBuildables[ MAX_GENTITIES ]; int numBuildablesForRemoval; - // map/cvar-set values - float gravity; - int humanMaxStage; - int humanStage2Threshold; - int humanStage3Threshold; - int alienMaxStage; - int alienStage2Threshold; - int alienStage3Threshold; - int alienKills; int humanKills; diff --git a/src/game/g_main.c b/src/game/g_main.c index 196e6a8b..d44b13fb 100644 --- a/src/game/g_main.c +++ b/src/game/g_main.c @@ -28,12 +28,16 @@ level_locals_t level; typedef struct { vmCvar_t *vmCvar; - char *cvarName; - char *defaultString; - int cvarFlags; - int modificationCount; // for tracking changes - qboolean trackChange; // track this variable, and announce if changed - void (*update)( const char *, vmCvar_t * ); + char *cvarName; + char *defaultString; + int cvarFlags; + int modificationCount; // for tracking changes + qboolean trackChange; // track this variable, and announce if changed + /* certain cvars can be set in worldspawn, but we don't want those values to + persist, so keep track of non-worldspawn changes and restore that on map + end. unfortunately, if the server crashes, the value set in worldspawn may + persist */ + char *explicit; } cvarTable_t; gentity_t g_entities[ MAX_GENTITIES ]; @@ -139,13 +143,11 @@ vmCvar_t g_censorship; vmCvar_t g_tag; -static void G_cvgravity( const char *name, vmCvar_t *cvar ); -static void G_cvhumanMaxStage( const char *name, vmCvar_t *cvar ); -static void G_cvhumanStage2Threshold( const char *name, vmCvar_t *cvar ); -static void G_cvhumanStage3Threshold( const char *name, vmCvar_t *cvar ); -static void G_cvalienMaxStage( const char *name, vmCvar_t *cvar ); -static void G_cvalienStage2Threshold( const char *name, vmCvar_t *cvar ); -static void G_cvalienStage3Threshold( const char *name, vmCvar_t *cvar ); + +// copy cvars that can be set in worldspawn so they can be restored later +static char cv_gravity[ MAX_CVAR_VALUE_STRING ]; +static char cv_humanMaxStage[ MAX_CVAR_VALUE_STRING ]; +static char cv_alienMaxStage[ MAX_CVAR_VALUE_STRING ]; static cvarTable_t gameCvarTable[ ] = { @@ -190,7 +192,7 @@ static cvarTable_t gameCvarTable[ ] = { &g_dedicated, "dedicated", "0", 0, 0, qfalse }, { &g_speed, "g_speed", "320", 0, 0, qtrue }, - { &g_gravity, "g_gravity", "800", 0, 0, qtrue, G_cvgravity }, + { &g_gravity, "g_gravity", "800", 0, 0, qtrue, cv_gravity }, { &g_knockback, "g_knockback", "1000", 0, 0, qtrue }, { &g_inactivity, "g_inactivity", "0", 0, 0, qtrue }, { &g_debugMove, "g_debugMove", "0", 0, 0, qfalse }, @@ -217,14 +219,14 @@ static cvarTable_t gameCvarTable[ ] = { &g_humanRepeaterBuildQueueTime, "g_humanRepeaterBuildQueueTime", DEFAULT_HUMAN_REPEATER_QUEUE_TIME, CVAR_ARCHIVE, 0, qfalse }, { &g_humanStage, "g_humanStage", "0", 0, 0, qfalse }, { &g_humanCredits, "g_humanCredits", "0", 0, 0, qfalse }, - { &g_humanMaxStage, "g_humanMaxStage", DEFAULT_HUMAN_MAX_STAGE, 0, 0, qfalse, G_cvhumanMaxStage }, - { &g_humanStage2Threshold, "g_humanStage2Threshold", DEFAULT_HUMAN_STAGE2_THRESH, 0, 0, qfalse, G_cvhumanStage2Threshold }, - { &g_humanStage3Threshold, "g_humanStage3Threshold", DEFAULT_HUMAN_STAGE3_THRESH, 0, 0, qfalse, G_cvhumanStage3Threshold }, + { &g_humanMaxStage, "g_humanMaxStage", DEFAULT_HUMAN_MAX_STAGE, 0, 0, qfalse, cv_humanMaxStage }, + { &g_humanStage2Threshold, "g_humanStage2Threshold", DEFAULT_HUMAN_STAGE2_THRESH, 0, 0, qfalse }, + { &g_humanStage3Threshold, "g_humanStage3Threshold", DEFAULT_HUMAN_STAGE3_THRESH, 0, 0, qfalse }, { &g_alienStage, "g_alienStage", "0", 0, 0, qfalse }, { &g_alienCredits, "g_alienCredits", "0", 0, 0, qfalse }, - { &g_alienMaxStage, "g_alienMaxStage", DEFAULT_ALIEN_MAX_STAGE, 0, 0, qfalse, G_cvalienMaxStage }, - { &g_alienStage2Threshold, "g_alienStage2Threshold", DEFAULT_ALIEN_STAGE2_THRESH, 0, 0, qfalse, G_cvalienStage2Threshold }, - { &g_alienStage3Threshold, "g_alienStage3Threshold", DEFAULT_ALIEN_STAGE3_THRESH, 0, 0, qfalse, G_cvalienStage3Threshold }, + { &g_alienMaxStage, "g_alienMaxStage", DEFAULT_ALIEN_MAX_STAGE, 0, 0, qfalse, cv_alienMaxStage }, + { &g_alienStage2Threshold, "g_alienStage2Threshold", DEFAULT_ALIEN_STAGE2_THRESH, 0, 0, qfalse }, + { &g_alienStage3Threshold, "g_alienStage3Threshold", DEFAULT_ALIEN_STAGE3_THRESH, 0, 0, qfalse }, { &g_teamImbalanceWarnings, "g_teamImbalanceWarnings", "30", CVAR_ARCHIVE, 0, qfalse }, { &g_freeFundPeriod, "g_freeFundPeriod", DEFAULT_FREEKILL_PERIOD, CVAR_ARCHIVE, 0, qtrue }, @@ -339,35 +341,6 @@ Q_EXPORT intptr_t vmMain( int command, int arg0, int arg1, int arg2, int arg3, i return -1; } -static void G_cvgravity( const char *name, vmCvar_t *cvar ) -{ - level.gravity = cvar->value; -} -static void G_cvhumanMaxStage( const char *name, vmCvar_t *cvar ) -{ - level.humanMaxStage = cvar->integer; -} -static void G_cvhumanStage2Threshold( const char *name, vmCvar_t *cvar ) -{ - level.humanStage2Threshold = cvar->integer; -} -static void G_cvhumanStage3Threshold( const char *name, vmCvar_t *cvar ) -{ - level.humanStage3Threshold = cvar->integer; -} -static void G_cvalienMaxStage( const char *name, vmCvar_t *cvar ) -{ - level.alienMaxStage = cvar->integer; -} -static void G_cvalienStage2Threshold( const char *name, vmCvar_t *cvar ) -{ - level.alienStage2Threshold = cvar->integer; -} -static void G_cvalienStage3Threshold( const char *name, vmCvar_t *cvar ) -{ - level.alienStage3Threshold = cvar->integer; -} - void QDECL G_Printf( const char *fmt, ... ) { @@ -479,8 +452,8 @@ void G_RegisterCvars( void ) if( cv->vmCvar ) cv->modificationCount = cv->vmCvar->modificationCount; - if( cv->update ) - cv->update( cv->cvarName, cv->vmCvar ); + if( cv->explicit ) + strcpy( cv->explicit, cv->vmCvar->string ); } } @@ -508,8 +481,8 @@ void G_UpdateCvars( void ) trap_SendServerCommand( -1, va( "print \"Server: %s changed to %s\n\"", cv->cvarName, cv->vmCvar->string ) ); - if( cv->update ) - cv->update( cv->cvarName, cv->vmCvar ); + if( !level.spawning && cv->explicit ) + strcpy( cv->explicit, cv->vmCvar->string ); } } } @@ -517,6 +490,23 @@ void G_UpdateCvars( void ) /* ================= +G_RestoreCvars +================= +*/ +void G_RestoreCvars( void ) +{ + int i; + cvarTable_t *cv; + + for( i = 0, cv = gameCvarTable; i < gameCvarTableSize; i++, cv++ ) + { + if( cv->vmCvar && cv->explicit ) + trap_Cvar_Set( cv->cvarName, cv->explicit ); + } +} + +/* +================= G_MapConfigs ================= */ @@ -640,6 +630,8 @@ void G_InitGame( int levelTime, int randomSeed, int restart ) // test to see if a custom buildable layout will be loaded G_LayoutSelect( ); + // this has to be flipped after the first UpdateCvars + level.spawning = qtrue; // parse the key/value pairs and spawn gentities G_SpawnEntitiesFromString( ); @@ -715,6 +707,8 @@ void G_ShutdownGame( int restart ) // in case of a map_restart G_ClearVotes( ); + G_RestoreCvars( ); + G_Printf( "==== ShutdownGame ====\n" ); if( level.logFile ) @@ -1286,8 +1280,8 @@ void G_CalculateStages( void ) humanPlayerCountMod = 0.1f; if( g_alienCredits.integer >= - (int)( ceil( (float)level.alienStage2Threshold * alienPlayerCountMod ) ) && - g_alienStage.integer == S1 && level.alienMaxStage > S1 ) + (int)( ceil( (float)g_alienStage2Threshold.integer * alienPlayerCountMod ) ) && + g_alienStage.integer == S1 && g_alienMaxStage.integer > S1 ) { trap_Cvar_Set( "g_alienStage", va( "%d", S2 ) ); level.alienStage2Time = level.time; @@ -1296,8 +1290,8 @@ void G_CalculateStages( void ) } if( g_alienCredits.integer >= - (int)( ceil( (float)level.alienStage3Threshold * alienPlayerCountMod ) ) && - g_alienStage.integer == S2 && level.alienMaxStage > S2 ) + (int)( ceil( (float)g_alienStage3Threshold.integer * alienPlayerCountMod ) ) && + g_alienStage.integer == S2 && g_alienMaxStage.integer > S2 ) { trap_Cvar_Set( "g_alienStage", va( "%d", S3 ) ); level.alienStage3Time = level.time; @@ -1306,8 +1300,8 @@ void G_CalculateStages( void ) } if( g_humanCredits.integer >= - (int)( ceil( (float)level.humanStage2Threshold * humanPlayerCountMod ) ) && - g_humanStage.integer == S1 && level.humanMaxStage > S1 ) + (int)( ceil( (float)g_humanStage2Threshold.integer * humanPlayerCountMod ) ) && + g_humanStage.integer == S1 && g_humanMaxStage.integer > S1 ) { trap_Cvar_Set( "g_humanStage", va( "%d", S2 ) ); level.humanStage2Time = level.time; @@ -1316,8 +1310,8 @@ void G_CalculateStages( void ) } if( g_humanCredits.integer >= - (int)( ceil( (float)level.humanStage3Threshold * humanPlayerCountMod ) ) && - g_humanStage.integer == S2 && level.humanMaxStage > S2 ) + (int)( ceil( (float)g_humanStage3Threshold.integer * humanPlayerCountMod ) ) && + g_humanStage.integer == S2 && g_humanMaxStage.integer > S2 ) { trap_Cvar_Set( "g_humanStage", va( "%d", S3 ) ); level.humanStage3Time = level.time; @@ -1349,17 +1343,17 @@ void G_CalculateStages( void ) lastHumanStageModCount = g_humanStage.modificationCount; } - if( g_alienStage.integer == S1 && level.alienMaxStage > S1 ) - alienNextStageThreshold = (int)( ceil( (float)level.alienStage2Threshold * alienPlayerCountMod ) ); - else if( g_alienStage.integer == S2 && level.alienMaxStage > S2 ) - alienNextStageThreshold = (int)( ceil( (float)level.alienStage3Threshold * alienPlayerCountMod ) ); + if( g_alienStage.integer == S1 && g_alienMaxStage.integer > S1 ) + alienNextStageThreshold = (int)( ceil( (float)g_alienStage2Threshold.integer * alienPlayerCountMod ) ); + else if( g_alienStage.integer == S2 && g_alienMaxStage.integer > S2 ) + alienNextStageThreshold = (int)( ceil( (float)g_alienStage3Threshold.integer * alienPlayerCountMod ) ); else alienNextStageThreshold = -1; - if( g_humanStage.integer == S1 && level.humanMaxStage > S1 ) - humanNextStageThreshold = (int)( ceil( (float)level.humanStage2Threshold * humanPlayerCountMod ) ); - else if( g_humanStage.integer == S2 && level.humanMaxStage > S2 ) - humanNextStageThreshold = (int)( ceil( (float)level.humanStage3Threshold * humanPlayerCountMod ) ); + if( g_humanStage.integer == S1 && g_humanMaxStage.integer > S1 ) + humanNextStageThreshold = (int)( ceil( (float)g_humanStage2Threshold.integer * humanPlayerCountMod ) ); + else if( g_humanStage.integer == S2 && g_humanMaxStage.integer > S2 ) + humanNextStageThreshold = (int)( ceil( (float)g_humanStage3Threshold.integer * humanPlayerCountMod ) ); else humanNextStageThreshold = -1; @@ -2379,6 +2373,8 @@ void G_RunFrame( int levelTime ) // get any cvar changes G_UpdateCvars( ); CheckCvars( ); + // now we are done spawning + level.spawning = qfalse; // // go through all allocated objects diff --git a/src/game/g_mover.c b/src/game/g_mover.c index 48f3c37b..ad660d0a 100644 --- a/src/game/g_mover.c +++ b/src/game/g_mover.c @@ -2456,7 +2456,7 @@ void SP_func_pendulum( gentity_t *ent ) if( length < 8 ) length = 8; - freq = 1 / ( M_PI * 2 ) * sqrt( level.gravity / ( 3 * length ) ); + freq = 1 / ( M_PI * 2 ) * sqrt( g_gravity.value / ( 3 * length ) ); ent->s.pos.trDuration = ( 1000 / freq ); diff --git a/src/game/g_spawn.c b/src/game/g_spawn.c index 43e2c34b..45b10f93 100644 --- a/src/game/g_spawn.c +++ b/src/game/g_spawn.c @@ -31,6 +31,7 @@ qboolean G_SpawnString( const char *key, const char *defaultString, char **out ) { *out = (char *)defaultString; // G_Error( "G_SpawnString() called while not spawning" ); + return qfalse; } for( i = 0; i < level.numSpawnVars; i++ ) @@ -602,33 +603,23 @@ void SP_worldspawn( void ) trap_SetConfigstring( CS_MOTD, g_motd.string ); // message of the day - G_SpawnFloat( "gravity", "800", &level.gravity ); - - G_SpawnInt( "humanMaxStage", DEFAULT_HUMAN_MAX_STAGE, &level.humanMaxStage ); - - G_SpawnInt( "humanStage2Threshold", DEFAULT_HUMAN_STAGE2_THRESH, - &level.humanStage2Threshold ); + if( G_SpawnString( "gravity", "", &s ) ) + trap_Cvar_Set( "g_gravity", s ); - G_SpawnInt( "humanStage3Threshold", DEFAULT_HUMAN_STAGE3_THRESH, - &level.humanStage3Threshold ); + if( G_SpawnString( "humanMaxStage", "", &s ) ) + trap_Cvar_Set( "g_humanMaxStage", s ); - G_SpawnInt( "alienMaxStage", DEFAULT_ALIEN_MAX_STAGE, - &level.alienMaxStage ); + if( G_SpawnString( "alienMaxStage", "", &s ) ) + trap_Cvar_Set( "g_alienMaxStage", s ); - G_SpawnInt( "alienStage2Threshold", DEFAULT_ALIEN_STAGE2_THRESH, - &level.alienStage2Threshold ); + if( G_SpawnString( "disabledEquipment", "", &s ) ) + trap_Cvar_Set( "g_disabledEquipment", s ); - G_SpawnInt( "alienStage3Threshold", DEFAULT_ALIEN_STAGE3_THRESH, - &level.alienStage3Threshold ); + if( G_SpawnString( "disabledClasses", "", &s ) ) + trap_Cvar_Set( "g_disabledClasses", s ); - G_SpawnString( "disabledEquipment", "", &s ); - trap_Cvar_Set( "g_disabledEquipment", s ); - - G_SpawnString( "disabledClasses", "", &s ); - trap_Cvar_Set( "g_disabledClasses", s ); - - G_SpawnString( "disabledBuildables", "", &s ); - trap_Cvar_Set( "g_disabledBuildables", s ); + if( G_SpawnString( "disabledBuildables", "", &s ) ) + trap_Cvar_Set( "g_disabledBuildables", s ); g_entities[ ENTITYNUM_WORLD ].s.number = ENTITYNUM_WORLD; g_entities[ ENTITYNUM_WORLD ].classname = "worldspawn"; @@ -657,8 +648,6 @@ Parses textual entity definitions out of an entstring and spawns gentities. */ void G_SpawnEntitiesFromString( void ) { - // allow calls to G_Spawn*() - level.spawning = qtrue; level.numSpawnVars = 0; // the worldspawn is not an actual entity, but it still @@ -672,7 +661,5 @@ void G_SpawnEntitiesFromString( void ) // parse ents while( G_ParseSpawnVars( ) ) G_SpawnGEntityFromSpawnVars( ); - - level.spawning = qfalse; // any future calls to G_Spawn*() will be errors } diff --git a/src/game/g_trigger.c b/src/game/g_trigger.c index 0985b0f1..65bf1bd1 100644 --- a/src/game/g_trigger.c +++ b/src/game/g_trigger.c @@ -185,7 +185,7 @@ void AimAtTarget( gentity_t *self ) } height = ent->s.origin[ 2 ] - origin[ 2 ]; - gravity = level.gravity; + gravity = g_gravity.value; time = sqrt( height / ( 0.5 * gravity ) ); if( !time ) |