]> de.git.xonotic.org Git - voretournament/voretournament.git/blob - data/qcsrc/client/teamradar.qc
Make bots jump while being swallowed, to make it even harder to eat them. They should...
[voretournament/voretournament.git] / data / qcsrc / client / teamradar.qc
1 float teamradar_angle; // player yaw angle\r
2 vector teamradar_origin3d_in_texcoord; // player origin\r
3 vector teamradar_origin2d; // 2D origin\r
4 vector teamradar_size2d; // 2D size\r
5 vector teamradar_extraclip_mins, teamradar_extraclip_maxs; // don't even ask\r
6 float teamradar_size; // 2D scale factor\r
7 float cl_teamradar_scale; // window size = ...qu\r
8 float cl_teamradar_nohudhack;\r
9 float v_flipped;\r
10 \r
11 float vlen2d(vector v)\r
12 {\r
13         return sqrt(v_x * v_x + v_y * v_y);\r
14 }\r
15 \r
16 float vlen_maxnorm2d(vector v)\r
17 {\r
18         return max4(v_x, v_y, -v_x, -v_y);\r
19 }\r
20 \r
21 float vlen_minnorm2d(vector v)\r
22 {\r
23         return min(max(v_x, -v_x), max(v_y, -v_y));\r
24 }\r
25 \r
26 vector teamradar_3dcoord_to_texcoord(vector in)\r
27 {\r
28         vector out;\r
29         out_x = (in_x - mi_picmin_x) / (mi_picmax_x - mi_picmin_x);\r
30         out_y = (in_y - mi_picmin_y) / (mi_picmax_y - mi_picmin_y);\r
31         out_z = 0;\r
32         return out;\r
33 }\r
34 \r
35 vector teamradar_texcoord_to_2dcoord(vector in)\r
36 {\r
37         vector out;\r
38         in -= teamradar_origin3d_in_texcoord;\r
39 \r
40         out = rotate(in, teamradar_angle * DEG2RAD);\r
41         out_y = - out_y; // screen space is reversed\r
42 \r
43         out = out * teamradar_size;\r
44         if(v_flipped)\r
45                 out_x = -out_x;\r
46         out += teamradar_origin2d;\r
47         return out;\r
48 }\r
49 \r
50 vector yinvert(vector v)\r
51 {\r
52         v_y = 1 - v_y;\r
53         return v;\r
54 }\r
55 \r
56 void draw_teamradar_background(float bg, float fg)\r
57 {\r
58         float fga;\r
59         vector fgc;\r
60         if(bg > 0)\r
61         {\r
62                 R_BeginPolygon("", 0);\r
63                 R_PolygonVertex('1 0 0' * (teamradar_origin2d_x - teamradar_size2d_x * 0.5 + teamradar_extraclip_mins_x) + '0 1 0' * (teamradar_origin2d_y - teamradar_size2d_y * 0.5 + teamradar_extraclip_mins_y), '0 0 0', '0 0 0', bg);\r
64                 R_PolygonVertex('1 0 0' * (teamradar_origin2d_x + teamradar_size2d_x * 0.5 + teamradar_extraclip_maxs_x) + '0 1 0' * (teamradar_origin2d_y - teamradar_size2d_y * 0.5 + teamradar_extraclip_mins_y), '0 0 0', '0 0 0', bg);\r
65                 R_PolygonVertex('1 0 0' * (teamradar_origin2d_x + teamradar_size2d_x * 0.5 + teamradar_extraclip_maxs_x) + '0 1 0' * (teamradar_origin2d_y + teamradar_size2d_y * 0.5 + teamradar_extraclip_maxs_y), '0 0 0', '0 0 0', bg);\r
66                 R_PolygonVertex('1 0 0' * (teamradar_origin2d_x - teamradar_size2d_x * 0.5 + teamradar_extraclip_mins_x) + '0 1 0' * (teamradar_origin2d_y + teamradar_size2d_y * 0.5 + teamradar_extraclip_maxs_y), '0 0 0', '0 0 0', bg);\r
67                 R_EndPolygon();\r
68         }\r
69 \r
70         if(fg > 0 && minimapname != "")\r
71         {\r
72                 fga = 1;\r
73                 fgc = '1 1 1' * fg;\r
74                 R_BeginPolygon(minimapname, DRAWFLAG_SCREEN | DRAWFLAG_MIPMAP);\r
75                 if(v_flipped)\r
76                 {\r
77                         R_PolygonVertex(teamradar_texcoord_to_2dcoord(mi_pictexcoord3), yinvert(mi_pictexcoord3), fgc, fga);\r
78                         R_PolygonVertex(teamradar_texcoord_to_2dcoord(mi_pictexcoord2), yinvert(mi_pictexcoord2), fgc, fga);\r
79                         R_PolygonVertex(teamradar_texcoord_to_2dcoord(mi_pictexcoord1), yinvert(mi_pictexcoord1), fgc, fga);\r
80                         R_PolygonVertex(teamradar_texcoord_to_2dcoord(mi_pictexcoord0), yinvert(mi_pictexcoord0), fgc, fga);\r
81                 }\r
82                 else\r
83                 {\r
84                         R_PolygonVertex(teamradar_texcoord_to_2dcoord(mi_pictexcoord0), yinvert(mi_pictexcoord0), fgc, fga);\r
85                         R_PolygonVertex(teamradar_texcoord_to_2dcoord(mi_pictexcoord1), yinvert(mi_pictexcoord1), fgc, fga);\r
86                         R_PolygonVertex(teamradar_texcoord_to_2dcoord(mi_pictexcoord2), yinvert(mi_pictexcoord2), fgc, fga);\r
87                         R_PolygonVertex(teamradar_texcoord_to_2dcoord(mi_pictexcoord3), yinvert(mi_pictexcoord3), fgc, fga);\r
88                 }\r
89                 R_EndPolygon();\r
90         }\r
91 }\r
92 \r
93 void(vector coord3d, vector pangles, vector rgb) draw_teamradar_player =\r
94 {\r
95         vector coord, rgb2;\r
96 \r
97         coord = teamradar_texcoord_to_2dcoord(teamradar_3dcoord_to_texcoord(coord3d));\r
98 \r
99         makevectors(pangles - '0 1 0' * teamradar_angle);\r
100         if(v_flipped)\r
101         {\r
102                 v_forward_x = -v_forward_x;\r
103                 v_right_x = -v_right_x;\r
104                 v_up_x = -v_up_x;\r
105         }\r
106         v_forward_z = 0;\r
107         v_forward = normalize(v_forward);\r
108         v_forward_y *= -1.0;\r
109         v_right_x = -v_forward_y;\r
110         v_right_y = v_forward_x;\r
111 \r
112         if(rgb == '1 1 1')\r
113                 rgb2 = '0 0 0';\r
114         else\r
115                 rgb2 = '1 1 1';\r
116 \r
117         R_BeginPolygon("", 0);\r
118         R_PolygonVertex(coord+v_forward*3, '0 0 0', rgb2, sbar_alpha_fg);\r
119         R_PolygonVertex(coord+v_right*4-v_forward*2.5, '0 1 0', rgb2, sbar_alpha_fg);\r
120         R_PolygonVertex(coord-v_forward*2, '1 0 0', rgb2, sbar_alpha_fg);\r
121         R_PolygonVertex(coord-v_right*4-v_forward*2.5, '1 1 0', rgb2, sbar_alpha_fg);\r
122         R_EndPolygon();\r
123 \r
124         R_BeginPolygon("", 0);\r
125         R_PolygonVertex(coord+v_forward*2, '0 0 0', rgb, sbar_alpha_fg);\r
126         R_PolygonVertex(coord+v_right*3-v_forward*2, '0 1 0', rgb, sbar_alpha_fg);\r
127         R_PolygonVertex(coord-v_forward, '1 0 0', rgb, sbar_alpha_fg);\r
128         R_PolygonVertex(coord-v_right*3-v_forward*2, '1 1 0', rgb, sbar_alpha_fg);\r
129         R_EndPolygon();\r
130 };\r
131 \r
132 void draw_teamradar_icon(vector coord, float icon, entity pingdata, vector rgb, float a)\r
133 {\r
134         float dt;\r
135         vector v;\r
136         float i;\r
137 \r
138         coord = teamradar_texcoord_to_2dcoord(teamradar_3dcoord_to_texcoord(coord));\r
139         drawpic(coord - '4 4 0', strcat("gfx/teamradar_icon_", ftos(icon)), '8 8 0', rgb, a, 0);\r
140 \r
141         if(pingdata)\r
142         {\r
143                 for(i = 0; i < MAX_TEAMRADAR_TIMES; ++i)\r
144                 {\r
145                         dt = pingdata.(teamradar_times[i]);\r
146                         if(dt == 0)\r
147                                 continue;\r
148                         dt = time - dt;\r
149                         if(dt >= 1 || dt <= 0)\r
150                                 continue;\r
151                         v = '2 2 0' * teamradar_size * dt;\r
152                         drawpic(coord - 0.5 * v, "gfx/teamradar_ping", v, '1 1 1', (1 - dt) * a, DRAWFLAG_ADDITIVE);\r
153                 }\r
154         }\r
155 }\r
156 \r
157 void draw_teamradar_link(vector start, vector end, float colors)\r
158 {\r
159         vector c0, c1, norm;\r
160 \r
161         start = teamradar_texcoord_to_2dcoord(teamradar_3dcoord_to_texcoord(start));\r
162         end = teamradar_texcoord_to_2dcoord(teamradar_3dcoord_to_texcoord(end));\r
163         norm = normalize(start - end);\r
164         norm_z = norm_x;\r
165         norm_x = -norm_y;\r
166         norm_y = norm_z;\r
167         norm_z = 0;\r
168 \r
169         c0 = colormapPaletteColor(colors & 0x0F, FALSE);\r
170         c1 = colormapPaletteColor((colors & 0xF0) / 0x10, FALSE);\r
171 \r
172         R_BeginPolygon("", 0);\r
173         R_PolygonVertex(start - norm, '0 0 0', c0, sbar_alpha_fg);\r
174         R_PolygonVertex(start + norm, '0 1 0', c0, sbar_alpha_fg);\r
175         R_PolygonVertex(end + norm, '1 1 0', c1, sbar_alpha_fg);\r
176         R_PolygonVertex(end - norm, '1 0 0', c1, sbar_alpha_fg);\r
177         R_EndPolygon();\r
178 }\r
179 \r
180 float cl_teamradar_scale;\r
181 float cl_teamradar_background_alpha;\r
182 float cl_teamradar_foreground_alpha;\r
183 float cl_teamradar_rotation;\r
184 vector cl_teamradar_size;\r
185 vector cl_teamradar_position;\r
186 float cl_teamradar_zoommode;\r
187 \r
188 void teamradar_loadcvars()\r
189 {\r
190         v_flipped = cvar("v_flipped");\r
191         if(ons_showmap)\r
192         {\r
193                 cl_teamradar_scale = 42; // dummy, not used (see zoommode)\r
194                 cl_teamradar_background_alpha = 1 * (1 - cvar("_menu_alpha"));\r
195                 cl_teamradar_foreground_alpha = 1 * (1 - cvar("_menu_alpha"));\r
196                 cl_teamradar_rotation = cvar("cl_teamradar_rotation");\r
197                 if(!cl_teamradar_rotation)\r
198                         cl_teamradar_rotation = 4;\r
199                 cl_teamradar_size = '256 256 0'; // TODO make somewhat variable?\r
200                 cl_teamradar_position = '0.5 0.5 0';\r
201                 cl_teamradar_zoommode = 3;\r
202                 cl_teamradar_nohudhack = 0;\r
203         }\r
204         else\r
205         {\r
206                 cl_teamradar_scale = cvar("cl_teamradar_scale");\r
207                 cl_teamradar_background_alpha = cvar("cl_teamradar_background_alpha") * sbar_alpha_fg;\r
208                 cl_teamradar_foreground_alpha = cvar("cl_teamradar_foreground_alpha") * sbar_alpha_fg;\r
209                 cl_teamradar_rotation = cvar("cl_teamradar_rotation");\r
210                 cl_teamradar_size = stov(cvar_string("cl_teamradar_size"));\r
211                 cl_teamradar_position = stov(cvar_string("cl_teamradar_position"));\r
212                 cl_teamradar_zoommode = cvar("cl_teamradar_zoommode");\r
213 \r
214                 // others default to 0\r
215                 // match this to defaultVoretournament.cfg!\r
216                 if(!cl_teamradar_scale) cl_teamradar_scale = 4096;\r
217                 if(!cl_teamradar_background_alpha) cl_teamradar_background_alpha = 0.4 * sbar_alpha_fg;\r
218                 if(!cl_teamradar_foreground_alpha) cl_teamradar_foreground_alpha = 0.8 * sbar_alpha_fg;\r
219                 if(!cl_teamradar_size_x) cl_teamradar_size_x = 128;\r
220                 if(!cl_teamradar_size_y) cl_teamradar_size_y = cl_teamradar_size_x;\r
221 \r
222                 cl_teamradar_size_z = 0;\r
223                 cl_teamradar_nohudhack = cl_teamradar_position_z;\r
224                 cl_teamradar_position_z = 0;\r
225         }\r
226 }\r
227 \r
228 void() teamradar_view =\r
229 {\r
230         local float color1, color2; // color already declared as a global in sbar.qc\r
231         local vector rgb;\r
232         local entity tm;\r
233         float scale2d, normalsize, bigsize;\r
234         float f;\r
235 \r
236         if(minimapname == "" && !ons_showmap)\r
237                 return;\r
238 \r
239         teamradar_loadcvars();\r
240 \r
241         switch(cl_teamradar_zoommode)\r
242         {\r
243                 default:\r
244                 case 0:\r
245                         f = current_zoomfraction;\r
246                         break;\r
247                 case 1:\r
248                         f = 1 - current_zoomfraction;\r
249                         break;\r
250                 case 2:\r
251                         f = 0;\r
252                         break;\r
253                 case 3:\r
254                         f = 1;\r
255                         break;\r
256         }\r
257 \r
258         switch(cl_teamradar_rotation)\r
259         {\r
260                 case 0:\r
261                         teamradar_angle = view_angles_y - 90;\r
262                         break;\r
263                 default:\r
264                         teamradar_angle = 90 * cl_teamradar_rotation;\r
265                         break;\r
266         }\r
267 \r
268         scale2d = vlen_maxnorm2d(mi_picmax - mi_picmin);\r
269         teamradar_size2d = cl_teamradar_size;\r
270 \r
271         teamradar_origin2d =\r
272                   '1 0 0' * (0.5 * teamradar_size2d_x + cl_teamradar_position_x * (vid_conwidth - teamradar_size2d_x))\r
273                 + '0 1 0' * (0.5 * teamradar_size2d_y + cl_teamradar_position_y * (vid_conheight - teamradar_size2d_y));\r
274         \r
275         teamradar_extraclip_mins = teamradar_extraclip_maxs = '0 0 0';\r
276         if(cl_teamradar_position == '1 0 0')\r
277         {\r
278                 if(cl_teamradar_nohudhack < 2)\r
279                         teamradar_origin2d_y += 25;\r
280                 if(cl_teamradar_nohudhack < 1)\r
281                         teamradar_extraclip_mins_y -= 25;\r
282         }\r
283         else if(cl_teamradar_position == '0 1 0' || cl_teamradar_position == '1 1 0')\r
284         {\r
285                 if(cl_teamradar_nohudhack < 2)\r
286                         teamradar_origin2d_y -= 50;\r
287                 //if(cl_teamradar_nohudhack < 1)\r
288                         //teamradar_extraclip_size_y += 50; // don't, the HUD looks nice\r
289         }\r
290 \r
291         // pixels per world qu to match the teamradar_size2d_x range in the longest dimension\r
292         if(cl_teamradar_rotation == 0)\r
293         {\r
294                 // max-min distance must fit the radar in any rotation\r
295                 bigsize = vlen_minnorm2d(teamradar_size2d) * scale2d / (1.05 * vlen2d(mi_max - mi_min));\r
296         }\r
297         else\r
298         {\r
299                 vector c0, c1, c2, c3, span;\r
300                 c0 = rotate(mi_min, teamradar_angle * DEG2RAD);\r
301                 c1 = rotate(mi_max, teamradar_angle * DEG2RAD);\r
302                 c2 = rotate('1 0 0' * mi_min_x + '0 1 0' * mi_max_y, teamradar_angle * DEG2RAD);\r
303                 c3 = rotate('1 0 0' * mi_max_x + '0 1 0' * mi_min_y, teamradar_angle * DEG2RAD);\r
304                 span = '0 0 0';\r
305                 span_x = max4(c0_x, c1_x, c2_x, c3_x) - min4(c0_x, c1_x, c2_x, c3_x);\r
306                 span_y = max4(c0_y, c1_y, c2_y, c3_y) - min4(c0_y, c1_y, c2_y, c3_y);\r
307 \r
308                 // max-min distance must fit the radar in x=x, y=y\r
309                 bigsize = min(\r
310                         teamradar_size2d_x * scale2d / (1.05 * span_x),\r
311                         teamradar_size2d_y * scale2d / (1.05 * span_y)\r
312                 );\r
313         }\r
314 \r
315         normalsize = vlen_maxnorm2d(teamradar_size2d) * scale2d / cl_teamradar_scale;\r
316         if(bigsize > normalsize)\r
317                 normalsize = bigsize;\r
318 \r
319         teamradar_size =\r
320                   f * bigsize\r
321                 + (1 - f) * normalsize;\r
322         teamradar_origin3d_in_texcoord = teamradar_3dcoord_to_texcoord(\r
323                   f * (mi_min + mi_max) * 0.5\r
324                 + (1 - f) * view_origin);\r
325 \r
326         color1 = GetPlayerColor(player_localentnum-1);\r
327         rgb = GetTeamRGB(color1);\r
328 \r
329         drawsetcliparea(\r
330                 teamradar_origin2d_x - teamradar_size2d_x * 0.5 + teamradar_extraclip_mins_x,\r
331                 teamradar_origin2d_y - teamradar_size2d_y * 0.5 + teamradar_extraclip_mins_y,\r
332                 teamradar_size2d_x + teamradar_extraclip_maxs_x - teamradar_extraclip_mins_x,\r
333                 teamradar_size2d_y + teamradar_extraclip_maxs_y - teamradar_extraclip_mins_y\r
334         );\r
335 \r
336         draw_teamradar_background(cl_teamradar_background_alpha, cl_teamradar_foreground_alpha);\r
337 \r
338         if(ons_showmap)\r
339         {\r
340                 drawresetcliparea();\r
341 \r
342                 vector frame_origin, frame_size;\r
343                 frame_origin = frame_size = '0 0 0';\r
344 \r
345                 frame_origin_x = teamradar_origin2d_x - teamradar_size2d_x * 0.55859375; // matches the picture\r
346                 frame_origin_y = teamradar_origin2d_y - teamradar_size2d_y * 0.55859375; // matches the picture\r
347                 frame_size_x = teamradar_size2d_x * 1.1171875; // matches the picture\r
348                 frame_size_y = teamradar_size2d_y * 1.1171875; // matches the picture\r
349                 drawpic(frame_origin, "gfx/ons-frame.tga", frame_size, '1 1 1', sbar_alpha_fg, 0);\r
350                 drawpic(frame_origin, "gfx/ons-frame-team.tga", frame_size, rgb, sbar_alpha_fg, 0);\r
351 \r
352                 drawsetcliparea(\r
353                         teamradar_origin2d_x - teamradar_size2d_x * 0.5,\r
354                         teamradar_origin2d_y - teamradar_size2d_y * 0.5,\r
355                         teamradar_size2d_x,\r
356                         teamradar_size2d_y\r
357                 );\r
358         }\r
359 \r
360         for(tm = world; (tm = find(tm, classname, "radarlink")); )\r
361                 draw_teamradar_link(tm.origin, tm.velocity, tm.team);\r
362         for(tm = world; (tm = findflags(tm, teamradar_icon, 0xFFFFFF)); )\r
363                 draw_teamradar_icon(tm.origin, tm.teamradar_icon, tm, tm.teamradar_color, tm.alpha * sbar_alpha_fg);\r
364         for(tm = world; (tm = find(tm, classname, "entcs_receiver")); )\r
365         {\r
366                 color2 = GetPlayerColor(tm.sv_entnum);\r
367                 //if(color == COLOR_SPECTATOR || color == color2)\r
368                         draw_teamradar_player(tm.origin, tm.angles, GetTeamRGB(color2));\r
369         }\r
370         draw_teamradar_player(view_origin, view_angles, '1 1 1');\r
371 \r
372         drawresetcliparea();\r
373 };\r
374 \r
375 \r
376 \r
377 // radar links\r
378 \r
379 void Ent_RadarLink()\r
380 {\r
381         float sendflags;\r
382         sendflags = ReadByte();\r
383 \r
384         InterpolateOrigin_Undo();\r
385 \r
386         self.iflags = IFLAG_VELOCITY;\r
387         self.classname = "radarlink";\r
388 \r
389         if(sendflags & 1)\r
390         {\r
391                 self.origin_x = ReadCoord();\r
392                 self.origin_y = ReadCoord();\r
393                 self.origin_z = ReadCoord();\r
394         }\r
395 \r
396         if(sendflags & 2)\r
397         {\r
398                 self.velocity_x = ReadCoord();\r
399                 self.velocity_y = ReadCoord();\r
400                 self.velocity_z = ReadCoord();\r
401         }\r
402 \r
403         if(sendflags & 4)\r
404         {\r
405                 self.team = ReadByte();\r
406         }\r
407 \r
408         InterpolateOrigin_Note();\r
409 }\r