From f6a4036b2beedf57f2f94b63ee0212adfc0c1e2d Mon Sep 17 00:00:00 2001 From: Paweł Redman Date: Fri, 16 Feb 2018 15:02:55 +0100 Subject: Rewrite G_CalculateStages to fix bugs with trigger_stage. --- src/game/g_main.c | 69 ++++++++++++++++++++++++++++--------------------------- 1 file changed, 35 insertions(+), 34 deletions(-) (limited to 'src') diff --git a/src/game/g_main.c b/src/game/g_main.c index 7e72b87..741f61a 100644 --- a/src/game/g_main.c +++ b/src/game/g_main.c @@ -1690,8 +1690,6 @@ void G_CalculateStages( void ) { float alienPlayerCountMod = level.averageNumAlienClients / PLAYER_COUNT_MOD; float humanPlayerCountMod = level.averageNumHumanClients / PLAYER_COUNT_MOD; - static int lastAlienStageModCount = 1; - static int lastHumanStageModCount = 1; static int alienTriggerStage = 0; static int humanTriggerStage = 0; @@ -1706,9 +1704,7 @@ void G_CalculateStages( void ) g_alienStage.integer == S1 && g_alienMaxStage.integer > S1 ) { trap_Cvar_Set( "g_alienStage", va( "%d", S2 ) ); - level.alienStage2Time = level.time; - lastAlienStageModCount = g_alienStage.modificationCount; - G_LogPrintf("Stage: A 2: Aliens reached Stage 2\n"); + g_alienStage.integer = S2; // update immediately } if( g_alienKills.integer >= @@ -1716,9 +1712,7 @@ void G_CalculateStages( void ) g_alienStage.integer == S2 && g_alienMaxStage.integer > S2 ) { trap_Cvar_Set( "g_alienStage", va( "%d", S3 ) ); - level.alienStage3Time = level.time; - lastAlienStageModCount = g_alienStage.modificationCount; - G_LogPrintf("Stage: A 3: Aliens reached Stage 3\n"); + g_alienStage.integer = S3; } if( g_humanKills.integer >= @@ -1726,9 +1720,7 @@ void G_CalculateStages( void ) g_humanStage.integer == S1 && g_humanMaxStage.integer > S1 ) { trap_Cvar_Set( "g_humanStage", va( "%d", S2 ) ); - level.humanStage2Time = level.time; - lastHumanStageModCount = g_humanStage.modificationCount; - G_LogPrintf("Stage: H 2: Humans reached Stage 2\n"); + g_humanStage.integer = S2; } if( g_humanKills.integer >= @@ -1736,36 +1728,45 @@ void G_CalculateStages( void ) g_humanStage.integer == S2 && g_humanMaxStage.integer > S2 ) { trap_Cvar_Set( "g_humanStage", va( "%d", S3 ) ); - level.humanStage3Time = level.time; - G_LogPrintf("Stage: H 3: Humans reached Stage 3\n"); - lastHumanStageModCount = g_humanStage.modificationCount; + g_humanStage.integer = S3; } - - if( g_alienStage.modificationCount > lastAlienStageModCount ) + + while( alienTriggerStage < MIN( g_alienStage.integer, S3 ) ) { - G_Checktrigger_stages( PTE_ALIENS, g_alienStage.integer ); - while( alienTriggerStage < MIN( g_alienStage.integer, S3 ) ) - G_Checktrigger_stages( PTE_ALIENS, ++alienTriggerStage ); + alienTriggerStage++; + + switch( alienTriggerStage ) + { + case S2: + level.alienStage2Time = level.time; + G_LogPrintf( "Stage: A 2: Aliens reached Stage 2\n" ); + break; + case S3: + level.alienStage3Time = level.time; + G_LogPrintf( "Stage: A 3: Aliens reached Stage 3\n" ); + break; + } - if( g_alienStage.integer == S2 ) - level.alienStage2Time = level.time; - else if( g_alienStage.integer == S3 ) - level.alienStage3Time = level.time; - - lastAlienStageModCount = g_alienStage.modificationCount; + G_Checktrigger_stages( PTE_ALIENS, alienTriggerStage ); } - - if( g_humanStage.modificationCount > lastHumanStageModCount ) + + while( humanTriggerStage < MIN( g_humanStage.integer, S3 ) ) { - while( humanTriggerStage < MIN( g_humanStage.integer, S3 ) ) - G_Checktrigger_stages( PTE_HUMANS, ++humanTriggerStage ); + humanTriggerStage++; - if( g_humanStage.integer == S2 ) - level.humanStage2Time = level.time; - else if( g_humanStage.integer == S3 ) - level.humanStage3Time = level.time; + switch( humanTriggerStage ) + { + case S2: + level.humanStage2Time = level.time; + G_LogPrintf( "Stage: H 2: Humans reached Stage 2\n" ); + break; + case S3: + level.humanStage3Time = level.time; + G_LogPrintf( "Stage: H 3: Humans reached Stage 3\n" ); + break; + } - lastHumanStageModCount = g_humanStage.modificationCount; + G_Checktrigger_stages( PTE_HUMANS, humanTriggerStage ); } } -- cgit