Revert "revert the mapvote change, it didnt really work online.", and fix it
authordiv0 <div0@f962a42d-fe04-0410-a3ab-8c8b0445ebaa>
Sun, 17 Jan 2010 16:27:00 +0000 (16:27 +0000)
committerdiv0 <div0@f962a42d-fe04-0410-a3ab-8c8b0445ebaa>
Sun, 17 Jan 2010 16:27:00 +0000 (16:27 +0000)
git-svn-id: svn://svn.icculus.org/nexuiz/trunk@8513 f962a42d-fe04-0410-a3ab-8c8b0445ebaa

data/defaultNexuiz.cfg
data/qcsrc/client/mapvoting.qc
data/qcsrc/server/g_world.qc

index c736639..264952f 100644 (file)
@@ -1127,7 +1127,7 @@ seta g_maplist_votable_suggestions 2
 seta g_maplist_votable_suggestions_override_mostrecent 0
 seta g_maplist_votable_nodetail 1      "nodetail only shows total count instead of all vote counts per map, so votes don't influence others that much"
 seta g_maplist_votable_abstain 0       "when 1, you can abstain from your vote"
-seta g_maplist_votable_screenshot_dir "maps"   "where to look for map screenshots"
+seta g_maplist_votable_screenshot_dir "maps levelshots"        "where to look for map screenshots"
 alias suggestmap "cmd suggestmap $1"
 
 set g_chat_flood_spl 3 "normal chat: seconds between lines to not count as flooding"
index 4cb824a..45dac42 100644 (file)
@@ -275,10 +275,13 @@ void MapVote_CheckPic(string pic, string pk3, float id)
        MapVote_CheckPK3(pic, pk3, id);
 }
 
+#define NUM_SSDIRS 4
+string ssdirs[NUM_SSDIRS];
+float n_ssdirs;
 void MapVote_Init()
 {
-       float i, power;
-       string map, pk3, ssdir;
+       float i, j, power;
+       string map, pk3, s;
 
        precache_sound ("misc/invshot.wav");
 
@@ -287,8 +290,16 @@ void MapVote_Init()
 
        mv_active = 1;
 
-       ssdir = ReadString();
-       
+       for(n_ssdirs = 0; ; ++n_ssdirs)
+       {
+               s = ReadString();
+               if(s == "")
+                       break;
+               if(n_ssdirs < NUM_SSDIRS)
+                       ssdirs[n_ssdirs] = s;
+       }
+       n_ssdirs = min(n_ssdirs, NUM_SSDIRS);
+
        mv_num_maps = min(MAPVOTE_COUNT, ReadByte());
        mv_abstain = ReadByte();
        if(mv_abstain)
@@ -314,9 +325,11 @@ void MapVote_Init()
                {
                        map = strzone(ReadString());
                        pk3 = strzone(ReadString());
+                       j = bound(0, ReadByte(), n_ssdirs - 1);
+       
                        mv_maps[i] = map;
                        mv_pk3[i] = pk3;
-                       map = strzone(strcat(ssdir, "/", map));
+                       map = strzone(strcat(ssdirs[j], "/", map));
                        mv_pics[i] = map;
 
                        mv_preview[i] = false;
@@ -333,6 +346,10 @@ void MapVote_Init()
                }
        }
 
+       for(i = 0; i < n_ssdirs; ++i)
+               ssdirs[n_ssdirs] = string_null;
+       n_ssdirs = 0;
+
        // do we NEED this, or can we handle key presses directly in CSQC?
        localcmd("\nin_bind 7 1 \"impulse 1\"; in_bind 7 2 \"impulse 2\"; in_bind 7 3 \"impulse 3\"; in_bind 7 4 \"impulse 4\"; in_bind 7 5 \"impulse 5\"; in_bind 7 6 \"impulse 6\"; in_bind 7 7 \"impulse 7\"; in_bind 7 8 \"impulse 8\"; in_bind 7 9 \"impulse 9\"; in_bind 7 0 \"impulse 10\"; in_bind 7 KP_1 \"impulse 1\"; in_bind 7 KP_2 \"impulse 2\"; in_bind 7 KP_3 \"impulse 3\"; in_bind 7 KP_4 \"impulse 4\"; in_bind 7 KP_5 \"impulse 5\"; in_bind 7 KP_6 \"impulse 6\"; in_bind 7 KP_7 \"impulse 7\"; in_bind 7 KP_8 \"impulse 8\"; in_bind 7 KP_9 \"impulse 9\"; in_bind 7 KP_0 \"impulse 10\"; in_bindmap 7 0\n");
 }
