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