Skip to content

Commit

Permalink
mint-arena: Select current gametype/map in in-game 'start new arena' …
Browse files Browse the repository at this point in the history
…menu

Changing gametype also keeps the map selected if it's allowed in the
gametype.
  • Loading branch information
zturtleman committed Sep 17, 2024
1 parent 6755ee5 commit 8adf1ef
Showing 1 changed file with 33 additions and 14 deletions.
47 changes: 33 additions & 14 deletions code/q3_ui/ui_startserver.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ typedef struct {

qboolean multiplayer;
int currentmap;
char currentmapname[MAX_QPATH];
int nummaps;
int page;
int maxpages;
Expand Down Expand Up @@ -254,8 +255,7 @@ static void StartServer_Update( void ) {
}

// set the map name
info = UI_GetArenaInfoByNumber( s_startserver.maplist[ s_startserver.currentmap ]);
Q_strncpyz( s_startserver.mapname.string, Info_ValueForKey( info, "map" ), MAX_NAMELENGTH);
Q_strncpyz( s_startserver.mapname.string, s_startserver.currentmapname, MAX_NAMELENGTH);
}

Q_strupr( s_startserver.mapname.string );
Expand All @@ -268,11 +268,18 @@ StartServer_MapEvent
=================
*/
static void StartServer_MapEvent( void* ptr, int event ) {
const char *info;

if( event != QM_ACTIVATED) {
return;
}

s_startserver.currentmap = (s_startserver.page*MAX_MAPSPERPAGE) + (((menucommon_s*)ptr)->id - ID_PICTURES);

info = UI_GetArenaInfoByNumber( s_startserver.maplist[ s_startserver.currentmap ] );
Q_strncpyz( s_startserver.currentmapname, Info_ValueForKey( info, "map" ),
sizeof( s_startserver.currentmapname ) );

StartServer_Update();
}

Expand All @@ -295,6 +302,7 @@ static void StartServer_GametypeEvent( void* ptr, int event ) {

count = UI_GetNumArenas();
s_startserver.nummaps = 0;
s_startserver.currentmap = 0;
matchbits = 1 << gametype_remap[s_startserver.gametype.curvalue];
if( gametype_remap[s_startserver.gametype.curvalue] == GT_FFA ) {
matchbits |= ( 1 << GT_SINGLE_PLAYER );
Expand All @@ -307,12 +315,19 @@ static void StartServer_GametypeEvent( void* ptr, int event ) {
continue;
}

if ( !Q_stricmp( s_startserver.currentmapname, Info_ValueForKey( info, "map" ) ) ) {
s_startserver.currentmap = s_startserver.nummaps;
}

s_startserver.maplist[ s_startserver.nummaps ] = i;
s_startserver.nummaps++;
}
s_startserver.maxpages = (s_startserver.nummaps + MAX_MAPSPERPAGE-1)/MAX_MAPSPERPAGE;
s_startserver.page = 0;
s_startserver.currentmap = 0;
s_startserver.page = s_startserver.currentmap / MAX_MAPSPERPAGE;

info = UI_GetArenaInfoByNumber( s_startserver.maplist[ s_startserver.currentmap ] );
Q_strncpyz( s_startserver.currentmapname, Info_ValueForKey( info, "map" ),
sizeof( s_startserver.currentmapname ) );

StartServer_Update();
}
Expand Down Expand Up @@ -585,6 +600,17 @@ static void StartServer_MenuInit( qboolean multiplayer ) {
Menu_AddItem( &s_startserver.menu, &s_startserver.mapname );
Menu_AddItem( &s_startserver.menu, &s_startserver.item_null );

if ( trap_Cvar_VariableValue("sv_running") ) {
int gametype;

gametype = (int) Com_Clamp(0, ARRAY_LEN(gametype_remap2) - 1,
trap_Cvar_VariableValue("g_gametype"));
s_startserver.gametype.curvalue = gametype_remap2[gametype];

Q_strncpyz( s_startserver.currentmapname, CG_Cvar_VariableString( "mapname" ),
sizeof( s_startserver.currentmapname ) );
}

StartServer_GametypeEvent( NULL, QM_ACTIVATED );
}

Expand Down Expand Up @@ -782,7 +808,6 @@ static void ServerOptions_Start( void ) {
int skill;
int n;
char buf[64];
const char *info;

timelimit = atoi( MField_Buffer( &s_serveroptions.timelimit.field ) );
fraglimit = atoi( MField_Buffer( &s_serveroptions.fraglimit.field ) );
Expand Down Expand Up @@ -891,9 +916,8 @@ static void ServerOptions_Start( void ) {
}

// the wait commands will allow the dedicated to take effect
info = UI_GetArenaInfoByNumber( s_startserver.maplist[ s_startserver.currentmap ]);
trap_Cmd_ExecuteText( EXEC_APPEND, va( "wait ; wait ; g_gametype %d ; map %s\n",
s_serveroptions.gametype, Info_ValueForKey( info, "map" ) ) );
s_serveroptions.gametype, s_startserver.currentmapname ) );

// remove bots
if ( trap_Cvar_VariableValue("sv_running") ) {
Expand Down Expand Up @@ -1263,8 +1287,6 @@ ServerOptions_SetMenuItems
*/
static void ServerOptions_SetMenuItems( void ) {
static char picname[64];
char mapname[MAX_NAMELENGTH];
const char *info;

switch( s_serveroptions.gametype ) {
case GT_FFA:
Expand Down Expand Up @@ -1323,12 +1345,9 @@ static void ServerOptions_SetMenuItems( void ) {
s_serveroptions.pure.curvalue = Com_Clamp( 0, 1, trap_Cvar_VariableValue( "sv_pure" ) );

// set the map pic
info = UI_GetArenaInfoByNumber( s_startserver.maplist[ s_startserver.currentmap ]);
Q_strncpyz( mapname, Info_ValueForKey( info, "map"), MAX_NAMELENGTH );

Com_sprintf( picname, sizeof(picname), "levelshots/%s_small", mapname );
Com_sprintf( picname, sizeof(picname), "levelshots/%s_small", s_startserver.currentmapname );
if ( !trap_R_RegisterShaderNoMip( picname ) ) {
Com_sprintf( picname, sizeof(picname), "levelshots/%s", mapname );
Com_sprintf( picname, sizeof(picname), "levelshots/%s", s_startserver.currentmapname );
}
s_serveroptions.mappic.generic.name = picname;

Expand Down

0 comments on commit 8adf1ef

Please sign in to comment.