Xonotic
radar.qc
Go to the documentation of this file.
1 #include "radar.qh"
2 
3 #include <client/draw.qh>
4 #include <client/mapvoting.qh>
5 #include <client/teamradar.qh>
6 #include <common/ent_cs.qh>
9 
10 // Radar (#6)
11 
12 void HUD_Radar_Export(int fh)
13 {
14  // allow saving cvars that aesthetically change the panel into hud skin files
15  HUD_Write_Cvar("hud_panel_radar_foreground_alpha");
16  HUD_Write_Cvar("hud_panel_radar_rotation");
17  HUD_Write_Cvar("hud_panel_radar_zoommode");
18  HUD_Write_Cvar("hud_panel_radar_scale");
19  HUD_Write_Cvar("hud_panel_radar_maximized_scale");
20  HUD_Write_Cvar("hud_panel_radar_maximized_size");
21  HUD_Write_Cvar("hud_panel_radar_maximized_rotation");
22  HUD_Write_Cvar("hud_panel_radar_maximized_zoommode");
23 }
24 
26 {
28 }
29 
30 void HUD_Radar_Show_Maximized(bool doshow, bool clickable)
31 {
32  TC(bool, doshow);
35 
36  if ( doshow )
37  {
38  if (clickable)
39  {
41 
42  // we must unset the player's buttons, as they aren't released elsewhere
43  localcmd("-fire\n");
44  localcmd("-fire2\n");
45  localcmd("-use\n");
46  localcmd("-hook\n");
47  localcmd("-jump\n");
48  }
49  }
50  else if ( hud_panel_radar_mouse )
51  {
53  mouseClicked = 0;
54  }
55 }
57 {
58  HUD_Radar_Show_Maximized(false,false);
59 }
60 
61 
62 float HUD_Radar_InputEvent(int bInputType, float nPrimary, float nSecondary)
63 {
64  TC(int, bInputType);
66  return false;
67 
68  if(bInputType == 3)
69  {
70  mousepos_x = nPrimary;
71  mousepos_y = nSecondary;
72  return true;
73  }
74 
75  if (bInputType == 2)
76  return false;
77 
78  // at this point bInputType can only be 0 or 1 (key pressed or released)
79  bool key_pressed = (bInputType == 0);
80 
81  if(nPrimary == K_MOUSE1)
82  {
83  if(key_pressed)
85  else
87  }
88  else if(nPrimary == K_MOUSE2)
89  {
90  if(key_pressed)
92  else
94  }
95  else if (nPrimary == K_ESCAPE && key_pressed)
96  {
98  }
99  else
100  {
101  // allow console/use binds to work without hiding the map
102  string con_keys = strcat(findkeysforcommand("toggleconsole", 0), " ", findkeysforcommand("+use", 0)) ;
103  int keys = tokenize(con_keys); // findkeysforcommand returns data for this
104  int i;
105  for (i = 0; i < keys; ++i)
106  {
107  if(nPrimary == stof(argv(i)))
108  return false;
109  }
110 
111  if ( STAT(HEALTH) <= 0 )
112  {
113  // Show scoreboard
114  con_keys = findkeysforcommand("+showscores", 0);
115  keys = tokenize(con_keys);
116  for (i = 0; i < keys; ++i)
117  {
118  if ( nPrimary == stof(argv(i)) )
119  {
120  hud_panel_radar_temp_hidden = key_pressed;
121  return false;
122  }
123  }
124  }
125  else if (key_pressed)
127 
128  return false;
129  }
130 
131  return true;
132 }
133 
135 {
136  if ( !hud_panel_radar_mouse ) return;
137  if(mv_active) return;
138 
139  if ( intermission )
140  {
142  return;
143  }
144 
145  if(mouseClicked & S_MOUSE2)
146  {
148  return;
149  }
150 
151  panel = HUD_PANEL(RADAR);
153 
154 
156  panel_size_x = bound(0.2, panel_size_x, 1) * vid_conwidth;
157  panel_size_y = bound(0.2, panel_size_y, 1) * vid_conheight;
158  panel_pos_x = (vid_conwidth - panel_size_x) / 2;
159  panel_pos_y = (vid_conheight - panel_size_y) / 2;
160 
161  if(mouseClicked & S_MOUSE1)
162  {
163  // click outside
164  if ( mousepos_x < panel_pos_x || mousepos_x > panel_pos_x + panel_size_x ||
165  mousepos_y < panel_pos_y || mousepos_y > panel_pos_y + panel_size_y )
166  {
168  return;
169  }
171  localcmd(sprintf("cmd ons_spawn %f %f %f",pos_x,pos_y,pos_z));
172 
174  return;
175  }
176 }
177 
178 float HUD_Radar_GetZoomFactor(int zoommode)
179 {
180  switch(zoommode)
181  {
182  case 1: return 1 - current_zoomfraction;
183  case 2: return 0;
184  case 3: return 1;
185  }
186  return current_zoomfraction;
187 }
188 
189 float HUD_Radar_GetAngle(int rotation)
190 {
191  if (rotation)
192  return 90 * rotation;
193  return view_angles.y - 90;
194 }
195 
196 void HUD_Radar()
197 {
199  {
201  {
202  if (!hud_draw_maximized) return;
203  }
204  else
205  {
206  if (autocvar_hud_panel_radar == 0) return;
207  if (autocvar_hud_panel_radar != 2 && !teamplay) return;
209  {
210  panel.update_time = time; // forces reload of panel attributes
211  radar_panel_modified = false;
212  }
213  }
214  }
215 
217  return;
218 
220 
221  float zoom_factor = 0;
222 
224  {
226  panel_size.x = bound(0.2, panel_size.x, 1) * vid_conwidth;
227  panel_size.y = bound(0.2, panel_size.y, 1) * vid_conheight;
228  panel_pos.x = (vid_conwidth - panel_size.x) / 2;
229  panel_pos.y = (vid_conheight - panel_size.y) / 2;
230 
231  string panel_bg;
232  panel_bg = strcat(hud_skin_path, "/border_default"); // always use the default border when maximized
233  if(precache_pic(panel_bg) == "")
234  panel_bg = "gfx/hud/default/border_default"; // fallback
235  if(!radar_panel_modified && panel_bg != panel.current_panel_bg)
236  radar_panel_modified = true;
237  strcpy(panel.current_panel_bg, panel_bg);
238 
241  }
242 
244  {
247  }
248 
249  vector pos, mySize;
250  pos = panel_pos;
251  mySize = panel_size;
252 
255  else
258  if(panel_bg_padding)
259  {
260  pos += '1 1 0' * panel_bg_padding;
261  mySize -= '2 2 0' * panel_bg_padding;
262  }
263 
264  int color2;
265  float scale2d, normalsize, bigsize;
266 
267  teamradar_origin2d = HUD_Shift(pos + 0.5 * mySize);
268  teamradar_size2d = mySize;
269 
270  if(minimapname == "")
271  return;
272 
274 
275  scale2d = vlen_maxnorm2d(mi_picmax - mi_picmin);
276  teamradar_size2d = HUD_Scale(mySize);
277 
278  teamradar_extraclip_mins = teamradar_extraclip_maxs = '0 0 0'; // we always center
279 
280  // pixels per world qu to match the teamradar_size2d_x range in the longest dimension
282  {
283  // max-min distance must fit the radar in any rotation
284  bigsize = vlen_minnorm2d(teamradar_size2d) * scale2d / (1.05 * vlen(vec2(mi_scale)));
285  }
286  else
287  {
288  vector c0, c1, c2, c3, span;
289  c0 = Rotate(mi_min, teamradar_angle * DEG2RAD);
290  c1 = Rotate(mi_max, teamradar_angle * DEG2RAD);
291  c2 = Rotate('1 0 0' * mi_min.x + '0 1 0' * mi_max.y, teamradar_angle * DEG2RAD);
292  c3 = Rotate('1 0 0' * mi_max.x + '0 1 0' * mi_min.y, teamradar_angle * DEG2RAD);
293  span = '0 0 0';
294  span.x = max(c0_x, c1_x, c2_x, c3_x) - min(c0_x, c1_x, c2_x, c3_x);
295  span.y = max(c0_y, c1_y, c2_y, c3_y) - min(c0_y, c1_y, c2_y, c3_y);
296 
297  // max-min distance must fit the radar in x=x, y=y
298  bigsize = min(
299  teamradar_size2d.x * scale2d / (1.05 * span.x),
300  teamradar_size2d.y * scale2d / (1.05 * span.y)
301  );
302  }
303 
304  normalsize = vlen_maxnorm2d(teamradar_size2d) * scale2d / hud_panel_radar_scale;
305  if(bigsize > normalsize)
306  normalsize = bigsize;
307 
308  teamradar_size = zoom_factor * bigsize + (1 - zoom_factor) * normalsize;
310 
311  drawsetcliparea(pos.x, pos.y, mySize.x, mySize.y);
312 
314 
315  IL_EACH(g_radarlinks, true, draw_teamradar_link(it.origin, it.velocity, it.team));
316 
317  bool mutator_returnvalue = MUTATOR_CALLHOOK(TeamRadar_Draw); // TODO: allow players to show on the radar as well!
318 
319  IL_EACH(g_radaricons, it.teamradar_icon, {
320  if ( hud_panel_radar_mouse )
321  if ( GetResource(it, RES_HEALTH) >= 0 )
322  if ( it.team == myteam + 1 || mutator_returnvalue || !teamplay )
323  {
324  vector coord = teamradar_texcoord_to_2dcoord(teamradar_3dcoord_to_texcoord(it.origin));
325  if(vdist((mousepos - coord), <, 8))
326  {
327  vector brightcolor;
328  brightcolor_x = min(1,it.teamradar_color_x*1.5);
329  brightcolor_y = min(1,it.teamradar_color_y*1.5);
330  brightcolor_z = min(1,it.teamradar_color_z*1.5);
331  drawpic(coord - '8 8 0', "gfx/teamradar_icon_glow", '16 16 0', brightcolor, panel_fg_alpha, 0);
332  }
333  }
334  entity icon = REGISTRY_GET(RadarIcons, it.teamradar_icon);
335  draw_teamradar_icon(it.origin, icon, it, spritelookupcolor(it, icon.netname, it.teamradar_color), panel_fg_alpha);
336  });
337  AL_EACH(_entcs, e, it != NULL, {
338  if (!it.m_entcs_private) continue;
339  if (it.sv_entnum == current_player) continue;
340  color2 = entcs_GetTeam(it.sv_entnum);
341  draw_teamradar_player(it.origin, it.angles, Team_ColorRGB(color2));
342  });
343  draw_teamradar_player(entcs_receiver(current_player).origin, view_angles, '1 1 1');
344 
346 
347  if ( hud_panel_radar_mouse )
348  {
349  string message = _("Click to select teleport destination");
350 
351  if ( STAT(HEALTH) <= 0 )
352  {
353  message = _("Click to select spawn location");
354  }
355 
356  drawcolorcodedstring(pos + '0.5 0 0' * (mySize_x - stringwidth(message, true, hud_fontsize)) - '0 1 0' * hud_fontsize_y * 2,
358 
359  hud_panel_radar_bottom = pos_y + mySize_y + hud_fontsize_y;
360  }
361 }
bool radar_panel_modified
Definition: hud.qh:74
float vid_conheight
#define IL_EACH(this, cond, body)
bool hud_panel_radar_maximized
Definition: hud.qh:69
float K_ESCAPE
Definition: keycodes.qc:9
vector teamradar_extraclip_maxs
Definition: teamradar.qh:16
float panel_fg_alpha
Definition: hud.qh:166
float DEG2RAD
Definition: csprogsdefs.qc:961
float current_player
Definition: hud.qh:182
int hud_panel_radar_zoommode
Definition: teamradar.qh:24
vector teamradar_3dcoord_to_texcoord(vector in)
Definition: teamradar.qc:8
bool autocvar__hud_configure
Definition: hud_config.qh:3
#define stringwidth
Definition: csprogsdefs.qh:29
vector Team_ColorRGB(int teamid)
Definition: teams.qh:76
vector panel_size
Definition: hud.qh:160
IntrusiveList g_radarlinks
Definition: main.qh:79
entity() spawn
#define REGISTRY_GET(id, i)
Definition: registry.qh:43
bool hud_draw_maximized
Definition: hud.qh:68
float hud_panel_radar_foreground_alpha
Definition: teamradar.qh:21
vector view_origin
Definition: main.qh:93
float intermission
Definition: csprogsdefs.qc:148
void HUD_Radar_Show_Maximized(bool doshow, bool clickable)
Definition: radar.qc:30
void HUD_Scale_Disable()
Definition: hud.qc:83
vector teamradar_extraclip_mins
Definition: teamradar.qh:16
origin
Definition: ent_cs.qc:114
float vid_conwidth
int hud_panel_radar_rotation
Definition: teamradar.qh:22
float mv_active
Definition: mapvoting.qh:19
void teamradar_loadcvars()
Definition: teamradar.qc:173
vector autocvar_hud_panel_radar_maximized_size
Definition: radar.qh:8
vector teamradar_2dcoord_to_texcoord(vector in)
Definition: teamradar.qc:33
bool hud_panel_radar_temp_hidden
Definition: hud.qh:72
#define strcpy(this, s)
Definition: string.qh:49
int mouseClicked
Definition: hud_config.qh:12
bool hud_panel_radar_mouse
Definition: hud.qh:70
float teamradar_angle
Definition: teamradar.qh:12
vector view_angles
Definition: csprogsdefs.qc:150
float HUD_Radar_InputEvent(int bInputType, float nPrimary, float nSecondary)
Definition: radar.qc:62
string hud_skin_path
Definition: hud.qh:133
#define HUD_Panel_DrawBg()
Definition: hud.qh:54
vector mi_center
Definition: main.qh:24
void draw_teamradar_link(vector start, vector end, int colors)
Definition: teamradar.qc:149
float hud_panel_radar_bottom
Definition: hud.qh:71
void draw_teamradar_icon(vector coord, entity icon, entity pingdata, vector rgb, float a)
Definition: teamradar.qc:128
bool HUD_Radar_Clickable()
Definition: radar.qc:25
ERASEABLE float vlen_maxnorm2d(vector v)
Definition: vector.qh:60
void HUD_Scale_Enable()
Definition: hud.qc:90
vector HUD_Shift(vector v)
Definition: hud.qc:104
spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 f1 s1 strcat(_("Level %s: "), "^BG%s\3\, _("^BGPress ^F2%s^BG to enter the game"))
vector HUD_Scale(vector v)
Definition: hud.qc:97
vector mi_scale
Definition: main.qh:25
void HUD_Radar()
Definition: radar.qc:196
float K_MOUSE2
Definition: keycodes.qc:130
string message
Definition: powerups.qc:19
#define NULL
Definition: post.qh:17
float current_zoomfraction
Definition: main.qh:117
const float DRAWFLAG_NORMAL
Definition: csprogsdefs.qc:317
ERASEABLE float vlen_minnorm2d(vector v)
Definition: vector.qh:66
entity panel
Definition: hud.qh:144
#define TC(T, sym)
Definition: _all.inc:82
void draw_teamradar_player(vector coord3d, vector pangles, vector rgb)
Definition: teamradar.qc:88
vector panel_pos
Definition: hud.qh:159
float teamplay
Definition: progsdefs.qc:31
void draw_teamradar_background(float fg)
Definition: teamradar.qc:60
vector(float skel, float bonenum) _skel_get_boneabs_hidden
float teamradar_size
Definition: teamradar.qh:17
void HUD_Radar_Export(int fh)
Definition: radar.qc:12
float K_MOUSE1
Definition: keycodes.qc:129
void HUD_Radar_Hide_Maximized()
Definition: radar.qc:56
vector teamradar_origin3d_in_texcoord
Definition: teamradar.qh:13
vector teamradar_origin2d
Definition: teamradar.qh:14
#define AL_EACH(this, T, cond, body)
Definition: arraylist.qh:59
int hud_panel_radar_maximized_zoommode
Definition: teamradar.qh:25
vector teamradar_texcoord_to_3dcoord(vector in, float oz)
Definition: teamradar.qc:51
float HUD_Radar_GetAngle(int rotation)
Definition: radar.qc:189
vector mousepos
Definition: hud.qh:102
string minimapname
Definition: main.qh:27
#define MUTATOR_CALLHOOK(id,...)
Definition: base.qh:140
#define vec2(...)
Definition: vector.qh:90
float hud_panel_radar_scale
Definition: teamradar.qh:20
vector hud_fontsize
Definition: main.qh:63
const int S_MOUSE2
Definition: hud_config.qh:10
ERASEABLE vector Rotate(vector v, float a)
Definition: vector.qh:105
const int S_MOUSE1
Definition: hud_config.qh:9
if(IS_DEAD(this))
Definition: impulse.qc:92
float time
Definition: csprogsdefs.qc:16
float HUD_Radar_GetZoomFactor(int zoommode)
Definition: radar.qc:178
#define HUD_Write_Cvar(cvar)
Definition: hud_config.qh:38
bool autocvar_hud_panel_radar_dynamichud
Definition: radar.qh:5
vector teamradar_size2d
Definition: teamradar.qh:15
IntrusiveList g_radaricons
Definition: main.qh:80
#define HUD_PANEL(NAME)
Definition: hud.qh:51
Header file that describes the resource system.
void HUD_Radar_Mouse()
Definition: radar.qc:134
int hud_panel_radar_maximized_rotation
Definition: teamradar.qh:26
void HUD_Panel_LoadCvars()
Definition: hud.qc:216
float panel_bg_padding
Definition: hud.qh:171
int autocvar_hud_panel_radar
Definition: radar.qh:4