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