]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/client/teamradar.qc
Remove direct server #includes from client
[xonotic/xonotic-data.pk3dir.git] / qcsrc / client / teamradar.qc
1 #include "teamradar.qh"
2
3 #include "autocvars.qh"
4 #include "defs.qh"
5 #include "hud.qh"
6 #include "main.qh"
7 #include "miscfunctions.qh"
8
9 #include "../common/util.qh"
10
11 #include "../csqcmodellib/interpolate.qh"
12
13 float vlen2d(vector v)
14 {
15         return sqrt(v.x * v.x + v.y * v.y);
16 }
17
18 float vlen_maxnorm2d(vector v)
19 {
20         return max(v.x, v.y, -v.x, -v.y);
21 }
22
23 float vlen_minnorm2d(vector v)
24 {
25         return min(max(v.x, -v.x), max(v.y, -v.y));
26 }
27
28 vector teamradar_3dcoord_to_texcoord(vector in)
29 {
30         vector out;
31         out.x = (in.x - mi_picmin.x) / (mi_picmax.x - mi_picmin.x);
32         out.y = (in.y - mi_picmin.y) / (mi_picmax.y - mi_picmin.y);
33         out.z = 0;
34         return out;
35 }
36
37 vector teamradar_texcoord_to_2dcoord(vector in)
38 {
39         vector out;
40         in -= teamradar_origin3d_in_texcoord;
41
42         out = rotate(in, teamradar_angle * DEG2RAD);
43         out.y = - out.y; // screen space is reversed
44
45         out = out * teamradar_size;
46         if(v_flipped)
47                 out.x = -out.x;
48         out += teamradar_origin2d;
49         return out;
50 }
51
52 vector yinvert(vector v)
53 {
54         v.y = 1 - v.y;
55         return v;
56 }
57
58 void draw_teamradar_background(float fg)
59 {
60         float fga;
61         vector fgc;
62
63         if(fg > 0 && minimapname != "")
64         {
65                 fga = 1;
66                 fgc = '1 1 1' * fg;
67                 R_BeginPolygon(minimapname, DRAWFLAG_SCREEN | DRAWFLAG_MIPMAP);
68                 if(v_flipped)
69                 {
70                         R_PolygonVertex(teamradar_texcoord_to_2dcoord(mi_pictexcoord3), yinvert(mi_pictexcoord3), fgc, fga);
71                         R_PolygonVertex(teamradar_texcoord_to_2dcoord(mi_pictexcoord2), yinvert(mi_pictexcoord2), fgc, fga);
72                         R_PolygonVertex(teamradar_texcoord_to_2dcoord(mi_pictexcoord1), yinvert(mi_pictexcoord1), fgc, fga);
73                         R_PolygonVertex(teamradar_texcoord_to_2dcoord(mi_pictexcoord0), yinvert(mi_pictexcoord0), fgc, fga);
74                 }
75                 else
76                 {
77                         R_PolygonVertex(teamradar_texcoord_to_2dcoord(mi_pictexcoord0), yinvert(mi_pictexcoord0), fgc, fga);
78                         R_PolygonVertex(teamradar_texcoord_to_2dcoord(mi_pictexcoord1), yinvert(mi_pictexcoord1), fgc, fga);
79                         R_PolygonVertex(teamradar_texcoord_to_2dcoord(mi_pictexcoord2), yinvert(mi_pictexcoord2), fgc, fga);
80                         R_PolygonVertex(teamradar_texcoord_to_2dcoord(mi_pictexcoord3), yinvert(mi_pictexcoord3), fgc, fga);
81                 }
82                 R_EndPolygon();
83         }
84 }
85
86 void draw_teamradar_player(vector coord3d, vector pangles, vector rgb)
87 {
88         vector coord, rgb2;
89
90         coord = teamradar_texcoord_to_2dcoord(teamradar_3dcoord_to_texcoord(coord3d));
91
92         makevectors(pangles - '0 1 0' * teamradar_angle);
93         if(v_flipped)
94         {
95                 v_forward.x = -v_forward.x;
96                 v_right.x = -v_right.x;
97                 v_up.x = -v_up.x;
98         }
99         v_forward.z = 0;
100         v_forward = normalize(v_forward);
101         v_forward.y *= -1.0;
102         v_right.x = -v_forward.y;
103         v_right.y = v_forward.x;
104
105         if(rgb == '1 1 1')
106                 rgb2 = '0 0 0';
107         else
108                 rgb2 = '1 1 1';
109
110         R_BeginPolygon("", 0);
111         R_PolygonVertex(coord+v_forward*3, '0 0 0', rgb2, panel_fg_alpha);
112         R_PolygonVertex(coord+v_right*4-v_forward*2.5, '0 1 0', rgb2, panel_fg_alpha);
113         R_PolygonVertex(coord-v_forward*2, '1 0 0', rgb2, panel_fg_alpha);
114         R_PolygonVertex(coord-v_right*4-v_forward*2.5, '1 1 0', rgb2, panel_fg_alpha);
115         R_EndPolygon();
116
117         R_BeginPolygon("", 0);
118         R_PolygonVertex(coord+v_forward*2, '0 0 0', rgb, panel_fg_alpha);
119         R_PolygonVertex(coord+v_right*3-v_forward*2, '0 1 0', rgb, panel_fg_alpha);
120         R_PolygonVertex(coord-v_forward, '1 0 0', rgb, panel_fg_alpha);
121         R_PolygonVertex(coord-v_right*3-v_forward*2, '1 1 0', rgb, panel_fg_alpha);
122         R_EndPolygon();
123 }
124
125 void draw_teamradar_icon(vector coord, float icon, entity pingdata, vector rgb, float a)
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(int i = 0; i < MAX_TEAMRADAR_TIMES; ++i)
133                 {
134                         float dt = pingdata.(teamradar_times[i]);
135                         if(dt == 0)
136                                 continue;
137                         dt = time - dt;
138                         if(dt >= 1 || dt <= 0)
139                                 continue;
140                         vector 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 void teamradar_loadcvars()
170 {
171         v_flipped = autocvar_v_flipped;
172         hud_panel_radar_scale = autocvar_hud_panel_radar_scale;
173         if (hud_panel_radar_maximized && !autocvar__hud_configure)
174         {
175                 if (autocvar_hud_panel_radar_maximized_scale > 0)
176                         hud_panel_radar_scale = autocvar_hud_panel_radar_maximized_scale;
177         }
178         hud_panel_radar_foreground_alpha = autocvar_hud_panel_radar_foreground_alpha * panel_fg_alpha;
179         hud_panel_radar_rotation = autocvar_hud_panel_radar_rotation;
180         hud_panel_radar_zoommode = autocvar_hud_panel_radar_zoommode;
181         hud_panel_radar_maximized_rotation = autocvar_hud_panel_radar_maximized_rotation;
182         hud_panel_radar_maximized_zoommode = autocvar_hud_panel_radar_maximized_zoommode;
183
184         // others default to 0
185         // match this to defaultXonotic.cfg!
186         if(!hud_panel_radar_scale) hud_panel_radar_scale = 4096;
187         if(!hud_panel_radar_foreground_alpha) hud_panel_radar_foreground_alpha = 0.8 * panel_fg_alpha;
188         if(!hud_panel_radar_size.x) hud_panel_radar_size.x = 128;
189         if(!hud_panel_radar_size.y) hud_panel_radar_size.y = hud_panel_radar_size.x;
190 }
191
192 // radar links
193
194 void Ent_RadarLink()
195 {
196         int sendflags = ReadByte();
197
198         InterpolateOrigin_Undo();
199
200         self.iflags = IFLAG_VELOCITY | IFLAG_ORIGIN;
201         self.classname = "radarlink";
202
203         if(sendflags & 1)
204         {
205                 self.origin_x = ReadCoord();
206                 self.origin_y = ReadCoord();
207                 self.origin_z = ReadCoord();
208                 setorigin(self, self.origin);
209         }
210
211         if(sendflags & 2)
212         {
213                 self.velocity_x = ReadCoord();
214                 self.velocity_y = ReadCoord();
215                 self.velocity_z = ReadCoord();
216         }
217
218         if(sendflags & 4)
219         {
220                 self.team = ReadByte();
221         }
222
223         InterpolateOrigin_Note();
224 }