1 #include "cl_vehicles.qh"
2 const string vCROSS_BURST = "gfx/vehicles/crosshair_burst.tga";
3 const string vCROSS_DROP = "gfx/vehicles/crosshair_drop.tga";
4 const string vCROSS_GUIDE = "gfx/vehicles/crosshair_guide.tga";
5 const string vCROSS_HEAL = "gfx/vehicles/crosshair_heal.tga";
6 const string vCROSS_HINT = "gfx/vehicles/crosshair_hint.tga";
7 const string vCROSS_LOCK = "gfx/vehicles/crosshair_lock.tga";
8 const string vCROSS_RAIN = "gfx/vehicles/crosshair_rain.tga";
12 const int MAX_AXH = 4;
13 entity AuxiliaryXhair[MAX_AXH];
22 void vehicle_alarm(entity e, int ch, Sound s0und)
25 if (!autocvar_cl_vehicles_alarm) {
29 sound(e, ch, s0und, VOL_BASEVOICE, ATTEN_NONE);
32 void AuxiliaryXhair_Draw2D(entity this)
34 if (scoreboard_active) {
38 vector pos = project_3d_to_2d(this.origin);
40 if (!(pos.z < 0 || pos.x < 0 || pos.y < 0 || pos.x > vid_conwidth || pos.y > vid_conheight)) {
41 vector size = draw_getimagesize(this.axh_image) * autocvar_cl_vehicles_crosshair_size;
42 pos.x -= 0.5 * size.x;
43 pos.y -= 0.5 * size.y;
45 drawpic(pos, this.axh_image, size, this.colormod, autocvar_crosshair_alpha * this.alpha, this.axh_drawflag);
48 if (time - this.cnt > this.axh_fadetime) {
49 this.draw2d = func_null;
53 NET_HANDLE(ENT_CLIENT_AUXILIARYXHAIR, bool isnew)
57 int axh_id = bound(0, ReadByte(), MAX_AXH);
58 entity axh = AuxiliaryXhair[axh_id];
60 if (axh == NULL || wasfreed(axh)) {
61 axh = new(auxiliary_crosshair);
62 axh.draw2d = func_null;
63 axh.drawmask = MASK_NORMAL;
64 axh.axh_drawflag = DRAWFLAG_ADDITIVE;
65 axh.axh_fadetime = 0.1;
66 axh.axh_image = vCROSS_HINT;
68 AuxiliaryXhair[axh_id] = axh;
69 IL_PUSH(g_drawables_2d, axh);
73 axh.origin_x = ReadCoord();
74 axh.origin_y = ReadCoord();
75 axh.origin_z = ReadCoord();
79 axh.colormod_x = ReadByte() / 255;
80 axh.colormod_y = ReadByte() / 255;
81 axh.colormod_z = ReadByte() / 255;
85 axh.draw2d = AuxiliaryXhair_Draw2D;
89 NET_HANDLE(TE_CSQC_VEHICLESETUP, bool isnew)
91 int hud_id = ReadByte();
94 // hud_id == 0 means we exited a vehicle, so stop alarm sound/s
95 // note: HUD_NORMAL is set to 0 currently too, but we'll check both just in case
96 if (hud_id == 0 || hud_id == HUD_NORMAL) {
97 sound(this, CH_TRIGGER_SINGLE, SND_Null, VOL_BASEVOICE, ATTEN_NONE);
98 sound(this, CH_PAIN_SINGLE, SND_Null, VOL_BASEVOICE, ATTEN_NONE);
100 for (int i = 0; i < MAX_AXH; ++i) {
101 entity axh = AuxiliaryXhair[i];
103 if (axh != NULL && !wasfreed(axh)) {
104 AuxiliaryXhair[i] = NULL;
111 // Init auxiliary crosshairs
112 for (int i = 0; i < MAX_AXH; ++i) {
113 entity axh = AuxiliaryXhair[i];
115 if (axh != NULL && !wasfreed(axh)) { // MADNESS? THIS IS QQQQCCCCCCCCC (wasfreed, why do you exsist?)
120 axh.draw2d = func_null;
121 axh.drawmask = MASK_NORMAL;
122 axh.axh_drawflag = DRAWFLAG_NORMAL;
123 axh.axh_fadetime = 0.1;
124 axh.axh_image = vCROSS_HINT;
126 AuxiliaryXhair[i] = axh;
127 IL_PUSH(g_drawables_2d, axh);
130 if (hud_id == HUD_BUMBLEBEE_GUN) {
131 AuxiliaryXhair[0].axh_image = vCROSS_BURST; // Plasma cannons
132 AuxiliaryXhair[1].axh_image = vCROSS_BURST; // Raygun
134 Vehicle info = Vehicles_from(hud_id);
135 info.vr_setup(info, NULL);
139 void Vehicles_drawHUD(string vehicle, string vehicleWeapon1, string vehicleWeapon2, string iconAmmo1, vector colorAmmo1, string iconAmmo2, vector colorAmmo2)
142 vector tmpSize = '0 0 0';
143 vector tmpPos = '0 0 0';
145 float hudAlpha = autocvar_hud_panel_fg_alpha * hud_fade_alpha;
146 float barAlpha = autocvar_hud_progressbar_alpha * hudAlpha;
147 float blinkValue = 0.55 + sin(time * 7) * 0.45;
149 float health = STAT(VEHICLESTAT_HEALTH) * 0.01;
150 float shield = STAT(VEHICLESTAT_SHIELD) * 0.01;
151 float energy = STAT(VEHICLESTAT_ENERGY) * 0.01;
152 float ammo1 = STAT(VEHICLESTAT_AMMO1) * 0.01;
153 float reload1 = STAT(VEHICLESTAT_RELOAD1) * 0.01;
154 float ammo2 = STAT(VEHICLESTAT_AMMO2) * 0.01;
155 float reload2 = STAT(VEHICLESTAT_RELOAD2) * 0.01;
157 // HACK to deal with the inconsistent use of the vehicle stats
158 ammo1 = (ammo1) ? ammo1 : energy;
161 string frame = strcat(hud_skin_path, "/vehicle_frame");
162 if (precache_pic(frame) == "") {
163 frame = "gfx/hud/default/vehicle_frame";
166 vehicleHud_Size = draw_getimagesize(frame) * autocvar_cl_vehicles_hudscale;
167 vehicleHud_Pos.x = (vid_conwidth - vehicleHud_Size.x) / 2;
168 vehicleHud_Pos.y = vid_conheight - vehicleHud_Size.y;
170 if (teamplay && autocvar_hud_panel_bg_color_team) {
171 drawpic(vehicleHud_Pos, frame, vehicleHud_Size, myteamcolors * autocvar_hud_panel_bg_color_team, autocvar_hud_panel_bg_alpha * hud_fade_alpha, DRAWFLAG_NORMAL);
173 drawpic(vehicleHud_Pos, frame, vehicleHud_Size, autocvar_hud_panel_bg_color, autocvar_hud_panel_bg_alpha * hud_fade_alpha, DRAWFLAG_NORMAL);
176 if (!autocvar__vehicles_shownchasemessage && time < vh_notice_time) {
177 float tmpblinkValue = 0.55 + sin(time * 3) * 0.45;
178 tmpPos.x = vehicleHud_Pos.x + vehicleHud_Size.x * (96 / 256) - tmpSize.x;
179 tmpPos.y = vehicleHud_Pos.y;
180 tmpSize = '1 1 1' * hud_fontsize;
181 drawstring(tmpPos, sprintf(_("Press %s"), getcommandkey(_("drop weapon"), "dropweapon")), tmpSize, '1 0 0' + '0 1 1' * tmpblinkValue, hudAlpha, DRAWFLAG_NORMAL);
185 tmpSize.x = vehicleHud_Size.x / 3;
186 tmpSize.y = vehicleHud_Size.y;
187 tmpPos.x = vehicleHud_Pos.x + vehicleHud_Size.x / 3;
188 tmpPos.y = vehicleHud_Pos.y;
191 drawpic_skin(tmpPos, vehicle, tmpSize, '1 0 0' + '0 1 1' * blinkValue, hudAlpha, DRAWFLAG_NORMAL);
193 drawpic_skin(tmpPos, vehicle, tmpSize, '1 1 1' * health + '1 0 0' * (1 - health), hudAlpha, DRAWFLAG_NORMAL);
196 if (vehicleWeapon1) {
197 drawpic_skin(tmpPos, vehicleWeapon1, tmpSize, '1 1 1' * ammo1 + '1 0 0' * (1 - ammo1), hudAlpha, DRAWFLAG_NORMAL);
199 if (vehicleWeapon2) {
200 drawpic_skin(tmpPos, vehicleWeapon2, tmpSize, '1 1 1' * ammo2 + '1 0 0' * (1 - ammo2), hudAlpha, DRAWFLAG_NORMAL);
203 drawpic_skin(tmpPos, "vehicle_shield", tmpSize, '1 1 1' * shield + '1 0 0' * (1 - shield), hudAlpha * shield, DRAWFLAG_NORMAL);
206 tmpSize.y = vehicleHud_Size.y / 2;
207 tmpPos.x = vehicleHud_Pos.x + vehicleHud_Size.x * (32 / 768);
208 tmpPos.y = vehicleHud_Pos.y;
210 drawsetcliparea(tmpPos.x + (tmpSize.x * (1 - health)), tmpPos.y, tmpSize.x, tmpSize.y);
211 drawpic_skin(tmpPos, "vehicle_bar_northwest", tmpSize, autocvar_hud_progressbar_health_color, barAlpha, DRAWFLAG_NORMAL);
214 tmpPos.y = vehicleHud_Pos.y + vehicleHud_Size.y / 2;
216 drawsetcliparea(tmpPos.x + (tmpSize.x * (1 - shield)), tmpPos.y, tmpSize.x, tmpSize.y);
217 drawpic_skin(tmpPos, "vehicle_bar_southwest", tmpSize, autocvar_hud_progressbar_armor_color, barAlpha, DRAWFLAG_NORMAL);
220 tmpPos.x = vehicleHud_Pos.x + vehicleHud_Size.x * (480 / 768);
221 tmpPos.y = vehicleHud_Pos.y;
224 drawsetcliparea(tmpPos.x, tmpPos.y, tmpSize.x * ammo1, tmpSize.y);
226 drawsetcliparea(tmpPos.x, tmpPos.y, tmpSize.x * reload1, tmpSize.y);
229 drawpic_skin(tmpPos, "vehicle_bar_northeast", tmpSize, colorAmmo1, barAlpha, DRAWFLAG_NORMAL);
232 tmpPos.y = vehicleHud_Pos.y + vehicleHud_Size.y / 2;
235 drawsetcliparea(tmpPos.x, tmpPos.y, tmpSize.x * ammo2, tmpSize.y);
237 drawsetcliparea(tmpPos.x, tmpPos.y, tmpSize.x * reload2, tmpSize.y);
240 drawpic_skin(tmpPos, "vehicle_bar_southeast", tmpSize, colorAmmo2, barAlpha, DRAWFLAG_NORMAL);
244 tmpSize.x = vehicleHud_Size.x * (80 / 768);
245 tmpSize.y = vehicleHud_Size.y * (80 / 256);
246 tmpPos.x = vehicleHud_Pos.x + vehicleHud_Size.x * (64 / 768);
247 tmpPos.y = vehicleHud_Pos.y + vehicleHud_Size.y * (48 / 256);
250 if (alarm1time < time) {
251 alarm1time = time + 2;
252 vehicle_alarm(NULL, CH_PAIN_SINGLE, SND_VEH_ALARM);
254 drawpic_skin(tmpPos, "vehicle_icon_health", tmpSize, '1 1 1', hudAlpha * blinkValue, DRAWFLAG_NORMAL);
257 vehicle_alarm(NULL, CH_PAIN_SINGLE, SND_Null);
260 drawpic_skin(tmpPos, "vehicle_icon_health", tmpSize, '1 1 1', hudAlpha, DRAWFLAG_NORMAL);
264 tmpPos.y = vehicleHud_Pos.y + vehicleHud_Size.y / 2;
267 if (alarm2time < time) {
268 alarm2time = time + 1;
269 vehicle_alarm(NULL, CH_TRIGGER_SINGLE, SND_VEH_ALARM_SHIELD);
271 drawpic_skin(tmpPos, "vehicle_icon_shield", tmpSize, '1 1 1', hudAlpha * blinkValue, DRAWFLAG_NORMAL);
274 vehicle_alarm(NULL, CH_TRIGGER_SINGLE, SND_Null);
277 drawpic_skin(tmpPos, "vehicle_icon_shield", tmpSize, '1 1 1', hudAlpha, DRAWFLAG_NORMAL);
281 tmpPos.x = vehicleHud_Pos.x + vehicleHud_Size.x * (624 / 768);
282 tmpPos.y = vehicleHud_Pos.y + vehicleHud_Size.y * (48 / 256);
286 drawpic_skin(tmpPos, iconAmmo1, tmpSize, '1 1 1', hudAlpha, DRAWFLAG_NORMAL);
288 drawpic_skin(tmpPos, iconAmmo1, tmpSize, '1 1 1', hudAlpha * 0.2, DRAWFLAG_NORMAL);
293 tmpPos.y = vehicleHud_Pos.y + vehicleHud_Size.y / 2;
297 drawpic_skin(tmpPos, iconAmmo2, tmpSize, '1 1 1', hudAlpha, DRAWFLAG_NORMAL);
299 drawpic_skin(tmpPos, iconAmmo2, tmpSize, '1 1 1', hudAlpha * 0.2, DRAWFLAG_NORMAL);
304 void Vehicles_drawCrosshair(string crosshair)
306 vector tmpSize = '0 0 0';
307 vector tmpPos = '0 0 0';
311 tmpSize = draw_getimagesize(crosshair) * autocvar_cl_vehicles_crosshair_size;
312 tmpPos.x = (vid_conwidth - tmpSize.x) / 2;
313 tmpPos.y = (vid_conheight - tmpSize.y) / 2;
315 vector wcross_color = '1 1 1';
316 if (autocvar_cl_vehicles_crosshair_colorize) {
317 wcross_color = crosshair_getcolor(NULL, STAT(VEHICLESTAT_HEALTH));
320 drawpic(tmpPos, crosshair, tmpSize, wcross_color, autocvar_crosshair_alpha, DRAWFLAG_NORMAL);