]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/server/miscfunctions.qc
Move server-side chat handling to its own file, and add a note about miscfunctions
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / miscfunctions.qc
index b748c17a00ccd96fd25ac4efc93f2ee242d7e1a0..9a0c4ae6531df63260b0581f1d630f841e5fd89c 100644 (file)
@@ -1,3 +1,5 @@
+// NOTE: Please do NOT add new functions to this file! It is a dumping ground that is in the process of being cleaned up, please find a proper home for your code!
+
 #include "miscfunctions.qh"
 
 #include "antilag.qh"
@@ -88,191 +90,6 @@ void WarpZone_crosshair_trace(entity pl)
        WarpZone_traceline_antilag(pl, CS(pl).cursor_trace_start, CS(pl).cursor_trace_start + normalize(CS(pl).cursor_trace_endpos - CS(pl).cursor_trace_start) * max_shot_distance, MOVE_NORMAL, pl, ANTILAG_LATENCY(pl));
 }
 
-entity findnearest(vector point, bool checkitems, vector axismod)
-{
-    vector dist;
-    int num_nearest = 0;
-
-    IL_EACH(((checkitems) ? g_items : g_locations), ((checkitems) ? (it.target == "###item###") : (it.classname == "target_location")),
-    {
-       if ((it.items == IT_KEY1 || it.items == IT_KEY2) && it.target == "###item###")
-            dist = it.oldorigin;
-        else
-            dist = it.origin;
-        dist = dist - point;
-        dist = dist.x * axismod.x * '1 0 0' + dist.y * axismod.y * '0 1 0' + dist.z * axismod.z * '0 0 1';
-        float len = vlen2(dist);
-
-        int l;
-        for (l = 0; l < num_nearest; ++l)
-        {
-            if (len < nearest_length[l])
-                break;
-        }
-
-        // now i tells us where to insert at
-        //   INSERTION SORT! YOU'VE SEEN IT! RUN!
-        if (l < NUM_NEAREST_ENTITIES)
-        {
-            for (int j = NUM_NEAREST_ENTITIES - 1; j >= l; --j)
-            {
-                nearest_length[j + 1] = nearest_length[j];
-                nearest_entity[j + 1] = nearest_entity[j];
-            }
-            nearest_length[l] = len;
-            nearest_entity[l] = it;
-            if (num_nearest < NUM_NEAREST_ENTITIES)
-                num_nearest = num_nearest + 1;
-        }
-    });
-
-    // now use the first one from our list that we can see
-    for (int j = 0; j < num_nearest; ++j)
-    {
-        traceline(point, nearest_entity[j].origin, true, NULL);
-        if (trace_fraction == 1)
-        {
-            if (j != 0)
-                LOG_TRACEF("Nearest point (%s) is not visible, using a visible one.", nearest_entity[0].netname);
-            return nearest_entity[j];
-        }
-    }
-
-    if (num_nearest == 0)
-        return NULL;
-
-    LOG_TRACE("Not seeing any location point, using nearest as fallback.");
-    /* DEBUGGING CODE:
-    dprint("Candidates were: ");
-    for(j = 0; j < num_nearest; ++j)
-    {
-       if(j != 0)
-               dprint(", ");
-       dprint(nearest_entity[j].netname);
-    }
-    dprint("\n");
-    */
-
-    return nearest_entity[0];
-}
-
-string NearestLocation(vector p)
-{
-    string ret = "somewhere";
-    entity loc = findnearest(p, false, '1 1 1');
-    if (loc)
-        ret = loc.message;
-    else
-    {
-        loc = findnearest(p, true, '1 1 4');
-        if (loc)
-            ret = loc.netname;
-    }
-    return ret;
-}
-
-string PlayerHealth(entity this)
-{
-       float myhealth = floor(GetResource(this, RES_HEALTH));
-       if(myhealth == -666)
-               return "spectating";
-       else if(myhealth == -2342 || (myhealth == 2342 && mapvote_initialized))
-               return "observing";
-       else if(myhealth <= 0 || IS_DEAD(this))
-               return "dead";
-       return ftos(myhealth);
-}
-
-string WeaponNameFromWeaponentity(entity this, .entity weaponentity)
-{
-       entity wepent = this.(weaponentity);
-       if(!wepent)
-               return "none";
-       else if(wepent.m_weapon != WEP_Null)
-               return wepent.m_weapon.m_name;
-       else if(wepent.m_switchweapon != WEP_Null)
-               return wepent.m_switchweapon.m_name;
-       return "none"; //REGISTRY_GET(Weapons, wepent.cnt).m_name;
-}
-
-string formatmessage(entity this, string msg)
-{
-       float p, p1, p2;
-       float n;
-       vector cursor = '0 0 0';
-       entity cursor_ent = NULL;
-       string escape;
-       string replacement;
-       p = 0;
-       n = 7;
-       bool traced = false;
-
-       MUTATOR_CALLHOOK(PreFormatMessage, this, msg);
-       msg = M_ARGV(1, string);
-
-       while (1) {
-               if (n < 1)
-                       break; // too many replacements
-
-               n = n - 1;
-               p1 = strstrofs(msg, "%", p); // NOTE: this destroys msg as it's a tempstring!
-               p2 = strstrofs(msg, "\\", p); // NOTE: this destroys msg as it's a tempstring!
-
-               if (p1 < 0)
-                       p1 = p2;
-
-               if (p2 < 0)
-                       p2 = p1;
-
-               p = min(p1, p2);
-
-               if (p < 0)
-                       break;
-
-               if(!traced)
-               {
-                       WarpZone_crosshair_trace_plusvisibletriggers(this);
-                       cursor = trace_endpos;
-                       cursor_ent = trace_ent;
-                       traced = true;
-               }
-
-               replacement = substring(msg, p, 2);
-               escape = substring(msg, p + 1, 1);
-
-               .entity weaponentity = weaponentities[0]; // TODO: unhardcode
-
-               switch(escape)
-               {
-                       case "%": replacement = "%"; break;
-                       case "\\":replacement = "\\"; break;
-                       case "n": replacement = "\n"; break;
-                       case "a": replacement = ftos(floor(GetResource(this, RES_ARMOR))); break;
-                       case "h": replacement = PlayerHealth(this); break;
-                       case "l": replacement = NearestLocation(this.origin); break;
-                       case "y": replacement = NearestLocation(cursor); break;
-                       case "d": replacement = NearestLocation(this.death_origin); break;
-                       case "w": replacement = WeaponNameFromWeaponentity(this, weaponentity); break;
-                       case "W": replacement = GetAmmoName(this.(weaponentity).m_weapon.ammo_type); break;
-                       case "x": replacement = ((cursor_ent.netname == "" || !cursor_ent) ? "nothing" : cursor_ent.netname); break;
-                       case "s": replacement = ftos(vlen(this.velocity - this.velocity_z * '0 0 1')); break;
-                       case "S": replacement = ftos(vlen(this.velocity)); break;
-                       case "t": replacement = seconds_tostring(ceil(max(0, autocvar_timelimit * 60 + game_starttime - time))); break;
-                       case "T": replacement = seconds_tostring(floor(time - game_starttime)); break;
-                       default:
-                       {
-                               MUTATOR_CALLHOOK(FormatMessage, this, escape, replacement, msg);
-                               replacement = M_ARGV(2, string);
-                               break;
-                       }
-               }
-
-               msg = strcat(substring(msg, 0, p), replacement, substring(msg, p+2, strlen(msg) - (p+2)));
-               p = p + strlen(replacement);
-       }
-       return msg;
-}
-
 /*
 =============
 GetCvars