]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/client/waypointsprites.qc
Merge branch 'master' into Mario/vehicles
[xonotic/xonotic-data.pk3dir.git] / qcsrc / client / waypointsprites.qc
index 2df3dd411bc6d9f4da76ef4124a81fa51658c8fc..f63b3cf3c85da63e2c09fb5a39e422f88954a1ea 100644 (file)
@@ -1,51 +1,20 @@
-float waypointsprite_initialized;
-float waypointsprite_fadedistance;
-float waypointsprite_normdistance;
-float waypointsprite_minscale;
-float waypointsprite_minalpha;
-float waypointsprite_distancealphaexponent;
-float waypointsprite_timealphaexponent;
-float waypointsprite_scale;
-float waypointsprite_fontsize;
-float waypointsprite_edgefadealpha;
-float waypointsprite_edgefadescale;
-float waypointsprite_edgefadedistance;
-float waypointsprite_edgeoffset_bottom;
-float waypointsprite_edgeoffset_left;
-float waypointsprite_edgeoffset_right;
-float waypointsprite_edgeoffset_top;
-float waypointsprite_crosshairfadealpha;
-float waypointsprite_crosshairfadescale;
-float waypointsprite_crosshairfadedistance;
-float waypointsprite_distancefadealpha;
-float waypointsprite_distancefadescale;
-float waypointsprite_distancefadedistance;
-float waypointsprite_alpha;
-
-.float helpme;
-.float rule;
-.string netname; // primary picture
-.string netname2; // secondary picture
-.string netname3; // tertiary picture
-.float team; // team that gets netname2
-.float lifetime;
-.float fadetime;
-.float maxdistance;
-.float hideflags;
-.float spawntime;
-.float health;
-.float build_started;
-.float build_starthealth;
-.float build_finished;
-
-const float SPRITE_HEALTHBAR_WIDTH = 144;
-const float SPRITE_HEALTHBAR_HEIGHT = 9;
-const float SPRITE_HEALTHBAR_MARGIN = 6;
-const float SPRITE_HEALTHBAR_BORDER = 2;
-const float SPRITE_HEALTHBAR_BORDERALPHA = 1;
-const float SPRITE_HEALTHBAR_HEALTHALPHA = 0.5;
-const float SPRITE_ARROW_SCALE = 1.0;
-const float SPRITE_HELPME_BLINK = 2;
+#include "waypointsprites.qh"
+#include "_all.qh"
+
+#include "hud.qh"
+#include "teamradar.qh"
+
+#include "../common/buffs.qh"
+#include "../common/constants.qh"
+#include "../common/teams.qh"
+
+#include "../common/weapons/all.qh"
+
+#include "../csqcmodellib/interpolate.qh"
+
+#include "../warpzonelib/mathlib.qh"
+
+.float alpha;
 
 void drawrotpic(vector org, float rot, string pic, vector sz, vector hotspot, vector rgb, float a, float f)
 {
@@ -55,9 +24,9 @@ void drawrotpic(vector org, float rot, string pic, vector sz, vector hotspot, ve
 
        // hotspot-relative coordinates of the corners
        v1 = hotspot;
-       v2 = hotspot + '1 0 0' * sz_x;
-       v3 = hotspot + '1 0 0' * sz_x + '0 1 0' * sz_y;
-       v4 = hotspot                  + '0 1 0' * sz_y;
+       v2 = hotspot + '1 0 0' * sz.x;
+       v3 = hotspot + '1 0 0' * sz.x + '0 1 0' * sz.y;
+       v4 = hotspot                  + '0 1 0' * sz.y;
 
        // rotate them, and make them absolute
        rot = -rot; // rotate by the opposite angle, as our coordinate system is reversed
@@ -85,7 +54,7 @@ void drawquad(vector o, vector ri, vector up, string pic, vector rgb, float a, f
        R_EndPolygon();
 }
 
-void drawhealthbar(vector org, float rot, float h, vector sz, vector hotspot, float width, float height, float margin, float border, float align, vector rgb, float a, vector hrgb, float ha, float f)
+void drawhealthbar(vector org, float rot, float h, vector sz, vector hotspot, float width, float theheight, float margin, float border, float align, vector rgb, float a, vector hrgb, float ha, float f)
 {
        vector o, ri, up;
        float owidth; // outer width
@@ -103,13 +72,13 @@ void drawhealthbar(vector org, float rot, float h, vector sz, vector hotspot, fl
        up = rotate(up, rot);
 
        owidth = width + 2 * border;
-       o = o - up * (margin + border + height) + ri * (sz_x - owidth) * 0.5;
+       o = o - up * (margin + border + theheight) + ri * (sz.x - owidth) * 0.5;
 
        drawquad(o - up * border,                               ri * owidth,    up * border, "", rgb,  a,  f);
-       drawquad(o + up * height,                               ri * owidth,    up * border, "", rgb,  a,  f);
-       drawquad(o,                                             ri * border,    up * height, "", rgb,  a,  f);
-       drawquad(o + ri * (owidth - border),                    ri * border,    up * height, "", rgb,  a,  f);
-       drawquad(o + ri * (border + align * ((1 - h) * width)), ri * width * h, up * height, "", hrgb, ha, f);
+       drawquad(o + up * theheight,                               ri * owidth,    up * border, "", rgb,  a,  f);
+       drawquad(o,                                             ri * border,    up * theheight, "", rgb,  a,  f);
+       drawquad(o + ri * (owidth - border),                    ri * border,    up * theheight, "", rgb,  a,  f);
+       drawquad(o + ri * (border + align * ((1 - h) * width)), ri * width * h, up * theheight, "", hrgb, ha, f);
 }
 
 // returns location of sprite text
@@ -149,12 +118,12 @@ vector drawspritetext(vector o, float ang, float minwidth, vector rgb, float a,
        float sw, w, h;
        float aspect, sa, ca;
 
-       sw = stringwidth(s, FALSE, fontsize);
+       sw = stringwidth(s, false, fontsize);
        if(sw > minwidth)
                w = sw;
        else
                w = minwidth;
-       h = fontsize_y;
+       h = fontsize.y;
 
        // how do corners work?
        aspect = vid_conwidth / vid_conheight;
@@ -172,31 +141,35 @@ vector drawspritetext(vector o, float ang, float minwidth, vector rgb, float a,
        }
 
        // align
-       o_x -= w * algnx;
-       o_y -= h * algny;
+       o.x -= w * algnx;
+       o.y -= h * algny;
 
        // we want to be onscreen
-       if(o_x < 0)
-               o_x = 0;
-       if(o_y < 0)
-               o_y = 0;
-       if(o_x > vid_conwidth - w)
-               o_x = vid_conwidth - w;
-       if(o_y > vid_conheight - h)
-               o_x = vid_conheight - h;
+       if(o.x < 0)
+               o.x = 0;
+       if(o.y < 0)
+               o.y = 0;
+       if(o.x > vid_conwidth - w)
+               o.x = vid_conwidth - w;
+       if(o.y > vid_conheight - h)
+               o.x = vid_conheight - h;
 
-       o_x += 0.5 * (w - sw);
+       o.x += 0.5 * (w - sw);
 
        drawstring(o, s, fontsize, rgb, a, DRAWFLAG_NORMAL);
 
-       o_x += 0.5 * sw;
-       o_y += 0.5 * h;
+       o.x += 0.5 * sw;
+       o.y += 0.5 * h;
 
        return o;
 }
 
 float spritelookupblinkvalue(string s)
 {
+       if(substring(s, 0, 4) == "wpn-")
+       if(get_weaponinfo(stof(substring(s, 4, strlen(s)))).spawnflags & WEP_FLAG_SUPERWEAPON)
+               return 2;
+
        switch(s)
        {
                case "ons-cp-atck-neut": return 2;
@@ -204,6 +177,8 @@ float spritelookupblinkvalue(string s)
                case "ons-cp-atck-blue": return 2;
                case "ons-cp-dfnd-red":  return 0.5;
                case "ons-cp-dfnd-blue": return 0.5;
+               case "item_health_mega": return 2;
+               case "item_armor_large": return 2;
                case "item-invis":       return 2;
                case "item-extralife":   return 2;
                case "item-speed":       return 2;
@@ -229,7 +204,15 @@ vector spritelookupcolor(string s, vector def)
 string spritelookuptext(string s)
 {
        if(substring(s, 0, 4) == "wpn-") { return (get_weaponinfo(stof(substring(s, 4, strlen(s)))).message); }
-       if(substring(s, 0, 5) == "buff-") { return Buff_PrettyName(Buff_Type_FromSprite(s)); }
+       if (substring(s, 0, 5) == "buff-")
+       {
+               entity buff = BUFF_NULL;
+               FOREACH(BUFFS, it.m_sprite == s, LAMBDA(
+                       buff = it;
+                       break;
+               ));
+               return buff.m_prettyName;
+       }
 
        switch(s)
        {
@@ -251,6 +234,9 @@ string spritelookuptext(string s)
                case "keycarrier-red": return _("Key carrier");
                case "keycarrier-yellow": return _("Key carrier");
                case "redbase": return _("Red base");
+               case "yellowbase": return _("Yellow base");
+               case "neutralbase": return _("White base");
+               case "pinkbase": return _("Pink base");
                case "waypoint": return _("Waypoint");
                case "ons-gen-red": return _("Generator");
                case "ons-gen-blue": return _("Generator");
@@ -276,6 +262,8 @@ string spritelookuptext(string s)
                case "dom-blue": return _("Control point");
                case "dom-yellow": return _("Control point");
                case "dom-pink": return _("Control point");
+               case "item_health_mega": return _("Mega health");
+               case "item_armor_large": return _("Large armor");
                case "item-invis": return _("Invisibility");
                case "item-extralife": return _("Extra life");
                case "item-speed": return _("Speed");
@@ -286,6 +274,7 @@ string spritelookuptext(string s)
                case "frozen": return _("Frozen!");
                case "tagged-target": return _("Tagged");
                case "vehicle": return _("Vehicle");
+               case "intruder": return _("Intruder!");
                default: return s;
        }
 }
@@ -297,58 +286,57 @@ vector fixrgbexcess_move(vector rgb, vector src, vector dst)
 }
 vector fixrgbexcess(vector rgb)
 {
-       if(rgb_x > 1)
+       if(rgb.x > 1)
        {
                rgb = fixrgbexcess_move(rgb, '1 0 0', '0 1 1');
-               if(rgb_y > 1)
+               if(rgb.y > 1)
                {
                        rgb = fixrgbexcess_move(rgb, '0 1 0', '0 0 1');
-                       if(rgb_z > 1)
-                               rgb_z = 1;
+                       if(rgb.z > 1)
+                               rgb.z = 1;
                }
-               else if(rgb_z > 1)
+               else if(rgb.z > 1)
                {
                        rgb = fixrgbexcess_move(rgb, '0 0 1', '0 1 0');
-                       if(rgb_y > 1)
-                               rgb_y = 1;
+                       if(rgb.y > 1)
+                               rgb.y = 1;
                }
        }
-       else if(rgb_y > 1)
+       else if(rgb.y > 1)
        {
                rgb = fixrgbexcess_move(rgb, '0 1 0', '1 0 1');
-               if(rgb_x > 1)
+               if(rgb.x > 1)
                {
                        rgb = fixrgbexcess_move(rgb, '1 0 0', '0 0 1');
-                       if(rgb_z > 1)
-                               rgb_z = 1;
+                       if(rgb.z > 1)
+                               rgb.z = 1;
                }
-               else if(rgb_z > 1)
+               else if(rgb.z > 1)
                {
                        rgb = fixrgbexcess_move(rgb, '0 0 1', '1 0 0');
-                       if(rgb_x > 1)
-                               rgb_x = 1;
+                       if(rgb.x > 1)
+                               rgb.x = 1;
                }
        }
-       else if(rgb_z > 1)
+       else if(rgb.z > 1)
        {
                rgb = fixrgbexcess_move(rgb, '0 0 1', '1 1 0');
-               if(rgb_x > 1)
+               if(rgb.x > 1)
                {
                        rgb = fixrgbexcess_move(rgb, '1 0 0', '0 1 0');
-                       if(rgb_y > 1)
-                               rgb_y = 1;
+                       if(rgb.y > 1)
+                               rgb.y = 1;
                }
-               else if(rgb_y > 1)
+               else if(rgb.y > 1)
                {
                        rgb = fixrgbexcess_move(rgb, '0 1 0', '1 0 0');
-                       if(rgb_x > 1)
-                               rgb_x = 1;
+                       if(rgb.x > 1)
+                               rgb.x = 1;
                }
        }
        return rgb;
 }
 
-float waypointsprite_count, waypointsprite_newcount;
 void Draw_WaypointSprite()
 {
        string spriteimage;
@@ -378,6 +366,14 @@ void Draw_WaypointSprite()
        // choose the sprite
        switch(self.rule)
        {
+               case SPRITERULE_SPECTATOR:
+                       if(!(
+                               (autocvar_g_waypointsprite_itemstime == 1 && t == NUM_SPECTATOR + 1)
+                       ||      (autocvar_g_waypointsprite_itemstime == 2 && (t == NUM_SPECTATOR + 1 || warmup_stage))
+                               ))
+                               return;
+                       spriteimage = self.netname;
+                       break;
                case SPRITERULE_DEFAULT:
                        if(self.team)
                        {
@@ -431,7 +427,7 @@ void Draw_WaypointSprite()
        {
                if(self.helpme && time < self.helpme)
                        a *= SPRITE_HELPME_BLINK;
-               else
+               else if(!self.lifetime) // fading out waypoints don't blink
                        a *= spritelookupblinkvalue(spriteimage);
        }
 
@@ -441,7 +437,7 @@ void Draw_WaypointSprite()
                a = 1;
        }
 
-       if(a <= 0)
+       if(a <= 0.003)
                return;
 
        rgb = fixrgbexcess(rgb);
@@ -450,27 +446,27 @@ void Draw_WaypointSprite()
        float ang;
 
        o = project_3d_to_2d(self.origin);
-       if(o_z < 0
-       || o_x < (vid_conwidth * waypointsprite_edgeoffset_left)
-       || o_y < (vid_conheight * waypointsprite_edgeoffset_top)
-       || o_x > (vid_conwidth - (vid_conwidth * waypointsprite_edgeoffset_right))
-       || o_y > (vid_conheight - (vid_conheight * waypointsprite_edgeoffset_bottom)))
+       if(o.z < 0
+       || o.x < (vid_conwidth * waypointsprite_edgeoffset_left)
+       || o.y < (vid_conheight * waypointsprite_edgeoffset_top)
+       || o.x > (vid_conwidth - (vid_conwidth * waypointsprite_edgeoffset_right))
+       || o.y > (vid_conheight - (vid_conheight * waypointsprite_edgeoffset_bottom)))
        {
                // scale it to be just in view
                vector d;
                float f1, f2;
 
                d = o - '0.5 0 0' * vid_conwidth - '0 0.5 0' * vid_conheight;
-               ang = atan2(-d_x, -d_y);
-               if(o_z < 0)
+               ang = atan2(-d.x, -d.y);
+               if(o.z < 0)
                        ang += M_PI;
 
-               f1 = d_x / vid_conwidth;
-               f2 = d_y / vid_conheight;
+               f1 = d.x / vid_conwidth;
+               f2 = d.y / vid_conheight;
 
                if(max(f1, -f1) > max(f2, -f2))
                {
-                       if(d_z * f1 > 0)
+                       if(d.z * f1 > 0)
                        {
                                // RIGHT edge
                                d = d * ((0.5 - waypointsprite_edgeoffset_right) / f1);
@@ -483,7 +479,7 @@ void Draw_WaypointSprite()
                }
                else
                {
-                       if(d_z * f2 > 0)
+                       if(d.z * f2 > 0)
                        {
                                // BOTTOM edge
                                d = d * ((0.5 - waypointsprite_edgeoffset_bottom) / f2);
@@ -504,21 +500,21 @@ void Draw_WaypointSprite()
 #else
                vector d;
                d = o - '0.5 0 0' * vid_conwidth - '0 0.5 0' * vid_conheight;
-               ang = atan2(-d_x, -d_y);
+               ang = atan2(-d.x, -d.y);
 #endif
        }
-       o_z = 0;
+       o.z = 0;
 
        float edgedistance_min, crosshairdistance;
-               edgedistance_min = min((o_y - (vid_conheight * waypointsprite_edgeoffset_top)),
-       (o_x - (vid_conwidth * waypointsprite_edgeoffset_left)),
-       (vid_conwidth - (vid_conwidth * waypointsprite_edgeoffset_right)) - o_x,
-       (vid_conheight - (vid_conheight * waypointsprite_edgeoffset_bottom)) - o_y);
+               edgedistance_min = min((o.y - (vid_conheight * waypointsprite_edgeoffset_top)),
+       (o.x - (vid_conwidth * waypointsprite_edgeoffset_left)),
+       (vid_conwidth - (vid_conwidth * waypointsprite_edgeoffset_right)) - o.x,
+       (vid_conheight - (vid_conheight * waypointsprite_edgeoffset_bottom)) - o.y);
 
        float vidscale;
        vidscale = max(vid_conwidth / vid_width, vid_conheight / vid_height);
 
-       crosshairdistance = sqrt( pow(o_x - vid_conwidth/2, 2) + pow(o_y - vid_conheight/2, 2) );
+       crosshairdistance = sqrt( pow(o.x - vid_conwidth/2, 2) + pow(o.y - vid_conheight/2, 2) );
 
        t = waypointsprite_scale * vidscale;
        a *= waypointsprite_alpha;
@@ -614,7 +610,7 @@ void Ent_RemoveWaypointSprite()
 
 void Ent_WaypointSprite()
 {
-       float sendflags, f, t;
+       int sendflags, f, t;
        sendflags = ReadByte();
 
        if(!self.spawntime)
@@ -720,7 +716,7 @@ void WaypointSprite_Load_Frames(string ext)
 {
        float dh, n, i, o, f;
        string s, sname, sframes;
-       dh = search_begin(strcat("models/sprites/*_frame*", ext), FALSE, FALSE);
+       dh = search_begin(strcat("models/sprites/*_frame*", ext), false, false);
        if (dh < 0)
                 return;
        float ext_len = strlen(ext);