Xonotic QuakeC
The free, fast arena FPS with crisp movement and a wide array of weapons
radar.qc
Go to the documentation of this file.
1#include "radar.qh"
2
3#include <client/draw.qh>
5#include <client/mapvoting.qh>
6#include <client/teamradar.qh>
7#include <common/ent_cs.qh>
10
11// Radar (#6)
12
13void HUD_Radar_Export(int fh)
14{
15 // allow saving cvars that aesthetically change the panel into hud skin files
16 HUD_Write_Cvar("hud_panel_radar_foreground_alpha");
17 HUD_Write_Cvar("hud_panel_radar_rotation");
18 HUD_Write_Cvar("hud_panel_radar_zoommode");
19 HUD_Write_Cvar("hud_panel_radar_scale");
20 HUD_Write_Cvar("hud_panel_radar_maximized_scale");
21 HUD_Write_Cvar("hud_panel_radar_maximized_size");
22 HUD_Write_Cvar("hud_panel_radar_maximized_rotation");
23 HUD_Write_Cvar("hud_panel_radar_maximized_zoommode");
24}
25
30
31void HUD_Radar_Show_Maximized(bool doshow, bool clickable)
32{
33 TC(bool, doshow);
36
37 if (doshow)
38 {
39 if (clickable)
40 {
43 }
44 }
45 else if (hud_panel_radar_mouse)
46 {
48 mouseClicked = 0;
49 }
50}
52{
53 HUD_Radar_Show_Maximized(false, false);
54}
55
56
57float HUD_Radar_InputEvent(int bInputType, float nPrimary, float nSecondary)
58{
59 TC(int, bInputType);
61 return false;
62
63 if (bInputType == 3)
64 {
65 mousepos.x = nPrimary;
66 mousepos.y = nSecondary;
67 return true;
68 }
69
70 if (bInputType == 2)
71 return false;
72
73 // at this point bInputType can only be 0 or 1 (key pressed or released)
74 bool key_pressed = bInputType == 0;
75
76 if (nPrimary == K_MOUSE1)
77 {
78 if (key_pressed)
80 else
82 }
83 else if (nPrimary == K_MOUSE2)
84 {
85 if (key_pressed)
87 else
89 }
90 else if (nPrimary == K_ESCAPE && key_pressed)
92 else
93 {
94 // allow console/use binds to work without hiding the map
95 string con_keys = strcat(findkeysforcommand("toggleconsole", 0), " ", findkeysforcommand("+use", 0)) ;
96 int keys = tokenize(con_keys); // findkeysforcommand returns data for this
97 int i;
98 for (i = 0; i < keys; ++i)
99 if (nPrimary == stof(argv(i)))
100 return false;
101
102 if (STAT(HEALTH) <= 0)
103 {
104 // Show scoreboard
105 con_keys = findkeysforcommand("+showscores", 0);
106 keys = tokenize(con_keys);
107 for (i = 0; i < keys; ++i)
108 if (nPrimary == stof(argv(i)))
109 {
110 hud_panel_radar_temp_hidden = key_pressed;
111 return false;
112 }
113 }
114 else if (key_pressed)
116
117 return false;
118 }
119
120 return true;
121}
122
124{
126 return;
127
129 {
131 return;
132 }
133
134 panel = HUD_PANEL(RADAR);
136
138 panel_size.x = bound(0.2, panel_size.x, 1) * vid_conwidth;
139 panel_size.y = bound(0.2, panel_size.y, 1) * vid_conheight;
140 panel_pos.x = (vid_conwidth - panel_size.x) * 0.5;
141 panel_pos.y = (vid_conheight - panel_size.y) * 0.5;
142
144 {
145 // click outside
146 if (mousepos.x < panel_pos.x || mousepos.x > panel_pos.x + panel_size.x
147 || mousepos.y < panel_pos.y || mousepos.y > panel_pos.y + panel_size.y)
148 {
150 return;
151 }
153 localcmd(sprintf("cmd ons_spawn %f %f %f", pos.x, pos.y, pos.z));
154
156 return;
157 }
158}
159
160float HUD_Radar_GetZoomFactor(int zoommode)
161{
162 switch (zoommode)
163 {
164 case 1: return 1 - current_zoomfraction;
165 case 2: return 0;
166 case 3: return 1;
167 }
169}
170
171float HUD_Radar_GetAngle(int rotation)
172{
173 if (rotation)
174 return 90 * rotation * DEG2RAD;
175 return (view_angles.y - 90) * DEG2RAD;
176}
177
178void HUD_Radar(bool should_draw)
179{
180 if (!should_draw)
181 return;
183 {
185 {
187 return;
188 }
189 else
190 {
192 return;
194 return;
196 {
197 panel.update_time = time; // forces reload of panel attributes
198 radar_panel_modified = false;
199 }
200 }
201 }
202
204 return;
206 return;
207
209
210 float zoom_factor = 0;
211
213 {
215 panel_size.x = bound(0.2, panel_size.x, 1) * vid_conwidth;
216 panel_size.y = bound(0.2, panel_size.y, 1) * vid_conheight;
217 panel_pos.x = (vid_conwidth - panel_size.x) / 2;
218 panel_pos.y = (vid_conheight - panel_size.y) / 2;
219
220 string panel_bg = strcat(hud_skin_path, "/border_default"); // always use the default border when maximized
221 if (precache_pic(panel_bg) == "")
222 panel_bg = "gfx/hud/default/border_default"; // fallback
223 if (!radar_panel_modified && panel_bg != panel.current_panel_bg)
225 strcpy(panel.current_panel_bg, panel_bg);
226
227 // use zoom_factor 1 when the radar is clickable, since we need to be able to click anywhere on it
230 }
231
233 {
236 }
237
238 vector pos = panel_pos;
239 vector mySize = panel_size;
240
243 else
247 {
248 pos += '1 1 0' * panel_bg_padding;
249 mySize -= '2 2 0' * panel_bg_padding;
250 }
251
252 teamradar_origin2d = HUD_Shift(pos + 0.5 * mySize);
253 teamradar_size2d = mySize;
254
256 return;
257
259
260 float scale2d = vlen_maxnorm2d(mi_picmax - mi_picmin);
261 teamradar_size2d = HUD_Scale(mySize);
262
263 teamradar_extraclip_mins = teamradar_extraclip_maxs = '0 0 0'; // we always center
264
265 float bigsize;
266 // pixels per world qu to match the teamradar_size2d.x range in the longest dimension
268 {
269 // max-min distance must fit the radar in any rotation
270 bigsize = vlen_minnorm2d(teamradar_size2d) * scale2d / (1.05 * vlen(vec2(mi_scale)));
271 }
272 else
273 {
274 vector c0, c1, c2, c3, span;
277 c2 = Rotate('1 0 0' * mi_min.x + '0 1 0' * mi_max.y, teamradar_angle);
278 c3 = Rotate('1 0 0' * mi_max.x + '0 1 0' * mi_min.y, teamradar_angle);
279 span = '0 0 0';
280 span.x = max(c0.x, c1.x, c2.x, c3.x) - min(c0.x, c1.x, c2.x, c3.x);
281 span.y = max(c0.y, c1.y, c2.y, c3.y) - min(c0.y, c1.y, c2.y, c3.y);
282
283 // max-min distance must fit the radar in x=x, y=y
284 bigsize = min(
285 teamradar_size2d.x * scale2d / (1.05 * span.x),
286 teamradar_size2d.y * scale2d / (1.05 * span.y)
287 );
288 }
289
290 float normalsize = vlen_maxnorm2d(teamradar_size2d) * scale2d / hud_panel_radar_scale;
291 if (bigsize > normalsize)
292 normalsize = bigsize;
293
294 teamradar_size = zoom_factor * bigsize + (1 - zoom_factor) * normalsize;
296
297 drawsetcliparea(pos.x, pos.y, mySize.x, mySize.y);
298
300
301 IL_EACH(g_radarlinks, true, draw_teamradar_link(it.origin, it.velocity, it.team));
302
303 bool mutator_returnvalue = MUTATOR_CALLHOOK(TeamRadar_Draw); // TODO: allow players to show on the radar as well!
304
305 IL_EACH(g_radaricons, it.teamradar_icon,
306 {
307 if (hud_panel_radar_mouse
308 && GetResource(it, RES_HEALTH) >= 0
309 && (it.team == myteam + 1 || mutator_returnvalue || !teamplay))
310 {
311 vector coord = teamradar_texcoord_to_2dcoord(teamradar_3dcoord_to_texcoord(it.origin));
312 if (vdist(mousepos - coord, <, 8))
313 {
314 vector brightcolor;
315 brightcolor.x = min(1, it.teamradar_color.x * 1.5);
316 brightcolor.y = min(1, it.teamradar_color.y * 1.5);
317 brightcolor.z = min(1, it.teamradar_color.z * 1.5);
318 drawpic(coord - '8 8 0', "gfx/teamradar_icon_glow", '16 16 0', brightcolor, panel_fg_alpha, 0);
319 }
320 }
321 entity icon = REGISTRY_GET(RadarIcons, it.teamradar_icon);
322 draw_teamradar_icon(it.origin, icon, it, spritelookupcolor(it, icon.netname, it.teamradar_color), panel_fg_alpha);
323 });
324 int color2;
325 AL_EACH(_entcs, e, it != NULL,
326 {
327 if (!it.m_entcs_private || it.sv_entnum == current_player)
328 continue;
329 color2 = entcs_GetTeam(it.sv_entnum);
330 draw_teamradar_player(it.origin, it.angles, Team_ColorRGB(color2));
331 });
333
335
337 {
338 string message = (STAT(HEALTH) <= 0)
339 ? _("Click to select spawn location")
340 : _("Click to select teleport destination");
341
342 drawcolorcodedstring(pos + '0.5 0 0' * (mySize.x - stringwidth(message, true, hud_fontsize)) - '0 1 0' * hud_fontsize.y * 2,
344
345 hud_panel_radar_bottom = pos.y + mySize.y + hud_fontsize.y;
346 }
347}
#define AL_EACH(this, T, cond, body)
Definition arraylist.qh:59
#define MUTATOR_CALLHOOK(id,...)
Definition base.qh:143
var entity(vector mins, vector maxs,.entity tofield) findbox_tofield_OrFallback
Header file that describes the resource system.
#define drawsetcliparea(xposition, yposition, w, h)
Definition draw.qh:39
#define drawcolorcodedstring(position, text, scale, alpha, flag)
Definition draw.qh:30
string message
Definition powerups.qc:19
void Release_Common_Keys()
Definition main.qc:475
vector view_origin
Definition main.qh:109
vector hud_fontsize
Definition main.qh:77
vector mi_scale
Definition main.qh:38
vector mi_center
Definition main.qh:37
IntrusiveList g_radarlinks
Definition main.qh:94
IntrusiveList g_radaricons
Definition main.qh:95
string minimapname
Definition main.qh:40
float current_zoomfraction
Definition main.qh:148
bool mv_active
Definition mapvoting.qh:17
vector mi_picmin
Definition util.qh:131
vector mi_min
Definition util.qh:127
vector mi_max
Definition util.qh:128
vector mi_picmax
Definition util.qh:132
const float DRAWFLAG_NORMAL
float DEG2RAD
vector view_angles
float time
float intermission
vector origin
#define stringwidth
#define entcs_receiver(...)
Definition ent_cs.qh:65
ArrayList _entcs
Definition ent_cs.qh:56
int entcs_GetTeam(int i)
Definition ent_cs.qh:133
void HUD_Panel_LoadCvars()
Definition hud.qc:215
vector HUD_Shift(vector v)
Definition hud.qc:105
void HUD_Scale_Enable()
Definition hud.qc:91
vector HUD_Scale(vector v)
Definition hud.qc:98
void HUD_Scale_Disable()
Definition hud.qc:84
vector panel_size
Definition hud.qh:163
float hud_panel_radar_bottom
Definition hud.qh:72
bool hud_panel_radar_mouse
Definition hud.qh:71
bool radar_panel_modified
Definition hud.qh:75
float panel_fg_alpha
Definition hud.qh:169
#define HUD_PANEL(NAME)
Definition hud.qh:52
float panel_bg_padding
Definition hud.qh:174
bool hud_draw_maximized
Definition hud.qh:69
bool hud_panel_radar_maximized
Definition hud.qh:70
bool hud_panel_radar_temp_hidden
Definition hud.qh:73
#define HUD_Panel_DrawBg()
Definition hud.qh:55
float current_player
Definition hud.qh:185
string hud_skin_path
Definition hud.qh:136
vector panel_pos
Definition hud.qh:162
vector mousepos
Definition hud.qh:103
entity panel
Definition hud.qh:147
#define HUD_Write_Cvar(cvar)
Definition hud_config.qh:40
const int S_MOUSE1
Definition hud_config.qh:10
bool autocvar__hud_configure
Definition hud_config.qh:3
int mouseClicked
Definition hud_config.qh:13
const int S_MOUSE2
Definition hud_config.qh:11
#define IL_EACH(this, cond, body)
float K_MOUSE1
Definition keycodes.qc:129
float K_MOUSE2
Definition keycodes.qc:130
float K_ESCAPE
Definition keycodes.qc:9
#define TC(T, sym)
Definition _all.inc:82
noref float vid_conwidth
Definition draw.qh:8
noref float vid_conheight
Definition draw.qh:9
#define STAT(...)
Definition stats.qh:82
void localcmd(string command,...)
float stof(string val,...)
void drawresetcliparea(void)
float bound(float min, float value, float max)
string precache_pic(string name,...)
float vlen(vector v)
float min(float f,...)
float tokenize(string s)
string argv(float n)
float max(float f,...)
strcat(_("^F4Countdown stopped!"), "\n^BG", _("Teams are too unbalanced."))
#define NULL
Definition post.qh:14
void HUD_Radar_Show_Maximized(bool doshow, bool clickable)
Definition radar.qc:31
void HUD_Radar_Mouse()
Definition radar.qc:123
void HUD_Radar_Export(int fh)
Definition radar.qc:13
void HUD_Radar(bool should_draw)
Definition radar.qc:178
float HUD_Radar_InputEvent(int bInputType, float nPrimary, float nSecondary)
Definition radar.qc:57
float HUD_Radar_GetZoomFactor(int zoommode)
Definition radar.qc:160
float HUD_Radar_GetAngle(int rotation)
Definition radar.qc:171
bool HUD_Radar_Clickable()
Definition radar.qc:26
void HUD_Radar_Hide_Maximized()
Definition radar.qc:51
bool autocvar_hud_panel_radar_dynamichud
Definition radar.qh:5
int autocvar_hud_panel_radar
Definition radar.qh:4
vector autocvar_hud_panel_radar_maximized_size
Definition radar.qh:8
#define REGISTRY_GET(id, i)
Definition registry.qh:43
int scoreboard_ui_enabled
Definition scoreboard.qh:39
vector
Definition self.qh:92
#define strcpy(this, s)
Definition string.qh:52
vector teamradar_texcoord_to_3dcoord(vector in, float oz)
Definition teamradar.qc:48
void draw_teamradar_player(vector coord3d, vector pangles, vector rgb)
Definition teamradar.qc:82
void draw_teamradar_background(float fg)
Definition teamradar.qc:57
vector teamradar_3dcoord_to_texcoord(vector in)
Definition teamradar.qc:8
void draw_teamradar_icon(vector coord, entity icon, entity pingdata, vector rgb, float a)
Definition teamradar.qc:121
void teamradar_loadcvars()
Definition teamradar.qc:165
vector teamradar_2dcoord_to_texcoord(vector in)
Definition teamradar.qc:31
void draw_teamradar_link(vector start, vector end, int colors)
Definition teamradar.qc:142
int hud_panel_radar_maximized_rotation
Definition teamradar.qh:26
int hud_panel_radar_zoommode
Definition teamradar.qh:24
int hud_panel_radar_maximized_zoommode
Definition teamradar.qh:25
float teamradar_size
Definition teamradar.qh:17
int hud_panel_radar_rotation
Definition teamradar.qh:22
float hud_panel_radar_scale
Definition teamradar.qh:20
vector teamradar_origin2d
Definition teamradar.qh:14
vector teamradar_extraclip_mins
Definition teamradar.qh:16
vector teamradar_extraclip_maxs
Definition teamradar.qh:16
vector teamradar_size2d
Definition teamradar.qh:15
float teamradar_angle
Definition teamradar.qh:12
vector teamradar_origin3d_in_texcoord
Definition teamradar.qh:13
float hud_panel_radar_foreground_alpha
Definition teamradar.qh:21
vector Team_ColorRGB(int teamid)
Definition teams.qh:76
bool teamplay
Definition teams.qh:59
ERASEABLE float vlen_maxnorm2d(vector v)
Definition vector.qh:60
ERASEABLE vector Rotate(vector v, float a)
Definition vector.qh:105
ERASEABLE float vlen_minnorm2d(vector v)
Definition vector.qh:66
#define vec2(...)
Definition vector.qh:90
vector spritelookupcolor(entity this, string s, vector def)