Skip to content

Commit

Permalink
New cvar: g_autoGameLimits: if set, uses the frag, capture and time…
Browse files Browse the repository at this point in the history
… limits set in the .info or .arena files rather than the ones specified by the user. (#332)
  • Loading branch information
NeonKnightOA committed Apr 4, 2024
1 parent e2f919f commit 0019d03
Show file tree
Hide file tree
Showing 3 changed files with 119 additions and 36 deletions.
8 changes: 8 additions & 0 deletions code/game/g_cmds.c
Original file line number Diff line number Diff line change
Expand Up @@ -1854,6 +1854,10 @@ void Cmd_CallVote_f( gentity_t *ent ) {
Com_sprintf( level.voteDisplayString, sizeof( level.voteDisplayString ), "%s", "Next map?" );
} else if ( Q_strequal( arg1, "fraglimit" ) ) {
i = atoi(arg2);
if(g_autoGameLimits.integer) {
trap_SendServerCommand( ent-g_entities, "print \"Cannot set fraglimit while g_autoGameLimits is active.\n\"" );
return;
}
if(!allowedFraglimit(i)) {
trap_SendServerCommand( ent-g_entities, "print \"Cannot set fraglimit.\n\"" );
return;
Expand All @@ -1869,6 +1873,10 @@ void Cmd_CallVote_f( gentity_t *ent ) {
}
else if ( Q_strequal( arg1, "timelimit" ) ) {
i = atoi(arg2);
if(g_autoGameLimits.integer) {
trap_SendServerCommand( ent-g_entities, "print \"Cannot set timelimit while g_autoGameLimits is active.\n\"" );
return;
}
if(!allowedTimelimit(i)) {
trap_SendServerCommand( ent-g_entities, "print \"Cannot set timelimit.\n\"" );
return;
Expand Down
3 changes: 3 additions & 0 deletions code/game/g_local.h
Original file line number Diff line number Diff line change
Expand Up @@ -1204,6 +1204,8 @@ extern vmCvar_t g_mapInfoTimeToBeatGold;
extern vmCvar_t g_mapInfoTimeToBeatSilver;
extern vmCvar_t g_mapInfoTimeToBeatBronze;

extern vmCvar_t g_autoGameLimits;

void trap_Printf( const char *fmt );
void trap_Error( const char *fmt ) __attribute__((noreturn));
int trap_Milliseconds( void );
Expand Down Expand Up @@ -1465,6 +1467,7 @@ qboolean G_GametypeUsesRunes(int check); /* Whether the gametype uses the Runes.
int G_GetAttackingTeam(void); /* Returns the team that's currently on offense in eCTF AvD. */
void MapInfoSaveIntoCvars(mapinfo_result_t *info); /* Saves the values from the .info file into cvars for later use.*/
void G_SetMapFragLimit (char *mapname); /* Sets the fraglimit for the map.*/
void G_SetMapCaptureLimit (char *mapname); /* Sets the capturelimit for the map.*/
void G_SetMapTimeLimit (char *mapname); /* Sets the timelimit for the map.*/
void G_SetMapSpecial (char *mapname); /* Sets the special condition for the map.*/
void G_SetMapBots (char *mapname); /* Sets the bot list for the map.*/
Expand Down
144 changes: 108 additions & 36 deletions code/game/g_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,8 @@ vmCvar_t g_mapInfoTimeToBeatGold;
vmCvar_t g_mapInfoTimeToBeatSilver;
vmCvar_t g_mapInfoTimeToBeatBronze;

vmCvar_t g_autoGameLimits;

mapinfo_result_t mapinfo;

// bk001129 - made static to avoid aliasing
Expand Down Expand Up @@ -451,7 +453,9 @@ static cvarTable_t gameCvarTable[] = {
{ &g_mapInfoTimeToBeatPlatinum, "sp_TimeToBeatPlatinum", "0", 0, 0, qtrue},
{ &g_mapInfoTimeToBeatGold, "sp_TimeToBeatGold", "0", 0, 0, qtrue},
{ &g_mapInfoTimeToBeatSilver, "sp_TimeToBeatSilver", "0", 0, 0, qtrue},
{ &g_mapInfoTimeToBeatBronze, "sp_TimeToBeatBronze", "0", 0, 0, qtrue}
{ &g_mapInfoTimeToBeatBronze, "sp_TimeToBeatBronze", "0", 0, 0, qtrue},

{ &g_autoGameLimits, "g_autoGameLimits", "0", CVAR_ARCHIVE, 0, qtrue}
};

// bk001129 - made static to avoid aliasing
Expand Down Expand Up @@ -807,20 +811,25 @@ void G_InitGame( int levelTime, int randomSeed, int restart )

MapInfoPrint(&mapinfo);
MapInfoSaveIntoCvars(&mapinfo);
if ( g_gametype.integer == GT_SINGLE_PLAYER || g_autoGameLimits.integer) {
if (G_GametypeUsesFragLimit(g_gametype.integer)) {
G_SetMapFragLimit(mapname);
G_Printf("^3Content of sp_FragLimit: ^7%i.\n",g_mapInfoFragLimit.integer);
}
else if (G_GametypeUsesCaptureLimit(g_gametype.integer)) {
G_SetMapCaptureLimit(mapname);
G_Printf("^3Content of sp_CaptureLimit: ^7%i.\n",g_mapInfoCaptureLimit.integer);
}
G_SetMapTimeLimit(mapname);
G_Printf("^3Content of sp_TimeLimit: ^7%i.\n",g_mapInfoTimeLimit.integer);
}

//disable unwanted cvars
if( g_gametype.integer == GT_SINGLE_PLAYER ) {
char specialMatch[64];

G_SetMapFragLimit(mapname);
G_SetMapTimeLimit(mapname);
G_SetMapSpecial(mapname);
G_SetMapBots(mapname);

G_Printf("^3Content of sp_FragLimit: ^7%i.\n",g_mapInfoFragLimit.integer);
G_Printf("^3Content of sp_TimeLimit: ^7%i.\n",g_mapInfoTimeLimit.integer);
G_Printf("^3Content of sp_Special: ^7%i.\n",g_mapInfoSpecial.integer);
G_Printf("^3Content of sp_Bots: ^7%i.\n",g_mapInfoBotList.integer);

Q_strncpyz( specialMatch, g_mapInfoSpecial.string, sizeof(specialMatch) );

Expand Down Expand Up @@ -935,6 +944,9 @@ void G_InitGame( int levelTime, int randomSeed, int restart )
}
g_regen.integer = 0;
g_doWarmup.integer = 0;

G_SetMapBots(mapname);
G_Printf("^3Content of sp_Bots: ^7%i.\n",g_mapInfoBotList.integer);
}

G_ProcessIPBans();
Expand Down Expand Up @@ -1110,13 +1122,6 @@ void G_InitGame( int levelTime, int randomSeed, int restart )
G_RunScript("mapscripts/g_default.cfg");
if(G_RunScript(va("mapscripts/g_%s_%i.cfg",mapname,g_gametype.integer)))
G_RunScript(va("mapscripts/g_default_%i.cfg",g_gametype.integer) );

if (g_gametype.integer == GT_SINGLE_PLAYER) {
G_Printf("^3Content of sp_FragLimit: ^7%i.\n",g_mapInfoFragLimit.integer);
G_Printf("^3Content of sp_TimeLimit: ^7%i.\n",g_mapInfoTimeLimit.integer);
G_Printf("^3Content of sp_Special: ^7%i.\n",g_mapInfoSpecial.integer);
G_Printf("^3Content of sp_Bots: ^7%i.\n",g_mapInfoBotList.integer);
}
}


Expand Down Expand Up @@ -2260,12 +2265,18 @@ void CheckExitRules( void )
return;
}

if ( g_timelimit.integer < 0 || g_timelimit.integer > INT_MAX / 60000 ) {
G_Printf( "timelimit %i is out of range, defaulting to 0\n", g_timelimit.integer );
trap_Cvar_Set( "timelimit", "0" );
if (g_autoGameLimits.integer) {
G_Printf( "g_autoGameLimits set, timelimit cannot be changed.\n" );
trap_Cvar_Set( "timelimit", va("%i",g_mapInfoTimeLimit.integer) );
trap_Cvar_Update( &g_timelimit );
}

else {
if ( g_timelimit.integer < 0 || g_timelimit.integer > INT_MAX / 60000 ) {
G_Printf( "timelimit %i is out of range, defaulting to 0\n", g_timelimit.integer );
trap_Cvar_Set( "timelimit", "0" );
trap_Cvar_Update( &g_timelimit );
}
}
if ( g_timelimit.integer > 0 && !level.warmupTime ) {
if ( (level.time - level.startTime)/60000 >= g_timelimit.integer ) {
trap_SendServerCommand( -1, "print \"Timelimit hit.\n\"");
Expand All @@ -2279,11 +2290,18 @@ void CheckExitRules( void )
}

if (G_GametypeUsesFragLimit(g_gametype.integer)) {
if ( g_fraglimit.integer < 0 ) {
G_Printf( "fraglimit %i is out of range, defaulting to 0\n", g_fraglimit.integer );
trap_Cvar_Set( "fraglimit", "0" );
if (g_autoGameLimits.integer) {
G_Printf( "g_autoGameLimits set, fraglimit cannot be changed.\n" );
trap_Cvar_Set( "fraglimit", va("%i",g_mapInfoFragLimit.integer) );
trap_Cvar_Update( &g_fraglimit );
}
else {
if ( g_fraglimit.integer < 0 ) {
G_Printf( "fraglimit %i is out of range, defaulting to 0\n", g_fraglimit.integer );
trap_Cvar_Set( "fraglimit", "0" );
trap_Cvar_Update( &g_fraglimit );
}
}
if ( g_fraglimit.integer ) {
if ( G_IsATeamGametype(g_gametype.integer) ) {
if ( level.teamScores[TEAM_RED] >= g_fraglimit.integer ) {
Expand Down Expand Up @@ -2319,12 +2337,18 @@ void CheckExitRules( void )
}
}
else if (G_GametypeUsesCaptureLimit(g_gametype.integer)) {
if ( g_capturelimit.integer < 0 ) {
G_Printf( "capturelimit %i is out of range, defaulting to 0\n", g_capturelimit.integer );
trap_Cvar_Set( "capturelimit", "0" );
if (g_autoGameLimits.integer) {
G_Printf( "g_autoGameLimits set, capturelimit cannot be changed.\n" );
trap_Cvar_Set( "capturelimit", va("%i",g_mapInfoCaptureLimit.integer) );
trap_Cvar_Update( &g_capturelimit );
}

else {
if ( g_capturelimit.integer < 0 ) {
G_Printf( "capturelimit %i is out of range, defaulting to 0\n", g_capturelimit.integer );
trap_Cvar_Set( "capturelimit", "0" );
trap_Cvar_Update( &g_capturelimit );
}
}
if ( g_capturelimit.integer ) {
if (G_IsATeamGametype(g_gametype.integer)) {
if ( level.teamScores[TEAM_RED] >= g_capturelimit.integer ) {
Expand Down Expand Up @@ -3318,22 +3342,66 @@ void G_SetMapFragLimit (char *mapname) {
else {
G_Printf("^3No fraglimit info found in .info for %s. Looking in arena files.\n",mapname);
}
// TO-DO: If found, set the timelimit from gameinfo.txt.
// If not, look in the arena files for the timelimit.
// TO-DO: If found, set the fraglimit from gameinfo.txt.
// If not, look in the arena files for the fraglimit.

arenainfo = G_GetArenaInfoByMap(mapname);
if ( !arenainfo ) {
G_Printf("^4No arena info found for the map %s. Assigning default value.\n",mapname);
g_timelimit.integer = (int) GT_SINGLE_DEFAULT_SCORELIMIT;
trap_Cvar_Set("fraglimit", va("%s",GT_SINGLE_DEFAULT_SCORELIMIT));
g_mapInfoFragLimit.integer = g_fraglimit.integer;
return;
}

if (atoi(Info_ValueForKey(arenainfo, "fraglimit"))) {
G_Printf("^2Fraglimit info found in arena file for %s: %i.\n",mapname,Info_ValueForKey(arenainfo, "fraglimit"));
g_fraglimit.integer = (int) Info_ValueForKey(arenainfo, "fraglimit");
G_Printf("^2Fraglimit info found in arena file for %s: %s.\n",mapname,Info_ValueForKey(arenainfo, "fraglimit"));
trap_Cvar_Set("fraglimit", va("%s",Info_ValueForKey(arenainfo, "fraglimit")));
g_mapInfoFragLimit.integer = g_fraglimit.integer;
return;
}
G_Printf("^4No fraglimit info found in arena files for %s. Assigning default value.\n",mapname);
g_timelimit.integer = (int) GT_SINGLE_DEFAULT_SCORELIMIT;
trap_Cvar_Set("fraglimit", va("%s",GT_SINGLE_DEFAULT_SCORELIMIT));
g_mapInfoFragLimit.integer = g_fraglimit.integer;
return;
}
/*
===================
G_SetMapCaptureLimit
Sets the map's capture limit. Saves it in the capturelimit cvar.
===================
*/
void G_SetMapCaptureLimit (char *mapname) {
const char *arenainfo;
// If the capturelimit is present in the .info file, use that.
if (g_mapInfoCaptureLimit.integer > 0) {
G_Printf("^2Capturelimit info found in .info for %s: %i.\n",mapname,g_mapInfoCaptureLimit.integer);
g_capturelimit.integer = g_mapInfoCaptureLimit.integer;
return;
}
else {
G_Printf("^3No capturelimit info found in .info for %s. Looking in arena files.\n",mapname);
}
// TO-DO: If found, set the capturelimit from gameinfo.txt.
// If not, look in the arena files for the capturelimit.

arenainfo = G_GetArenaInfoByMap(mapname);
if ( !arenainfo ) {
G_Printf("^4No arena info found for the map %s. Assigning default value.\n",mapname);
trap_Cvar_Set("capturelimit", va("%s",GT_CTF_DEFAULT_SCORELIMIT));
g_mapInfoCaptureLimit.integer = g_capturelimit.integer;
return;
}

if (atoi(Info_ValueForKey(arenainfo, "fraglimit"))) {
G_Printf("^2Capturelimit info found in arena file for %s: %s.\n",mapname,Info_ValueForKey(arenainfo, "capturelimit"));
trap_Cvar_Set("capturelimit", va("%s",Info_ValueForKey(arenainfo, "capturelimit")));
g_mapInfoCaptureLimit.integer = g_capturelimit.integer;
return;
}
G_Printf("^4No capturelimit info found in arena files for %s. Assigning default value.\n",mapname);
trap_Cvar_Set("capturelimit", va("%s",GT_CTF_DEFAULT_SCORELIMIT));
g_mapInfoCaptureLimit.integer = g_capturelimit.integer;
return;
}
/*
Expand All @@ -3360,16 +3428,20 @@ void G_SetMapTimeLimit (char *mapname) {
arenainfo = G_GetArenaInfoByMap(mapname);
if ( !arenainfo ) {
G_Printf("^4No arena info found for the map %s. Assigning default value.\n",mapname);
g_timelimit.integer = (int) GT_SINGLE_DEFAULT_TIMELIMIT;
trap_Cvar_Set("timelimit", va("%s",GT_SINGLE_DEFAULT_TIMELIMIT));
g_mapInfoTimeLimit.integer = g_timelimit.integer;
return;
}

if (atoi(Info_ValueForKey(arenainfo, "timelimit"))) {
G_Printf("^2Timelimit info found in arena file for %s: %i.\n",mapname,Info_ValueForKey(arenainfo, "timelimit"));
g_timelimit.integer = (int) Info_ValueForKey(arenainfo, "timelimit");
G_Printf("^2Timelimit info found in arena file for %s: %s.\n",mapname,Info_ValueForKey(arenainfo, "timelimit"));
trap_Cvar_Set("timelimit", va("%s",Info_ValueForKey(arenainfo, "timelimit")));
g_mapInfoTimeLimit.integer = g_timelimit.integer;
return;
}
G_Printf("^4No timelimit info found in arena files for %s. Assigning default value.\n",mapname);
g_timelimit.integer = (int) GT_SINGLE_DEFAULT_TIMELIMIT;
trap_Cvar_Set("timelimit", va("%s",GT_SINGLE_DEFAULT_TIMELIMIT));
g_mapInfoTimeLimit.integer = g_timelimit.integer;
return;
}
/*
Expand Down

0 comments on commit 0019d03

Please sign in to comment.