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