X-Git-Url: https://de.git.xonotic.org/?p=xonotic%2Fxonotic-data.pk3dir.git;a=blobdiff_plain;f=qcsrc%2Fserver%2Fmiscfunctions.qc;h=5b8ec7127fd861a81b3dde4d32fa8e25ac5390c4;hp=f8f5ebe2304275b4b220e4d7d4c59f5824876b43;hb=affe25ca493e6b2e6b59e55fa1e258954bc60020;hpb=aa3becb7d6b63184cf4c64416b598be242cae239 diff --git a/qcsrc/server/miscfunctions.qc b/qcsrc/server/miscfunctions.qc index f8f5ebe230..5b8ec7127f 100644 --- a/qcsrc/server/miscfunctions.qc +++ b/qcsrc/server/miscfunctions.qc @@ -16,9 +16,6 @@ void WarpZone_crosshair_trace(entity pl) void() spawnfunc_info_player_deathmatch; // needed for the other spawnpoints void() spawnpoint_use; -float race_GetTime(float pos); -string race_GetName(float pos); -string race_PlaceName(float pos); string GetMapname(); string ColoredTeamName(float t); @@ -184,6 +181,7 @@ void GameLogClose() vector PL_VIEW_OFS; vector PL_MIN; vector PL_MAX; +vector PL_HEAD; vector PL_CROUCH_VIEW_OFS; vector PL_CROUCH_MIN; vector PL_CROUCH_MAX; @@ -194,6 +192,7 @@ void relocate_spawnpoint() PL_VIEW_OFS = stov(cvar_string("sv_player_viewoffset")); PL_MIN = stov(cvar_string("sv_player_mins")); PL_MAX = stov(cvar_string("sv_player_maxs")); + PL_HEAD = stov(cvar_string("sv_player_headsize")); PL_CROUCH_VIEW_OFS = stov(cvar_string("sv_player_crouch_viewoffset")); PL_CROUCH_MIN = stov(cvar_string("sv_player_crouch_mins")); PL_CROUCH_MAX = stov(cvar_string("sv_player_crouch_maxs")); @@ -638,6 +637,7 @@ void GetCvars(float f) GetCvars_handleFloat(s, f, cvar_cl_forceplayermodelsfromxonotic, "cl_forceplayermodelsfromxonotic"); #endif GetCvars_handleFloatOnce(s, f, cvar_cl_gunalign, "cl_gunalign"); + GetCvars_handleFloat(s, f, cvar_cl_allow_uid2name, "cl_allow_uid2name"); // fixup of switchweapon (needed for LMS or when spectating is disabled, as PutClientInServer comes too early) if (f > 0) @@ -855,6 +855,7 @@ float g_pickup_ammo_anyway; float g_pickup_weapons_anyway; float g_weaponarena; float g_weaponarena_random; +float g_weaponarena_random_with_laser; string g_weaponarena_list; float g_weaponspeedfactor; float g_weaponratefactor; @@ -995,6 +996,7 @@ void readplayerstartcvars() g_weaponarena_random = cvar("g_weaponarena_random"); else g_weaponarena_random = 0; + g_weaponarena_random_with_laser = cvar("g_weaponarena_random_with_laser"); if (g_weaponarena) { @@ -1184,8 +1186,14 @@ void readlevelcvars(void) MUTATOR_ADD(mutator_nix); if(cvar("g_dodging")) MUTATOR_ADD(mutator_dodging); - if(cvar("g_rocket_flying") || (cvar("g_balance_rocketlauncher_detonatedelay") == 0 && stof(cvar_defstring("g_balance_rocketlauncher_detonatedelay")) != 0)) + if(cvar("g_rocket_flying")) MUTATOR_ADD(mutator_rocketflying); + if(cvar("g_vampire")) + MUTATOR_ADD(mutator_vampire); + + serverflags = 0; + if(cvar("sv_allow_fullbright")) + serverflags |= SERVERFLAG_ALLOW_FULLBRIGHT; g_bugrigs = cvar("g_bugrigs"); g_bugrigs_planar_movement = cvar("g_bugrigs_planar_movement"); @@ -1226,11 +1234,9 @@ void readlevelcvars(void) g_footsteps = cvar("g_footsteps"); g_grappling_hook = cvar("g_grappling_hook"); g_jetpack = cvar("g_jetpack"); - g_laserguided_missile = cvar("g_laserguided_missile"); g_midair = cvar("g_midair"); g_minstagib = cvar("g_minstagib"); g_norecoil = cvar("g_norecoil"); - g_vampire = cvar("g_vampire"); g_bloodloss = cvar("g_bloodloss"); sv_maxidle = cvar("sv_maxidle"); sv_maxidle_spectatorsareidle = cvar("sv_maxidle_spectatorsareidle"); @@ -1732,7 +1738,6 @@ void precache() #define INITPRIO_FIRST 0 #define INITPRIO_GAMETYPE 0 #define INITPRIO_GAMETYPE_FALLBACK 1 -#define INITPRIO_CVARS 5 #define INITPRIO_FINDTARGET 10 #define INITPRIO_DROPTOFLOOR 20 #define INITPRIO_SETLOCATION 90 @@ -2079,6 +2084,106 @@ void print_to(entity e, string s) print(s, "\n"); } +string uid2name(string myuid) { + string s; + s = db_get(ServerProgsDB, strcat("uid2name", myuid)); + + if(s == "") + s = "^1Unregistered Player"; + return s; +} + +float race_readTime(string map, float pos) +{ + string rr; + if(g_cts) + rr = CTS_RECORD; + else + rr = RACE_RECORD; + + return stof(db_get(ServerProgsDB, strcat(map, rr, "time", ftos(pos)))); +} + +string race_readUID(string map, float pos) +{ + string rr; + if(g_cts) + rr = CTS_RECORD; + else + rr = RACE_RECORD; + + return db_get(ServerProgsDB, strcat(map, rr, "crypto_idfp", ftos(pos))); +} + +float race_readPos(string map, float t) { + float i; + for (i = 1; i <= RANKINGS_CNT; ++i) + if (race_readTime(map, i) == 0 || race_readTime(map, i) > t) + return i; + + return 0; // pos is zero if unranked +} + +void race_writeTime(string map, float t, string myuid) +{ + string rr; + if(g_cts) + rr = CTS_RECORD; + else + rr = RACE_RECORD; + + float newpos; + newpos = race_readPos(map, t); + + float i, prevpos; + for(i = 1; i <= RANKINGS_CNT; ++i) + { + if(race_readUID(map, i) == myuid) + prevpos = i; + } + if (prevpos) { // player improved his existing record, only have to iterate on ranks between new and old recs + for (i = prevpos; i > newpos; --i) { + db_put(ServerProgsDB, strcat(map, rr, "time", ftos(i)), ftos(race_readTime(map, i - 1))); + db_put(ServerProgsDB, strcat(map, rr, "crypto_idfp", ftos(i)), race_readUID(map, i - 1)); + } + } else { // player has no ranked record yet + for (i = RANKINGS_CNT; i > newpos; --i) { + db_put(ServerProgsDB, strcat(map, rr, "time", ftos(i)), ftos(race_readTime(map, i - 1))); + db_put(ServerProgsDB, strcat(map, rr, "crypto_idfp", ftos(i)), race_readUID(map, i - 1)); + } + } + + // store new time itself + db_put(ServerProgsDB, strcat(map, rr, "time", ftos(newpos)), ftos(t)); + db_put(ServerProgsDB, strcat(map, rr, "crypto_idfp", ftos(newpos)), myuid); +} + +string race_readName(string map, float pos) +{ + string rr; + if(g_cts) + rr = CTS_RECORD; + else + rr = RACE_RECORD; + + return uid2name(db_get(ServerProgsDB, strcat(map, rr, "crypto_idfp", ftos(pos)))); +} + +string race_placeName(float pos) { + if(floor((mod(pos, 100))/10) * 10 != 10) // examples: 12th, 111th, 213th will not execute this block + { + if(mod(pos, 10) == 1) + return strcat(ftos(pos), "st"); + else if(mod(pos, 10) == 2) + return strcat(ftos(pos), "nd"); + else if(mod(pos, 10) == 3) + return strcat(ftos(pos), "rd"); + else + return strcat(ftos(pos), "th"); + } + else + return strcat(ftos(pos), "th"); +} string getrecords(float page) // 50 records per page { float rec; @@ -2100,6 +2205,7 @@ string getrecords(float page) // 50 records per page r = stof(db_get(ServerProgsDB, strcat(MapInfo_Map_bspname, "/captimerecord/time"))); if (r == 0) continue; + // TODO: uid2name h = db_get(ServerProgsDB, strcat(MapInfo_Map_bspname, "/captimerecord/netname")); s = strcat(s, strpad(32, MapInfo_Map_bspname), " ", strpad(-6, ftos_decimals(r, 2)), " ", h, "\n"); ++rec; @@ -2113,10 +2219,10 @@ string getrecords(float page) // 50 records per page { if (MapInfo_Get_ByID(i)) { - r = stof(db_get(ServerProgsDB, strcat(MapInfo_Map_bspname, RACE_RECORD, "time"))); + r = race_readTime(MapInfo_Map_bspname, 1); if (r == 0) continue; - h = db_get(ServerProgsDB, strcat(MapInfo_Map_bspname, RACE_RECORD, "netname")); + h = race_readName(MapInfo_Map_bspname, 1); s = strcat(s, strpad(32, MapInfo_Map_bspname), " ", strpad(-8, TIME_ENCODED_TOSTRING(r)), " ", h, "\n"); ++rec; } @@ -2129,10 +2235,10 @@ string getrecords(float page) // 50 records per page { if (MapInfo_Get_ByID(i)) { - r = stof(db_get(ServerProgsDB, strcat(MapInfo_Map_bspname, CTS_RECORD, "time"))); + r = race_readTime(MapInfo_Map_bspname, 1); if (r == 0) continue; - h = db_get(ServerProgsDB, strcat(MapInfo_Map_bspname, CTS_RECORD, "netname")); + h = race_readName(MapInfo_Map_bspname, 1); s = strcat(s, strpad(32, MapInfo_Map_bspname), " ", strpad(-8, TIME_ENCODED_TOSTRING(r)), " ", h, "\n"); ++rec; } @@ -2162,11 +2268,11 @@ string getrankings() for (i = 1; i <= RANKINGS_CNT; ++i) { - t = race_GetTime(i); + t = race_readTime(map, i); if (t == 0) continue; - n = race_GetName(i); - p = race_PlaceName(i); + n = race_readName(map, i); + p = race_placeName(i); s = strcat(s, strpad(8, p), " ", strpad(-8, TIME_ENCODED_TOSTRING(t)), " ", n, "\n"); } @@ -2178,6 +2284,193 @@ string getrankings() return strcat("Records for ", map, ":\n", s); } +#define LADDER_FIRSTPOINT 100 +#define LADDER_CNT 10 + // position X still gives LADDER_FIRSTPOINT/X points +#define LADDER_SIZE 30 + // ladder shows the top X players +string top_uids[LADDER_SIZE]; +float top_scores[LADDER_SIZE]; +string getladder() +{ + float i, j, k, uidcnt; + string s, temp_s; + + s = ""; + temp_s = ""; + + string rr; + if(g_cts) + rr = CTS_RECORD; + else + rr = RACE_RECORD; + + string myuid; + + for (k = 0; k < MapInfo_count; ++k) + { + if (MapInfo_Get_ByID(k)) + { + for (i = 0; i <= LADDER_CNT; ++i) { // i = 0 because it is the speed award + if(i == 0) // speed award + { + if(stof(db_get(ServerProgsDB, strcat(MapInfo_Map_bspname, rr, "speed/speed"))) == 0) + continue; + + myuid = db_get(ServerProgsDB, strcat(MapInfo_Map_bspname, rr, "speed/crypto_idfp")); + } + else // normal record, if it exists (else break) + { + if(race_readTime(MapInfo_Map_bspname, i) == 0) + continue; + + myuid = race_readUID(MapInfo_Map_bspname, i); + } + + // string s contains: + // arg 0 = # of speed recs + // arg 1 = # of 1st place recs + // arg 2 = # of 2nd place recs + // ... etc + // LADDER_CNT+1 = total points + + temp_s = db_get(TemporaryDB, strcat("ladder", myuid)); + if (temp_s == "") + { + db_put(TemporaryDB, strcat("uid", ftos(uidcnt)), myuid); + ++uidcnt; + for (j = 0; j <= LADDER_CNT + 1; ++j) + { + if(j != LADDER_CNT + 1) + temp_s = strcat(temp_s, "0 "); + else + temp_s = strcat(temp_s, "0"); + } + } + + tokenize_console(temp_s); + s = ""; + + if(i == 0) // speed award + for (j = 0; j <= LADDER_CNT; ++j) // loop over each arg in the string + { + if(j == 0) // speed award + s = strcat(s, ftos(stof(argv(j)) +1)); // add 1 to speed rec count and write + else + s = strcat(s, " ", argv(j)); // just copy over everything else + } + else // record + for (j = 0; j <= LADDER_CNT; ++j) // loop over each arg in the string + { + if(j == 0) + s = strcat(s, argv(j)); // speed award, dont prefix with " " + else if(j == i) // wanted rec! + s = strcat(s, " ", ftos(stof(argv(j)) +1)); // update argv(j) + else + s = strcat(s, " ", argv(j)); // just copy over everything else + } + + // total points are (by default) calculated like this: + // speedrec = floor(100 / 10) = 10 points + // 1st place = floor(100 / 1) = 100 points + // 2nd place = floor(100 / 2) = 50 points + // 3rd place = floor(100 / 3) = 33 points + // 4th place = floor(100 / 4) = 25 points + // 5th place = floor(100 / 5) = 20 points + // ... etc + + if(i == 0) + s = strcat(s, " ", ftos(stof(argv(LADDER_CNT+1)) + LADDER_FIRSTPOINT / 10)); // speed award, add LADDER_FIRSTPOINT / 10 points + else + s = strcat(s, " ", ftos(stof(argv(LADDER_CNT+1)) + floor(LADDER_FIRSTPOINT / i))); // record, add LADDER_FIRSTPOINT / i points + + db_put(TemporaryDB, strcat("ladder", myuid), s); + } + } + } + + float thiscnt; + string thisuid; + for (i = 0; i <= uidcnt; ++i) // for each known uid + { + thisuid = db_get(TemporaryDB, strcat("uid", ftos(i))); + temp_s = db_get(TemporaryDB, strcat("ladder", thisuid)); + tokenize_console(temp_s); + thiscnt = stof(argv(LADDER_CNT+1)); + + if(thiscnt > top_scores[LADDER_SIZE-1]) + for (j = 0; j < LADDER_SIZE; ++j) // for each place in ladder + { + if(thiscnt > top_scores[j]) + { + for (k = LADDER_SIZE-1; k >= j; --k) + { + top_uids[k] = top_uids[k-1]; + top_scores[k] = top_scores[k-1]; + } + top_uids[j] = thisuid; + top_scores[j] = thiscnt; + break; + } + } + } + + s = "^3-----------------------\n\n"; + + s = strcat(s, "Pos ^3|"); + s = strcat(s, " ^7Total ^3|"); + for (i = 1; i <= LADDER_CNT; ++i) + { + s = strcat(s, " ^7", race_placeName(i), " ^3|"); + } + s = strcat(s, " ^7Speed awards ^3| ^7Name"); + + s = strcat(s, "\n^3----+--------"); + for (i = 1; i <= min(9, LADDER_CNT); ++i) + { + s = strcat(s, "+-----"); + } +#if LADDER_CNT > 9 + for (i = 1; i <= LADDER_CNT - 9; ++i) + { + s = strcat(s, "+------"); + } +#endif + + s = strcat(s, "+--------------+--------------------\n"); + + for (i = 0; i < LADDER_SIZE; ++i) + { + temp_s = db_get(TemporaryDB, strcat("ladder", top_uids[i])); + tokenize_console(temp_s); + if (argv(LADDER_CNT+1) == "") // total is 0, skip + continue; + s = strcat(s, strpad(4, race_placeName(i+1)), "^3| ^7"); // pos + s = strcat(s, strpad(7, argv(LADDER_CNT+1)), "^3| ^7"); // total + for (j = 1; j <= min(9, LADDER_CNT); ++j) + { + s = strcat(s, strpad(4, argv(j)), "^3| ^7"); // 1st, 2nd, 3rd etc cnt + } +#if LADDER_CNT > 9 + for (j = 10; j <= LADDER_CNT; ++j) + { + s = strcat(s, strpad(4, argv(j)), " ^3| ^7"); // 1st, 2nd, 3rd etc cnt + } +#endif + + s = strcat(s, strpad(13, argv(0)), "^3| ^7"); // speed award cnt + s = strcat(s, uid2name(top_uids[i]), "\n"); // name + } + + MapInfo_ClearTemps(); + + if (s == "") + return "No ladder on this server!\n"; + else + return strcat("Top ", ftos(LADDER_SIZE), " ladder rankings:\n", s); +} + + float MoveToRandomMapLocation(entity e, float goodcontents, float badcontents, float badsurfaceflags, float attempts, float maxaboveground, float minviewdistance) { float m, i;