]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/client/teamradar.qc
Make client includes order insensitive
[xonotic/xonotic-data.pk3dir.git] / qcsrc / client / teamradar.qc
1 #if defined(CSQC)
2         #include "autocvars.qh"
3         #include "defs.qh"
4         #include "hud.qh"
5         #include "main.qh"
6         #include "miscfunctions.qh"
7         #include "teamradar.qh"
8         #include "../common/util.qh"
9         #include "../csqcmodellib/interpolate.qh"
10 #elif defined(MENUQC)
11 #elif defined(SVQC)
12 #endif
13
14 float vlen2d(vector v)
15 {
16         return sqrt(v.x * v.x + v.y * v.y);
17 }
18
19 float vlen_maxnorm2d(vector v)
20 {
21         return max(v.x, v.y, -v.x, -v.y);
22 }
23
24 float vlen_minnorm2d(vector v)
25 {
26         return min(max(v.x, -v.x), max(v.y, -v.y));
27 }
28
29 vector teamradar_3dcoord_to_texcoord(vector in)
30 {
31         vector out;
32         out.x = (in.x - mi_picmin.x) / (mi_picmax.x - mi_picmin.x);
33         out.y = (in.y - mi_picmin.y) / (mi_picmax.y - mi_picmin.y);
34         out.z = 0;
35         return out;
36 }
37
38 vector teamradar_texcoord_to_2dcoord(vector in)
39 {
40         vector out;
41         in -= teamradar_origin3d_in_texcoord;
42
43         out = rotate(in, teamradar_angle * DEG2RAD);
44         out.y = - out.y; // screen space is reversed
45
46         out = out * teamradar_size;
47         if(v_flipped)
48                 out.x = -out.x;
49         out += teamradar_origin2d;
50         return out;
51 }
52
53 vector yinvert(vector v)
54 {
55         v.y = 1 - v.y;
56         return v;
57 }
58
59 void draw_teamradar_background(float fg)
60 {
61         float fga;
62         vector fgc;
63
64         if(fg > 0 && minimapname != "")
65         {
66                 fga = 1;
67                 fgc = '1 1 1' * fg;
68                 R_BeginPolygon(minimapname, DRAWFLAG_SCREEN | DRAWFLAG_MIPMAP);
69                 if(v_flipped)
70                 {
71                         R_PolygonVertex(teamradar_texcoord_to_2dcoord(mi_pictexcoord3), yinvert(mi_pictexcoord3), fgc, fga);
72                         R_PolygonVertex(teamradar_texcoord_to_2dcoord(mi_pictexcoord2), yinvert(mi_pictexcoord2), fgc, fga);
73                         R_PolygonVertex(teamradar_texcoord_to_2dcoord(mi_pictexcoord1), yinvert(mi_pictexcoord1), fgc, fga);
74                         R_PolygonVertex(teamradar_texcoord_to_2dcoord(mi_pictexcoord0), yinvert(mi_pictexcoord0), fgc, fga);
75                 }
76                 else
77                 {
78                         R_PolygonVertex(teamradar_texcoord_to_2dcoord(mi_pictexcoord0), yinvert(mi_pictexcoord0), fgc, fga);
79                         R_PolygonVertex(teamradar_texcoord_to_2dcoord(mi_pictexcoord1), yinvert(mi_pictexcoord1), fgc, fga);
80                         R_PolygonVertex(teamradar_texcoord_to_2dcoord(mi_pictexcoord2), yinvert(mi_pictexcoord2), fgc, fga);
81                         R_PolygonVertex(teamradar_texcoord_to_2dcoord(mi_pictexcoord3), yinvert(mi_pictexcoord3), fgc, fga);
82                 }
83                 R_EndPolygon();
84         }
85 }
86
87 void draw_teamradar_player(vector coord3d, vector pangles, vector rgb)
88 {
89         vector coord, rgb2;
90
91         coord = teamradar_texcoord_to_2dcoord(teamradar_3dcoord_to_texcoord(coord3d));
92
93         makevectors(pangles - '0 1 0' * teamradar_angle);
94         if(v_flipped)
95         {
96                 v_forward.x = -v_forward.x;
97                 v_right.x = -v_right.x;
98                 v_up.x = -v_up.x;
99         }
100         v_forward.z = 0;
101         v_forward = normalize(v_forward);
102         v_forward.y *= -1.0;
103         v_right.x = -v_forward.y;
104         v_right.y = v_forward.x;
105
106         if(rgb == '1 1 1')
107                 rgb2 = '0 0 0';
108         else
109                 rgb2 = '1 1 1';
110
111         R_BeginPolygon("", 0);
112         R_PolygonVertex(coord+v_forward*3, '0 0 0', rgb2, panel_fg_alpha);
113         R_PolygonVertex(coord+v_right*4-v_forward*2.5, '0 1 0', rgb2, panel_fg_alpha);
114         R_PolygonVertex(coord-v_forward*2, '1 0 0', rgb2, panel_fg_alpha);
115         R_PolygonVertex(coord-v_right*4-v_forward*2.5, '1 1 0', rgb2, panel_fg_alpha);
116         R_EndPolygon();
117
118         R_BeginPolygon("", 0);
119         R_PolygonVertex(coord+v_forward*2, '0 0 0', rgb, panel_fg_alpha);
120         R_PolygonVertex(coord+v_right*3-v_forward*2, '0 1 0', rgb, panel_fg_alpha);
121         R_PolygonVertex(coord-v_forward, '1 0 0', rgb, panel_fg_alpha);
122         R_PolygonVertex(coord-v_right*3-v_forward*2, '1 1 0', rgb, panel_fg_alpha);
123         R_EndPolygon();
124 }
125
126 void draw_teamradar_icon(vector coord, float icon, entity pingdata, vector rgb, float a)
127 {
128         coord = teamradar_texcoord_to_2dcoord(teamradar_3dcoord_to_texcoord(coord));
129         drawpic(coord - '4 4 0', strcat("gfx/teamradar_icon_", ftos(icon)), '8 8 0', rgb, a, 0);
130
131         if(pingdata)
132         {
133                 for(int i = 0; i < MAX_TEAMRADAR_TIMES; ++i)
134                 {
135                         float dt = pingdata.(teamradar_times[i]);
136                         if(dt == 0)
137                                 continue;
138                         dt = time - dt;
139                         if(dt >= 1 || dt <= 0)
140                                 continue;
141                         vector v = '2 2 0' * teamradar_size * dt;
142                         drawpic(coord - 0.5 * v, "gfx/teamradar_ping", v, '1 1 1', (1 - dt) * a, DRAWFLAG_ADDITIVE);
143                 }
144         }
145 }
146
147 void draw_teamradar_link(vector start, vector end, int colors)
148 {
149         vector c0, c1, norm;
150
151         start = teamradar_texcoord_to_2dcoord(teamradar_3dcoord_to_texcoord(start));
152         end = teamradar_texcoord_to_2dcoord(teamradar_3dcoord_to_texcoord(end));
153         norm = normalize(start - end);
154         norm.z = norm.x;
155         norm.x = -norm.y;
156         norm.y = norm.z;
157         norm.z = 0;
158
159         c0 = colormapPaletteColor(colors & 0x0F, false);
160         c1 = colormapPaletteColor((colors & 0xF0) / 0x10, false);
161
162         R_BeginPolygon("", 0);
163         R_PolygonVertex(start - norm, '0 0 0', c0, panel_fg_alpha);
164         R_PolygonVertex(start + norm, '0 1 0', c0, panel_fg_alpha);
165         R_PolygonVertex(end + norm, '1 1 0', c1, panel_fg_alpha);
166         R_PolygonVertex(end - norm, '1 0 0', c1, panel_fg_alpha);
167         R_EndPolygon();
168 }
169
170 void teamradar_loadcvars()
171 {
172         v_flipped = autocvar_v_flipped;
173         hud_panel_radar_scale = autocvar_hud_panel_radar_scale;
174         if (hud_panel_radar_maximized && !autocvar__hud_configure)
175         {
176                 if (autocvar_hud_panel_radar_maximized_scale > 0)
177                         hud_panel_radar_scale = autocvar_hud_panel_radar_maximized_scale;
178         }
179         hud_panel_radar_foreground_alpha = autocvar_hud_panel_radar_foreground_alpha * panel_fg_alpha;
180         hud_panel_radar_rotation = autocvar_hud_panel_radar_rotation;
181         hud_panel_radar_zoommode = autocvar_hud_panel_radar_zoommode;
182         hud_panel_radar_maximized_rotation = autocvar_hud_panel_radar_maximized_rotation;
183         hud_panel_radar_maximized_zoommode = autocvar_hud_panel_radar_maximized_zoommode;
184
185         // others default to 0
186         // match this to defaultXonotic.cfg!
187         if(!hud_panel_radar_scale) hud_panel_radar_scale = 4096;
188         if(!hud_panel_radar_foreground_alpha) hud_panel_radar_foreground_alpha = 0.8 * panel_fg_alpha;
189         if(!hud_panel_radar_size.x) hud_panel_radar_size.x = 128;
190         if(!hud_panel_radar_size.y) hud_panel_radar_size.y = hud_panel_radar_size.x;
191 }
192
193 // radar links
194
195 void Ent_RadarLink()
196 {
197         int sendflags = ReadByte();
198
199         InterpolateOrigin_Undo();
200
201         self.iflags = IFLAG_VELOCITY | IFLAG_ORIGIN;
202         self.classname = "radarlink";
203
204         if(sendflags & 1)
205         {
206                 self.origin_x = ReadCoord();
207                 self.origin_y = ReadCoord();
208                 self.origin_z = ReadCoord();
209                 setorigin(self, self.origin);
210         }
211
212         if(sendflags & 2)
213         {
214                 self.velocity_x = ReadCoord();
215                 self.velocity_y = ReadCoord();
216                 self.velocity_z = ReadCoord();
217         }
218
219         if(sendflags & 4)
220         {
221                 self.team = ReadByte();
222         }
223
224         InterpolateOrigin_Note();
225 }