1 #include "sv_vehicles.qh"
3 bool SendAuxiliaryXhair(entity this, entity to, int sf)
5 WriteHeader(MSG_ENTITY, ENT_CLIENT_AUXILIARYXHAIR);
7 WriteByte(MSG_ENTITY, this.cnt);
9 WriteCoord(MSG_ENTITY, this.origin_x);
10 WriteCoord(MSG_ENTITY, this.origin_y);
11 WriteCoord(MSG_ENTITY, this.origin_z);
13 WriteByte(MSG_ENTITY, rint(this.colormod_x * 255));
14 WriteByte(MSG_ENTITY, rint(this.colormod_y * 255));
15 WriteByte(MSG_ENTITY, rint(this.colormod_z * 255));
20 void UpdateAuxiliaryXhair(entity own, vector loc, vector clr, int axh_id)
22 if(!IS_REAL_CLIENT(own))
25 axh_id = bound(0, axh_id, MAX_AXH);
26 entity axh = own.(AuxiliaryXhair[axh_id]);
28 if(axh == NULL || wasfreed(axh)) // MADNESS? THIS IS QQQQCCCCCCCCC (wasfreed, why do you exsist? Mario: because of sloppy code like this)
32 axh.drawonlytoclient = own;
34 Net_LinkEntity(axh, false, 0, SendAuxiliaryXhair);
40 own.(AuxiliaryXhair[axh_id]) = axh;
43 void CSQCVehicleSetup(entity own, int vehicle_id)
45 if(!IS_REAL_CLIENT(own))
50 WriteHeader(MSG_ONE, TE_CSQC_VEHICLESETUP);
51 WriteByte(MSG_ONE, vehicle_id);
54 void vehicles_locktarget(entity this, float incr, float decr, float _lock_time)
56 if(this.lock_target && IS_DEAD(this.lock_target))
58 this.lock_target = NULL;
59 this.lock_strength = 0;
63 if(this.lock_time > time)
66 if(this.lock_soundtime < time)
68 this.lock_soundtime = time + 0.5;
69 play2(this.owner, "vehicles/locked.wav");
77 if(SAME_TEAM(trace_ent, this))
80 if(IS_DEAD(trace_ent))
83 if(!(IS_VEHICLE(trace_ent) || IS_TURRET(trace_ent)))
86 if(trace_ent.alpha <= 0.5 && trace_ent.alpha != 0)
87 trace_ent = NULL; // invisible
90 if(this.lock_target == NULL && trace_ent != NULL)
91 this.lock_target = trace_ent;
93 if(this.lock_target && trace_ent == this.lock_target)
95 if(this.lock_strength != 1 && this.lock_strength + incr >= 1)
97 play2(this.owner, "vehicles/lock.wav");
98 this.lock_soundtime = time + 0.8;
100 else if (this.lock_strength != 1 && this.lock_soundtime < time)
102 play2(this.owner, "vehicles/locking.wav");
103 this.lock_soundtime = time + 0.3;
107 // Have a locking target
108 // Trace hit current target
109 if(trace_ent == this.lock_target && trace_ent != NULL)
111 this.lock_strength = min(this.lock_strength + incr, 1);
112 if(this.lock_strength == 1)
113 this.lock_time = time + _lock_time;
118 this.lock_strength = max(this.lock_strength - decr * 2, 0);
120 this.lock_strength = max(this.lock_strength - decr, 0);
122 if(this.lock_strength == 0)
123 this.lock_target = NULL;
127 float vehicle_altitude(entity this, float amax)
129 tracebox(this.origin, this.mins, this.maxs, this.origin - ('0 0 1' * amax), MOVE_WORLDONLY, this);
130 return vlen(this.origin - trace_endpos);
133 vector vehicles_force_fromtag_hover(entity this, string tag_name, float spring_length, float max_power)
135 force_fromtag_origin = gettaginfo(this, gettagindex(this, tag_name));
136 v_forward = normalize(v_forward) * -1;
137 traceline(force_fromtag_origin, force_fromtag_origin - (v_forward * spring_length), MOVE_NORMAL, this);
139 force_fromtag_power = (1 - trace_fraction) * max_power;
140 force_fromtag_normpower = force_fromtag_power / max_power;
142 return v_forward * force_fromtag_power;
145 vector vehicles_force_fromtag_maglev(entity this, string tag_name, float spring_length, float max_power)
147 force_fromtag_origin = gettaginfo(this, gettagindex(this, tag_name));
148 v_forward = normalize(v_forward) * -1;
149 traceline(force_fromtag_origin, force_fromtag_origin - (v_forward * spring_length), MOVE_NORMAL, this);
151 // TODO - this may NOT be compatible with wall/celing movement, unhardcode 0.25 (engine count multiplier)
152 if(trace_fraction == 1.0)
154 force_fromtag_normpower = -0.25;
158 force_fromtag_power = ((1 - trace_fraction) - trace_fraction) * max_power;
159 force_fromtag_normpower = force_fromtag_power / max_power;
161 return v_forward * force_fromtag_power;
164 // projectile handling
165 void vehicles_projectile_damage(entity this, entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force)
167 // Ignore damage from oterh projectiles from my owner (dont mess up volly's)
168 if(inflictor.owner == this.owner)
171 this.health -= damage;
172 this.velocity += force;
175 this.takedamage = DAMAGE_NO;
176 this.event_damage = func_null;
177 setthink(this, adaptor_think2use);
178 this.nextthink = time;
182 void vehicles_projectile_explode(entity this)
184 if(this.owner && other != NULL)
186 if(other == this.owner.vehicle)
189 if(other == this.owner.vehicle.tur_head)
193 PROJECTILE_TOUCH(this);
195 this.event_damage = func_null;
196 RadiusDamage (this, this.realowner, this.shot_dmg, 0, this.shot_radius, this, NULL, this.shot_force, this.totalfrags, other);
201 void vehicles_projectile_explode_use(entity this, entity actor, entity trigger)
203 vehicles_projectile_explode(this);
206 entity vehicles_projectile(entity this, string _mzlfx, Sound _mzlsound,
207 vector _org, vector _vel,
208 float _dmg, float _radi, float _force, float _size,
209 int _deahtype, float _projtype, float _health,
210 bool _cull, bool _clianim, entity _owner)
212 TC(Sound, _mzlsound);
217 PROJECTILE_MAKETRIGGER(proj);
218 setorigin(proj, _org);
220 proj.shot_dmg = _dmg;
221 proj.shot_radius = _radi;
222 proj.shot_force = _force;
223 proj.totalfrags = _deahtype;
224 proj.solid = SOLID_BBOX;
225 proj.movetype = MOVETYPE_FLYMISSILE;
226 proj.flags = FL_PROJECTILE;
227 proj.bot_dodge = true;
228 proj.bot_dodgerating = _dmg;
229 proj.velocity = _vel;
230 settouch(proj, vehicles_projectile_explode);
231 proj.use = vehicles_projectile_explode_use;
233 proj.realowner = _owner;
234 setthink(proj, SUB_Remove);
235 proj.nextthink = time + 30;
239 proj.takedamage = DAMAGE_AIM;
240 proj.event_damage = vehicles_projectile_damage;
241 proj.health = _health;
244 proj.flags = FL_PROJECTILE | FL_NOTARGET;
246 if(_mzlsound != SND_Null)
247 sound (this, CH_WEAPON_A, _mzlsound, VOL_BASE, ATTEN_NORM);
250 Send_Effect_(_mzlfx, proj.origin, proj.velocity, 1);
252 setsize (proj, '-1 -1 -1' * _size, '1 1 1' * _size);
254 CSQCProjectile(proj, _clianim, _projtype, _cull);
259 void vehicles_gib_explode(entity this)
261 sound (this, CH_SHOTS, SND_ROCKET_IMPACT, VOL_BASE, ATTEN_NORM);
262 Send_Effect(EFFECT_EXPLOSION_SMALL, randomvec() * 80 + (this.origin + '0 0 100'), '0 0 0', 1);
263 Send_Effect(EFFECT_EXPLOSION_SMALL, this.wp00.origin + '0 0 64', '0 0 0', 1);
267 void vehicles_gib_think(entity this)
273 this.nextthink = time + 0.1;
276 entity vehicle_tossgib(entity this, entity _template, vector _vel, string _tag, bool _burn, bool _explode, float _maxtime, vector _rot)
278 entity _gib = spawn();
279 _setmodel(_gib, _template.model);
280 vector org = gettaginfo(this, gettagindex(this, _tag));
281 setorigin(_gib, org);
282 _gib.velocity = _vel;
283 _gib.movetype = MOVETYPE_TOSS;
284 _gib.solid = SOLID_CORPSE;
285 _gib.colormod = '-0.5 -0.5 -0.5';
286 _gib.effects = EF_LOWPRECISION;
287 _gib.avelocity = _rot;
290 _gib.effects |= EF_FLAME;
294 setthink(_gib, vehicles_gib_explode);
295 _gib.nextthink = time + random() * _explode;
296 settouch(_gib, vehicles_gib_explode);
300 _gib.cnt = time + _maxtime;
301 setthink(_gib, vehicles_gib_think);
302 _gib.nextthink = time + _maxtime - 1;
308 bool vehicle_addplayerslot( entity _owner,
312 bool(entity) _framefunc,
313 void(entity,bool) _exitfunc, float(entity, entity) _enterfunc)
315 if(!(_owner.vehicle_flags & VHF_MULTISLOT))
316 _owner.vehicle_flags |= VHF_MULTISLOT;
318 _slot.PlayerPhysplug = _framefunc;
319 _slot.vehicle_exit = _exitfunc;
320 _slot.vehicle_enter = _enterfunc;
322 _slot.vehicle_flags = VHF_PLAYERSLOT;
323 _slot.vehicle_viewport = spawn();
324 _slot.vehicle_hudmodel = spawn();
325 _slot.vehicle_hudmodel.viewmodelforclient = _slot;
326 _slot.vehicle_viewport.effects = (EF_ADDITIVE | EF_DOUBLESIDED | EF_FULLBRIGHT | EF_NODEPTHTEST | EF_NOGUNBOB | EF_NOSHADOW | EF_LOWPRECISION | EF_SELECTABLE | EF_TELEPORT_BIT);
328 setmodel(_slot.vehicle_hudmodel, _hud_model);
329 setmodel(_slot.vehicle_viewport, MDL_Null);
331 setattachment(_slot.vehicle_hudmodel, _slot, "");
332 setattachment(_slot.vehicle_viewport, _slot.vehicle_hudmodel, "");
337 vector vehicle_aimturret(entity _vehic, vector _target, entity _turrret, string _tagname,
338 float _pichlimit_min, float _pichlimit_max,
339 float _rotlimit_min, float _rotlimit_max, float _aimspeed)
343 vtag = gettaginfo(_turrret, gettagindex(_turrret, _tagname));
344 vtmp = vectoangles(normalize(_target - vtag));
345 vtmp = AnglesTransform_ToAngles(AnglesTransform_LeftDivide(AnglesTransform_FromAngles(_vehic.angles), AnglesTransform_FromAngles(vtmp))) - _turrret.angles;
346 vtmp = AnglesTransform_Normalize(vtmp, true);
347 ftmp = _aimspeed * frametime;
348 vtmp_y = bound(-ftmp, vtmp_y, ftmp);
349 vtmp_x = bound(-ftmp, vtmp_x, ftmp);
350 _turrret.angles_y = bound(_rotlimit_min, _turrret.angles_y + vtmp_y, _rotlimit_max);
351 _turrret.angles_x = bound(_pichlimit_min, _turrret.angles_x + vtmp_x, _pichlimit_max);
355 void vehicles_reset_colors(entity this)
358 const vector cmod = '0 0 0';
359 if(this.team && teamplay)
360 cmap = 1024 + (this.team - 1) * 17;
363 if(autocvar_g_nodepthtestplayers)
364 eff |= EF_NODEPTHTEST;
365 if(autocvar_g_fullbrightplayers)
366 eff |= EF_FULLBRIGHT;
368 // Find all ents attacked to main model and setup effects, colormod etc.
369 FOREACH_ENTITY_ENT(tag_entity, this,
371 if(it != this.vehicle_shieldent)
380 // Also check head tags
381 FOREACH_ENTITY_ENT(tag_entity, this.tur_head,
383 if(it != this.vehicle_shieldent)
392 this.vehicle_hudmodel.effects = this.effects = eff; // | EF_LOWPRECISION;
393 this.vehicle_hudmodel.colormod = this.colormod = cmod;
394 this.vehicle_hudmodel.colormap = this.colormap = cmap;
395 this.vehicle_viewport.effects = (EF_ADDITIVE | EF_DOUBLESIDED | EF_FULLBRIGHT | EF_NODEPTHTEST | EF_NOGUNBOB | EF_NOSHADOW | EF_LOWPRECISION | EF_SELECTABLE | EF_TELEPORT_BIT);
398 this.avelocity = '0 0 0';
399 this.velocity = '0 0 0';
403 void vehicles_clearreturn(entity veh)
405 // Remove "return helper" entities, if any.
406 FOREACH_ENTITY_ENT(wp00, veh,
408 if(it.classname == "vehicle_return")
411 setthink(it, SUB_Remove);
412 it.nextthink = time + 0.1;
414 if(it.waypointsprite_attached)
415 WaypointSprite_Kill(it.waypointsprite_attached);
420 void vehicles_spawn(entity this);
421 void vehicles_return(entity this)
423 Send_Effect(EFFECT_TELEPORT, this.wp00.origin + '0 0 64', '0 0 0', 1);
425 setthink(this.wp00, vehicles_spawn);
426 this.wp00.nextthink = time;
428 if(this.waypointsprite_attached)
429 WaypointSprite_Kill(this.waypointsprite_attached);
434 void vehicles_showwp_goaway(entity this)
436 if(this.waypointsprite_attached)
437 WaypointSprite_Kill(this.waypointsprite_attached);
442 void vehicles_showwp(entity this)
448 setthink(ent, vehicles_return);
449 ent.nextthink = ent.cnt;
453 setthink(ent, vehicles_return);
454 ent.nextthink = time + 1;
457 ent.team = this.wp00.team;
458 ent.wp00 = this.wp00;
459 setorigin(ent, this.wp00.pos1);
461 ent.nextthink = time + 5;
462 setthink(ent, vehicles_showwp_goaway);
466 if(teamplay && ent.team)
467 rgb = Team_ColorRGB(ent.team);
470 entity wp = WaypointSprite_Spawn(WP_Vehicle, 0, 0, ent, '0 0 64', NULL, 0, ent, waypointsprite_attached, true, RADARICON_Vehicle);
472 if(ent.waypointsprite_attached)
474 WaypointSprite_UpdateRule(ent.waypointsprite_attached, ent.wp00.team, SPRITERULE_DEFAULT);
476 WaypointSprite_UpdateBuildFinished(ent.waypointsprite_attached, ent.nextthink);
477 WaypointSprite_Ping(ent.waypointsprite_attached);
481 void vehicles_setreturn(entity veh)
483 vehicles_clearreturn(veh);
485 entity ret = new(vehicle_return);
488 setthink(ret, vehicles_showwp);
492 ret.cnt = time + veh.respawntime;
493 ret.nextthink = min(time + veh.respawntime, time + veh.respawntime - 5);
497 ret.nextthink = min(time + veh.respawntime, time + veh.respawntime - 1);
500 setorigin(ret, veh.pos1 + '0 0 96');
503 void vehicle_use(entity this, entity actor, entity trigger)
505 LOG_DEBUG("vehicle ", this.netname, " used by ", actor.classname, "\n");
507 this.tur_head.team = actor.team;
509 if(this.tur_head.team == 0)
510 this.active = ACTIVE_NOT;
512 this.active = ACTIVE_ACTIVE;
514 if(this.active == ACTIVE_ACTIVE && !IS_DEAD(this) && !gameover)
516 LOG_DEBUG("Respawning vehicle: ", this.netname, "\n");
517 if(this.effects & EF_NODRAW)
519 setthink(this, vehicles_spawn);
520 this.nextthink = time + 3;
524 vehicles_setreturn(this);
525 vehicles_reset_colors(this);
530 void vehicles_regen(entity this, float timer, .float regen_field, float field_max, float rpause, float regen, float delta_time, float _healthscale)
532 if(this.(regen_field) < field_max)
533 if(timer + rpause < time)
536 regen = regen * (this.vehicle_health / this.max_health);
538 this.(regen_field) = min(this.(regen_field) + regen * delta_time, field_max);
541 this.owner.(regen_field) = (this.(regen_field) / field_max) * 100;
545 void shieldhit_think(entity this)
550 // setmodel(this, MDL_Null);
552 this.effects |= EF_NODRAW;
556 this.nextthink = time + 0.1;
560 void vehicles_painframe(entity this)
562 int myhealth = ((this.owner) ? this.owner.vehicle_health : ((this.vehicle_health / this.max_health) * 100));
565 if(this.pain_frame < time)
567 float _ftmp = myhealth / 50;
568 this.pain_frame = time + max(0.1, 0.1 + (random() * 0.5 * _ftmp));
569 Send_Effect(EFFECT_SMOKE_SMALL, (this.origin + (randomvec() * 80)), '0 0 0', 1);
571 if(this.vehicle_flags & VHF_DMGSHAKE)
572 this.velocity += randomvec() * 30;
574 if(this.vehicle_flags & VHF_DMGROLL)
575 if(this.vehicle_flags & VHF_DMGHEADROLL)
576 this.tur_head.angles += randomvec();
578 this.angles += randomvec();
582 void vehicles_frame(entity this, entity actor)
584 vehicles_painframe(this);
587 void vehicles_damage(entity this, entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force)
589 this.dmg_time = time;
592 if(DEATH_ISWEAPON(deathtype, WEP_VORTEX))
593 damage *= autocvar_g_vehicles_vortex_damagerate;
594 else if(DEATH_ISWEAPON(deathtype, WEP_MACHINEGUN))
595 damage *= autocvar_g_vehicles_machinegun_damagerate;
596 else if(DEATH_ISWEAPON(deathtype, WEP_RIFLE))
597 damage *= autocvar_g_vehicles_rifle_damagerate;
598 else if(DEATH_ISWEAPON(deathtype, WEP_VAPORIZER))
599 damage *= autocvar_g_vehicles_vaporizer_damagerate;
600 else if(DEATH_ISWEAPON(deathtype, WEP_SEEKER))
601 damage *= autocvar_g_vehicles_tag_damagerate;
602 else if(DEATH_WEAPONOF(deathtype) != WEP_Null)
603 damage *= autocvar_g_vehicles_weapon_damagerate;
605 this.enemy = attacker;
607 this.pain_finished = time;
609 if((this.vehicle_flags & VHF_HASSHIELD) && (this.vehicle_shield > 0))
611 if (wasfreed(this.vehicle_shieldent) || this.vehicle_shieldent == NULL)
613 this.vehicle_shieldent = spawn();
614 this.vehicle_shieldent.effects = EF_LOWPRECISION;
616 setmodel(this.vehicle_shieldent, MDL_VEH_SHIELD);
617 setattachment(this.vehicle_shieldent, this, "");
618 setorigin(this.vehicle_shieldent, real_origin(this) - this.origin);
619 this.vehicle_shieldent.scale = 256 / vlen(this.maxs - this.mins);
620 setthink(this.vehicle_shieldent, shieldhit_think);
623 this.vehicle_shieldent.colormod = '1 1 1';
624 this.vehicle_shieldent.alpha = 0.45;
625 this.vehicle_shieldent.angles = vectoangles(normalize(hitloc - (this.origin + this.vehicle_shieldent.origin))) - this.angles;
626 this.vehicle_shieldent.nextthink = time;
627 this.vehicle_shieldent.effects &= ~EF_NODRAW;
629 this.vehicle_shield -= damage;
631 if(this.vehicle_shield < 0)
633 this.vehicle_health -= fabs(this.vehicle_shield);
634 this.vehicle_shieldent.colormod = '2 0 0';
635 this.vehicle_shield = 0;
636 this.vehicle_shieldent.alpha = 0.75;
638 if(sound_allowed(MSG_BROADCAST, attacker))
639 spamsound (this, CH_PAIN, "onslaught/ons_hit2.wav", VOL_BASE, ATTEN_NORM); // FIXME: PLACEHOLDER
642 if(sound_allowed(MSG_BROADCAST, attacker))
643 spamsound (this, CH_PAIN, "onslaught/electricity_explode.wav", VOL_BASE, ATTEN_NORM); // FIXME: PLACEHOLDER
648 this.vehicle_health -= damage;
650 if(sound_allowed(MSG_BROADCAST, attacker))
651 spamsound (this, CH_PAIN, "onslaught/ons_hit2.wav", VOL_BASE, ATTEN_NORM); // FIXME: PLACEHOLDER
654 if(this.damageforcescale < 1 && this.damageforcescale > 0)
655 this.velocity += force * this.damageforcescale;
657 this.velocity += force;
659 if(this.vehicle_health <= 0)
662 if(this.vehicle_flags & VHF_DEATHEJECT)
663 vehicles_exit(this, VHEF_EJECT);
665 vehicles_exit(this, VHEF_RELEASE);
668 antilag_clear(this, this);
670 Vehicle info = Vehicles_from(this.vehicleid);
671 info.vr_death(info, this);
672 vehicles_setreturn(this);
676 bool vehicles_crushable(entity e)
678 if(IS_PLAYER(e) && time >= e.vehicle_enter_delay)
687 void vehicles_impact(entity this, float _minspeed, float _speedfac, float _maxpain)
689 if (trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT)
692 if(this.play_time < time)
694 float wc = vlen(this.velocity - this.oldvelocity);
695 //dprint("oldvel: ", vtos(this.oldvelocity), "\n");
696 //dprint("vel: ", vtos(this.velocity), "\n");
699 float take = min(_speedfac * wc, _maxpain);
700 Damage (this, NULL, NULL, take, DEATH_FALL.m_id, this.origin, '0 0 0');
701 this.play_time = time + 0.25;
703 //dprint("wc: ", ftos(wc), "\n");
704 //dprint("take: ", ftos(take), "\n");
709 // vehicle enter/exit handling
710 vector vehicles_findgoodexit(entity this, vector prefer_spot)
712 tracebox(this.origin + '0 0 32', STAT(PL_MIN, NULL), STAT(PL_MAX, NULL), prefer_spot, MOVE_NORMAL, this.owner);
713 if(trace_fraction == 1.0 && !trace_startsolid && !trace_allsolid)
716 float mysize = 1.5 * vlen(this.maxs - this.mins);
718 vector v2 = 0.5 * (this.absmin + this.absmax);
719 for(int i = 0; i < autocvar_g_vehicles_exit_attempts; ++i)
723 v = v2 + normalize(v) * mysize;
724 tracebox(v2, STAT(PL_MIN, NULL), STAT(PL_MAX, NULL), v, MOVE_NORMAL, this.owner);
725 if(trace_fraction == 1.0 && !trace_startsolid && !trace_allsolid)
732 void vehicles_exit(entity vehic, bool eject)
734 entity player = vehic.owner;
736 if(vehicles_exit_running)
738 LOG_TRACE("^1vehicles_exit already running! this is not good...\n");
742 vehicles_exit_running = true;
744 // TODO: this was in an IS_CLIENT check, make sure it isn't actually needed!
745 if(vehic.vehicle_flags & VHF_PLAYERSLOT)
747 vehic.vehicle_exit(vehic, eject);
748 vehicles_exit_running = false;
754 if (IS_REAL_CLIENT(player))
757 WriteByte (MSG_ONE, SVC_SETVIEWPORT);
758 WriteEntity( MSG_ONE, player);
760 WriteByte (MSG_ONE, SVC_SETVIEWANGLES);
761 WriteAngle(MSG_ONE, 0);
762 WriteAngle(MSG_ONE, vehic.angles_y);
763 WriteAngle(MSG_ONE, 0);
766 setsize(player, STAT(PL_MIN, NULL), STAT(PL_MAX, NULL));
768 player.takedamage = DAMAGE_AIM;
769 player.solid = SOLID_SLIDEBOX;
770 player.movetype = MOVETYPE_WALK;
771 player.effects &= ~EF_NODRAW;
772 player.teleportable = TELEPORT_NORMAL;
774 player.PlayerPhysplug = func_null;
775 player.vehicle = NULL;
776 player.view_ofs = STAT(PL_VIEW_OFS, NULL);
777 player.event_damage = PlayerDamage;
778 player.hud = HUD_NORMAL;
779 PS(player).m_switchweapon = vehic.m_switchweapon;
780 player.last_vehiclecheck = time + 3;
781 player.vehicle_enter_delay = time + 2;
783 CSQCVehicleSetup(player, HUD_NORMAL);
785 Kill_Notification(NOTIF_ONE, player, MSG_CENTER, CPID_VEHICLES);
786 Kill_Notification(NOTIF_ONE, player, MSG_CENTER, CPID_VEHICLES_OTHER); // kill all vehicle notifications when exiting a vehicle?
789 vehic.flags |= FL_NOTARGET;
792 vehic.avelocity = '0 0 0';
794 vehic.tur_head.nodrawtoclient = NULL;
799 WaypointSprite_Kill(vehic.wps_intruder);
801 MUTATOR_CALLHOOK(VehicleExit, player, vehic);
803 vehic.team = vehic.tur_head.team;
805 sound (vehic, CH_TRIGGER_SINGLE, SND_Null, 1, ATTEN_NORM);
806 vehic.vehicle_hudmodel.viewmodelforclient = vehic;
807 vehic.phase = time + 1;
809 vehic.vehicle_exit(vehic, eject);
811 vehicles_setreturn(vehic);
812 vehicles_reset_colors(vehic);
815 CSQCMODEL_AUTOINIT(vehic);
817 vehicles_exit_running = false;
820 void vehicles_touch(entity this)
822 if(MUTATOR_CALLHOOK(VehicleTouch, this, other))
825 // Vehicle currently in use
828 if(!forbidWeaponUse(this.owner))
830 if((this.origin_z + this.maxs_z) > (other.origin_z))
831 if(vehicles_crushable(other))
833 if(vdist(this.velocity, >=, 30))
834 Damage(other, this, this.owner, autocvar_g_vehicles_crush_dmg, DEATH_VH_CRUSH.m_id, '0 0 0', normalize(other.origin - this.origin) * autocvar_g_vehicles_crush_force);
836 return; // Dont do selfdamage when hitting "soft targets".
839 if(this.play_time < time) {
840 Vehicle info = Vehicles_from(this.vehicleid);
841 info.vr_impact(info, this);
847 if(autocvar_g_vehicles_enter)
850 vehicles_enter(other, this);
853 bool vehicle_impulse(entity this, int imp)
855 entity v = this.vehicle;
856 if (!v) return false;
857 if (IS_DEAD(v)) return false;
858 bool(entity,int) f = v.vehicles_impulse;
859 if (f && f(this,imp)) return true;
862 case IMP_weapon_drop.impulse:
864 stuffcmd(this, "\ntoggle cl_eventchase_vehicle\nset _vehicles_shownchasemessage 1\n");
871 void vehicles_enter(entity pl, entity veh)
873 // Remove this when bots know how to use vehicles
874 if((IS_BOT_CLIENT(pl) && !autocvar_g_vehicles_allow_bots))
878 || (veh.phase >= time)
879 || (pl.vehicle_enter_delay >= time)
880 || (STAT(FROZEN, pl))
885 if(autocvar_g_vehicles_enter) // vehicle's touch function should handle this if entering via use key is disabled (TODO)
886 if(veh.vehicle_flags & VHF_MULTISLOT)
887 if(veh.owner && SAME_TEAM(pl, veh))
890 if(time >= veh.gun1.phase)
891 if(veh.gun1.vehicle_enter)
892 if(veh.gun1.vehicle_enter(veh, pl))
896 if(time >= veh.gun2.phase)
897 if(veh.gun2.vehicle_enter)
898 if(veh.gun2.vehicle_enter(veh, pl))
904 if(DIFF_TEAM(pl, veh))
905 if(autocvar_g_vehicles_steal)
907 FOREACH_CLIENT(IS_PLAYER(it) && SAME_TEAM(it, veh), Send_Notification(NOTIF_ONE, it, MSG_CENTER, CENTER_VEHICLE_STEAL));
909 Send_Notification(NOTIF_ONE, pl, MSG_CENTER, CENTER_VEHICLE_STEAL_SELF);
911 if (autocvar_g_vehicles_steal_show_waypoint) {
912 entity wp = WaypointSprite_Spawn(WP_VehicleIntruder, 0, 0, pl, '0 0 68', NULL, veh.team, veh, wps_intruder, true, RADARICON_DANGER);
913 wp.colormod = Team_ColorRGB(pl.team);
918 RemoveGrapplingHook(pl);
920 veh.vehicle_ammo1 = 0;
921 veh.vehicle_ammo2 = 0;
922 veh.vehicle_reload1 = 0;
923 veh.vehicle_reload2 = 0;
924 veh.vehicle_energy = 0;
929 // .viewmodelforclient works better.
930 //veh.vehicle_hudmodel.drawonlytoclient = veh.owner;
932 veh.vehicle_hudmodel.viewmodelforclient = pl;
935 pl.view_ofs = STAT(PL_VIEW_OFS, NULL);
936 setsize (pl, STAT(PL_MIN, NULL), STAT(PL_MAX, NULL));
938 veh.event_damage = vehicles_damage;
940 pl.angles = veh.angles;
941 pl.takedamage = DAMAGE_NO;
942 pl.solid = SOLID_NOT;
943 pl.movetype = MOVETYPE_NOCLIP;
944 pl.teleportable = false;
946 pl.event_damage = func_null;
947 pl.view_ofs = '0 0 0';
948 veh.colormap = pl.colormap;
950 veh.tur_head.colormap = pl.colormap;
951 veh.m_switchweapon = PS(pl).m_switchweapon;
952 pl.hud = veh.vehicleid;
953 pl.PlayerPhysplug = veh.PlayerPhysplug;
955 pl.vehicle_ammo1 = veh.vehicle_ammo1;
956 pl.vehicle_ammo2 = veh.vehicle_ammo2;
957 pl.vehicle_reload1 = veh.vehicle_reload1;
958 pl.vehicle_reload2 = veh.vehicle_reload2;
959 pl.vehicle_energy = veh.vehicle_energy;
961 // Cant do this, hides attached objects too.
962 //veh.exteriormodeltoclient = veh.owner;
963 //veh.tur_head.exteriormodeltoclient = veh.owner;
969 veh.flags -= FL_NOTARGET;
971 if (IS_REAL_CLIENT(pl))
973 Send_Notification(NOTIF_ONE, pl, MSG_CENTER, CENTER_VEHICLE_ENTER);
976 WriteByte (MSG_ONE, SVC_SETVIEWPORT);
977 WriteEntity(MSG_ONE, veh.vehicle_viewport);
979 WriteByte (MSG_ONE, SVC_SETVIEWANGLES);
982 WriteAngle(MSG_ONE, veh.tur_head.angles_x + veh.angles_x); // tilt
983 WriteAngle(MSG_ONE, veh.tur_head.angles_y + veh.angles_y); // yaw
984 WriteAngle(MSG_ONE, 0); // roll
988 WriteAngle(MSG_ONE, veh.angles_x * -1); // tilt
989 WriteAngle(MSG_ONE, veh.angles_y); // yaw
990 WriteAngle(MSG_ONE, 0); // roll
994 vehicles_clearreturn(veh);
996 CSQCVehicleSetup(pl, veh.vehicleid);
998 MUTATOR_CALLHOOK(VehicleEnter, pl, veh);
1000 CSQCModel_UnlinkEntity(veh);
1001 Vehicle info = Vehicles_from(veh.vehicleid);
1002 info.vr_enter(info, veh);
1004 antilag_clear(pl, CS(pl));
1007 void vehicles_think(entity this)
1009 this.nextthink = time + autocvar_g_vehicles_thinkrate;
1012 this.owner.vehicle_weapon2mode = this.vehicle_weapon2mode;
1014 Vehicle info = Vehicles_from(this.vehicleid);
1015 info.vr_think(info, this);
1017 vehicles_painframe(this);
1019 CSQCMODEL_AUTOUPDATE(this);
1023 void vehicles_spawn(entity this)
1025 LOG_DEBUG("Spawning vehicle: ", this.classname, "\n");
1028 this.vehicle_hudmodel.viewmodelforclient = this;
1031 settouch(this, vehicles_touch);
1032 this.event_damage = vehicles_damage;
1033 this.iscreature = true;
1034 this.teleportable = false; // no teleporting for vehicles, too buggy
1035 this.damagedbycontents = true;
1036 this.movetype = MOVETYPE_WALK;
1037 this.solid = SOLID_SLIDEBOX;
1038 this.takedamage = DAMAGE_AIM;
1039 this.deadflag = DEAD_NO;
1040 this.bot_attack = true;
1041 this.flags = FL_NOTARGET;
1042 this.avelocity = '0 0 0';
1043 this.velocity = '0 0 0';
1044 setthink(this, vehicles_think);
1045 this.nextthink = time;
1048 this.lock_strength = 0;
1049 this.lock_target = NULL;
1050 this.misc_bulletcounter = 0;
1053 this.angles = this.pos2;
1054 setorigin(this, this.pos1);
1056 Send_Effect(EFFECT_TELEPORT, this.origin + '0 0 64', '0 0 0', 1);
1058 if(this.vehicle_controller)
1059 this.team = this.vehicle_controller.team;
1061 FOREACH_CLIENT(IS_PLAYER(it) && it.hook.aiment == this, RemoveGrapplingHook(it));
1063 vehicles_reset_colors(this);
1065 Vehicle info = Vehicles_from(this.vehicleid);
1066 info.vr_spawn(info, this);
1068 CSQCMODEL_AUTOINIT(this);
1071 bool vehicle_initialize(entity this, Vehicle info, bool nodrop)
1073 if(!autocvar_g_vehicles)
1080 info.vr_precache(info);
1082 if(this.targetname && this.targetname != "")
1084 this.vehicle_controller = find(NULL, target, this.targetname);
1085 if(!this.vehicle_controller)
1087 LOG_DEBUG("^1WARNING: ^7Vehicle with invalid .targetname\n");
1088 this.active = ACTIVE_ACTIVE;
1092 this.team = this.vehicle_controller.team;
1093 this.use = vehicle_use;
1097 if(this.vehicle_controller.team == 0)
1098 this.active = ACTIVE_NOT;
1100 this.active = ACTIVE_ACTIVE;
1104 else { this.active = ACTIVE_ACTIVE; }
1106 if(this.team && (!teamplay || !autocvar_g_vehicles_teams))
1109 if(this.mdl == "" || !this.mdl)
1110 _setmodel(this, info.model);
1112 _setmodel(this, this.mdl);
1114 this.vehicle_flags |= VHF_ISVEHICLE;
1116 this.vehicle_viewport = new(vehicle_viewport);
1117 this.vehicle_hudmodel = new(vehicle_hudmodel);
1118 this.tur_head = new(tur_head);
1119 this.tur_head.owner = this;
1120 this.takedamage = DAMAGE_NO;
1121 this.bot_attack = true;
1122 this.iscreature = true;
1123 this.teleportable = false; // no teleporting for vehicles, too buggy
1124 this.damagedbycontents = true;
1125 this.vehicleid = info.vehicleid;
1126 this.PlayerPhysplug = info.PlayerPhysplug;
1127 this.event_damage = func_null;
1128 settouch(this, vehicles_touch);
1129 setthink(this, vehicles_spawn);
1130 this.nextthink = time;
1131 this.effects = EF_NODRAW;
1132 this.dphitcontentsmask = DPCONTENTS_BODY | DPCONTENTS_SOLID;
1134 if(autocvar_g_playerclip_collisions)
1135 this.dphitcontentsmask |= DPCONTENTS_PLAYERCLIP;
1137 if(autocvar_g_nodepthtestplayers)
1138 this.effects |= EF_NODEPTHTEST;
1140 if(autocvar_g_fullbrightplayers)
1141 this.effects |= EF_FULLBRIGHT;
1143 _setmodel(this.vehicle_hudmodel, info.hud_model);
1144 setmodel(this.vehicle_viewport, MDL_Null);
1146 if(info.head_model != "")
1148 _setmodel(this.tur_head, info.head_model);
1149 setattachment(this.tur_head, this, info.tag_head);
1150 setattachment(this.vehicle_hudmodel, this.tur_head, info.tag_hud);
1151 setattachment(this.vehicle_viewport, this.vehicle_hudmodel, info.tag_view);
1155 setattachment(this.tur_head, this, "");
1156 setattachment(this.vehicle_hudmodel, this, info.tag_hud);
1157 setattachment(this.vehicle_viewport, this.vehicle_hudmodel, info.tag_view);
1160 setsize(this, info.mins, info.maxs);
1164 setorigin(this, this.origin);
1165 tracebox(this.origin + '0 0 100', info.mins, info.maxs, this.origin - '0 0 10000', MOVE_WORLDONLY, this);
1166 setorigin(this, trace_endpos);
1169 this.pos1 = this.origin;
1170 this.pos2 = this.angles;
1171 this.tur_head.team = this.team;
1173 info.vr_setup(info, this);
1175 if(this.active == ACTIVE_NOT)
1176 this.nextthink = 0; // wait until activated
1177 else if(autocvar_g_vehicles_delayspawn)
1178 this.nextthink = time + this.respawntime + (random() * autocvar_g_vehicles_delayspawn_jitter);
1180 this.nextthink = time + game_starttime;
1182 if(MUTATOR_CALLHOOK(VehicleSpawn, this))