index e05fb6c..8cc4606 100644 (file)
@@ -2073,11 +2073,15 @@ float mapvote_initialized;
 float mapvote_keeptwotime;
 float mapvote_timeout;
 string mapvote_message;
-string mapvote_screenshot_dir;
+#define MAPVOTE_SCREENSHOT_DIRS_COUNT 4
+string mapvote_screenshot_dirs[MAPVOTE_SCREENSHOT_DIRS_COUNT];
+float mapvote_screenshot_dirs_count;
 
 float mapvote_count;
 float mapvote_count_real;
 string mapvote_maps[MAPVOTE_COUNT];
+float mapvote_maps_screenshot_dir[MAPVOTE_COUNT];
+string mapvote_maps_pakfile[MAPVOTE_COUNT];
 float mapvote_maps_suggested[MAPVOTE_COUNT];
 string mapvote_suggestions[MAPVOTE_COUNT];
 float mapvote_suggestion_ptr;
@@ -2135,7 +2139,9 @@ string MapVote_Suggest(string m)
 
 void MapVote_AddVotable(string nextMap, float isSuggestion)
 {
-       float j;
+       float j, i, o;
+       string pakfile, mapfile;
+
        if(nextMap == "")
                return;
        for(j = 0; j < mapvote_count; ++j)
@@ -2145,6 +2151,26 @@ void MapVote_AddVotable(string nextMap, float isSuggestion)
                mapvote_maxlen = strlen(nextMap);
        mapvote_maps[mapvote_count] = strzone(nextMap);
        mapvote_maps_suggested[mapvote_count] = isSuggestion;
+
+       for(i = 0; i < mapvote_screenshot_dirs_count; ++i)
+       {
+               mapfile = strcat(mapvote_screenshot_dirs[i], "/", mapvote_maps[i]);
+               pakfile = whichpack(strcat(mapfile, ".tga"));
+               if(pakfile == "")
+                       pakfile = whichpack(strcat(mapfile, ".jpg"));
+               if(pakfile == "")
+                       pakfile = whichpack(strcat(mapfile, ".png"));
+               if(pakfile != "")
+                       break;
+       }
+       if(i >= mapvote_screenshot_dirs_count)
+               i = 0; // FIXME maybe network this error case, as that means there is no mapshot on the server?
+       for(o = strstr(pakfile, "/", 0)+1; o > 0; o = strstr(pakfile, "/", 0)+1)
+               pakfile = substring(pakfile, o, -1);
+
+       mapvote_maps_screenshot_dir[mapvote_count] = i;
+       mapvote_maps_pakfile[mapvote_count] = strzone(pakfile);
+
        mapvote_count += 1;
 }
 
@@ -2166,6 +2192,14 @@ void MapVote_Init()
                nmax = min(MAPVOTE_COUNT, cvar("g_maplist_votable"));
        smax = min3(nmax, cvar("g_maplist_votable_suggestions"), mapvote_suggestion_ptr);
 
+       // we need this for AddVotable, as that cycles through the screenshot dirs
+       mapvote_screenshot_dirs_count = tokenize_console(cvar_string("g_maplist_votable_screenshot_dir"));
+       if(mapvote_screenshot_dirs_count == 0)
+               mapvote_screenshot_dirs_count = tokenize_console("maps levelshots");
+       mapvote_screenshot_dirs_count = min(mapvote_screenshot_dirs_count, MAPVOTE_SCREENSHOT_DIRS_COUNT);
+       for(i = 0; i < mapvote_screenshot_dirs_count; ++i)
+               mapvote_screenshot_dirs[i] = strzone(argv(i));
+
        if(mapvote_suggestion_ptr)
                for(i = 0; i < 100 && mapvote_count < smax; ++i)
                        MapVote_AddVotable(mapvote_suggestions[floor(random() * mapvote_suggestion_ptr)], TRUE);
