Xonotic
cl_vehicles.qc
Go to the documentation of this file.
1 #include "cl_vehicles.qh"
2 
3 void vehicle_alarm(entity e, int ch, Sound s0und)
4 {
5  TC(Sound, s0und);
7  return;
8 
9  sound(e, ch, s0und, VOL_BASEVOICE, ATTEN_NONE);
10 }
11 
13 {
15  return;
16 
17  vector pos = project_3d_to_2d(this.origin);
18 
19  if (!(pos.z < 0 || pos.x < 0 || pos.y < 0 || pos.x > vid_conwidth || pos.y > vid_conheight))
20  {
21  vector size = draw_getimagesize(this.axh_image) * autocvar_cl_vehicles_crosshair_size;
22  pos.x -= 0.5 * size.x;
23  pos.y -= 0.5 * size.y;
24  pos.z = 0;
25  drawpic(pos, this.axh_image, size, this.colormod, autocvar_crosshair_alpha * this.alpha, this.axh_drawflag);
26  }
27 
28  if(time - this.cnt > this.axh_fadetime)
29  this.draw2d = func_null;
30 }
31 
32 NET_HANDLE(ENT_CLIENT_AUXILIARYXHAIR, bool isnew)
33 {
34  int sf = ReadByte();
35 
36  int axh_id = bound(0, ReadByte(), MAX_AXH);
37  entity axh = AuxiliaryXhair[axh_id];
38 
39  if(axh == NULL || wasfreed(axh))
40  {
41  axh = new(auxiliary_crosshair);
42  axh.draw2d = func_null;
43  axh.drawmask = MASK_NORMAL;
44  axh.axh_drawflag = DRAWFLAG_ADDITIVE;
45  axh.axh_fadetime = 0.1;
46  axh.axh_image = vCROSS_HINT;
47  axh.alpha = 1;
48  AuxiliaryXhair[axh_id] = axh;
49  IL_PUSH(g_drawables_2d, axh);
50  }
51 
52  if(sf & 2)
53  {
54  axh.origin = ReadVector();
55  }
56 
57  if(sf & 4)
58  {
59  axh.colormod_x = ReadByte() / 255;
60  axh.colormod_y = ReadByte() / 255;
61  axh.colormod_z = ReadByte() / 255;
62  }
63 
64  axh.cnt = time;
65  axh.draw2d = AuxiliaryXhair_Draw2D;
66  return true;
67 }
68 
69 NET_HANDLE(TE_CSQC_VEHICLESETUP, bool isnew)
70 {
71  int hud_id = ReadByte();
72  return = true;
73 
74  // hud_id == 0 means we exited a vehicle, so stop alarm sound/s
75  // note: HUD_NORMAL is set to 0 currently too, but we'll check both just in case
76  if(hud_id == 0 || hud_id == HUD_NORMAL)
77  {
79  sound(this, CH_PAIN_SINGLE, SND_Null, VOL_BASEVOICE, ATTEN_NONE);
80 
81  for(int i = 0; i < MAX_AXH; ++i)
82  {
83  entity axh = AuxiliaryXhair[i];
84 
85  if(axh != NULL && !wasfreed(axh))
86  {
87  AuxiliaryXhair[i] = NULL;
88  delete(axh);
89  }
90  }
91  return;
92  }
93 
94  // Init auxiliary crosshairs
95  for(int i = 0; i < MAX_AXH; ++i)
96  {
97  entity axh = AuxiliaryXhair[i];
98 
99  if(axh != NULL && !wasfreed(axh)) // MADNESS? THIS IS QQQQCCCCCCCCC (wasfreed, why do you exsist?)
100  delete(axh);
101 
102  axh = new(AuxiliaryXhair);
103  axh.draw2d = func_null;
104  axh.drawmask = MASK_NORMAL;
105  axh.axh_drawflag = DRAWFLAG_NORMAL;
106  axh.axh_fadetime = 0.1;
107  axh.axh_image = vCROSS_HINT;
108  axh.alpha = 1;
109  AuxiliaryXhair[i] = axh;
110  IL_PUSH(g_drawables_2d, axh);
111  }
112 
113  if(hud_id == HUD_BUMBLEBEE_GUN)
114  {
115  AuxiliaryXhair[0].axh_image = vCROSS_BURST; // Plasma cannons
116  AuxiliaryXhair[1].axh_image = vCROSS_BURST; // Raygun
117  } else {
118  Vehicle info = REGISTRY_GET(Vehicles, hud_id);
119  info.vr_setup(info, NULL);
120  }
121 }
122 
124  string vehicle,
125  string vehicleWeapon1,
126  string vehicleWeapon2,
127  string iconAmmo1,
128  vector colorAmmo1,
129  string iconAmmo2,
130  vector colorAmmo2)
131 {
132  // Initialize
133  vector tmpSize = '0 0 0';
134  vector tmpPos = '0 0 0';
135 
136  float hudAlpha = autocvar_hud_panel_fg_alpha * hud_fade_alpha;
137  float barAlpha = autocvar_hud_progressbar_alpha * hudAlpha;
138  float blinkValue = 0.55 + sin(time * 7) * 0.45;
139 
140  float health = STAT(VEHICLESTAT_HEALTH) * 0.01;
141  float shield = STAT(VEHICLESTAT_SHIELD) * 0.01;
142  float energy = STAT(VEHICLESTAT_ENERGY) * 0.01;
143  float ammo1 = STAT(VEHICLESTAT_AMMO1) * 0.01;
144  float reload1 = STAT(VEHICLESTAT_RELOAD1) * 0.01;
145  float ammo2 = STAT(VEHICLESTAT_AMMO2) * 0.01;
146  float reload2 = STAT(VEHICLESTAT_RELOAD2) * 0.01;
147 
148  // HACK to deal with the inconsistent use of the vehicle stats
149  ammo1 = (ammo1) ? ammo1 : energy;
150 
151  // Frame
152  string frame = strcat(hud_skin_path, "/vehicle_frame");
153  if (precache_pic(frame) == "")
154  frame = "gfx/hud/default/vehicle_frame";
155 
156  vehicleHud_Size = draw_getimagesize(frame) * autocvar_cl_vehicles_hudscale;
159 
162  else
164 
166  {
167  float tmpblinkValue = 0.55 + sin(time * 3) * 0.45;
168  tmpPos.x = vehicleHud_Pos.x + vehicleHud_Size.x * (96/256) - tmpSize.x;
169  tmpPos.y = vehicleHud_Pos.y;
170  tmpSize = '1 1 1' * hud_fontsize;
171  drawstring(tmpPos, sprintf(_("Press %s"), getcommandkey(_("drop weapon"), "dropweapon")), tmpSize, '1 0 0' + '0 1 1' * tmpblinkValue, hudAlpha, DRAWFLAG_NORMAL);
172  }
173 
174  // Model
175  tmpSize.x = vehicleHud_Size.x / 3;
176  tmpSize.y = vehicleHud_Size.y;
177  tmpPos.x = vehicleHud_Pos.x + vehicleHud_Size.x / 3;
178  tmpPos.y = vehicleHud_Pos.y;
179 
180  if(health < 0.25)
181  drawpic_skin(tmpPos, vehicle, tmpSize, '1 0 0' + '0 1 1' * blinkValue, hudAlpha, DRAWFLAG_NORMAL);
182  else
183  drawpic_skin(tmpPos, vehicle, tmpSize, '1 1 1' * health + '1 0 0' * (1 - health), hudAlpha, DRAWFLAG_NORMAL);
184 
185  if(vehicleWeapon1)
186  drawpic_skin(tmpPos, vehicleWeapon1, tmpSize, '1 1 1' * ammo1 + '1 0 0' * (1 - ammo1), hudAlpha, DRAWFLAG_NORMAL);
187  if(vehicleWeapon2)
188  drawpic_skin(tmpPos, vehicleWeapon2, tmpSize, '1 1 1' * ammo2 + '1 0 0' * (1 - ammo2), hudAlpha, DRAWFLAG_NORMAL);
189 
190  drawpic_skin(tmpPos, "vehicle_shield", tmpSize, '1 1 1' * shield + '1 0 0' * (1 - shield), hudAlpha * shield, DRAWFLAG_NORMAL);
191 
192  // Health bar
193  tmpSize.y = vehicleHud_Size.y / 2;
194  tmpPos.x = vehicleHud_Pos.x + vehicleHud_Size.x * (32/768);
195  tmpPos.y = vehicleHud_Pos.y;
196 
197  drawsetcliparea(tmpPos.x + (tmpSize.x * (1 - health)), tmpPos.y, tmpSize.x, tmpSize.y);
198  drawpic_skin(tmpPos, "vehicle_bar_northwest", tmpSize, autocvar_hud_progressbar_health_color, barAlpha, DRAWFLAG_NORMAL);
199 
200  // Shield bar
201  tmpPos.y = vehicleHud_Pos.y + vehicleHud_Size.y / 2;
202 
203  drawsetcliparea(tmpPos.x + (tmpSize.x * (1 - shield)), tmpPos.y, tmpSize.x, tmpSize.y);
204  drawpic_skin(tmpPos, "vehicle_bar_southwest", tmpSize, autocvar_hud_progressbar_armor_color, barAlpha, DRAWFLAG_NORMAL);
205 
206  // Ammo1 bar
207  tmpPos.x = vehicleHud_Pos.x + vehicleHud_Size.x * (480/768);
208  tmpPos.y = vehicleHud_Pos.y;
209 
210  if(ammo1)
211  drawsetcliparea(tmpPos.x, tmpPos.y, tmpSize.x * ammo1, tmpSize.y);
212  else
213  drawsetcliparea(tmpPos.x, tmpPos.y, tmpSize.x * reload1, tmpSize.y);
214 
215  drawpic_skin(tmpPos, "vehicle_bar_northeast", tmpSize, colorAmmo1, barAlpha, DRAWFLAG_NORMAL);
216 
217  // Ammo2 bar
218  tmpPos.y = vehicleHud_Pos.y + vehicleHud_Size.y / 2;
219 
220  if(ammo2)
221  drawsetcliparea(tmpPos.x, tmpPos.y, tmpSize.x * ammo2, tmpSize.y);
222  else
223  drawsetcliparea(tmpPos.x, tmpPos.y, tmpSize.x * reload2, tmpSize.y);
224 
225  drawpic_skin(tmpPos, "vehicle_bar_southeast", tmpSize, colorAmmo2, barAlpha, DRAWFLAG_NORMAL);
227 
228  // Health icon
229  tmpSize.x = vehicleHud_Size.x * (80/768);
230  tmpSize.y = vehicleHud_Size.y * (80/256);
231  tmpPos.x = vehicleHud_Pos.x + vehicleHud_Size.x * (64/768);
232  tmpPos.y = vehicleHud_Pos.y + vehicleHud_Size.y * (48/256);
233 
234  if(health < 0.25)
235  {
236  if(alarm1time < time)
237  {
238  alarm1time = time + 2;
239  vehicle_alarm(NULL, CH_PAIN_SINGLE, SND_VEH_ALARM);
240  }
241  drawpic_skin(tmpPos, "vehicle_icon_health", tmpSize, '1 1 1', hudAlpha * blinkValue, DRAWFLAG_NORMAL);
242  }
243  else
244  {
245  if(alarm1time)
246  {
247  vehicle_alarm(NULL, CH_PAIN_SINGLE, SND_Null);
248  alarm1time = 0;
249  }
250  drawpic_skin(tmpPos, "vehicle_icon_health", tmpSize, '1 1 1', hudAlpha, DRAWFLAG_NORMAL);
251  }
252 
253  // Shield icon
254  tmpPos.y = vehicleHud_Pos.y + vehicleHud_Size.y / 2;
255 
256  if(shield < 0.25)
257  {
258  if(alarm2time < time)
259  {
260  alarm2time = time + 1;
261  vehicle_alarm(NULL, CH_TRIGGER_SINGLE, SND_VEH_ALARM_SHIELD);
262  }
263  drawpic_skin(tmpPos, "vehicle_icon_shield", tmpSize, '1 1 1', hudAlpha * blinkValue, DRAWFLAG_NORMAL);
264  }
265  else
266  {
267  if(alarm2time)
268  {
270  alarm2time = 0;
271  }
272  drawpic_skin(tmpPos, "vehicle_icon_shield", tmpSize, '1 1 1', hudAlpha, DRAWFLAG_NORMAL);
273  }
274 
275  // Ammo1 icon
276  tmpPos.x = vehicleHud_Pos.x + vehicleHud_Size.x * (624/768);
277  tmpPos.y = vehicleHud_Pos.y + vehicleHud_Size.y * (48/256);
278 
279  if(iconAmmo1)
280  {
281  if(ammo1)
282  drawpic_skin(tmpPos, iconAmmo1, tmpSize, '1 1 1', hudAlpha, DRAWFLAG_NORMAL);
283  else
284  drawpic_skin(tmpPos, iconAmmo1, tmpSize, '1 1 1', hudAlpha * 0.2, DRAWFLAG_NORMAL);
285  }
286 
287  // Ammo2 icon
288  tmpPos.y = vehicleHud_Pos.y + vehicleHud_Size.y / 2;
289 
290  if(iconAmmo2)
291  {
292  if(ammo2)
293  drawpic_skin(tmpPos, iconAmmo2, tmpSize, '1 1 1', hudAlpha, DRAWFLAG_NORMAL);
294  else
295  drawpic_skin(tmpPos, iconAmmo2, tmpSize, '1 1 1', hudAlpha * 0.2, DRAWFLAG_NORMAL);
296  }
297 }
298 
299 void Vehicles_drawCrosshair(string crosshair)
300 {
301  vector tmpSize = '0 0 0';
302  vector tmpPos = '0 0 0';
303 
304  // Crosshair
305  if(crosshair)
306  {
307  tmpSize = draw_getimagesize(crosshair) * autocvar_cl_vehicles_crosshair_size;
308  tmpPos.x = (vid_conwidth - tmpSize.x) / 2;
309  tmpPos.y = (vid_conheight - tmpSize.y) / 2;
310 
311  vector wcross_color = '1 1 1';
313  wcross_color = crosshair_getcolor(NULL, STAT(VEHICLESTAT_HEALTH));
314 
315  drawpic(tmpPos, crosshair, tmpSize, wcross_color, autocvar_crosshair_alpha, DRAWFLAG_NORMAL);
316  }
317 }
float vh_notice_time
Definition: hud.qc:492
float vid_conheight
const string vCROSS_BURST
Definition: cl_vehicles.qh:13
bool autocvar_cl_vehicles_crosshair_colorize
Definition: cl_vehicles.qh:8
float alpha
Definition: items.qc:14
float autocvar_hud_panel_bg_color_team
Definition: hud.qh:197
vector project_3d_to_2d(vector vec)
Definition: view.qc:359
vector colormod
Definition: powerups.qc:21
void Vehicles_drawCrosshair(string crosshair)
Definition: cl_vehicles.qc:299
vector autocvar_hud_progressbar_armor_color
Definition: healtharmor.qh:24
float autocvar_hud_panel_fg_alpha
Definition: hud.qh:199
float autocvar_crosshair_alpha
Definition: crosshair.qh:10
bool scoreboard_active
Definition: scoreboard.qh:9
float autocvar_cl_vehicles_hudscale
Definition: cl_vehicles.qh:5
float alarm1time
Definition: cl_vehicles.qh:30
entity() spawn
#define REGISTRY_GET(id, i)
Definition: registry.qh:43
void Vehicles_drawHUD(string vehicle, string vehicleWeapon1, string vehicleWeapon2, string iconAmmo1, vector colorAmmo1, string iconAmmo2, vector colorAmmo2)
Definition: cl_vehicles.qc:123
const float ATTEN_NONE
Definition: sound.qh:27
#define getcommandkey(cmd_name, command)
Definition: main.qh:108
void vehicle_alarm(entity e, int ch, Sound s0und)
Definition: cl_vehicles.qc:3
bool autocvar_cl_vehicles_alarm
Definition: cl_vehicles.qh:3
float autocvar_hud_panel_bg_alpha
Definition: hud.qh:194
int axh_drawflag
Definition: cl_vehicles.qh:28
origin
Definition: ent_cs.qc:114
vector size
Definition: csprogsdefs.qc:114
float vid_conwidth
const int MAX_AXH
Definition: cl_vehicles.qh:23
float alarm2time
Definition: cl_vehicles.qh:31
const float DRAWFLAG_ADDITIVE
Definition: csprogsdefs.qc:318
const int CH_PAIN_SINGLE
Definition: sound.qh:19
string hud_skin_path
Definition: hud.qh:133
float cnt
Definition: powerups.qc:24
ERASEABLE entity IL_PUSH(IntrusiveList this, entity it)
Push to tail.
entity AuxiliaryXhair[MAX_AXH]
Definition: cl_vehicles.qh:24
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"))
bool autocvar__vehicles_shownchasemessage
Definition: cl_vehicles.qh:9
float axh_fadetime
Definition: cl_vehicles.qh:27
vector myteamcolors
Definition: hud.qh:136
vector autocvar_hud_progressbar_health_color
Definition: healtharmor.qh:26
#define drawpic_skin(pos, pic, sz, color, theAlpha, drawflag)
Definition: draw.qh:89
#define NULL
Definition: post.qh:17
const float DRAWFLAG_NORMAL
Definition: csprogsdefs.qc:317
#define TC(T, sym)
Definition: _all.inc:82
vector vehicleHud_Size
Definition: cl_vehicles.qh:33
Definition: sound.qh:119
float teamplay
Definition: progsdefs.qc:31
const float MASK_NORMAL
Definition: csprogsdefs.qc:164
NET_HANDLE(ENT_CLIENT_AUXILIARYXHAIR, bool isnew)
Definition: cl_vehicles.qc:32
const int CH_TRIGGER_SINGLE
Definition: sound.qh:13
vector(float skel, float bonenum) _skel_get_boneabs_hidden
vector vehicleHud_Pos
Definition: cl_vehicles.qh:34
vector crosshair_getcolor(entity this, float health_stat)
Definition: crosshair.qc:174
void AuxiliaryXhair_Draw2D(entity this)
Definition: cl_vehicles.qc:12
const string vCROSS_HINT
Definition: cl_vehicles.qh:17
float health
Definition: progsdefs.qc:137
float frame
primary framegroup animation (strength = 1 - lerpfrac - lerpfrac3 - lerpfrac4)
Definition: anim.qh:6
vector hud_fontsize
Definition: main.qh:63
const float VOL_BASEVOICE
Definition: sound.qh:37
float hud_fade_alpha
Definition: hud.qh:131
string axh_image
Definition: cl_vehicles.qh:26
#define sound(e, c, s, v, a)
Definition: sound.qh:52
entity vehicle
Definition: impulse.qc:21
float autocvar_hud_progressbar_alpha
Definition: hud.qh:201
float time
Definition: csprogsdefs.qc:16
vector autocvar_hud_panel_bg_color
Definition: hud.qh:196
var void func_null()
float autocvar_cl_vehicles_crosshair_size
Definition: cl_vehicles.qh:7
IntrusiveList g_drawables_2d
Definition: main.qh:78