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