@@ -2196,11 +2230,6 @@ void MapVote_Init()
                mapvote_keeptwotime = 0;
        mapvote_message = "Choose a map and press its key!";
 
-       mapvote_screenshot_dir = cvar_string("g_maplist_votable_screenshot_dir");
-       if(mapvote_screenshot_dir == "")
-               mapvote_screenshot_dir = "maps";
-       mapvote_screenshot_dir = strzone(mapvote_screenshot_dir);
-
        MapVote_Spawn();
 }
 
@@ -2210,7 +2239,7 @@ void MapVote_SendPicture(float id)
        WriteByte(MSG_ONE, SVC_TEMPENTITY);
        WriteByte(MSG_ONE, TE_CSQC_PICTURE);
        WriteByte(MSG_ONE, id);
-       WritePicture(MSG_ONE, strcat(mapvote_screenshot_dir, "/", mapvote_maps[id]), 3072);
+       WritePicture(MSG_ONE, strcat(mapvote_screenshot_dirs[mapvote_maps_screenshot_dir[id]], "/", mapvote_maps[id]), 3072);
 }
 
 float GameCommand_MapVote(string cmd)
@@ -2240,8 +2269,7 @@ float MapVote_GetMapMask()
 entity mapvote_ent;
 float MapVote_SendEntity(entity to, float sf)
 {
-       string mapfile, pakfile;
-       float i, o;
+       float i;
 
        if(sf & 1)
                sf &~= 2; // if we send 1, we don't need to also send 2
@@ -2252,7 +2280,9 @@ float MapVote_SendEntity(entity to, float sf)
        if(sf & 1)
        {
                // flag 1 == initialization
-               WriteString(MSG_ENTITY, mapvote_screenshot_dir);
+               for(i = 0; i < mapvote_screenshot_dirs_count; ++i)
+                       WriteString(MSG_ENTITY, mapvote_screenshot_dirs[i]);
+               WriteString(MSG_ENTITY, "");
                WriteByte(MSG_ENTITY, mapvote_count);
                WriteByte(MSG_ENTITY, mapvote_abstain);
                WriteByte(MSG_ENTITY, mapvote_detail);
@@ -2267,20 +2297,14 @@ float MapVote_SendEntity(entity to, float sf)
                                if(mapvote_abstain && i == mapvote_count - 1)
                                {
                                        WriteString(MSG_ENTITY, ""); // abstain needs no text
+                                       WriteByte(MSG_ENTITY, 0); // abstain needs no screenshot dir
                                        WriteString(MSG_ENTITY, ""); // abstain needs no pack
                                }
                                else
                                {
                                        WriteString(MSG_ENTITY, mapvote_maps[i]);
-                                       mapfile = strcat(mapvote_screenshot_dir, "/", mapvote_maps[i]);
-                                       pakfile = whichpack(strcat(mapfile, ".tga"));
-                                       if(pakfile == "")
-                                               pakfile = whichpack(strcat(mapfile, ".jpg"));
-                                       if(pakfile == "")
-                                               pakfile = whichpack(strcat(mapfile, ".png"));
-                                       for(o = strstr(pakfile, "/", 0)+1; o > 0; o = strstr(pakfile, "/", 0)+1)
-                                               pakfile = substring(pakfile, o, 999);
-                                       WriteString(MSG_ENTITY, pakfile);
+                                       WriteByte(MSG_ENTITY, mapvote_maps_screenshot_dir[i]);
+                                       WriteString(MSG_ENTITY, mapvote_maps_pakfile[i]);
                                }
                        }
        }
@@ -2444,6 +2468,8 @@ float MapVote_CheckRules_2()
                                                        {
                                                                strunzone(mapvote_maps[i]);
                                                                mapvote_maps[i] = "";
+                                                               strunzone(mapvote_maps_pakfile[i]);
+                                                               mapvote_maps_pakfile[i] = "";
                                                        }
                                                }
                                }