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