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