]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/client/waypointsprites.qc
Merge remote branch 'origin/master' into tzork/gm_nexball
[xonotic/xonotic-data.pk3dir.git] / qcsrc / client / waypointsprites.qc
index 26b05d6519ed82bed3952d5895fce14aaf25749e..78ddc8b793c22f4b080100ace1df2a94538979be 100644 (file)
@@ -10,6 +10,10 @@ 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;
@@ -18,6 +22,7 @@ float waypointsprite_distancefadescale;
 float waypointsprite_distancefadedistance;
 float waypointsprite_alpha;
 
+.float helpme;
 .float rule;
 .string netname; // primary picture
 .string netname2; // secondary picture
@@ -40,6 +45,7 @@ float SPRITE_HEALTHBAR_BORDER = 2;
 float SPRITE_HEALTHBAR_BORDERALPHA = 1;
 float SPRITE_HEALTHBAR_HEALTHALPHA = 0.5;
 float SPRITE_ARROW_SCALE = 1.0;
+float SPRITE_HELPME_BLINK = 2;
 
 void drawrotpic(vector org, float rot, string pic, vector sz, vector hotspot, vector rgb, float a, float f)
 {
@@ -109,32 +115,39 @@ void drawhealthbar(vector org, float rot, float h, vector sz, vector hotspot, fl
 // returns location of sprite text
 vector drawspritearrow(vector o, float ang, vector rgb, float a, float t)
 {
+       float SQRT2 = 1.414;
+       float BORDER; BORDER = 1.5 * t;
+       float TSIZE; TSIZE = 8 * t;
+       float RLENGTH; RLENGTH = 8 * t;
+       float RWIDTH; RWIDTH = 4 * t;
+       float MLENGTH; MLENGTH = 4 * t;
+
        R_BeginPolygon("", DRAWFLAG_NORMAL);
-       R_PolygonVertex(o + rotate('-11.5 9.5 0'*t, ang), '0 0 0', '0 0 0', a);
-       R_PolygonVertex(o + rotate('11.5 9.5 0'*t, ang), '0 0 0', '0 0 0', a);
-       R_PolygonVertex(o + rotate('0 -2 0'*t, ang), '0 0 0', '0 0 0', a);
+       R_PolygonVertex(o + rotate(eX * -(TSIZE + BORDER * (1 + SQRT2)) + eY * (TSIZE + BORDER), ang), '0 0 0', '0 0 0', a);
+       R_PolygonVertex(o + rotate(eX *  (TSIZE + BORDER * (1 + SQRT2)) + eY * (TSIZE + BORDER), ang), '0 0 0', '0 0 0', a);
+       R_PolygonVertex(o + rotate(eY * -(        BORDER *      SQRT2),                          ang), '0 0 0', '0 0 0', a);
        R_EndPolygon();
        R_BeginPolygon("", DRAWFLAG_NORMAL);
-       R_PolygonVertex(o + rotate('-5.5 9.5 0'*t, ang), '0 0 0', '0 0 0', a);
-       R_PolygonVertex(o + rotate('-5.5 17.5 0'*t, ang), '0 0 0', '0 0 0', a);
-       R_PolygonVertex(o + rotate('5.5 17.5 0'*t, ang), '0 0 0', '0 0 0', a);
-       R_PolygonVertex(o + rotate('5.5 9.5 0'*t, ang), '0 0 0', '0 0 0', a);
+       R_PolygonVertex(o + rotate(eX * -(RWIDTH + BORDER) + eY * (TSIZE           + BORDER), ang), '0 0 0', '0 0 0', a);
+       R_PolygonVertex(o + rotate(eX * -(RWIDTH + BORDER) + eY * (TSIZE + RLENGTH + BORDER), ang), '0 0 0', '0 0 0', a);
+       R_PolygonVertex(o + rotate(eX *  (RWIDTH + BORDER) + eY * (TSIZE + RLENGTH + BORDER), ang), '0 0 0', '0 0 0', a);
+       R_PolygonVertex(o + rotate(eX *  (RWIDTH + BORDER) + eY * (TSIZE           + BORDER), ang), '0 0 0', '0 0 0', a);
        R_EndPolygon();
 
-       R_BeginPolygon("", DRAWFLAG_NORMAL);
-       R_PolygonVertex(o + rotate('-8 8 0'*t, ang), '0 0 0', rgb, a);
-       R_PolygonVertex(o + rotate('8 8 0'*t, ang), '0 0 0', rgb, a);
-       R_PolygonVertex(o + rotate('0 0 0'*t, ang), '0 0 0', rgb, a);
+       R_BeginPolygon("", DRAWFLAG_ADDITIVE);
+       R_PolygonVertex(o + rotate(eX * -TSIZE + eY * TSIZE, ang), '0 0 0', rgb, a);
+       R_PolygonVertex(o + rotate(eX *  TSIZE + eY * TSIZE, ang), '0 0 0', rgb, a);
+       R_PolygonVertex(o + rotate('0 0 0',                  ang), '0 0 0', rgb, a);
        R_EndPolygon();
-       R_BeginPolygon("", DRAWFLAG_NORMAL);
-       R_PolygonVertex(o + rotate('-4 8 0'*t, ang), '0 0 0', rgb, a);
-       R_PolygonVertex(o + rotate('-4 16 0'*t, ang), '0 0 0', rgb, a);
-       R_PolygonVertex(o + rotate('4 16 0'*t, ang), '0 0 0', rgb, a);
-       R_PolygonVertex(o + rotate('4 8 0'*t, ang), '0 0 0', rgb, a);
+       R_BeginPolygon("", DRAWFLAG_ADDITIVE);
+       R_PolygonVertex(o + rotate(eX * -RWIDTH + eY *  TSIZE,            ang), '0 0 0', rgb, a);
+       R_PolygonVertex(o + rotate(eX * -RWIDTH + eY * (TSIZE + RLENGTH), ang), '0 0 0', rgb, a);
+       R_PolygonVertex(o + rotate(eX *  RWIDTH + eY * (TSIZE + RLENGTH), ang), '0 0 0', rgb, a);
+       R_PolygonVertex(o + rotate(eX *  RWIDTH + eY *  TSIZE,            ang), '0 0 0', rgb, a);
        R_EndPolygon();
 
        return
-               o + rotate('0 20 0'*t, ang);
+               o + rotate(eY * (TSIZE + RLENGTH + MLENGTH), ang);
 }
 
 // returns location of sprite healthbar
@@ -203,12 +216,37 @@ float spritelookupblinkvalue(string s)
                case "item-extralife":   return 2;
                case "item-speed":       return 2;
                case "item-strength":    return 2;
-               case "item-shueld":      return 2;
+               case "item-shield":      return 2;
                case "item-fuelregen":   return 2;
                case "item-jetpack":     return 2;
+               case "tagged-target":    return 2;
                default:                 return 1;
        }
 }
