]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/client/shownames.qc
holy crap it compiles
[xonotic/xonotic-data.pk3dir.git] / qcsrc / client / shownames.qc
1 // playerslots[i].isactive = player is in range and coordinates/status (health and armor) are up to date
2 // playerslots[i].origin = player origin TODO: should maybe move this so it's the origin of the shownames tag already in SSQC for culling?
3 // playerslots[i].healthvalue
4 // playerslots[i].armorvalue
5 // playerslots[i].sameteam = player is on same team as local client
6 //
7 void View_ShowNames()
8 {
9     if(!autocvar_hud_shownames)
10         return;
11
12     float i;
13     for(i = 0; i <= 255; ++i) // 255 players is engine limit
14     {
15         if(playerslots[i].isactive) // are the player coordinates/status current?
16         if(playerslots[i].sameteam || (!playerslots[i].sameteam && autocvar_hud_shownames_enemies))
17         {
18             float t;
19
20             float a;
21             a = autocvar_hud_panel_fg_alpha;
22
23             t = GetPlayerColor(player_localentnum - 1) + 1;
24
25             float dist;
26             dist = vlen(self.origin - view_origin);
27             
28
29             if(self.maxdistance > waypointsprite_normdistance)
30                 a *= pow(bound(0, (self.maxdistance - dist) / (self.maxdistance - waypointsprite_normdistance), 1), waypointsprite_distancealphaexponent);
31             else if(self.maxdistance > 0)
32                 a *= pow(bound(0, (waypointsprite_fadedistance - dist) / (waypointsprite_fadedistance - waypointsprite_normdistance), 1), waypointsprite_distancealphaexponent) * (1 - waypointsprite_minalpha) + waypointsprite_minalpha;
33
34             if(a <= 0)
35                 return;
36             
37             entity oldself;
38             oldself = self;
39             self = playerslots[i];
40             InterpolateOrigin_Do();
41             self = oldself;
42
43             // draw the sprite image
44             vector o;
45             o = project_3d_to_2d(playerslots[i].origin);
46
47             o_z = 0;
48
49             vector myPos, mySize;
50             mySize = (eX * autocvar_hud_shownames_aspect + eY) * autocvar_hud_shownames_height;
51             myPos = o - '0.5 0 0' * mySize_x - '0 1 0' * mySize_y;
52
53             vector iconpos, iconsize;
54             vector namepos, namesize;
55
56             iconpos = myPos;
57
58             if(autocvar_hud_shownames_status)
59             {
60                 if(playerslots[i].sameteam)
61                 {
62                     iconsize = eX * 2 * mySize_y + eY * mySize_y;
63                     // "ghost" backgrounds
64                     drawpic_aspect_skin(iconpos, "health", '1 1 0' * iconsize_y, '0 0 0', a * 0.5, DRAWFLAG_NORMAL);
65                     drawpic_aspect_skin(iconpos + '0.5 0 0' * iconsize_x, "armor", '1 1 0' * iconsize_y, '0 0 0', a * 0.5, DRAWFLAG_NORMAL);
66
67                     drawsetcliparea(0, myPos_y + iconsize_y - iconsize_y * min(1, playerslots[i].healthvalue/autocvar_hud_panel_healtharmor_maxhealth), vid_conwidth, myPos_y + iconsize_y);
68                     drawpic_aspect_skin(iconpos, "health", '1 1 0' * iconsize_y, '1 1 1', a, DRAWFLAG_NORMAL);
69
70                     drawsetcliparea(0, myPos_y + iconsize_y - iconsize_y * min(1, playerslots[i].armorvalue/autocvar_hud_panel_healtharmor_maxarmor), vid_conwidth, myPos_y + iconsize_y);
71                     drawpic_aspect_skin(iconpos + '0.5 0 0' * iconsize_x, "armor", '1 1 0' * iconsize_y, '1 1 1', a, DRAWFLAG_NORMAL);
72                     drawresetcliparea();
73                 }
74                 else if(autocvar_hud_shownames_status == 2)
75                 {
76                     iconsize = eX * 2 * mySize_y + eY * mySize_y;
77                     drawpic_aspect_skin(iconpos, "health_unknown", '1 1 0' * iconsize_y, '0 0 0', a, DRAWFLAG_NORMAL);
78                     drawpic_aspect_skin(iconpos + '0.5 0 0' * iconsize_x, "armor_unknown", '1 1 0' * iconsize_y, '0 0 0', a, DRAWFLAG_NORMAL);
79                 }
80             }
81
82             namepos = myPos + eX * 2 * iconsize_y;
83             namesize = eX * mySize_x - eX * 2 * iconsize_y + eY * mySize_y;
84
85             drawcolorcodedstring_aspect(namepos, GetPlayerName(i), namesize, a, DRAWFLAG_NORMAL);
86
87             /* Or maybe a health bar instead?
88              *
89             if(self.health >= 0)
90             {
91                 float align;
92                 if(self.build_finished)
93                     align = 0.5;
94                 else
95                     align = 0;
96                 drawhealthbar(o, rot * 90 * DEG2RAD, self.health, SPRITE_SIZE * t, SPRITE_HOTSPOT * t, SPRITE_HEALTHBAR_WIDTH * t, SPRITE_HEALTHBAR_HEIGHT * t, SPRITE_HEALTHBAR_MARGIN * t, SPRITE_HEALTHBAR_BORDER * t, align, self.teamradar_color, a * SPRITE_HEALTHBAR_BORDERALPHA, self.teamradar_color, a * SPRITE_HEALTHBAR_HEALTHALPHA, DRAWFLAG_NORMAL);
97             }
98             */
99         }
100     }
101 }