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