1#include "cl_vehicles.qh" 2const string vCROSS_BURST = "gfx/vehicles/crosshair_burst.tga"; 3const string vCROSS_DROP = "gfx/vehicles/crosshair_drop.tga"; 4const string vCROSS_GUIDE = "gfx/vehicles/crosshair_guide.tga"; 5const string vCROSS_HEAL = "gfx/vehicles/crosshair_heal.tga"; 6const string vCROSS_HINT = "gfx/vehicles/crosshair_hint.tga"; 7const string vCROSS_LOCK = "gfx/vehicles/crosshair_lock.tga"; 8const string vCROSS_RAIN = "gfx/vehicles/crosshair_rain.tga"; 9 10entity dropmark; 11 12const int MAX_AXH = 4; 13entity AuxiliaryXhair[MAX_AXH]; 14 15.string axh_image; 16.float axh_fadetime; 17.int axh_drawflag; 18 19float alarm1time; 20float alarm2time; 21 22void vehicle_alarm(entity e, int ch, Sound s0und) 23{ 24 TC(Sound, s0und); 25 if(!autocvar_cl_vehicles_alarm) 26 return; 27 28 sound(e, ch, s0und, VOL_BASEVOICE, ATTEN_NONE); 29} 30 31void AuxiliaryXhair_Draw2D(entity this) 32{ 33 if (scoreboard_active) 34 return; 35 36 vector size = draw_getimagesize(this.axh_image) * autocvar_cl_vehicles_crosshair_size; 37 vector pos = project_3d_to_2d(this.origin) - 0.5 * size; 38 39 if (!(pos.z < 0 || pos.x < 0 || pos.y < 0 || pos.x > vid_conwidth || pos.y > vid_conheight)) 40 { 41 pos.z = 0; 42 size.z = 0; 43 drawpic(pos, this.axh_image, size, this.colormod, autocvar_crosshair_alpha * this.alpha, this.axh_drawflag); 44 } 45 46 if(time - this.cnt > this.axh_fadetime) 47 this.draw2d = func_null; 48} 49 50NET_HANDLE(ENT_CLIENT_AUXILIARYXHAIR, bool isnew) 51{ 52 int sf = ReadByte(); 53 54 int axh_id = bound(0, ReadByte(), MAX_AXH); 55 entity axh = AuxiliaryXhair[axh_id]; 56 57 if(axh == NULL || wasfreed(axh)) 58 { 59 axh = new(auxiliary_crosshair); 60 axh.draw2d = func_null; 61 axh.drawmask = MASK_NORMAL; 62 axh.axh_drawflag = DRAWFLAG_ADDITIVE; 63 axh.axh_fadetime = 0.1; 64 axh.axh_image = vCROSS_HINT; 65 axh.alpha = 1; 66 AuxiliaryXhair[axh_id] = axh; 67 IL_PUSH(g_drawables_2d, axh); 68 } 69 70 if(sf & 2) 71 { 72 axh.origin_x = ReadCoord(); 73 axh.origin_y = ReadCoord(); 74 axh.origin_z = ReadCoord(); 75 } 76 77 if(sf & 4) 78 { 79 axh.colormod_x = ReadByte() / 255; 80 axh.colormod_y = ReadByte() / 255; 81 axh.colormod_z = ReadByte() / 255; 82 } 83 84 axh.cnt = time; 85 axh.draw2d = AuxiliaryXhair_Draw2D; 86 return true; 87} 88 89NET_HANDLE(TE_CSQC_VEHICLESETUP, bool isnew) 90{ 91 int hud_id = ReadByte(); 92 return = true; 93 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 { 98 sound(this, CH_TRIGGER_SINGLE, SND_Null, VOL_BASEVOICE, ATTEN_NONE); 99 sound(this, CH_PAIN_SINGLE, SND_Null, VOL_BASEVOICE, ATTEN_NONE); 100 101 for(int i = 0; i < MAX_AXH; ++i) 102 { 103 entity axh = AuxiliaryXhair[i]; 104 105 if(axh != NULL && !wasfreed(axh)) 106 { 107 AuxiliaryXhair[i] = NULL; 108 delete(axh); 109 } 110 } 111 return; 112 } 113 114 // Init auxiliary crosshairs 115 for(int i = 0; i < MAX_AXH; ++i) 116 { 117 entity axh = AuxiliaryXhair[i]; 118 119 if(axh != NULL && !wasfreed(axh)) // MADNESS? THIS IS QQQQCCCCCCCCC (wasfreed, why do you exsist?) 120 delete(axh); 121 122 axh = spawn(); 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; 128 axh.alpha = 1; 129 AuxiliaryXhair[i] = axh; 130 IL_PUSH(g_drawables_2d, axh); 131 } 132 133 if(hud_id == HUD_BUMBLEBEE_GUN) 134 { 135 AuxiliaryXhair[0].axh_image = vCROSS_BURST; // Plasma cannons 136 AuxiliaryXhair[1].axh_image = vCROSS_BURST; // Raygun 137 } else { 138 Vehicle info = Vehicles_from(hud_id); 139 info.vr_setup(info, NULL); 140 } 141} 142 143void Vehicles_drawHUD( 144 string vehicle, 145 string vehicleWeapon1, 146 string vehicleWeapon2, 147 string iconAmmo1, 148 vector colorAmmo1, 149 string iconAmmo2, 150 vector colorAmmo2) 151{ 152 // Initialize 153 vector tmpSize = '0 0 0'; 154 vector tmpPos = '0 0 0'; 155 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; 159 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; 167 168 // HACK to deal with the inconsistent use of the vehicle stats 169 ammo1 = (ammo1) ? ammo1 : energy; 170 171 // Frame 172 string frame = strcat(hud_skin_path, "/vehicle_frame"); 173 if (precache_pic(frame) == "") 174 frame = "gfx/hud/default/vehicle_frame"; 175 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; 179 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); 182 else 183 drawpic(vehicleHud_Pos, frame, vehicleHud_Size, autocvar_hud_panel_bg_color, autocvar_hud_panel_bg_alpha * hud_fade_alpha, DRAWFLAG_NORMAL); 184 185 if(!autocvar__vehicles_shownchasemessage && time < vh_notice_time) 186 { 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); 192 } 193 194 // Model 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; 199 200 if(health < 0.25) 201 drawpic_skin(tmpPos, vehicle, tmpSize, '1 0 0' + '0 1 1' * blinkValue, hudAlpha, DRAWFLAG_NORMAL); 202 else 203 drawpic_skin(tmpPos, vehicle, tmpSize, '1 1 1' * health + '1 0 0' * (1 - health), hudAlpha, DRAWFLAG_NORMAL); 204 205 if(vehicleWeapon1) 206 drawpic_skin(tmpPos, vehicleWeapon1, tmpSize, '1 1 1' * ammo1 + '1 0 0' * (1 - ammo1), hudAlpha, DRAWFLAG_NORMAL); 207 if(vehicleWeapon2) 208 drawpic_skin(tmpPos, vehicleWeapon2, tmpSize, '1 1 1' * ammo2 + '1 0 0' * (1 - ammo2), hudAlpha, DRAWFLAG_NORMAL); 209 210 drawpic_skin(tmpPos, "vehicle_shield", tmpSize, '1 1 1' * shield + '1 0 0' * (1 - shield), hudAlpha * shield, DRAWFLAG_NORMAL); 211 212 // Health bar 213 tmpSize.y = vehicleHud_Size.y / 2; 214 tmpPos.x = vehicleHud_Pos.x + vehicleHud_Size.x * (32/768); 215 tmpPos.y = vehicleHud_Pos.y; 216 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); 219 220 // Shield bar 221 tmpPos.y = vehicleHud_Pos.y + vehicleHud_Size.y / 2; 222 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); 225 226 // Ammo1 bar 227 tmpPos.x = vehicleHud_Pos.x + vehicleHud_Size.x * (480/768); 228 tmpPos.y = vehicleHud_Pos.y; 229 230 if(ammo1) 231 drawsetcliparea(tmpPos.x, tmpPos.y, tmpSize.x * ammo1, tmpSize.y); 232 else 233 drawsetcliparea(tmpPos.x, tmpPos.y, tmpSize.x * reload1, tmpSize.y); 234 235 drawpic_skin(tmpPos, "vehicle_bar_northeast", tmpSize, colorAmmo1, barAlpha, DRAWFLAG_NORMAL); 236 237 // Ammo2 bar 238 tmpPos.y = vehicleHud_Pos.y + vehicleHud_Size.y / 2; 239 240 if(ammo2) 241 drawsetcliparea(tmpPos.x, tmpPos.y, tmpSize.x * ammo2, tmpSize.y); 242 else 243 drawsetcliparea(tmpPos.x, tmpPos.y, tmpSize.x * reload2, tmpSize.y); 244 245 drawpic_skin(tmpPos, "vehicle_bar_southeast", tmpSize, colorAmmo2, barAlpha, DRAWFLAG_NORMAL); 246 drawresetcliparea(); 247 248 // Health icon 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); 253 254 if(health < 0.25) 255 { 256 if(alarm1time < time) 257 { 258 alarm1time = time + 2; 259 vehicle_alarm(NULL, CH_PAIN_SINGLE, SND_VEH_ALARM); 260 } 261 drawpic_skin(tmpPos, "vehicle_icon_health", tmpSize, '1 1 1', hudAlpha * blinkValue, DRAWFLAG_NORMAL); 262 } 263 else 264 { 265 if(alarm1time) 266 { 267 vehicle_alarm(NULL, CH_PAIN_SINGLE, SND_Null); 268 alarm1time = 0; 269 } 270 drawpic_skin(tmpPos, "vehicle_icon_health", tmpSize, '1 1 1', hudAlpha, DRAWFLAG_NORMAL); 271 } 272 273 // Shield icon 274 tmpPos.y = vehicleHud_Pos.y + vehicleHud_Size.y / 2; 275 276 if(shield < 0.25) 277 { 278 if(alarm2time < time) 279 { 280 alarm2time = time + 1; 281 vehicle_alarm(NULL, CH_TRIGGER_SINGLE, SND_VEH_ALARM_SHIELD); 282 } 283 drawpic_skin(tmpPos, "vehicle_icon_shield", tmpSize, '1 1 1', hudAlpha * blinkValue, DRAWFLAG_NORMAL); 284 } 285 else 286 { 287 if(alarm2time) 288 { 289 vehicle_alarm(NULL, CH_TRIGGER_SINGLE, SND_Null); 290 alarm2time = 0; 291 } 292 drawpic_skin(tmpPos, "vehicle_icon_shield", tmpSize, '1 1 1', hudAlpha, DRAWFLAG_NORMAL); 293 } 294 295 // Ammo1 icon 296 tmpPos.x = vehicleHud_Pos.x + vehicleHud_Size.x * (624/768); 297 tmpPos.y = vehicleHud_Pos.y + vehicleHud_Size.y * (48/256); 298 299 if(iconAmmo1) 300 { 301 if(ammo1) 302 drawpic_skin(tmpPos, iconAmmo1, tmpSize, '1 1 1', hudAlpha, DRAWFLAG_NORMAL); 303 else 304 drawpic_skin(tmpPos, iconAmmo1, tmpSize, '1 1 1', hudAlpha * 0.2, DRAWFLAG_NORMAL); 305 } 306 307 // Ammo2 icon 308 tmpPos.y = vehicleHud_Pos.y + vehicleHud_Size.y / 2; 309 310 if(iconAmmo2) 311 { 312 if(ammo2) 313 drawpic_skin(tmpPos, iconAmmo2, tmpSize, '1 1 1', hudAlpha, DRAWFLAG_NORMAL); 314 else 315 drawpic_skin(tmpPos, iconAmmo2, tmpSize, '1 1 1', hudAlpha * 0.2, DRAWFLAG_NORMAL); 316 } 317} 318 319void Vehicles_drawCrosshair(string crosshair) 320{ 321 vector tmpSize = '0 0 0'; 322 vector tmpPos = '0 0 0'; 323 324 // Crosshair 325 if(crosshair) 326 { 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; 330 331 vector wcross_color = '1 1 1'; 332 if(autocvar_cl_vehicles_crosshair_colorize) 333 wcross_color = crosshair_getcolor(NULL, STAT(VEHICLESTAT_HEALTH)); 334 335 drawpic(tmpPos, crosshair, tmpSize, wcross_color, autocvar_crosshair_alpha, DRAWFLAG_NORMAL); 336 } 337} 338