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