some very WIP race code, won't compile yet, but already contains most stuff from...
authorFruitieX <rasse@rasse-laptop.(none)>
Sun, 24 Oct 2010 13:15:05 +0000 (16:15 +0300)
committerFruitieX <rasse@rasse-laptop.(none)>
Sun, 24 Oct 2010 13:15:05 +0000 (16:15 +0300)
qcsrc/common/gamecommand.qc
qcsrc/common/util.qh
qcsrc/server/cl_physics.qc
qcsrc/server/clientcommands.qc
qcsrc/server/g_world.qc
qcsrc/server/gamecommand.qc
qcsrc/server/miscfunctions.qc
qcsrc/server/race.qc

index be2f5e78c202bfed5398a7260041bfea1bb7cfda..f6b54f155b842e6ff683ad236bfb7463f8d785ae 100644 (file)
@@ -831,6 +831,10 @@ float GameCommand_Generic(string command)
                print(records_reply);
                return TRUE;
        }
+       else if(argv(0) == "ladder") {
+               print(ladder_reply);
+               return TRUE;
+       }
        else if(argv(0) == "rankings") {
                print(rankings_reply);
                return TRUE;
index 77b3e03202817a61ef6325761c764ce0de357aff..65bede381e453829e834ca5e330b42e58034e7ed 100644 (file)
@@ -162,7 +162,7 @@ void check_unacceptable_compiler_bugs();
 float compressShotOrigin(vector v);
 vector decompressShotOrigin(float f);
 
-string rankings_reply, lsmaps_reply, lsnewmaps_reply, maplist_reply; // cached replies
+string rankings_reply, ladder_reply, lsmaps_reply, lsnewmaps_reply, maplist_reply; // cached replies
 string records_reply[10];
 
 float RandomSelection_totalweight;
index b005dd5f3f20c575914e76107a7891ffd4198d07..376e54f24eac3a1ce9682e23b2c5e60c767db204 100644 (file)
@@ -673,6 +673,7 @@ void SpecialCommand()
 
 float speedaward_speed;
 string speedaward_holder;
+string speedaward_uid;
 void race_send_speedaward(float msg)
 {
        // send the best speed of the round
@@ -685,6 +686,7 @@ void race_send_speedaward(float msg)
 
 float speedaward_alltimebest;
 string speedaward_alltimebest_holder;
+string speedaward_alltimebest_uid;
 void race_send_speedaward_alltimebest(float msg)
 {
        // send the best speed
@@ -1306,6 +1308,9 @@ void SV_PlayerPhysics()
                if(vlen(self.velocity - self.velocity_z * '0 0 1') > speedaward_speed) {
                        speedaward_speed = vlen(self.velocity - self.velocity_z * '0 0 1');
                        speedaward_holder = self.netname;
+                       if(speedaward_uid)
+                               strunzone(speedaward_uid);
+                       speedaward_uid = strzone(self.crypto_idfp);
                        speedaward_lastupdate = time;
                }
                if(speedaward_speed > speedaward_lastsent && time - speedaward_lastupdate > 1) {
@@ -1321,6 +1326,7 @@ void SV_PlayerPhysics()
                                speedaward_alltimebest_holder = speedaward_holder;
                                db_put(ServerProgsDB, strcat(GetMapname(), rr, "speed/speed"), ftos(speedaward_alltimebest));
                                db_put(ServerProgsDB, strcat(GetMapname(), rr, "speed/netname"), speedaward_alltimebest_holder);
+                               db_put(ServerProgsDB, strcat(GetMapname(), rr, "speed/crypto_idfp"), speedaward_alltimebest_holder);
                                race_send_speedaward_alltimebest(MSG_ALL);
                        }
                }
index a9fd886bfe9c331e34b7651faf4c4bca063703c5..a11ab82f9955577b47ebe4275e0aebc4b0fc207c 100644 (file)
@@ -303,6 +303,8 @@ void SV_ParseClientCommand(string s) {
        } else if(cmd == "records") {
                for(i = 0; i < 10; ++i)
                        sprint(self, records_reply[i]);
+       } else if(cmd == "ladder") {
+               sprint(self, ladder_reply);
        } else if(cmd == "rankings") {
                sprint(self, rankings_reply);
        } else if(cmd == "voice") {
index 08329a29d7e61a76a2f1e3097b307a93fa0fff78..053ed5124b134adc2d4d1837bef9b117bf1d4eb9 100644 (file)
@@ -697,6 +697,8 @@ void spawnfunc_worldspawn (void)
        {
                records_reply[i] = strzone(getrecords(i));
        }
+       if(g_cts)
+               ladder_reply = strzone(getladder());
 
        rankings_reply = strzone(getrankings());
 
index b5c68ca79bcbb84f2ce8aa11bb8627d26e9106ec..e864b52267b9998ca27b65de0b5ccedc3e400c7d 100644 (file)
@@ -924,6 +924,11 @@ void GameCommand(string command)
                        print(records_reply[i]);
                return;
        }
+       if (argv(0) == "ladder")
+       {
+               print(ladder_reply);
+               return;
+       }
        if (argv(0) == "rankings")
        {
                strunzone(rankings_reply);
index 05f297746c5243812b1a0e61d811002c8aa422c9..e5eb7e41f622efbacd00ce19debdfb730f7c3344 100644 (file)
@@ -16,7 +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();
@@ -2069,6 +2068,67 @@ void print_to(entity e, string s)
         print(s, "\n");
 }
 
+string uid2name(string myuid) {
+       // TODO TODO TODO!
+       // store uid in separate uid2name db IF CLIENT ALLOWS THIS
+       // - make it global for all mods
+       // perhaps show 10 first digits here if missing name?
+       string s;
+       s = db_get(ServerProgsDB, strcat("uid2name", myuid));
+       
+       if(s == "")
+               s = "^1Unregistered Player";
+       return s;
+}
+
+float race_GetTime(string map, float pos)
+{
+       float rr;
+       if(g_cts)
+               rr = CTS_RECORD;
+       else
+               rr = RACE_RECORD;
+
+       return stof(db_get(ServerProgsDB, strcat(map, rr, "time", ftos(pos))));
+}
+
+string race_GetUID(string map, float pos)
+{
+       float rr;
+       if(g_cts)
+               rr = CTS_RECORD;
+       else
+               rr = RACE_RECORD;
+
+       return stof(db_get(ServerProgsDB, strcat(map, rr, "time", ftos(pos))));
+}
+
+string race_GetName(string map, float pos)
+{
+       float 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(pos < 10 || pos > 20)
+       {
+               if(pos % 10 == 1)
+                       return strcat(ftos(pos), "st");
+               else if(pos % 10 == 2)
+                       return strcat(ftos(pos), "nd");
+               else if(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;
@@ -2090,6 +2150,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;
@@ -2103,10 +2164,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_GetTime(MapInfo_Map_bspname, 1);
                 if (r == 0)
                     continue;
-                h = db_get(ServerProgsDB, strcat(MapInfo_Map_bspname, RACE_RECORD, "netname"));
+               h = race_GetName(MapInfo_Map_bspname, 1)
                 s = strcat(s, strpad(32, MapInfo_Map_bspname), " ", strpad(-8, TIME_ENCODED_TOSTRING(r)), " ", h, "\n");
                 ++rec;
             }
@@ -2119,10 +2180,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_GetTime(MapInfo_Map_bspname, 1);
                 if (r == 0)
                     continue;
-                h = db_get(ServerProgsDB, strcat(MapInfo_Map_bspname, CTS_RECORD, "netname"));
+               h = race_GetName(MapInfo_Map_bspname, 1)
                 s = strcat(s, strpad(32, MapInfo_Map_bspname), " ", strpad(-8, TIME_ENCODED_TOSTRING(r)), " ", h, "\n");
                 ++rec;
             }
@@ -2152,10 +2213,10 @@ string getrankings()
 
     for (i = 1; i <= RANKINGS_CNT; ++i)
     {
-        t = race_GetTime(i);
+        t = race_GetTime(map, i);
        if (t == 0)
            continue;
-       n = race_GetName(i);
+       n = race_GetName(map, i);
        p = race_PlaceName(i);
         s = strcat(s, strpad(8, p), " ", strpad(-8, TIME_ENCODED_TOSTRING(t)), " ", n, "\n");
     }
@@ -2168,6 +2229,163 @@ string getrankings()
         return strcat("Records for ", map, ":\n", s);
 }
 
+const float LADDER_FIRSTPOINT = 100;
+const float LADDER_CNT = 10; // position X still gives LADDER_FIRSTPOINT/X points
+const float LADDER_SIZE = 30; // ladder shows the top X players
+string top_uids[LADDER_SIZE];
+float top_scores[LADDER_SIZE];
+float UIDCNT;
+string getladder()
+{
+    float i, j, k;
+    string s, len, temp_s;
+
+    s = "";
+    temp_s = "";
+
+    string myuid;
+
+    for (k = 0; k < MapInfo_count; ++k)
+    {
+        if (MapInfo_Get_ByID(k))
+       {
+               for (i = 0; i < LADDER_CNT; ++i) {
+                       if(stof(db_get(ServerProgsDB, strcat(GetMapname(), rr, "time", ftos(Ii)))) == 0)
+                           break;
+
+                       myuid = db_get(ServerProgsDB, strcat(GetMapname(), rr, "crypto_idfp", ftos(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");
+                           }
+                       }
+
+                       len = tokenize_console(temp_s);
+                       s = "";
+
+                       if(i == 0) // speedrec
+                           for (j = 0; j <= LADDER_CNT; ++j) // loop over each arg in the string
+                           {
+                               if(j == 0) // speed rec!
+                                   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 rec, 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)); // speedrec, 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));
+       len = 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 <= LADDER_CNT; ++i)
+    {
+       s = strcat(s, "+-----");
+    }
+    s = strcat(s, "+--------------+--------------------\n");
+
+    for (i = 0; i < LADDER_SIZE; ++i)
+    {
+       temp_s = db_get(TemporaryDB, strcat("ladder", top_uids[i]));
+       len = 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 <= LADDER_CNT; ++j)
+       {
+           s = strcat(s, strpad(4, argv(j)), "^3| ^7"); // 1st, 2nd, 3rd etc cnt
+       }
+       s = strcat(s, strpad(13, argv(0)), "^3| ^7"); // speed rec cnt
+       s = strcat(s, race_GetName_OfUID(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;
index 2de74ab523cd3d83e50f9ff4c9e21e54c77619e4..dc4839500f2589ec5735d2cd8139f980a9def070 100644 (file)
@@ -198,17 +198,6 @@ void race_SendStatus(float id, entity e)
        });
 }
 
-string race_PlaceName(float pos) {
-       if(pos == 1)
-               return "1st";
-       else if(pos == 2)
-               return "2nd";
-       else if(pos == 3)
-               return "3rd";
-       else
-               return strcat(ftos(pos), "th");
-}
-
 void race_SetTime(entity e, float t, float match_rec) {
        float pos, prevpos;
        pos = race_GetPos(t);