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;
175 return view_angles.y - 90;
176}
177
179{
181 {
183 {
185 return;
186 }
187 else
188 {
190 return;
192 return;
194 {
195 panel.update_time = time; // forces reload of panel attributes
196 radar_panel_modified = false;
197 }
198 }
199 }
200
202 return;
203
205
206 float zoom_factor = 0;
207
209 {
211 panel_size.x = bound(0.2, panel_size.x, 1) * vid_conwidth;
212 panel_size.y = bound(0.2, panel_size.y, 1) * vid_conheight;
213 panel_pos.x = (vid_conwidth - panel_size.x) / 2;
214 panel_pos.y = (vid_conheight - panel_size.y) / 2;
215
216 string panel_bg = strcat(hud_skin_path, "/border_default"); // always use the default border when maximized
217 if (precache_pic(panel_bg) == "")
218 panel_bg = "gfx/hud/default/border_default"; // fallback
219 if (!radar_panel_modified && panel_bg != panel.current_panel_bg)
221 strcpy(panel.current_panel_bg, panel_bg);
222
225 }
226
228 {
231 }
232
233 vector pos = panel_pos;
234 vector mySize = panel_size;
235
238 else
242 {
243 pos += '1 1 0' * panel_bg_padding;
244 mySize -= '2 2 0' * panel_bg_padding;
245 }
246
247 teamradar_origin2d = HUD_Shift(pos + 0.5 * mySize);
248 teamradar_size2d = mySize;
249
250 if (minimapname == "")
251 return;
252
254
255 float scale2d = vlen_maxnorm2d(mi_picmax - mi_picmin);
256 teamradar_size2d = HUD_Scale(mySize);
257
258 teamradar_extraclip_mins = teamradar_extraclip_maxs = '0 0 0'; // we always center
259
260 float bigsize;
261 // pixels per world qu to match the teamradar_size2d.x range in the longest dimension
263 {
264 // max-min distance must fit the radar in any rotation
265 bigsize = vlen_minnorm2d(teamradar_size2d) * scale2d / (1.05 * vlen(vec2(mi_scale)));
266 }
267 else
268 {
269 vector c0, c1, c2, c3, span;
272 c2 = Rotate('1 0 0' * mi_min.x + '0 1 0' * mi_max.y, teamradar_angle * DEG2RAD);
273 c3 = Rotate('1 0 0' * mi_max.x + '0 1 0' * mi_min.y, teamradar_angle * DEG2RAD);
274 span = '0 0 0';
275 span.x = max(c0.x, c1.x, c2.x, c3.x) - min(c0.x, c1.x, c2.x, c3.x);
276 span.y = max(c0.y, c1.y, c2.y, c3.y) - min(c0.y, c1.y, c2.y, c3.y);
277
278 // max-min distance must fit the radar in x=x, y=y
279 bigsize = min(
280 teamradar_size2d.x * scale2d / (1.05 * span.x),
281 teamradar_size2d.y * scale2d / (1.05 * span.y)
282 );
283 }
284
285 float normalsize = vlen_maxnorm2d(teamradar_size2d) * scale2d / hud_panel_radar_scale;
286 if (bigsize > normalsize)
287 normalsize = bigsize;
288
289 teamradar_size = zoom_factor * bigsize + (1 - zoom_factor) * normalsize;
291
292 drawsetcliparea(pos.x, pos.y, mySize.x, mySize.y);
293
295
296 IL_EACH(g_radarlinks, true, draw_teamradar_link(it.origin, it.velocity, it.team));
297
298 bool mutator_returnvalue = MUTATOR_CALLHOOK(TeamRadar_Draw); // TODO: allow players to show on the radar as well!
299
300 IL_EACH(g_radaricons, it.teamradar_icon,
301 {
302 if (hud_panel_radar_mouse
303 && GetResource(it, RES_HEALTH) >= 0
304 && (it.team == myteam + 1 || mutator_returnvalue || !teamplay))
305 {
306 vector coord = teamradar_texcoord_to_2dcoord(teamradar_3dcoord_to_texcoord(it.origin));
307 if (vdist(mousepos - coord, <, 8))
308 {
309 vector brightcolor;
310 brightcolor.x = min(1, it.teamradar_color.x * 1.5);
311 brightcolor.y = min(1, it.teamradar_color.y * 1.5);
312 brightcolor.z = min(1, it.teamradar_color.z * 1.5);
313 drawpic(coord - '8 8 0', "gfx/teamradar_icon_glow", '16 16 0', brightcolor, panel_fg_alpha, 0);
314 }
315 }
316 entity icon = REGISTRY_GET(RadarIcons, it.teamradar_icon);
317 draw_teamradar_icon(it.origin, icon, it, spritelookupcolor(it, icon.netname, it.teamradar_color), panel_fg_alpha);
318 });
319 int color2;
320 AL_EACH(_entcs, e, it != NULL,
321 {
322 if (!it.m_entcs_private || it.sv_entnum == current_player)
323 continue;
324 color2 = entcs_GetTeam(it.sv_entnum);
325 draw_teamradar_player(it.origin, it.angles, Team_ColorRGB(color2));
326 });
328
330
332 {
333 string message = (STAT(HEALTH) <= 0)
334 ? _("Click to select spawn location")
335 : _("Click to select teleport destination");
336
337 drawcolorcodedstring(pos + '0.5 0 0' * (mySize.x - stringwidth(message, true, hud_fontsize)) - '0 1 0' * hud_fontsize.y * 2,
339
340 hud_panel_radar_bottom = pos.y + mySize.y + hud_fontsize.y;
341 }
342}
#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:477
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:19
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()
Definition radar.qc:178
void HUD_Radar_Mouse()
Definition radar.qc:123
void HUD_Radar_Export(int fh)
Definition radar.qc:13
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:40
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:51
void draw_teamradar_player(vector coord3d, vector pangles, vector rgb)
Definition teamradar.qc:88
void draw_teamradar_background(float fg)
Definition teamradar.qc:60
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:128
void teamradar_loadcvars()
Definition teamradar.qc:173
vector teamradar_2dcoord_to_texcoord(vector in)
Definition teamradar.qc:33
void draw_teamradar_link(vector start, vector end, int colors)
Definition teamradar.qc:149
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)