+vector spritelookupcolor(string s, vector def)
+{
+       switch(s)
+       {
+               case "keycarrier-friend": return '0 1 0';
+               case "wpn-laser":         return '1 0.5 0.5';
+               case "wpn-shotgun":       return '0.5 0.25 0';
+               case "wpn-uzi":           return '1 1 0';
+               case "wpn-gl":            return '1 0 0';
+               case "wpn-electro":       return '0 0.5 1';
+               case "wpn-crylink":       return '1 0.5 1';
+               case "wpn-nex":           return '0.5 1 1';
+               case "wpn-hagar":         return '1 1 0.5';
+               case "wpn-rl":            return '1 1 0';
+               case "wpn-porto":         return '0.5 0.5 0.5';
+               case "wpn-minstanex":     return '0.5 1 1';
+               case "wpn-hookgun":       return '0 0.5 0';
+               case "wpn-fireball":      return '1 0.5 0';
+               case "wpn-hlac":          return '0 1 0';
+               case "wpn-campingrifle":  return '0.5 1 0';
+               case "wpn-minelayer":     return '0.75 1 0';
+               default:                  return def;
+       }
+}
 string spritelookuptext(string s)
 {
        switch(s)
@@ -245,6 +283,7 @@ string spritelookuptext(string s)
                case "race-checkpoint": return _("Checkpoint");
                case "race-finish": return _("Finish");
                case "race-start": return _("Start");
+               case "race-start-finish": return (race_checkpointtime || race_mycheckpointtime) ? _("Finish") : _("Start");
                case "nb-ball": return _("Ball");
                case "ka-ball": return _("Ball");
                case "ka-ballcarrier": return _("Ball carrier");
@@ -278,6 +317,7 @@ string spritelookuptext(string s)
                case "item-jetpack": return _("Jet Pack");
                case "freezetag_frozen": return _("Frozen!");
                case "tagged-target": return _("Tagged");
+               case "vehicle": return _("Vehicle");
                default: return s;
        }
 }
@@ -340,6 +380,7 @@ vector fixrgbexcess(vector rgb)
        return rgb;
 }
 
