]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - menu.c
patch from div0 that enables printf format warnings in gcc
[xonotic/darkplaces.git] / menu.c
diff --git a/menu.c b/menu.c
index b3562b2b756fa1515df03072cf1181abe3a7e0df..9f84b008cee1d5684f2c381ed55c0a6a298d99f9 100644 (file)
--- a/menu.c
+++ b/menu.c
@@ -376,12 +376,15 @@ static void M_Demo_Key (int k, char ascii)
 /* MAIN MENU */
 
 static int     m_main_cursor;
+static qboolean m_missingdata = false;
 
 static int MAIN_ITEMS = 4; // Nehahra: Menu Disable
 
 
 void M_Menu_Main_f (void)
 {
+       const char *s;
+       s = "gfx/mainmenu";
        if (gamemode == GAME_NEHAHRA)
        {
                if (NehGameType == TYPE_DEMO)
@@ -393,18 +396,22 @@ void M_Menu_Main_f (void)
        }
        else if (gamemode == GAME_NETHERWORLD)//VORTEX: menu restarting item
                MAIN_ITEMS = 6;
-       else if (gamemode == GAME_TRANSFUSION) {
+       else if (gamemode == GAME_TRANSFUSION)
+       {
+               s = "gfx/menu/mainmenu1";
                if (sv.active && !cl.intermission && cl.islocalgame)
                        MAIN_ITEMS = 8;
                else
                        MAIN_ITEMS = 7;
        }
-       else if (gamemode == GAME_NEXUIZ) {
-               MAIN_ITEMS = 2;
-       }
        else
                MAIN_ITEMS = 5;
 
+       // check if the game data is missing and use a different main menu if so
+       m_missingdata = Draw_CachePic (s, true)->tex == r_texture_notexture;
+       if (m_missingdata)
+               MAIN_ITEMS = 2;
+
        /*
        if (key_dest != key_menu)
        {
@@ -423,6 +430,23 @@ static void M_Main_Draw (void)
        int             f;
        cachepic_t      *p;
 
+       if (m_missingdata)
+       {
+               float y;
+               const char *s;
+               M_Background(640, 480); //fall back is always to 640x480, this makes it most readable at that.
+               y = 480/3-16;
+               s = "You have reached this menu due to missing or unlocatable content/data";M_PrintRed ((640-strlen(s)*8)*0.5, (480/3)-16, s);y+=8;
+               y+=8;
+               s = "You may consider adding";M_Print ((640-strlen(s)*8)*0.5, y, s);y+=8;
+               s = "-basedir /path/to/game";M_Print ((640-strlen(s)*8)*0.5, y, s);y+=8;
+               s = "to your launch commandline";M_Print ((640-strlen(s)*8)*0.5, y, s);y+=8;
+               M_Print (640/2 - 48, 480/2, "Open Console"); //The console usually better shows errors (failures)
+               M_Print (640/2 - 48, 480/2 + 8, "Quit");
+               M_DrawCharacter(640/2 - 56, 480/2 + (8 * m_main_cursor), 12+((int)(realtime*4)&1));
+               return;
+       }
+
        if (gamemode == GAME_TRANSFUSION) {
                int y1, y2, y3;
                M_Background(640, 480);
@@ -444,18 +468,7 @@ static void M_Main_Draw (void)
                M_DrawPic (0, 120 + m_main_cursor * 40, va("gfx/menu/mainmenu%iselected", y3));
                return;
        }
-       else if (gamemode == GAME_NEXUIZ)
-       {
-               M_Background(640, 480); //fall back is always to 640x480, this makes it most readable at that.
-               M_PrintRed (40, (480/3)-16, "You have reached this menu due to missing or unlocatable content/data");
-               M_Print ((640/2)-92, (480/3), "You may consider adding");
-               M_Print ((640/2)-136, (480/3)+8, "-basedir /path/to/nexuiz");
-               M_Print ((640/2)-76, (480/3)+16, "to your launch commandline");
-               M_Print (640/2 - 48, 480/2, "Open Console"); //The console usually better shows errors (failures)
-               M_Print (640/2 - 48, 480/2 + 8, "Quit");
-               M_DrawCharacter(640/2 - 56, 480/2 + (8 * m_main_cursor), 12+((int)(realtime*4)&1));
-               return;
-       }
+
        M_Background(320, 200);
        M_DrawPic (16, 4, "gfx/qplaque");
        p = Draw_CachePic ("gfx/ttl_main", true);
@@ -506,7 +519,24 @@ static void M_Main_Key (int key, char ascii)
        case K_ENTER:
                m_entersound = true;
 
-               if (gamemode == GAME_NEHAHRA)
+               if (m_missingdata)
+               {
+                       switch (m_main_cursor)
+                       {
+                       case 0:
+                               if (cls.state == ca_connected)
+                               {
+                                       m_state = m_none;
+                                       key_dest = key_game;
+                               }
+                               Con_ToggleConsole_f ();
+                               break;
+                       case 1:
+                               M_Menu_Quit_f ();
+                               break;
+                       }
+               }
+               else if (gamemode == GAME_NEHAHRA)
                {
                        switch (NehGameType)
                        {
@@ -693,22 +723,6 @@ static void M_Main_Key (int key, char ascii)
                                }
                        }
                }
-               else if (gamemode == GAME_NEXUIZ) {
-                       switch (m_main_cursor)
-                       {
-                       case 0:
-                               if (cls.state == ca_connected)
-                               {
-                                       m_state = m_none;
-                                       key_dest = key_game;
-                               }
-                               Con_ToggleConsole_f ();
-                               break;
-                       case 1:
-                               M_Menu_Quit_f ();
-                               break;
-                       }
-               }
                else
                {
                        switch (m_main_cursor)
@@ -866,7 +880,7 @@ static void M_ScanSaves (void)
 
        for (i=0 ; i<MAX_SAVEGAMES ; i++)
        {
-               strcpy (m_filenames[i], "--- UNUSED SLOT ---");
+               strlcpy (m_filenames[i], "--- UNUSED SLOT ---", sizeof(m_filenames[i]));
                loadable[i] = false;
                sprintf (name, "s%i.sav", (int)i);
                f = FS_Open (name, "rb", false, false);
@@ -877,10 +891,10 @@ static void M_ScanSaves (void)
                buf[sizeof(buf) - 1] = 0;
                t = buf;
                // version
-               COM_ParseToken(&t, false);
+               COM_ParseTokenConsole(&t);
                version = atoi(com_token);
                // description
-               COM_ParseToken(&t, false);
+               COM_ParseTokenConsole(&t);
                strlcpy (m_filenames[i], com_token, sizeof (m_filenames[i]));
 
        // change _ back to space
@@ -1285,7 +1299,7 @@ void M_Menu_Setup_f (void)
        key_dest = key_menu;
        m_state = m_setup;
        m_entersound = true;
-       strcpy(setup_myname, cl_name.string);
+       strlcpy(setup_myname, cl_name.string, sizeof(setup_myname));
        setup_top = setup_oldtop = cl_color.integer >> 4;
        setup_bottom = setup_oldbottom = cl_color.integer & 15;
        setup_rate = cl_rate.integer;
@@ -1962,7 +1976,7 @@ static void M_Options_Effects_Key (int k, char ascii)
 }
 
 
-#define        OPTIONS_GRAPHICS_ITEMS  18
+#define        OPTIONS_GRAPHICS_ITEMS  16
 
 static int options_graphics_cursor;
 
@@ -1981,12 +1995,12 @@ extern cvar_t r_shadow_realtime_world_dlightshadows;
 extern cvar_t r_shadow_realtime_world_lightmaps;
 extern cvar_t r_shadow_realtime_world_shadows;
 extern cvar_t r_bloom;
-extern cvar_t r_bloom_intensity;
-extern cvar_t r_bloom_power;
+extern cvar_t r_bloom_colorscale;
+extern cvar_t r_bloom_colorsubtract;
+extern cvar_t r_bloom_colorexponent;
 extern cvar_t r_bloom_blur;
 extern cvar_t r_bloom_resolution;
 extern cvar_t r_hdr;
-extern cvar_t r_hdr_bloomintensity;
 extern cvar_t r_hdr_scenebrightness;
 extern cvar_t r_hdr_glowintensity;
 extern cvar_t gl_picmip;
@@ -2007,10 +2021,10 @@ static void M_Menu_Options_Graphics_AdjustSliders (int dir)
        else if (options_graphics_cursor == optnum++) Cvar_SetValueQuick (&r_shadow_realtime_world_shadows,                     !r_shadow_realtime_world_shadows.integer);
        else if (options_graphics_cursor == optnum++) Cvar_SetValueQuick (&r_bloom,                                 !r_bloom.integer);
        else if (options_graphics_cursor == optnum++) Cvar_SetValueQuick (&r_hdr,                                   !r_hdr.integer);
-       else if (options_graphics_cursor == optnum++) Cvar_SetValueQuick (&r_hdr_bloomintensity,                    bound(0.125, r_hdr_bloomintensity.value + dir * 0.125, 4));
        else if (options_graphics_cursor == optnum++) Cvar_SetValueQuick (&r_hdr_glowintensity,                     bound(0, r_hdr_glowintensity.value + dir * 0.25, 4));
-       else if (options_graphics_cursor == optnum++) Cvar_SetValueQuick (&r_bloom_power,                           bound(1, r_bloom_power.value + dir * 1, 16));
-       else if (options_graphics_cursor == optnum++) Cvar_SetValueQuick (&r_bloom_intensity,                       bound(1, r_bloom_intensity.value + dir * 0.25, 16));
+       else if (options_graphics_cursor == optnum++) Cvar_SetValueQuick (&r_bloom_colorscale,                      bound(0.0625, r_bloom_colorscale.value + dir * 0.0625, 1));
+       else if (options_graphics_cursor == optnum++) Cvar_SetValueQuick (&r_bloom_colorsubtract,                   bound(0, r_bloom_colorsubtract.value + dir * 0.0625, 1-0.0625));
+       else if (options_graphics_cursor == optnum++) Cvar_SetValueQuick (&r_bloom_colorexponent,                   bound(1, r_bloom_colorexponent.value *= (dir > 0 ? 2 : 0.5), 8));
        else if (options_graphics_cursor == optnum++) Cvar_SetValueQuick (&r_bloom_blur,                            bound(1, r_bloom_blur.value + dir * 1, 16));
        else if (options_graphics_cursor == optnum++) Cvar_SetValueQuick (&r_bloom_resolution,                      bound(64, r_bloom_resolution.value + dir * 64, 2048));
        else if (options_graphics_cursor == optnum++) Cvar_SetValueQuick (&r_hdr_scenebrightness,                   bound(0.25, r_hdr_scenebrightness.value + dir * 0.125, 4));
@@ -2044,10 +2058,11 @@ static void M_Options_Graphics_Draw (void)
        M_Options_PrintCheckbox("        RT World Shadow", true, r_shadow_realtime_world_shadows.integer);
        M_Options_PrintCheckbox("           Bloom Effect", !r_hdr.integer, r_bloom.integer);
        M_Options_PrintCheckbox("       HDR Bloom Effect", r_hdr.integer, r_hdr.integer);
-       M_Options_PrintSlider(  "    HDR Bloom Intensity", r_hdr.integer, r_hdr_bloomintensity.value, 0.125, 4);
        M_Options_PrintSlider(  "     HDR Glow Intensity", r_hdr.integer, r_hdr_glowintensity.value, 0, 4);
-       M_Options_PrintSlider(  "Non-HDR Bloom Darkening", !r_hdr.integer && r_bloom.integer, r_bloom_power.value, 1, 16);
-       M_Options_PrintSlider(  "        Bloom Intensity", r_hdr.integer || r_bloom.integer, r_bloom_intensity.value, 1, 16);
+       M_Options_PrintSlider(  "      Bloom Color Scale", r_hdr.integer || r_bloom.integer, r_bloom_colorscale.value, 0.0625, 1);
+       M_Options_PrintSlider(  "   Bloom Color Subtract", r_hdr.integer || r_bloom.integer, r_bloom_colorsubtract.value, 0, 1-0.0625);
+       M_Options_PrintSlider(  "   Bloom Color Exponent", r_hdr.integer || r_bloom.integer, r_bloom_colorexponent.value, 1, 8);
+       M_Options_PrintSlider(  "        Bloom Intensity", r_hdr.integer || r_bloom.integer, r_bloom_colorscale.value, 0.125, 4);
        M_Options_PrintSlider(  "             Bloom Blur", r_hdr.integer || r_bloom.integer, r_bloom_blur.value, 1, 16);
        M_Options_PrintSlider(  "       Bloom Resolution", r_hdr.integer || r_bloom.integer, r_bloom_resolution.value, 64, 2048);
        M_Options_PrintSlider(  "       Scene Brightness", true, r_hdr_scenebrightness.value, 0.25, 4);
@@ -2633,7 +2648,7 @@ static void M_Keys_Draw (void)
 
                // LordHavoc: redesigned to print more than 2 keys, inspired by Tomaz's MiniRacer
                if (keys[0] == -1)
-                       strcpy(keystring, "???");
+                       strlcpy(keystring, "???", sizeof(keystring));
                else
                {
                        keystring[0] = 0;
@@ -2642,8 +2657,8 @@ static void M_Keys_Draw (void)
                                if (keys[j] != -1)
                                {
                                        if (j > 0)
-                                               strcat(keystring, " or ");
-                                       strcat(keystring, Key_KeynumToString (keys[j]));
+                                               strlcat(keystring, " or ", sizeof(keystring));
+                                       strlcat(keystring, Key_KeynumToString (keys[j]), sizeof(keystring));
                                }
                        }
                }
@@ -3130,6 +3145,12 @@ static int M_QuitMessage(char *line1, char *line2, char *line3, char *line4, cha
 
 static int M_ChooseQuitMessage(int request)
 {
+       if (m_missingdata)
+       {
+               // frag related quit messages are pointless for a fallback menu, so use something generic
+               if (request-- == 0) return M_QuitMessage("Are you sure you want to quit?","Press Y to quit, N to stay",NULL,NULL,NULL,NULL,NULL,NULL);
+               return 0;
+       }
        switch (gamemode)
        {
        case GAME_NORMAL:
@@ -3175,9 +3196,6 @@ static int M_ChooseQuitMessage(int request)
                if (request-- == 0) return M_QuitMessage("You prefer free beer over free speech?","Press Y to quit, N to stay",NULL,NULL,NULL,NULL,NULL,NULL);
                if (request-- == 0) return M_QuitMessage("Is OpenQuartz Propaganda?","Press Y to quit, N to stay",NULL,NULL,NULL,NULL,NULL,NULL);
                break;
-       case GAME_NEXUIZ: //frag related quit messages are pointless for a fallback menu!
-               if (request-- == 0) return M_QuitMessage("Are you sure you want to quit?","Press Y to quit, N to stay",NULL,NULL,NULL,NULL,NULL,NULL);
-               break;
        default:
                if (request-- == 0) return M_QuitMessage("Tired of fragging already?",NULL,NULL,NULL,NULL,NULL,NULL,NULL);
                if (request-- == 0) return M_QuitMessage("Quit now and forfeit your bodycount?",NULL,NULL,NULL,NULL,NULL,NULL,NULL);
@@ -3199,7 +3217,7 @@ void M_Menu_Quit_f (void)
        m_state = m_quit;
        m_entersound = true;
        // count how many there are
-       for (n = 0;M_ChooseQuitMessage(n);n++);
+       for (n = 1;M_ChooseQuitMessage(n);n++);
        // choose one
        M_ChooseQuitMessage(rand() % n);
 }
@@ -3251,8 +3269,8 @@ static void M_Quit_Draw (void)
        }
        lines = (lastline - firstline) + 1;
        M_Background(linelength * 8 + 16, lines * 8 + 16);
-       if (gamemode != GAME_NEXUIZ) //since this is a fallback menu for Nexuiz (no graphics), it is very hard to read with the box
-               M_DrawTextBox(0, 0, linelength, lines); //this is less obtrusive than hacking up the M_DrawTextBox function for Nexuiz
+       if (!m_missingdata) //since this is a fallback menu for missing data, it is very hard to read with the box
+               M_DrawTextBox(0, 0, linelength, lines); //this is less obtrusive than hacking up the M_DrawTextBox function
        for (i = 0, l = firstline;i < lines;i++, l++)
                M_Print(8 + 4 * (linelength - strlen(m_quit_message[l])), 8 + 8 * i, m_quit_message[l]);
 }
@@ -3281,7 +3299,7 @@ void M_Menu_LanConfig_f (void)
        if (StartingGame)
                lanConfig_cursor = 1;
        lanConfig_port = 26000;
-       sprintf(lanConfig_portname, "%u", lanConfig_port);
+       sprintf(lanConfig_portname, "%u", (unsigned int) lanConfig_port);
 
        M_Update_Return_Reason("");
 }
@@ -3447,7 +3465,7 @@ static void M_LanConfig_Key (int key, char ascii)
        l =  atoi(lanConfig_portname);
        if (l <= 65535)
                lanConfig_port = l;
-       sprintf(lanConfig_portname, "%u", lanConfig_port);
+       sprintf(lanConfig_portname, "%u", (unsigned int) lanConfig_port);
 }
 
 //=============================================================================
@@ -3833,6 +3851,19 @@ static episode_t defeatindetail2episodes[] =
        {"ATAC Campaign", 0, 3},
 };
 
+static level_t prydonlevels[] =
+{
+       {"curig2", "Capel Curig"},      // 0
+
+       {"tdastart", "Gateway"},                                // 1
+};
+
+static episode_t prydonepisodes[] =
+{
+       {"Prydon Gate", 0, 1},
+       {"The Dark Age", 1, 1}
+};
+
 static gamelevels_t sharewarequakegame = {"Shareware Quake", quakelevels, quakeepisodes, 2};
 static gamelevels_t registeredquakegame = {"Quake", quakelevels, quakeepisodes, 7};
 static gamelevels_t hipnoticgame = {"Scourge of Armagon", hipnoticlevels, hipnoticepisodes, 6};
@@ -3843,6 +3874,7 @@ static gamelevels_t goodvsbad2game = {"Good Vs. Bad 2", goodvsbad2levels, goodvs
 static gamelevels_t battlemechgame = {"Battlemech", battlemechlevels, battlemechepisodes, 1};
 static gamelevels_t openquartzgame = {"OpenQuartz", openquartzlevels, openquartzepisodes, 3};
 static gamelevels_t defeatindetail2game = {"Defeat In Detail 2", defeatindetail2levels, defeatindetail2episodes, 1};
+static gamelevels_t prydongame = {"Prydon Gate", prydonlevels, prydonepisodes, 2};
 
 typedef struct gameinfo_s
 {
@@ -3863,13 +3895,22 @@ static gameinfo_t gamelist[] =
        {GAME_BATTLEMECH, &battlemechgame, &battlemechgame},
        {GAME_OPENQUARTZ, &openquartzgame, &openquartzgame},
        {GAME_DEFEATINDETAIL2, &defeatindetail2game, &defeatindetail2game},
-       {(gamemode_t)-1, &sharewarequakegame, &registeredquakegame} // final fallback
+       {GAME_PRYDON, &prydongame, &prydongame},
+       {GAME_NORMAL, NULL, NULL} // terminator
 };
 
 static gamelevels_t *lookupgameinfo(void)
 {
-       int i;
-       for (i = 0;gamelist[i].gameid >= 0 && gamelist[i].gameid != gamemode;i++);
+       int i = 0;
+       while (gamelist[i].gameid != gamemode)
+       {
+               if (gamelist[i].notregistered == NULL)
+               {
+                       i = 0;
+                       break;
+               }
+               i++;
+       }
        if (registered.integer)
                return gamelist[i].registered;
        else
@@ -4190,8 +4231,6 @@ static void M_NetStart_Change (int dir)
 
        case 8:
                Cvar_SetValueQuick (&sv_maxrate, sv_maxrate.integer + dir*500);
-               if (sv_maxrate.integer > NET_MAXRATE)
-                       Cvar_SetValueQuick (&sv_maxrate, NET_MAXRATE);
                if (sv_maxrate.integer < NET_MINRATE)
                        Cvar_SetValueQuick (&sv_maxrate, NET_MINRATE);
                break;
@@ -4618,7 +4657,7 @@ void M_Draw (void)
                break;
        }
 
-       if (gamemode == GAME_TRANSFUSION) {
+       if (gamemode == GAME_TRANSFUSION && !m_missingdata) {
                if (m_state != m_credits) {
                        cachepic_t      *p, *drop1, *drop2, *drop3;
                        int g, scale_x, scale_y, scale_y_repeat, top_offset;
@@ -4801,6 +4840,7 @@ static mfunction_t *m_keyup;
 
 void MR_SetRouting (qboolean forceold);
 
+void MP_Error(const char *format, ...) DP_FUNC_PRINTF(1);
 void MP_Error(const char *format, ...)
 {
        static qboolean processingError = false;