]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/client/teamradar.qc
Merge branch 'master' into terencehill/quickmenu
[xonotic/xonotic-data.pk3dir.git] / qcsrc / client / teamradar.qc
1 #include "teamradar.qh"
2 #include "_all.qh"
3
4 #include "hud.qh"
5
6 #include "../common/util.qh"
7
8 #include "../csqcmodellib/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 z)
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 = z;
59         return out;
60 }
61
62 vector yinvert(vector v)
63 {
64         v.y = 1 - v.y;
65         return v;
66 }
67
68 void draw_teamradar_background(float fg)
69 {
70         float fga;
71         vector fgc;
72
73         if(fg > 0 && minimapname != "")
74         {
75                 fga = 1;
76                 fgc = '1 1 1' * fg;
77                 R_BeginPolygon(minimapname, DRAWFLAG_SCREEN | DRAWFLAG_MIPMAP);
78                 if(v_flipped)
79                 {
80                         R_PolygonVertex(teamradar_texcoord_to_2dcoord(mi_pictexcoord3), yinvert(mi_pictexcoord3), fgc, fga);
81                         R_PolygonVertex(teamradar_texcoord_to_2dcoord(mi_pictexcoord2), yinvert(mi_pictexcoord2), fgc, fga);
82                         R_PolygonVertex(teamradar_texcoord_to_2dcoord(mi_pictexcoord1), yinvert(mi_pictexcoord1), fgc, fga);
83                         R_PolygonVertex(teamradar_texcoord_to_2dcoord(mi_pictexcoord0), yinvert(mi_pictexcoord0), fgc, fga);
84                 }
85                 else
86                 {
87                         R_PolygonVertex(teamradar_texcoord_to_2dcoord(mi_pictexcoord0), yinvert(mi_pictexcoord0), fgc, fga);
88                         R_PolygonVertex(teamradar_texcoord_to_2dcoord(mi_pictexcoord1), yinvert(mi_pictexcoord1), fgc, fga);
89                         R_PolygonVertex(teamradar_texcoord_to_2dcoord(mi_pictexcoord2), yinvert(mi_pictexcoord2), fgc, fga);
90                         R_PolygonVertex(teamradar_texcoord_to_2dcoord(mi_pictexcoord3), yinvert(mi_pictexcoord3), fgc, fga);
91                 }
92                 R_EndPolygon();
93         }
94 }
95
96 void draw_teamradar_player(vector coord3d, vector pangles, vector rgb)
97 {
98         vector coord, rgb2;
99
100         coord = teamradar_texcoord_to_2dcoord(teamradar_3dcoord_to_texcoord(coord3d));
101
102         makevectors(pangles - '0 1 0' * teamradar_angle);
103         if(v_flipped)
104         {
105                 v_forward.x = -v_forward.x;
106                 v_right.x = -v_right.x;
107                 v_up.x = -v_up.x;
108         }
109         v_forward.z = 0;
110         v_forward = normalize(v_forward);
111         v_forward.y *= -1.0;
112         v_right.x = -v_forward.y;
113         v_right.y = v_forward.x;
114
115         if(rgb == '1 1 1')
116                 rgb2 = '0 0 0';
117         else
118                 rgb2 = '1 1 1';
119
120         R_BeginPolygon("", 0);
121         R_PolygonVertex(coord+v_forward*3, '0 0 0', rgb2, panel_fg_alpha);
122         R_PolygonVertex(coord+v_right*4-v_forward*2.5, '0 1 0', rgb2, panel_fg_alpha);
123         R_PolygonVertex(coord-v_forward*2, '1 0 0', rgb2, panel_fg_alpha);
124         R_PolygonVertex(coord-v_right*4-v_forward*2.5, '1 1 0', rgb2, panel_fg_alpha);
125         R_EndPolygon();
126
127         R_BeginPolygon("", 0);
128         R_PolygonVertex(coord+v_forward*2, '0 0 0', rgb, panel_fg_alpha);
129         R_PolygonVertex(coord+v_right*3-v_forward*2, '0 1 0', rgb, panel_fg_alpha);
130         R_PolygonVertex(coord-v_forward, '1 0 0', rgb, panel_fg_alpha);
131         R_PolygonVertex(coord-v_right*3-v_forward*2, '1 1 0', rgb, panel_fg_alpha);
132         R_EndPolygon();
133 }
134
135 void draw_teamradar_icon(vector coord, float icon, entity pingdata, vector rgb, float a)
136 {
137         coord = teamradar_texcoord_to_2dcoord(teamradar_3dcoord_to_texcoord(coord));
138         drawpic(coord - '4 4 0', strcat("gfx/teamradar_icon_", ftos(icon)), '8 8 0', rgb, a, 0);
139
140         if(pingdata)
141         {
142                 for(int i = 0; i < MAX_TEAMRADAR_TIMES; ++i)
143                 {
144                         float dt = pingdata.(teamradar_times[i]);
145                         if(dt == 0)
146                                 continue;
147                         dt = time - dt;
148                         if(dt >= 1 || dt <= 0)
149                                 continue;
150                         vector v = '2 2 0' * teamradar_size * dt;
151                         drawpic(coord - 0.5 * v, "gfx/teamradar_ping", v, '1 1 1', (1 - dt) * a, DRAWFLAG_ADDITIVE);
152                 }
153         }
154 }
155
156 void draw_teamradar_link(vector start, vector end, int colors)
157 {
158         vector c0, c1, norm;
159
160         start = teamradar_texcoord_to_2dcoord(teamradar_3dcoord_to_texcoord(start));
161         end = teamradar_texcoord_to_2dcoord(teamradar_3dcoord_to_texcoord(end));
162         norm = normalize(start - end);
163         norm.z = norm.x;
164         norm.x = -norm.y;
165         norm.y = norm.z;
166         norm.z = 0;
167
168         c0 = colormapPaletteColor(colors & 0x0F, false);
169         c1 = colormapPaletteColor((colors & 0xF0) / 0x10, false);
170
171         R_BeginPolygon("", 0);
172         R_PolygonVertex(start - norm, '0 0 0', c0, panel_fg_alpha);
173         R_PolygonVertex(start + norm, '0 1 0', c0, panel_fg_alpha);
174         R_PolygonVertex(end + norm, '1 1 0', c1, panel_fg_alpha);
175         R_PolygonVertex(end - norm, '1 0 0', c1, panel_fg_alpha);
176         R_EndPolygon();
177 }
178
179 void teamradar_loadcvars()
180 {
181         v_flipped = autocvar_v_flipped;
182         hud_panel_radar_scale = autocvar_hud_panel_radar_scale;
183         if (hud_panel_radar_maximized && !autocvar__hud_configure)
184         {
185                 if (autocvar_hud_panel_radar_maximized_scale > 0)
186                         hud_panel_radar_scale = autocvar_hud_panel_radar_maximized_scale;
187         }
188         hud_panel_radar_foreground_alpha = autocvar_hud_panel_radar_foreground_alpha * panel_fg_alpha;
189         hud_panel_radar_rotation = autocvar_hud_panel_radar_rotation;
190         hud_panel_radar_zoommode = autocvar_hud_panel_radar_zoommode;
191         hud_panel_radar_maximized_rotation = autocvar_hud_panel_radar_maximized_rotation;
192         hud_panel_radar_maximized_zoommode = autocvar_hud_panel_radar_maximized_zoommode;
193
194         // others default to 0
195         // match this to defaultXonotic.cfg!
196         if(!hud_panel_radar_scale) hud_panel_radar_scale = 4096;
197         if(!hud_panel_radar_foreground_alpha) hud_panel_radar_foreground_alpha = 0.8 * panel_fg_alpha;
198         if(!hud_panel_radar_size.x) hud_panel_radar_size.x = 128;
199         if(!hud_panel_radar_size.y) hud_panel_radar_size.y = hud_panel_radar_size.x;
200 }
201
202 // radar links
203
204 void Ent_RadarLink()
205 {
206         int sendflags = ReadByte();
207
208         InterpolateOrigin_Undo();
209
210         self.iflags = IFLAG_VELOCITY | IFLAG_ORIGIN;
211         self.classname = "radarlink";
212
213         if(sendflags & 1)
214         {
215                 self.origin_x = ReadCoord();
216                 self.origin_y = ReadCoord();
217                 self.origin_z = ReadCoord();
218                 setorigin(self, self.origin);
219         }
220
221         if(sendflags & 2)
222         {
223                 self.velocity_x = ReadCoord();
224                 self.velocity_y = ReadCoord();
225                 self.velocity_z = ReadCoord();
226         }
227
228         if(sendflags & 4)
229         {
230                 self.team = ReadByte();
231         }
232
233         InterpolateOrigin_Note();
234 }