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