From e232c7dd25f0f9d0c2d3521af3725226e3f02fcd Mon Sep 17 00:00:00 2001 From: div0 Date: Sun, 20 Jul 2008 15:23:16 +0000 Subject: [PATCH] g_maplist_votable_screenshot_dir: take map screenshots out of another dir; minor cleanups (like, merge random selections, add DB support to CSQC) git-svn-id: svn://svn.icculus.org/nexuiz/trunk@3848 f962a42d-fe04-0410-a3ab-8c8b0445ebaa --- data/defaultNexuiz.cfg | 1 + data/qcsrc/client/Defs.qc | 2 +- data/qcsrc/client/Main.qc | 28 ++++++++++++- data/qcsrc/client/csqc_builtins.qc | 8 +++- data/qcsrc/client/main.qh | 2 + data/qcsrc/client/mapvoting.qc | 3 +- data/qcsrc/client/pre.qh | 2 + data/qcsrc/client/progs.src | 5 +++ data/qcsrc/common/constants.qh | 4 +- data/qcsrc/common/util.qc | 2 + data/qcsrc/common/util.qh | 2 + data/qcsrc/server/cl_client.qc | 18 ++++++++- data/qcsrc/server/g_world.qc | 65 +++++++++++++----------------- data/qcsrc/server/miscfunctions.qc | 18 +++++++-- data/qcsrc/server/sv_main.qc | 2 +- 15 files changed, 114 insertions(+), 48 deletions(-) diff --git a/data/defaultNexuiz.cfg b/data/defaultNexuiz.cfg index 2f7016465..1d994bbf1 100644 --- a/data/defaultNexuiz.cfg +++ b/data/defaultNexuiz.cfg @@ -814,6 +814,7 @@ seta g_maplist_votable_suggestions 2 seta g_maplist_votable_suggestions_override_mostrecent 0 seta g_maplist_votable_nodetail 0 // 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_textonly 0 // use old style centerprint alias suggestmap "cmd suggestmap $1" diff --git a/data/qcsrc/client/Defs.qc b/data/qcsrc/client/Defs.qc index 704a52e6b..e0a4c5966 100644 --- a/data/qcsrc/client/Defs.qc +++ b/data/qcsrc/client/Defs.qc @@ -10,7 +10,6 @@ -#define CSQC 1 /* ============================================================================== @@ -170,3 +169,4 @@ vector dmg_origin; .float sv_entnum; // entity number sent from server float vid_conwidth, vid_conheight; float caps_team1, caps_team2; +float configdb; diff --git a/data/qcsrc/client/Main.qc b/data/qcsrc/client/Main.qc index 25b78cccb..3a3aba2f2 100644 --- a/data/qcsrc/client/Main.qc +++ b/data/qcsrc/client/Main.qc @@ -21,6 +21,16 @@ float using_gps; float __engine_check; #endif +string config_get(string key, string defaultvalue) +{ + string s; + s = db_get(configdb, strcat("/s/", key)); + if(s == "") + return defaultvalue; + else + return db_get(configdb, strcat("/v/", key)); +} + void CSQC_Init(void) { #ifdef USE_FTE @@ -37,6 +47,9 @@ void CSQC_Init(void) float i; CSQC_CheckEngine(); + + configdb = db_create(); + drawfont = 0; menu_visible = FALSE; menu_show = menu_show_error; @@ -75,6 +88,7 @@ void CSQC_Shutdown(void) return 0; #pragma TARGET fte #endif + db_close(configdb); buf_del(databuf); } @@ -393,6 +407,15 @@ string Net_ReadPicture() return img; } +void Net_Config() +{ + string key, value; + key = ReadString(); + value = ReadString(); + db_put(configdb, strcat("/v/", key), value); + db_put(configdb, strcat("/s/", key), "1"); +} + // CSQC_Parse_TempEntity : Handles all temporary entity network data in the CSQC layer. // You must ALWAYS first acquire the temporary ID, which is sent as a byte. // Return value should be 1 if CSQC handled the temporary entity, otherwise return 0 to have the engine process the event. @@ -431,7 +454,10 @@ float CSQC_Parse_TempEntity() Net_Mapvote(); bHandled = true; break; - + case TE_CSQC_CONFIG: + Net_Config(); + bHandled = true; + break; default: // No special logic for this temporary entity; return 0 so the engine can handle it bHandled = false; diff --git a/data/qcsrc/client/csqc_builtins.qc b/data/qcsrc/client/csqc_builtins.qc index fd8c1a412..cef8dbaa1 100644 --- a/data/qcsrc/client/csqc_builtins.qc +++ b/data/qcsrc/client/csqc_builtins.qc @@ -20,7 +20,7 @@ entity (entity start, .string fld, string match) find = #18; string (string s) precache_sound = #19; string (string s) precache_model = #20; -void (string s) dprint = #25; +//void (string s) dprint = #25; string (float f) ftos = #26; string (vector v) vtos = #27; void () coredump = #28; @@ -262,3 +262,9 @@ entity(float num) edict_num = #459; string(void) ReadPicture = #501; string(string filename) whichpack = #503; float(entity ent) num_for_edict = #512; +float(string s, string separator1, ...) tokenizebyseparator = #479; +string(string in) uri_unescape = #511; +float(float caseinsensitive, string s, ...) crc16 = #494; +string(string info, string key) infoget = #227; +string(string info, string key, string value, ...) infoadd = #226; +string(string in) uri_escape = #510; diff --git a/data/qcsrc/client/main.qh b/data/qcsrc/client/main.qh index 82b750568..886c2d0b1 100644 --- a/data/qcsrc/client/main.qh +++ b/data/qcsrc/client/main.qh @@ -86,3 +86,5 @@ float sbar_font; float csqc_flags; #define CSQC_FLAG_READPICTURE 1 + +string config_get(string key, string defaultvalue); diff --git a/data/qcsrc/client/mapvoting.qc b/data/qcsrc/client/mapvoting.qc index cefc73c32..6576970ae 100644 --- a/data/qcsrc/client/mapvoting.qc +++ b/data/qcsrc/client/mapvoting.qc @@ -217,6 +217,7 @@ void MapVote_Init() if(mv_abstain) mv_abstain = 1; // must be 1 for bool-true, makes stuff easier mv_detail = ReadByte(); + mv_ownvote = -1; if(mv_num_maps <= 8) @@ -237,7 +238,7 @@ void MapVote_Init() pk3 = strzone(ReadString()); mv_maps[i] = map; mv_pk3[i] = pk3; - map = strzone(strcat("maps/", map)); + map = strzone(strcat(config_get("mv_screenshot_dir", "maps"), "/", map)); mv_pics[i] = map; mv_preview[i] = false; diff --git a/data/qcsrc/client/pre.qh b/data/qcsrc/client/pre.qh index 706da5ed1..5b117982d 100644 --- a/data/qcsrc/client/pre.qh +++ b/data/qcsrc/client/pre.qh @@ -1,3 +1,5 @@ #ifdef USE_FTE #pragma target FTE #endif + +#define CSQC 1 diff --git a/data/qcsrc/client/progs.src b/data/qcsrc/client/progs.src index 40b27d5b4..be67db42e 100644 --- a/data/qcsrc/client/progs.src +++ b/data/qcsrc/client/progs.src @@ -4,8 +4,11 @@ pre.qh Defs.qc csqc_constants.qc ../common/constants.qh + csqc_builtins.qc +../common/util.qh + main.qh miscfunctions.qc @@ -21,3 +24,5 @@ mapvoting.qc Main.qc View.qc +../common/util.qc +../common/gamecommand.qc diff --git a/data/qcsrc/common/constants.qh b/data/qcsrc/common/constants.qh index 27c1dfc98..22e496e5f 100644 --- a/data/qcsrc/common/constants.qh +++ b/data/qcsrc/common/constants.qh @@ -2,7 +2,8 @@ // Revision 1: additional statistics sent (flag caps, returns, deaths) // Revision 2: Mapvote preview pictures // Revision 3: optimized map vote protocol -#define CSQC_REVISION 3 +// Revision 4: CSQC config var system +#define CSQC_REVISION 4 // probably put these in common/ // so server/ and client/ can be synced better @@ -173,6 +174,7 @@ const float TE_CSQC_RETURNS = 103; const float TE_CSQC_DEATHS = 104; const float TE_CSQC_PICTURE = 105; const float TE_CSQC_MAPVOTE = 106; +const float TE_CSQC_CONFIG = 107; const float STAT_KH_KEYS = 32; const float STAT_CTF_STATE = 33; diff --git a/data/qcsrc/common/util.qc b/data/qcsrc/common/util.qc index 1476dd3d0..0a685eb9b 100644 --- a/data/qcsrc/common/util.qc +++ b/data/qcsrc/common/util.qc @@ -16,6 +16,7 @@ string wordwrap(string s, float l) } #ifndef MENUQC +#ifndef CSQC void wordwrap_buffer_sprint(string s) { wordwrap_buffer = strcat(wordwrap_buffer, s); @@ -36,6 +37,7 @@ void wordwrap_sprint(string s, float l) return; } #endif +#endif string unescape(string in) { diff --git a/data/qcsrc/common/util.qh b/data/qcsrc/common/util.qh index e92577da6..5e238b963 100644 --- a/data/qcsrc/common/util.qh +++ b/data/qcsrc/common/util.qh @@ -13,8 +13,10 @@ void dprint_load() // NOTE: s IS allowed to be a tempstring string wordwrap(string s, float l); #ifndef MENUQC +#ifndef CSQC void wordwrap_sprint(string s, float l); #endif +#endif void wordwrap_cb(string s, float l, void(string) callback) float GameCommand_Generic(string cmd); diff --git a/data/qcsrc/server/cl_client.qc b/data/qcsrc/server/cl_client.qc index 57fbb30bf..4cf9c2fa6 100644 --- a/data/qcsrc/server/cl_client.qc +++ b/data/qcsrc/server/cl_client.qc @@ -147,7 +147,7 @@ entity Spawn_WeightedPoint(entity firstspot, float lower, float upper, float exp RandomSelection_Init(); for(spot = firstspot; spot; spot = spot.chain) - RandomSelection_Add(spot, 0, pow(bound(lower, spot.frags, upper), exponent) * spot.cnt); + RandomSelection_Add(spot, 0, pow(bound(lower, spot.frags, upper), exponent) * spot.cnt, spot.frags >= lower); return RandomSelection_chosen_ent; } @@ -2218,5 +2218,21 @@ void PlayerPostThink (void) //do nothing } + /* + float i; + for(i = 0; i < 1000; ++i) + { + vector end; + end = self.origin + '0 0 1024' + 512 * randomvec(); + tracebox(self.origin, self.mins, self.maxs, end, MOVE_NORMAL, self); + if(trace_fraction < 1) + if(!(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT)) + { + print("I HIT SOLID: ", vtos(self.origin), " -> ", vtos(end), "\n"); + break; + } + } + */ + Arena_Warmup(); } diff --git a/data/qcsrc/server/g_world.qc b/data/qcsrc/server/g_world.qc index b6dfc670e..b3d80573f 100644 --- a/data/qcsrc/server/g_world.qc +++ b/data/qcsrc/server/g_world.qc @@ -1892,36 +1892,12 @@ void CheckRules_World() NextLevel(); }; -float randsel_value; -float randsel_priority; -float randsel_count; -void RandSel_Init() -{ - randsel_value = -1; - randsel_priority = -1; - randsel_count = -1; -} -void RandSel_Add(float priority, float value) -{ - if(priority > randsel_priority) - { - randsel_priority = priority; - randsel_value = value; - randsel_count = 1; - } - else if(priority == randsel_priority) - { - randsel_count += 1; - if(ceil(random() * randsel_count) == 1) - randsel_value = value; - } -} - float mapvote_nextthink; float mapvote_initialized; float mapvote_keeptwotime; float mapvote_timeout; string mapvote_message; +string mapvote_screenshot_dir; float mapvote_count; float mapvote_count_real; @@ -2058,6 +2034,11 @@ 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); + if(!cvar("g_maplist_textonly")) MapVote_SendData(MSG_BROADCAST); } @@ -2069,7 +2050,7 @@ void MapVote_SendPicture(float id) WriteByte(MSG_ONE, TE_CSQC_MAPVOTE); WriteByte(MSG_ONE, MAPVOTE_NET_PIC); WriteByte(MSG_ONE, id); - WritePicture(MSG_ONE, strcat("maps/", mapvote_maps[id]), 1024); + WritePicture(MSG_ONE, strcat(mapvote_screenshot_dir, "/", mapvote_maps[id]), 1024); } float GameCommand_MapVote(string cmd) @@ -2101,7 +2082,12 @@ float MapVote_GetMapMask() void MapVote_SendData(float targ) { string mapfile; - float i, o, c; + float i, o; + WriteByte(targ, SVC_TEMPENTITY); + WriteByte(targ, TE_CSQC_CONFIG); + WriteString(targ, "mv_screenshot_dir"); + WriteString(targ, mapvote_screenshot_dir); + WriteByte(targ, SVC_TEMPENTITY); WriteByte(targ, TE_CSQC_MAPVOTE); WriteByte(targ, MAPVOTE_NET_INIT); @@ -2117,8 +2103,12 @@ void MapVote_SendData(float targ) if(mapvote_maps[i] != "") { WriteString(targ, mapvote_maps[i]); - mapfile = strcat("maps/", mapvote_maps[i], ".bsp"); - mapfile = whichpack(mapfile); + mapfile = strcat(mapvote_screenshot_dir, "/", mapvote_maps[i]); + mapfile = whichpack(strcat(mapfile, ".tga")); + if(mapfile == "") + mapfile = whichpack(strcat(mapfile, ".jpg")); + if(mapfile == "") + mapfile = whichpack(strcat(mapfile, ".png")); for(o = strstr(mapfile, "/", 0)+1; o > 0; o = strstr(mapfile, "/", 0)+1) mapfile = substring(mapfile, o, 999); WriteString(targ, mapfile); @@ -2143,7 +2133,6 @@ void MapVote_UpdateData(float targ) void MapVote_TellVote(float targ, float vote) { - float i; WriteByte(targ, SVC_TEMPENTITY); WriteByte(targ, TE_CSQC_MAPVOTE); WriteByte(targ, MAPVOTE_NET_OWNVOTE); @@ -2221,20 +2210,20 @@ float MapVote_CheckRules_2() if(mapvote_abstain) mapvote_voters_real -= mapvote_votes[mapvote_count - 1]; - RandSel_Init(); + RandomSelection_Init(); for(i = 0; i < mapvote_count_real; ++i) if(mapvote_maps[i] != "") - RandSel_Add(mapvote_votes[i], i); - firstPlace = randsel_value; - firstPlaceVotes = randsel_priority; + RandomSelection_Add(world, i, 1, mapvote_votes[i]); + firstPlace = RandomSelection_chosen_float; + firstPlaceVotes = RandomSelection_best_priority; //dprint("First place: ", ftos(firstPlace), "\n"); //dprint("First place votes: ", ftos(firstPlaceVotes), "\n"); - RandSel_Init(); + RandomSelection_Init(); for(i = 0; i < mapvote_count_real; ++i) if(mapvote_maps[i] != "") if(i != firstPlace) - RandSel_Add(mapvote_votes[i], i); - secondPlace = randsel_value; - secondPlaceVotes = randsel_priority; + RandomSelection_Add(world, i, 1, mapvote_votes[i]); + secondPlace = RandomSelection_chosen_float; + secondPlaceVotes = RandomSelection_best_priority; //dprint("Second place: ", ftos(secondPlace), "\n"); //dprint("Second place votes: ", ftos(secondPlaceVotes), "\n"); diff --git a/data/qcsrc/server/miscfunctions.qc b/data/qcsrc/server/miscfunctions.qc index c1c4ba8a1..bac71171c 100644 --- a/data/qcsrc/server/miscfunctions.qc +++ b/data/qcsrc/server/miscfunctions.qc @@ -3,6 +3,7 @@ void() spawnpoint_use; string ColoredTeamName(float t); float RandomSelection_totalweight; +float RandomSelection_best_priority; entity RandomSelection_chosen_ent; float RandomSelection_chosen_float; void RandomSelection_Init() @@ -10,14 +11,25 @@ void RandomSelection_Init() RandomSelection_totalweight = 0; RandomSelection_chosen_ent = world; RandomSelection_chosen_float = 0; + RandomSelection_best_priority = -1; } -void RandomSelection_Add(entity e, float f, float weight) +void RandomSelection_Add(entity e, float f, float weight, float priority) { - RandomSelection_totalweight += weight; - if(random() * RandomSelection_totalweight <= weight) + if(priority > RandomSelection_best_priority) { + RandomSelection_best_priority = priority; RandomSelection_chosen_ent = e; RandomSelection_chosen_float = f; + RandomSelection_totalweight = weight; + } + else if(priority == RandomSelection_best_priority) + { + RandomSelection_totalweight += weight; + if(random() * RandomSelection_totalweight <= weight) + { + RandomSelection_chosen_ent = e; + RandomSelection_chosen_float = f; + } } } diff --git a/data/qcsrc/server/sv_main.qc b/data/qcsrc/server/sv_main.qc index a9cefaba4..90cd94cce 100644 --- a/data/qcsrc/server/sv_main.qc +++ b/data/qcsrc/server/sv_main.qc @@ -193,7 +193,7 @@ void StartFrame (void) { RandomSelection_Init(); for(self = world; (self = find(self, classname, "player")); ) - RandomSelection_Add(self, 0, 1); + RandomSelection_Add(self, 0, 1, 0); self = RandomSelection_chosen_ent; SelectSpawnPoint(0); } -- 2.39.2