1 #include "cl_vehicles.qh"
3 const string vCROSS_BURST = "gfx/vehicles/crosshair_burst.tga";
4 const string vCROSS_DROP = "gfx/vehicles/crosshair_drop.tga";
5 const string vCROSS_GUIDE = "gfx/vehicles/crosshair_guide.tga";
6 const string vCROSS_HEAL = "gfx/vehicles/crosshair_heal.tga";
7 const string vCROSS_HINT = "gfx/vehicles/crosshair_hint.tga";
8 const string vCROSS_LOCK = "gfx/vehicles/crosshair_lock.tga";
9 const string vCROSS_RAIN = "gfx/vehicles/crosshair_rain.tga";
13 const int MAX_AXH = 4;
14 entity AuxiliaryXhair[MAX_AXH];
23 void vehicle_alarm(entity e, int ch, Sound s0und)
26 if(!autocvar_cl_vehicles_alarm)
29 sound(e, ch, s0und, VOL_BASEVOICE, ATTEN_NONE);
32 void AuxiliaryXhair_Draw2D(entity this)
34 if (scoreboard_active)
37 vector pos = project_3d_to_2d(this.origin);
39 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;
52 NET_HANDLE(ENT_CLIENT_AUXILIARYXHAIR, bool isnew)
56 int axh_id = bound(0, ReadByte(), MAX_AXH);
57 entity axh = AuxiliaryXhair[axh_id];
59 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);
74 axh.origin = ReadVector();
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)
98 sound(this, CH_TRIGGER_SINGLE, SND_Null, VOL_BASEVOICE, ATTEN_NONE);
99 sound(this, CH_PAIN_SINGLE, SND_Null, VOL_BASEVOICE, ATTEN_NONE);
101 for(int i = 0; i < MAX_AXH; ++i)
103 entity axh = AuxiliaryXhair[i];
105 if(axh != NULL && !wasfreed(axh))
107 AuxiliaryXhair[i] = NULL;
114 // Init auxiliary crosshairs
115 for(int i = 0; i < MAX_AXH; ++i)
117 entity axh = AuxiliaryXhair[i];
119 if(axh != NULL && !wasfreed(axh)) // MADNESS? THIS IS QQQQCCCCCCCCC (wasfreed, why do you exsist?)
122 axh = new(AuxiliaryXhair);
123 axh.draw2d = func_null;
124 axh.drawmask = MASK_NORMAL;
125 axh.axh_drawflag = DRAWFLAG_NORMAL;
126 axh.axh_fadetime = 0.1;
127 axh.axh_image = vCROSS_HINT;
129 AuxiliaryXhair[i] = axh;
130 IL_PUSH(g_drawables_2d, axh);
133 if(hud_id == HUD_BUMBLEBEE_GUN)
135 AuxiliaryXhair[0].axh_image = vCROSS_BURST; // Plasma cannons
136 AuxiliaryXhair[1].axh_image = vCROSS_BURST; // Raygun
138 Vehicle info = REGISTRY_GET(Vehicles, hud_id);
139 info.vr_setup(info, NULL);
143 void Vehicles_drawHUD(
145 string vehicleWeapon1,
146 string vehicleWeapon2,
153 vector tmpSize = '0 0 0';
154 vector tmpPos = '0 0 0';
156 float hudAlpha = autocvar_hud_panel_fg_alpha * hud_fade_alpha;
157 float barAlpha = autocvar_hud_progressbar_alpha * hudAlpha;
158 float blinkValue = 0.55 + sin(time * 7) * 0.45;
160 float health = STAT(VEHICLESTAT_HEALTH) * 0.01;
161 float shield = STAT(VEHICLESTAT_SHIELD) * 0.01;
162 float energy = STAT(VEHICLESTAT_ENERGY) * 0.01;
163 float ammo1 = STAT(VEHICLESTAT_AMMO1) * 0.01;
164 float reload1 = STAT(VEHICLESTAT_RELOAD1) * 0.01;
165 float ammo2 = STAT(VEHICLESTAT_AMMO2) * 0.01;
166 float reload2 = STAT(VEHICLESTAT_RELOAD2) * 0.01;
168 // HACK to deal with the inconsistent use of the vehicle stats
169 ammo1 = (ammo1) ? ammo1 : energy;
172 string frame = strcat(hud_skin_path, "/vehicle_frame");
173 if (precache_pic(frame) == "")
174 frame = "gfx/hud/default/vehicle_frame";
176 vehicleHud_Size = draw_getimagesize(frame) * autocvar_cl_vehicles_hudscale;
177 vehicleHud_Pos.x = (vid_conwidth - vehicleHud_Size.x) / 2;
178 vehicleHud_Pos.y = vid_conheight - vehicleHud_Size.y;
180 if(teamplay && autocvar_hud_panel_bg_color_team)
181 drawpic(vehicleHud_Pos, frame, vehicleHud_Size, myteamcolors * autocvar_hud_panel_bg_color_team, autocvar_hud_panel_bg_alpha * hud_fade_alpha, DRAWFLAG_NORMAL);
183 drawpic(vehicleHud_Pos, frame, vehicleHud_Size, autocvar_hud_panel_bg_color, autocvar_hud_panel_bg_alpha * hud_fade_alpha, DRAWFLAG_NORMAL);
185 if(!autocvar__vehicles_shownchasemessage && time < vh_notice_time)
187 float tmpblinkValue = 0.55 + sin(time * 3) * 0.45;
188 tmpPos.x = vehicleHud_Pos.x + vehicleHud_Size.x * (96/256) - tmpSize.x;
189 tmpPos.y = vehicleHud_Pos.y;
190 tmpSize = '1 1 1' * hud_fontsize;
191 drawstring(tmpPos, sprintf(_("Press %s"), getcommandkey(_("drop weapon"), "dropweapon")), tmpSize, '1 0 0' + '0 1 1' * tmpblinkValue, hudAlpha, DRAWFLAG_NORMAL);
195 tmpSize.x = vehicleHud_Size.x / 3;
196 tmpSize.y = vehicleHud_Size.y;
197 tmpPos.x = vehicleHud_Pos.x + vehicleHud_Size.x / 3;
198 tmpPos.y = vehicleHud_Pos.y;
201 drawpic_skin(tmpPos, vehicle, tmpSize, '1 0 0' + '0 1 1' * blinkValue, hudAlpha, DRAWFLAG_NORMAL);
203 drawpic_skin(tmpPos, vehicle, tmpSize, '1 1 1' * health + '1 0 0' * (1 - health), hudAlpha, DRAWFLAG_NORMAL);
206 drawpic_skin(tmpPos, vehicleWeapon1, tmpSize, '1 1 1' * ammo1 + '1 0 0' * (1 - ammo1), hudAlpha, DRAWFLAG_NORMAL);
208 drawpic_skin(tmpPos, vehicleWeapon2, tmpSize, '1 1 1' * ammo2 + '1 0 0' * (1 - ammo2), hudAlpha, DRAWFLAG_NORMAL);
210 drawpic_skin(tmpPos, "vehicle_shield", tmpSize, '1 1 1' * shield + '1 0 0' * (1 - shield), hudAlpha * shield, DRAWFLAG_NORMAL);
213 tmpSize.y = vehicleHud_Size.y / 2;
214 tmpPos.x = vehicleHud_Pos.x + vehicleHud_Size.x * (32/768);
215 tmpPos.y = vehicleHud_Pos.y;
217 drawsetcliparea(tmpPos.x + (tmpSize.x * (1 - health)), tmpPos.y, tmpSize.x, tmpSize.y);
218 drawpic_skin(tmpPos, "vehicle_bar_northwest", tmpSize, autocvar_hud_progressbar_health_color, barAlpha, DRAWFLAG_NORMAL);
221 tmpPos.y = vehicleHud_Pos.y + vehicleHud_Size.y / 2;
223 drawsetcliparea(tmpPos.x + (tmpSize.x * (1 - shield)), tmpPos.y, tmpSize.x, tmpSize.y);
224 drawpic_skin(tmpPos, "vehicle_bar_southwest", tmpSize, autocvar_hud_progressbar_armor_color, barAlpha, DRAWFLAG_NORMAL);
227 tmpPos.x = vehicleHud_Pos.x + vehicleHud_Size.x * (480/768);
228 tmpPos.y = vehicleHud_Pos.y;
231 drawsetcliparea(tmpPos.x, tmpPos.y, tmpSize.x * ammo1, tmpSize.y);
233 drawsetcliparea(tmpPos.x, tmpPos.y, tmpSize.x * reload1, tmpSize.y);
235 drawpic_skin(tmpPos, "vehicle_bar_northeast", tmpSize, colorAmmo1, barAlpha, DRAWFLAG_NORMAL);
238 tmpPos.y = vehicleHud_Pos.y + vehicleHud_Size.y / 2;
241 drawsetcliparea(tmpPos.x, tmpPos.y, tmpSize.x * ammo2, tmpSize.y);
243 drawsetcliparea(tmpPos.x, tmpPos.y, tmpSize.x * reload2, tmpSize.y);
245 drawpic_skin(tmpPos, "vehicle_bar_southeast", tmpSize, colorAmmo2, barAlpha, DRAWFLAG_NORMAL);
249 tmpSize.x = vehicleHud_Size.x * (80/768);
250 tmpSize.y = vehicleHud_Size.y * (80/256);
251 tmpPos.x = vehicleHud_Pos.x + vehicleHud_Size.x * (64/768);
252 tmpPos.y = vehicleHud_Pos.y + vehicleHud_Size.y * (48/256);
256 if(alarm1time < time)
258 alarm1time = time + 2;
259 vehicle_alarm(NULL, CH_PAIN_SINGLE, SND_VEH_ALARM);
261 drawpic_skin(tmpPos, "vehicle_icon_health", tmpSize, '1 1 1', hudAlpha * blinkValue, DRAWFLAG_NORMAL);
267 vehicle_alarm(NULL, CH_PAIN_SINGLE, SND_Null);
270 drawpic_skin(tmpPos, "vehicle_icon_health", tmpSize, '1 1 1', hudAlpha, DRAWFLAG_NORMAL);
274 tmpPos.y = vehicleHud_Pos.y + vehicleHud_Size.y / 2;
278 if(alarm2time < time)
280 alarm2time = time + 1;
281 vehicle_alarm(NULL, CH_TRIGGER_SINGLE, SND_VEH_ALARM_SHIELD);
283 drawpic_skin(tmpPos, "vehicle_icon_shield", tmpSize, '1 1 1', hudAlpha * blinkValue, DRAWFLAG_NORMAL);
289 vehicle_alarm(NULL, CH_TRIGGER_SINGLE, SND_Null);
292 drawpic_skin(tmpPos, "vehicle_icon_shield", tmpSize, '1 1 1', hudAlpha, DRAWFLAG_NORMAL);
296 tmpPos.x = vehicleHud_Pos.x + vehicleHud_Size.x * (624/768);
297 tmpPos.y = vehicleHud_Pos.y + vehicleHud_Size.y * (48/256);
302 drawpic_skin(tmpPos, iconAmmo1, tmpSize, '1 1 1', hudAlpha, DRAWFLAG_NORMAL);
304 drawpic_skin(tmpPos, iconAmmo1, tmpSize, '1 1 1', hudAlpha * 0.2, DRAWFLAG_NORMAL);
308 tmpPos.y = vehicleHud_Pos.y + vehicleHud_Size.y / 2;
313 drawpic_skin(tmpPos, iconAmmo2, tmpSize, '1 1 1', hudAlpha, DRAWFLAG_NORMAL);
315 drawpic_skin(tmpPos, iconAmmo2, tmpSize, '1 1 1', hudAlpha * 0.2, DRAWFLAG_NORMAL);
319 void Vehicles_drawCrosshair(string crosshair)
321 vector tmpSize = '0 0 0';
322 vector tmpPos = '0 0 0';
327 tmpSize = draw_getimagesize(crosshair) * autocvar_cl_vehicles_crosshair_size;
328 tmpPos.x = (vid_conwidth - tmpSize.x) / 2;
329 tmpPos.y = (vid_conheight - tmpSize.y) / 2;
331 vector wcross_color = '1 1 1';
332 if(autocvar_cl_vehicles_crosshair_colorize)
333 wcross_color = crosshair_getcolor(NULL, STAT(VEHICLESTAT_HEALTH));
335 drawpic(tmpPos, crosshair, tmpSize, wcross_color, autocvar_crosshair_alpha, DRAWFLAG_NORMAL);