+float waypointsprite_count, waypointsprite_newcount;
 void Draw_WaypointSprite()
 {
        string spriteimage;
@@ -362,7 +403,7 @@ void Draw_WaypointSprite()
 
        InterpolateOrigin_Do();
 
-       t = GetPlayerColor(player_localentnum - 1) + 1;
+       t = GetPlayerColor(player_localnum) + 1;
 
        spriteimage = "";
 
@@ -395,6 +436,8 @@ void Draw_WaypointSprite()
 
        if(spriteimage == "")
                return;
+
+       ++waypointsprite_newcount;
        
        float dist;
        dist = vlen(self.origin - view_origin);
@@ -409,9 +452,20 @@ void Draw_WaypointSprite()
 
        vector rgb;
        rgb = self.teamradar_color;
+       rgb = spritelookupcolor(spriteimage, rgb);
+       if(rgb == '0 0 0')
+       {
+               self.teamradar_color = '1 0 1';
+               print(sprintf("WARNING: sprite of name %s has no color, using pink so you notice it\n", spriteimage)); 
+       }
 
        if(time - floor(time) > 0.5)
-               a *= spritelookupblinkvalue(spriteimage);
+       {
+               if(self.helpme && time < self.helpme)
+                       a *= SPRITE_HELPME_BLINK;
+               else
+                       a *= spritelookupblinkvalue(spriteimage);
+       }
 
        if(a > 1)
        {
@@ -428,7 +482,11 @@ void Draw_WaypointSprite()
        float ang;
 
        o = project_3d_to_2d(self.origin);
-       if(o_z < 0 || o_x < 0 || o_y < 0 || o_x > vid_conwidth || o_y > vid_conheight)
+       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;
@@ -447,12 +505,12 @@ void Draw_WaypointSprite()
                        if(d_z * f1 > 0)
                        {
                                // RIGHT edge
-                               d = d * (0.5 / f1);
+                               d = d * ((0.5 - waypointsprite_edgeoffset_right) / f1);
                        }
                        else
                        {
                                // LEFT edge
-                               d = d * (-0.5 / f1);
+                               d = d * (-(0.5 - waypointsprite_edgeoffset_left) / f1);
                        }
                }
                else
@@ -460,12 +518,12 @@ void Draw_WaypointSprite()
                        if(d_z * f2 > 0)
                        {
                                // BOTTOM edge
-                               d = d * (0.5 / f2);
+                               d = d * ((0.5 - waypointsprite_edgeoffset_bottom) / f2);
                        }
                        else
                        {
                                // TOP edge
-                               d = d * (-0.5 / f2);
+                               d = d * (-(0.5 - waypointsprite_edgeoffset_top) / f2);
                        }
                }
 
@@ -473,12 +531,21 @@ void Draw_WaypointSprite()
        }
        else
        {
+#if 1
                ang = M_PI;
+#else
+               vector d;
+               d = o - '0.5 0 0' * vid_conwidth - '0 0.5 0' * vid_conheight;
+               ang = atan2(-d_x, -d_y);
+#endif
        }
        o_z = 0;
 
        float edgedistance_min, crosshairdistance;
-       edgedistance_min = min4(o_y, o_x,vid_conwidth - o_x, vid_conheight - 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);
@@ -519,8 +586,14 @@ void Draw_WaypointSprite()
        o = drawspritearrow(o, ang, rgb, a, SPRITE_ARROW_SCALE * t);
        
        string txt;
-       txt = spritelookuptext(spriteimage);
-       txt = strtoupper(txt);
+       if(autocvar_g_waypointsprite_spam && waypointsprite_count >= autocvar_g_waypointsprite_spam)
+               txt = _("Spam");
+       else
+               txt = spritelookuptext(spriteimage);
+       if(self.helpme && time < self.helpme)
+               txt = sprintf(_("%s needing help!"), txt);
+       if(autocvar_g_waypointsprite_uppercase)
+               txt = strtoupper(txt);
 
        if(self.health >= 0)
        {
@@ -661,6 +734,9 @@ void Ent_WaypointSprite()
                self.teamradar_color_x = ReadByte() / 255.0;
                self.teamradar_color_y = ReadByte() / 255.0;
                self.teamradar_color_z = ReadByte() / 255.0;
+               self.helpme = ReadByte() * 0.1;
+               if(self.helpme > 0)
+                       self.helpme += servertime;
        }
 
        InterpolateOrigin_Note();
@@ -704,6 +780,10 @@ void WaypointSprite_Load()
        waypointsprite_edgefadealpha = autocvar_g_waypointsprite_edgefadealpha;
        waypointsprite_edgefadescale = autocvar_g_waypointsprite_edgefadescale;
        waypointsprite_edgefadedistance = autocvar_g_waypointsprite_edgefadedistance;
+       waypointsprite_edgeoffset_bottom = autocvar_g_waypointsprite_edgeoffset_bottom;
+       waypointsprite_edgeoffset_left = autocvar_g_waypointsprite_edgeoffset_left;
+       waypointsprite_edgeoffset_right = autocvar_g_waypointsprite_edgeoffset_right;
+       waypointsprite_edgeoffset_top = autocvar_g_waypointsprite_edgeoffset_top;
        waypointsprite_crosshairfadealpha = autocvar_g_waypointsprite_crosshairfadealpha;
        waypointsprite_crosshairfadescale = autocvar_g_waypointsprite_crosshairfadescale;
        waypointsprite_crosshairfadedistance = autocvar_g_waypointsprite_crosshairfadedistance;
@@ -718,4 +798,7 @@ void WaypointSprite_Load()
                WaypointSprite_Load_Frames(".jpg");
                waypointsprite_initialized = true;
        }
+
+       waypointsprite_count = waypointsprite_newcount;
+       waypointsprite_newcount = 0;
 }