4 #include "../movetypes.qh"
5 #include "../movetypes.qh"
6 #include "../prandom.qh"
7 #include "../scoreboard.qh"
8 #include "../t_items.qh"
10 #include "../../common/buffs.qh"
11 #include "../../common/constants.qh"
12 #include "../../common/stats.qh"
13 #include "../../common/util.qh"
15 #include "../../csqcmodellib/cl_model.qh"
19 const string vCROSS_AIM = "gfx/vehicles/crosshair_aim.tga";
20 const string vCROSS_DROP = "gfx/vehicles/crosshair_drop.tga";
21 const string vCROSS_HEAL = "gfx/vehicles/crosshair_heal.tga";
22 const string vCROSS_HINT = "gfx/vehicles/crosshair_hint.tga";
23 const string vCROSS_LOCK = "gfx/vehicles/crosshair_lock.tga";
24 const string vCROSS_TAG = "gfx/vehicles/crosshair_tag.tga";
26 const int SBRM_FIRST = 1;
27 const int SBRM_VOLLY = 1;
28 const int SBRM_GUIDE = 2;
29 const int SBRM_ARTILLERY = 3;
30 const int SBRM_LAST = 3;
32 const int RSM_FIRST = 1;
33 const int RSM_BOMB = 1;
34 const int RSM_FLARE = 2;
35 const int RSM_LAST = 2;
37 const int MAX_AXH = 4;
38 entity AuxiliaryXhairs[MAX_AXH];
39 entityclass(AuxiliaryXhair);
40 class(AuxiliaryXhair) .string axh_image;
41 class(AuxiliaryXhair) .float axh_fadetime;
42 class(AuxiliaryXhair) .float axh_drawflag;
51 void AuxiliaryXhair_Draw2D()
53 if (scoreboard_showscores)
56 vector size = draw_getimagesize(self.axh_image) * autocvar_cl_vehicles_crosshair_size;
57 vector pos = project_3d_to_2d(self.move_origin) - 0.5 * size;
59 if (!(pos.z < 0 || pos.x < 0 || pos.y < 0 || pos.x > vid_conwidth || pos.y > vid_conheight))
63 drawpic(pos, self.axh_image, size, self.colormod, autocvar_crosshair_alpha * self.alpha, self.axh_drawflag);
66 if(time - self.cnt > self.axh_fadetime)
67 self.draw2d = func_null;
70 void Net_AuXair2(bool bIsNew)
72 int axh_id = bound(0, ReadByte(), MAX_AXH);
73 entity axh = AuxiliaryXhairs[axh_id];
75 if(axh == world || wasfreed(axh)) // MADNESS? THIS IS QQQQCCCCCCCCC (wasfreed, why do you exsist?)
78 axh.draw2d = func_null;
79 axh.drawmask = MASK_NORMAL;
80 axh.axh_drawflag = DRAWFLAG_ADDITIVE;
81 axh.axh_fadetime = 0.1;
82 axh.axh_image = vCROSS_HINT;
85 AuxiliaryXhairs[axh_id] = axh;
88 axh.move_origin_x = ReadCoord();
89 axh.move_origin_y = ReadCoord();
90 axh.move_origin_z = ReadCoord();
91 axh.colormod_x = ReadByte() / 255;
92 axh.colormod_y = ReadByte() / 255;
93 axh.colormod_z = ReadByte() / 255;
95 axh.draw2d = AuxiliaryXhair_Draw2D;
98 void Net_VehicleSetup()
100 int hud_id = ReadByte();
103 if(hud_id > HUD_VEHICLE_LAST)
105 weapon2mode = hud_id - HUD_VEHICLE_LAST;
109 // hud_id == 0 means we exited a vehicle, so stop alarm sound/s
112 sound(self, CH_TRIGGER_SINGLE, "misc/null.wav", VOL_BASEVOICE, ATTEN_NONE);
113 sound(self, CH_PAIN_SINGLE, "misc/null.wav", VOL_BASEVOICE, ATTEN_NONE);
117 hud_id = bound(HUD_VEHICLE_FIRST, hud_id, HUD_VEHICLE_LAST);
119 // Init auxiliary crosshairs
121 for(i = 0; i < MAX_AXH; ++i)
123 entity axh = AuxiliaryXhairs[i];
125 if(axh != world && !wasfreed(axh)) // MADNESS? THIS IS QQQQCCCCCCCCC (wasfreed, why do you exsist?)
129 axh.draw2d = func_null;
130 axh.drawmask = MASK_NORMAL;
131 axh.axh_drawflag = DRAWFLAG_NORMAL;
132 axh.axh_fadetime = 0.1;
133 axh.axh_image = vCROSS_HINT;
135 AuxiliaryXhairs[i] = axh;
141 AuxiliaryXhairs[0].axh_image = vCROSS_HINT; // Minigun1
142 AuxiliaryXhairs[1].axh_image = vCROSS_HINT; // Minigun2
146 AuxiliaryXhairs[0].axh_image = vCROSS_LOCK; // Rocket
150 AuxiliaryXhairs[1].axh_image = vCROSS_LOCK;
154 AuxiliaryXhairs[0].axh_image = vCROSS_LOCK; // Raygun-locked
155 AuxiliaryXhairs[1].axh_image = vCROSS_TAG; // Gunner1
156 AuxiliaryXhairs[2].axh_image = vCROSS_TAG; // Gunner2
159 case HUD_BUMBLEBEE_GUN:
160 AuxiliaryXhairs[0].axh_image = vCROSS_TAG; // Plasma cannons
161 AuxiliaryXhairs[1].axh_image = vCROSS_TAG; // Raygun
166 void Vehicles_drawHUD(
168 string vehicleWeapon1,
169 string vehicleWeapon2,
176 if(autocvar_r_letterbox)
179 if(scoreboard_showscores)
183 vector hudSize = '0 0 0';
184 vector hudPos = '0 0 0';
185 vector tmpSize = '0 0 0';
186 vector tmpPos = '0 0 0';
188 float hudAlpha = autocvar_hud_panel_fg_alpha;
189 float barAlpha = autocvar_hud_progressbar_alpha * hudAlpha;
190 float blinkValue = 0.55 + sin(time * 7) * 0.45;
192 float health = getstati(STAT_VEHICLESTAT_HEALTH) * 0.01;
193 float shield = getstati(STAT_VEHICLESTAT_SHIELD) * 0.01;
194 float energy = getstati(STAT_VEHICLESTAT_ENERGY) * 0.01;
195 float ammo1 = getstati(STAT_VEHICLESTAT_AMMO1) * 0.01;
196 float reload1 = getstati(STAT_VEHICLESTAT_RELOAD1) * 0.01;
197 float ammo2 = getstati(STAT_VEHICLESTAT_AMMO2) * 0.01;
198 float reload2 = getstati(STAT_VEHICLESTAT_RELOAD2) * 0.01;
200 // HACK to deal with the inconcistent use of the vehicle stats
201 ammo1 = (ammo1) ? ammo1 : energy;
204 string frame = strcat(hud_skin_path, "/vehicle_frame");
205 if (precache_pic(frame) == "")
206 frame = "gfx/hud/default/vehicle_frame";
208 hudSize = draw_getimagesize(frame) * autocvar_cl_vehicles_hudscale;
209 hudPos.x = (vid_conwidth - hudSize.x) / 2;
210 hudPos.y = vid_conheight - hudSize.y;
212 if(teamplay && autocvar_hud_panel_bg_color_team)
213 drawpic(hudPos, frame, hudSize, myteamcolors * autocvar_hud_panel_bg_color_team, autocvar_hud_panel_bg_alpha, DRAWFLAG_NORMAL);
215 drawpic(hudPos, frame, hudSize, autocvar_hud_panel_bg_color, autocvar_hud_panel_bg_alpha, DRAWFLAG_NORMAL);
218 tmpSize.x = hudSize.x / 3;
219 tmpSize.y = hudSize.y;
220 tmpPos.x = hudPos.x + hudSize.x / 3;
224 drawpic_skin(tmpPos, vehicle, tmpSize, '1 0 0' + '0 1 1' * blinkValue, hudAlpha, DRAWFLAG_NORMAL);
226 drawpic_skin(tmpPos, vehicle, tmpSize, '1 1 1' * health + '1 0 0' * (1 - health), hudAlpha, DRAWFLAG_NORMAL);
229 drawpic_skin(tmpPos, vehicleWeapon1, tmpSize, '1 1 1' * ammo1 + '1 0 0' * (1 - ammo1), hudAlpha, DRAWFLAG_NORMAL);
231 drawpic_skin(tmpPos, vehicleWeapon2, tmpSize, '1 1 1' * ammo2 + '1 0 0' * (1 - ammo2), hudAlpha, DRAWFLAG_NORMAL);
233 drawpic_skin(tmpPos, "vehicle_shield", tmpSize, '1 1 1' * shield + '1 0 0' * (1 - shield), hudAlpha * shield, DRAWFLAG_NORMAL);
236 tmpSize.y = hudSize.y / 2;
237 tmpPos.x = hudPos.x + hudSize.x * (32/768);
240 drawsetcliparea(tmpPos.x + (tmpSize.x * (1 - health)), tmpPos.y, tmpSize.x, tmpSize.y);
241 drawpic_skin(tmpPos, "vehicle_bar_northwest", tmpSize, autocvar_hud_progressbar_health_color, barAlpha, DRAWFLAG_NORMAL);
244 tmpPos.y = hudPos.y + hudSize.y / 2;
246 drawsetcliparea(tmpPos.x + (tmpSize.x * (1 - shield)), tmpPos.y, tmpSize.x, tmpSize.y);
247 drawpic_skin(tmpPos, "vehicle_bar_southwest", tmpSize, autocvar_hud_progressbar_armor_color, barAlpha, DRAWFLAG_NORMAL);
250 tmpPos.x = hudPos.x + hudSize.x * (480/768);
254 drawsetcliparea(tmpPos.x, tmpPos.y, tmpSize.x * ammo1, tmpSize.y);
256 drawsetcliparea(tmpPos.x, tmpPos.y, tmpSize.x * reload1, tmpSize.y);
258 drawpic_skin(tmpPos, "vehicle_bar_northeast", tmpSize, colorAmmo1, barAlpha, DRAWFLAG_NORMAL);
261 tmpPos.y = hudPos.y + hudSize.y / 2;
264 drawsetcliparea(tmpPos.x, tmpPos.y, tmpSize.x * ammo2, tmpSize.y);
266 drawsetcliparea(tmpPos.x, tmpPos.y, tmpSize.x * reload2, tmpSize.y);
268 drawpic_skin(tmpPos, "vehicle_bar_southeast", tmpSize, colorAmmo2, barAlpha, DRAWFLAG_NORMAL);
272 tmpSize.x = hudSize.x * (80/768);
273 tmpSize.y = hudSize.y * (80/256);
274 tmpPos.x = hudPos.x + hudSize.x * (64/768);
275 tmpPos.y = hudPos.y + hudSize.y * (48/256);
279 if(alarm1time < time)
281 alarm1time = time + 2;
282 sound(self, CH_PAIN_SINGLE, "vehicles/alarm.wav", VOL_BASEVOICE, ATTEN_NONE);
284 drawpic_skin(tmpPos, "vehicle_icon_health", tmpSize, '1 1 1', hudAlpha * blinkValue, DRAWFLAG_NORMAL);
290 sound(self, CH_PAIN_SINGLE, "misc/null.wav", VOL_BASEVOICE, ATTEN_NONE);
293 drawpic_skin(tmpPos, "vehicle_icon_health", tmpSize, '1 1 1', hudAlpha, DRAWFLAG_NORMAL);
297 tmpPos.y = hudPos.y + hudSize.y / 2;
301 if(alarm2time < time)
303 alarm2time = time + 1;
304 sound(self, CH_TRIGGER_SINGLE, "vehicles/alarm_shield.wav", VOL_BASEVOICE, ATTEN_NONE);
306 drawpic_skin(tmpPos, "vehicle_icon_shield", tmpSize, '1 1 1', hudAlpha * blinkValue, DRAWFLAG_NORMAL);
312 sound(self, CH_TRIGGER_SINGLE, "misc/null.wav", VOL_BASEVOICE, ATTEN_NONE);
315 drawpic_skin(tmpPos, "vehicle_icon_shield", tmpSize, '1 1 1', hudAlpha, DRAWFLAG_NORMAL);
319 tmpPos.x = hudPos.x + hudSize.x * (624/768);
320 tmpPos.y = hudPos.y + hudSize.y * (48/256);
325 drawpic_skin(tmpPos, iconAmmo1, tmpSize, '1 1 1', hudAlpha, DRAWFLAG_NORMAL);
327 drawpic_skin(tmpPos, iconAmmo1, tmpSize, '1 1 1', hudAlpha * 0.2, DRAWFLAG_NORMAL);
331 tmpPos.y = hudPos.y + hudSize.y / 2;
336 drawpic_skin(tmpPos, iconAmmo2, tmpSize, '1 1 1', hudAlpha, DRAWFLAG_NORMAL);
338 drawpic_skin(tmpPos, iconAmmo2, tmpSize, '1 1 1', hudAlpha * 0.2, DRAWFLAG_NORMAL);
341 // Bumblebee gunner crosshairs
342 if(hud == HUD_BUMBLEBEE)
344 tmpSize = '1 1 1' * hud_fontsize;
345 tmpPos.x = hudPos.x + hudSize.x * (520/768);
347 if(!AuxiliaryXhairs[1].draw2d)
349 tmpPos.y = hudPos.y + hudSize.y * (96/256) - tmpSize.y;
350 drawstring(tmpPos, _("No right gunner!"), tmpSize, '1 1 1', hudAlpha * blinkValue, DRAWFLAG_NORMAL);
353 if(!AuxiliaryXhairs[2].draw2d)
355 tmpPos.y = hudPos.y + hudSize.y * (160/256);
356 drawstring(tmpPos, _("No left gunner!"), tmpSize, '1 1 1', hudAlpha * blinkValue, DRAWFLAG_NORMAL);
360 // Raptor bomb crosshair
361 if(hud == HUD_RAPTOR && weapon2mode != RSM_FLARE)
368 dropmark.owner = self;
369 dropmark.gravity = 1;
374 setorigin(dropmark, pmove_org);
375 dropmark.velocity = pmove_vel;
376 tracetoss(dropmark, self);
378 where = project_3d_to_2d(trace_endpos);
380 setorigin(dropmark, trace_endpos);
381 tmpSize = draw_getimagesize(vCROSS_DROP) * autocvar_cl_vehicles_crosshair_size;
383 if (!(where.z < 0 || where.x < 0 || where.y < 0 || where.x > vid_conwidth || where.y > vid_conheight))
385 where.x -= tmpSize.x * 0.5;
386 where.y -= tmpSize.y * 0.5;
388 drawpic(where, vCROSS_DROP, tmpSize, '0 1 0', autocvar_crosshair_alpha * 0.9, DRAWFLAG_ADDITIVE);
389 drawpic(where, vCROSS_DROP, tmpSize, '0 1 0', autocvar_crosshair_alpha * 0.6, DRAWFLAG_NORMAL); // Ensure visibility against bright bg
391 dropmark.cnt = time + 5;
395 if(dropmark.cnt > time)
397 where = project_3d_to_2d(dropmark.origin);
398 tmpSize = draw_getimagesize(vCROSS_DROP) * autocvar_cl_vehicles_crosshair_size * 1.25;
400 if (!(where.z < 0 || where.x < 0 || where.y < 0 || where.x > vid_conwidth || where.y > vid_conheight))
402 where.x -= tmpSize.x * 0.5;
403 where.y -= tmpSize.y * 0.5;
405 drawpic(where, vCROSS_DROP, tmpSize, '1 0 0', autocvar_crosshair_alpha * 0.9, DRAWFLAG_ADDITIVE);
406 drawpic(where, vCROSS_DROP, tmpSize, '1 0 0', autocvar_crosshair_alpha * 0.6, DRAWFLAG_NORMAL); // Ensure visibility against bright bg
415 tmpSize = draw_getimagesize(crosshair) * autocvar_cl_vehicles_crosshair_size;
416 tmpPos.x = (vid_conwidth - tmpSize.x) / 2;
417 tmpPos.y = (vid_conheight - tmpSize.y) / 2;
419 drawpic(tmpPos, crosshair, tmpSize, '1 1 1', autocvar_crosshair_alpha, DRAWFLAG_NORMAL);
423 void CSQC_BUMBLE_HUD()
425 Vehicles_drawHUD("vehicle_bumble", "vehicle_bumble_weapon1", "vehicle_bumble_weapon2",
426 "vehicle_icon_ammo1", autocvar_hud_progressbar_vehicles_ammo1_color,
427 "vehicle_icon_ammo1", autocvar_hud_progressbar_vehicles_ammo1_color,
431 void CSQC_BUMBLE_GUN_HUD()
433 Vehicles_drawHUD("vehicle_gunner", "vehicle_gunner_weapon1", string_null,
434 "vehicle_icon_ammo1", autocvar_hud_progressbar_vehicles_ammo1_color,
435 string_null, '0 0 0',
439 void CSQC_SPIDER_HUD()
445 case SBRM_VOLLY: crosshair = vCROSS_LOCK; break;
446 case SBRM_GUIDE: crosshair = vCROSS_AIM; break;
447 default: crosshair = vCROSS_TAG;
450 Vehicles_drawHUD("vehicle_spider", "vehicle_spider_weapon1", "vehicle_spider_weapon2",
451 "vehicle_icon_ammo1", autocvar_hud_progressbar_vehicles_ammo1_color,
452 "vehicle_icon_ammo2", autocvar_hud_progressbar_vehicles_ammo2_color,
456 void CSQC_RAPTOR_HUD()
462 case RSM_FLARE: crosshair = vCROSS_LOCK; break;
463 default: crosshair = vCROSS_AIM;
466 Vehicles_drawHUD("vehicle_raptor", "vehicle_raptor_weapon1", "vehicle_raptor_weapon2",
467 "vehicle_icon_ammo1", autocvar_hud_progressbar_vehicles_ammo1_color,
468 "vehicle_icon_ammo2", autocvar_hud_progressbar_vehicles_ammo2_color,
472 void CSQC_WAKIZASHI_HUD()
474 Vehicles_drawHUD("vehicle_racer", "vehicle_racer_weapon1", "vehicle_racer_weapon2",
475 "vehicle_icon_ammo1", autocvar_hud_progressbar_vehicles_ammo1_color,
476 "vehicle_icon_ammo2", autocvar_hud_progressbar_vehicles_ammo2_color,
480 void Vehicles_Precache()
482 precache_model("models/vehicles/bomblet.md3");
483 precache_model("models/vehicles/clusterbomb.md3");
484 precache_model("models/vehicles/clusterbomb_fragment.md3");
485 precache_model("models/vehicles/rocket01.md3");
486 precache_model("models/vehicles/rocket02.md3");
488 precache_sound("vehicles/alarm.wav");
489 precache_sound("vehicles/alarm_shield.wav");
492 void RaptorCBShellfragDraw()
497 Movetype_Physics_MatchTicrate(autocvar_cl_gibs_ticrate, autocvar_cl_gibs_sloppy);
498 self.move_avelocity += randomvec() * 15;
499 self.renderflags = 0;
502 self.alpha = bound(0, self.nextthink - time, 1);
504 if(self.alpha < ALPHA_MIN_VISIBLE)
508 void RaptorCBShellfragToss(vector _org, vector _vel, vector _ang)
513 setmodel(sfrag, "models/vehicles/clusterbomb_fragment.md3");
514 setorigin(sfrag, _org);
516 sfrag.move_movetype = MOVETYPE_BOUNCE;
517 sfrag.gravity = 0.15;
518 sfrag.solid = SOLID_CORPSE;
520 sfrag.draw = RaptorCBShellfragDraw;
522 sfrag.move_origin = sfrag.origin = _org;
523 sfrag.move_velocity = _vel;
524 sfrag.move_avelocity = prandomvec() * vlen(sfrag.move_velocity);
525 sfrag.angles = self.move_angles = _ang;
527 sfrag.move_time = time;
528 sfrag.damageforcescale = 4;
530 sfrag.nextthink = time + 3;
531 sfrag.cnt = time + 2;
533 sfrag.drawmask = MASK_NORMAL;