1 #include "sv_vehicles.qh"
4 bool vehicle_send(entity to, int sf)
6 WriteByte(MSG_ENTITY, ENT_CLIENT_VEHICLE);
7 WriteByte(MSG_ENTITY, sf);
11 WriteByte(MSG_ENTITY, self.vehicleid);
21 // player handles the .vehicle stuff, we need only set ourselves up for driving
40 bool SendAuxiliaryXhair(entity this, entity to, int sf)
43 WriteHeader(MSG_ENTITY, ENT_CLIENT_AUXILIARYXHAIR);
45 WriteByte(MSG_ENTITY, this.cnt);
47 WriteCoord(MSG_ENTITY, this.origin_x);
48 WriteCoord(MSG_ENTITY, this.origin_y);
49 WriteCoord(MSG_ENTITY, this.origin_z);
51 WriteByte(MSG_ENTITY, rint(this.colormod_x * 255));
52 WriteByte(MSG_ENTITY, rint(this.colormod_y * 255));
53 WriteByte(MSG_ENTITY, rint(this.colormod_z * 255));
58 void UpdateAuxiliaryXhair(entity own, vector loc, vector clr, int axh_id)
60 if(!IS_REAL_CLIENT(own))
65 axh_id = bound(0, axh_id, MAX_AXH);
66 axh = own.(AuxiliaryXhair[axh_id]);
68 if(axh == world || wasfreed(axh)) // MADNESS? THIS IS QQQQCCCCCCCCC (wasfreed, why do you exsist?)
72 axh.drawonlytoclient = own;
74 Net_LinkEntity(axh, false, 0, SendAuxiliaryXhair);
80 own.(AuxiliaryXhair[axh_id]) = axh;
83 void CSQCVehicleSetup(entity own, int vehicle_id)
85 if(!IS_REAL_CLIENT(own))
90 WriteHeader(MSG_ONE, TE_CSQC_VEHICLESETUP);
91 WriteByte(MSG_ONE, vehicle_id);
94 void vehicles_locktarget(entity this, float incr, float decr, float _lock_time)
96 if(this.lock_target && IS_DEAD(this.lock_target))
98 this.lock_target = world;
99 this.lock_strength = 0;
103 if(this.lock_time > time)
106 if(this.lock_soundtime < time)
108 this.lock_soundtime = time + 0.5;
109 play2(this.owner, "vehicles/locked.wav");
115 if(trace_ent != world)
117 if(SAME_TEAM(trace_ent, this))
120 if(IS_DEAD(trace_ent))
123 if(!(IS_VEHICLE(trace_ent) || IS_TURRET(trace_ent)))
126 if(trace_ent.alpha <= 0.5 && trace_ent.alpha != 0)
127 trace_ent = world; // invisible
130 if(this.lock_target == world && trace_ent != world)
131 this.lock_target = trace_ent;
133 if(this.lock_target && trace_ent == this.lock_target)
135 if(this.lock_strength != 1 && this.lock_strength + incr >= 1)
137 play2(this.owner, "vehicles/lock.wav");
138 this.lock_soundtime = time + 0.8;
140 else if (this.lock_strength != 1 && this.lock_soundtime < time)
142 play2(this.owner, "vehicles/locking.wav");
143 this.lock_soundtime = time + 0.3;
147 // Have a locking target
148 // Trace hit current target
149 if(trace_ent == this.lock_target && trace_ent != world)
151 this.lock_strength = min(this.lock_strength + incr, 1);
152 if(this.lock_strength == 1)
153 this.lock_time = time + _lock_time;
158 this.lock_strength = max(this.lock_strength - decr * 2, 0);
160 this.lock_strength = max(this.lock_strength - decr, 0);
162 if(this.lock_strength == 0)
163 this.lock_target = world;
167 vector vehicles_force_fromtag_hover(entity this, string tag_name, float spring_length, float max_power)
169 force_fromtag_origin = gettaginfo(this, gettagindex(this, tag_name));
170 v_forward = normalize(v_forward) * -1;
171 traceline(force_fromtag_origin, force_fromtag_origin - (v_forward * spring_length), MOVE_NORMAL, this);
173 force_fromtag_power = (1 - trace_fraction) * max_power;
174 force_fromtag_normpower = force_fromtag_power / max_power;
176 return v_forward * force_fromtag_power;
179 vector vehicles_force_fromtag_maglev(entity this, string tag_name, float spring_length, float max_power)
181 force_fromtag_origin = gettaginfo(this, gettagindex(this, tag_name));
182 v_forward = normalize(v_forward) * -1;
183 traceline(force_fromtag_origin, force_fromtag_origin - (v_forward * spring_length), MOVE_NORMAL, this);
185 // TODO - this may NOT be compatible with wall/celing movement, unhardcode 0.25 (engine count multiplier)
186 if(trace_fraction == 1.0)
188 force_fromtag_normpower = -0.25;
192 force_fromtag_power = ((1 - trace_fraction) - trace_fraction) * max_power;
193 force_fromtag_normpower = force_fromtag_power / max_power;
195 return v_forward * force_fromtag_power;
198 // projectile handling
199 void vehicles_projectile_damage(entity this, entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force)
201 // Ignore damage from oterh projectiles from my owner (dont mess up volly's)
202 if(inflictor.owner == this.owner)
205 this.health -= damage;
206 this.velocity += force;
209 this.takedamage = DAMAGE_NO;
210 this.event_damage = func_null;
211 this.think = this.use;
212 this.nextthink = time;
216 void vehicles_projectile_explode()
218 if(self.owner && other != world)
220 if(other == self.owner.vehicle)
223 if(other == self.owner.vehicle.tur_head)
229 self.event_damage = func_null;
230 RadiusDamage (self, self.realowner, self.shot_dmg, 0, self.shot_radius, self, world, self.shot_force, self.totalfrags, other);
235 entity vehicles_projectile(entity this, string _mzlfx, Sound _mzlsound,
236 vector _org, vector _vel,
237 float _dmg, float _radi, float _force, float _size,
238 int _deahtype, float _projtype, float _health,
239 bool _cull, bool _clianim, entity _owner)
241 TC(Sound, _mzlsound);
246 PROJECTILE_MAKETRIGGER(proj);
247 setorigin(proj, _org);
249 proj.shot_dmg = _dmg;
250 proj.shot_radius = _radi;
251 proj.shot_force = _force;
252 proj.totalfrags = _deahtype;
253 proj.solid = SOLID_BBOX;
254 proj.movetype = MOVETYPE_FLYMISSILE;
255 proj.flags = FL_PROJECTILE;
256 proj.bot_dodge = true;
257 proj.bot_dodgerating = _dmg;
258 proj.velocity = _vel;
259 proj.touch = vehicles_projectile_explode;
260 proj.use = vehicles_projectile_explode;
262 proj.realowner = _owner;
263 proj.think = SUB_Remove_self;
264 proj.nextthink = time + 30;
268 proj.takedamage = DAMAGE_AIM;
269 proj.event_damage = vehicles_projectile_damage;
270 proj.health = _health;
273 proj.flags = FL_PROJECTILE | FL_NOTARGET;
275 if(_mzlsound != SND_Null)
276 sound (this, CH_WEAPON_A, _mzlsound, VOL_BASE, ATTEN_NORM);
279 Send_Effect_(_mzlfx, proj.origin, proj.velocity, 1);
281 setsize (proj, '-1 -1 -1' * _size, '1 1 1' * _size);
283 CSQCProjectile(proj, _clianim, _projtype, _cull);
288 void vehicles_gib_explode()
290 sound (self, CH_SHOTS, SND_ROCKET_IMPACT, VOL_BASE, ATTEN_NORM);
291 Send_Effect(EFFECT_EXPLOSION_SMALL, randomvec() * 80 + (self.origin + '0 0 100'), '0 0 0', 1);
292 Send_Effect(EFFECT_EXPLOSION_SMALL, self.wp00.origin + '0 0 64', '0 0 0', 1);
296 void vehicles_gib_think()
302 self.nextthink = time + 0.1;
305 entity vehicle_tossgib(entity _template, vector _vel, string _tag, bool _burn, bool _explode, float _maxtime, vector _rot)
307 entity _gib = spawn();
308 _setmodel(_gib, _template.model);
309 vector org = gettaginfo(self, gettagindex(self, _tag));
310 setorigin(_gib, org);
311 _gib.velocity = _vel;
312 _gib.movetype = MOVETYPE_TOSS;
313 _gib.solid = SOLID_CORPSE;
314 _gib.colormod = '-0.5 -0.5 -0.5';
315 _gib.effects = EF_LOWPRECISION;
316 _gib.avelocity = _rot;
319 _gib.effects |= EF_FLAME;
323 _gib.think = vehicles_gib_explode;
324 _gib.nextthink = time + random() * _explode;
325 _gib.touch = vehicles_gib_explode;
329 _gib.cnt = time + _maxtime;
330 _gib.think = vehicles_gib_think;
331 _gib.nextthink = time + _maxtime - 1;
337 bool vehicle_addplayerslot( entity _owner,
341 bool(entity) _framefunc,
342 void(bool) _exitfunc, float() _enterfunc)
344 if(!(_owner.vehicle_flags & VHF_MULTISLOT))
345 _owner.vehicle_flags |= VHF_MULTISLOT;
347 _slot.PlayerPhysplug = _framefunc;
348 _slot.vehicle_exit = _exitfunc;
349 _slot.vehicle_enter = _enterfunc;
351 _slot.vehicle_flags = VHF_PLAYERSLOT;
352 _slot.vehicle_viewport = spawn();
353 _slot.vehicle_hudmodel = spawn();
354 _slot.vehicle_hudmodel.viewmodelforclient = _slot;
355 _slot.vehicle_viewport.effects = (EF_ADDITIVE | EF_DOUBLESIDED | EF_FULLBRIGHT | EF_NODEPTHTEST | EF_NOGUNBOB | EF_NOSHADOW | EF_LOWPRECISION | EF_SELECTABLE | EF_TELEPORT_BIT);
357 _setmodel(_slot.vehicle_hudmodel, _hud_model);
358 setmodel(_slot.vehicle_viewport, MDL_Null);
360 setattachment(_slot.vehicle_hudmodel, _slot, "");
361 setattachment(_slot.vehicle_viewport, _slot.vehicle_hudmodel, "");
366 vector vehicle_aimturret(entity _vehic, vector _target, entity _turrret, string _tagname,
367 float _pichlimit_min, float _pichlimit_max,
368 float _rotlimit_min, float _rotlimit_max, float _aimspeed)
372 vtag = gettaginfo(_turrret, gettagindex(_turrret, _tagname));
373 vtmp = vectoangles(normalize(_target - vtag));
374 vtmp = AnglesTransform_ToAngles(AnglesTransform_LeftDivide(AnglesTransform_FromAngles(_vehic.angles), AnglesTransform_FromAngles(vtmp))) - _turrret.angles;
375 vtmp = AnglesTransform_Normalize(vtmp, true);
376 ftmp = _aimspeed * frametime;
377 vtmp_y = bound(-ftmp, vtmp_y, ftmp);
378 vtmp_x = bound(-ftmp, vtmp_x, ftmp);
379 _turrret.angles_y = bound(_rotlimit_min, _turrret.angles_y + vtmp_y, _rotlimit_max);
380 _turrret.angles_x = bound(_pichlimit_min, _turrret.angles_x + vtmp_x, _pichlimit_max);
384 void vehicles_reset_colors()
387 float _effects = 0, _colormap;
388 vector _glowmod, _colormod;
390 if(autocvar_g_nodepthtestplayers)
391 _effects |= EF_NODEPTHTEST;
393 if(autocvar_g_fullbrightplayers)
394 _effects |= EF_FULLBRIGHT;
397 _colormap = 1024 + (self.team - 1) * 17;
404 // Find all ents attacked to main model and setup effects, colormod etc.
405 e = findchainentity(tag_entity, self);
408 if(e != self.vehicle_shieldent)
410 e.effects = _effects; // | EF_LOWPRECISION;
411 e.colormod = _colormod;
412 e.colormap = _colormap;
417 // Also check head tags
418 e = findchainentity(tag_entity, self.tur_head);
421 if(e != self.vehicle_shieldent)
423 e.effects = _effects; // | EF_LOWPRECISION;
424 e.colormod = _colormod;
425 e.colormap = _colormap;
431 self.vehicle_hudmodel.effects = self.effects = _effects; // | EF_LOWPRECISION;
432 self.vehicle_hudmodel.colormod = self.colormod = _colormod;
433 self.vehicle_hudmodel.colormap = self.colormap = _colormap;
434 self.vehicle_viewport.effects = (EF_ADDITIVE | EF_DOUBLESIDED | EF_FULLBRIGHT | EF_NODEPTHTEST | EF_NOGUNBOB | EF_NOSHADOW | EF_LOWPRECISION | EF_SELECTABLE | EF_TELEPORT_BIT);
437 self.avelocity = '0 0 0';
438 self.velocity = '0 0 0';
439 self.effects = _effects;
442 void vehicles_clearreturn(entity veh)
444 // Remove "return helper", if any.
445 for (entity ret = findchain(classname, "vehicle_return"); ret; ret = ret.chain)
450 ret.think = SUB_Remove_self;
451 ret.nextthink = time + 0.1;
453 if(ret.waypointsprite_attached)
454 WaypointSprite_Kill(ret.waypointsprite_attached);
461 void vehicles_spawn();
462 void vehicles_return()
464 Send_Effect(EFFECT_TELEPORT, self.wp00.origin + '0 0 64', '0 0 0', 1);
466 self.wp00.think = vehicles_spawn;
467 self.wp00.nextthink = time;
469 if(self.waypointsprite_attached)
470 WaypointSprite_Kill(self.waypointsprite_attached);
475 void vehicles_showwp_goaway()
477 if(self.waypointsprite_attached)
478 WaypointSprite_Kill(self.waypointsprite_attached);
484 void vehicles_showwp()
486 entity oldself = world;
491 self.think = vehicles_return;
492 self.nextthink = self.cnt;
496 self.think = vehicles_return;
497 self.nextthink = time +1;
501 setmodel(self, MDL_Null);
502 self.team = oldself.wp00.team;
503 self.wp00 = oldself.wp00;
504 setorigin(self, oldself.wp00.pos1);
506 self.nextthink = time + 5;
507 self.think = vehicles_showwp_goaway;
510 if(teamplay && self.team)
511 rgb = Team_ColorRGB(self.team);
514 entity wp = WaypointSprite_Spawn(WP_Vehicle, 0, 0, self, '0 0 64', world, 0, self, waypointsprite_attached, true, RADARICON_Vehicle);
516 if(self.waypointsprite_attached)
518 WaypointSprite_UpdateRule(self.waypointsprite_attached, self.wp00.team, SPRITERULE_DEFAULT);
520 WaypointSprite_UpdateBuildFinished(self.waypointsprite_attached, self.nextthink);
521 WaypointSprite_Ping(self.waypointsprite_attached);
528 void vehicles_setreturn(entity veh)
532 vehicles_clearreturn(veh);
534 ret = new(vehicle_return);
537 ret.think = vehicles_showwp;
541 ret.cnt = time + veh.respawntime;
542 ret.nextthink = min(time + veh.respawntime, time + veh.respawntime - 5);
546 ret.nextthink = min(time + veh.respawntime, time + veh.respawntime - 1);
549 setmodel(ret, MDL_Null);
550 setorigin(ret, veh.pos1 + '0 0 96');
556 LOG_TRACE("vehicle ",self.netname, " used by ", activator.classname, "\n");
558 self.tur_head.team = activator.team;
560 if(self.tur_head.team == 0)
561 self.active = ACTIVE_NOT;
563 self.active = ACTIVE_ACTIVE;
565 if(self.active == ACTIVE_ACTIVE && !IS_DEAD(self) && !gameover)
567 LOG_TRACE("Respawning vehicle: ", self.netname, "\n");
568 if(self.effects & EF_NODRAW)
570 self.think = vehicles_spawn;
571 self.nextthink = time + 3;
575 vehicles_setreturn(self);
576 vehicles_reset_colors();
581 void vehicles_regen(entity this, float timer, .float regen_field, float field_max, float rpause, float regen, float delta_time, float _healthscale)
583 if(this.(regen_field) < field_max)
584 if(timer + rpause < time)
587 regen = regen * (this.vehicle_health / this.max_health);
589 this.(regen_field) = min(this.(regen_field) + regen * delta_time, field_max);
592 this.owner.(regen_field) = (this.(regen_field) / field_max) * 100;
596 void shieldhit_think()
601 // setmodel(self, MDL_Null);
603 self.effects |= EF_NODRAW;
607 self.nextthink = time + 0.1;
611 void vehicles_painframe(entity this)
613 int myhealth = ((this.owner) ? this.owner.vehicle_health : ((this.vehicle_health / this.max_health) * 100));
616 if(this.pain_frame < time)
618 float _ftmp = myhealth / 50;
619 this.pain_frame = time + max(0.1, 0.1 + (random() * 0.5 * _ftmp));
620 Send_Effect(EFFECT_SMOKE_SMALL, (this.origin + (randomvec() * 80)), '0 0 0', 1);
622 if(this.vehicle_flags & VHF_DMGSHAKE)
623 this.velocity += randomvec() * 30;
625 if(this.vehicle_flags & VHF_DMGROLL)
626 if(this.vehicle_flags & VHF_DMGHEADROLL)
627 this.tur_head.angles += randomvec();
629 this.angles += randomvec();
633 void vehicles_frame(entity this, entity actor)
635 vehicles_painframe(this);
638 void vehicles_damage(entity this, entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force)
640 this.dmg_time = time;
643 if(DEATH_ISWEAPON(deathtype, WEP_VORTEX))
644 damage *= autocvar_g_vehicles_vortex_damagerate;
646 if(DEATH_ISWEAPON(deathtype, WEP_MACHINEGUN))
647 damage *= autocvar_g_vehicles_machinegun_damagerate;
649 if(DEATH_ISWEAPON(deathtype, WEP_RIFLE))
650 damage *= autocvar_g_vehicles_rifle_damagerate;
652 if(DEATH_ISWEAPON(deathtype, WEP_VAPORIZER))
653 damage *= autocvar_g_vehicles_vaporizer_damagerate;
655 if(DEATH_ISWEAPON(deathtype, WEP_SEEKER))
656 damage *= autocvar_g_vehicles_tag_damagerate;
658 if(DEATH_WEAPONOF(deathtype) != WEP_Null)
659 damage *= autocvar_g_vehicles_weapon_damagerate;
661 this.enemy = attacker;
663 this.pain_finished = time;
665 if((this.vehicle_flags & VHF_HASSHIELD) && (this.vehicle_shield > 0))
667 if (wasfreed(this.vehicle_shieldent) || this.vehicle_shieldent == world)
669 this.vehicle_shieldent = spawn();
670 this.vehicle_shieldent.effects = EF_LOWPRECISION;
672 setmodel(this.vehicle_shieldent, MDL_VEH_SHIELD);
673 setattachment(this.vehicle_shieldent, this, "");
674 setorigin(this.vehicle_shieldent, real_origin(this) - this.origin);
675 this.vehicle_shieldent.scale = 256 / vlen(this.maxs - this.mins);
676 this.vehicle_shieldent.think = shieldhit_think;
679 this.vehicle_shieldent.colormod = '1 1 1';
680 this.vehicle_shieldent.alpha = 0.45;
681 this.vehicle_shieldent.angles = vectoangles(normalize(hitloc - (this.origin + this.vehicle_shieldent.origin))) - this.angles;
682 this.vehicle_shieldent.nextthink = time;
683 this.vehicle_shieldent.effects &= ~EF_NODRAW;
685 this.vehicle_shield -= damage;
687 if(this.vehicle_shield < 0)
689 this.vehicle_health -= fabs(this.vehicle_shield);
690 this.vehicle_shieldent.colormod = '2 0 0';
691 this.vehicle_shield = 0;
692 this.vehicle_shieldent.alpha = 0.75;
694 if(sound_allowed(MSG_BROADCAST, attacker))
695 spamsound (this, CH_PAIN, "onslaught/ons_hit2.wav", VOL_BASE, ATTEN_NORM); // FIXME: PLACEHOLDER
698 if(sound_allowed(MSG_BROADCAST, attacker))
699 spamsound (this, CH_PAIN, "onslaught/electricity_explode.wav", VOL_BASE, ATTEN_NORM); // FIXME: PLACEHOLDER
704 this.vehicle_health -= damage;
706 if(sound_allowed(MSG_BROADCAST, attacker))
707 spamsound (this, CH_PAIN, "onslaught/ons_hit2.wav", VOL_BASE, ATTEN_NORM); // FIXME: PLACEHOLDER
710 if(this.damageforcescale < 1 && this.damageforcescale > 0)
711 this.velocity += force * this.damageforcescale;
713 this.velocity += force;
715 if(this.vehicle_health <= 0)
718 if(this.vehicle_flags & VHF_DEATHEJECT)
719 WITH(entity, self, this, vehicles_exit(VHEF_EJECT));
721 WITH(entity, self, this, vehicles_exit(VHEF_RELEASE));
724 antilag_clear(this, this);
726 Vehicle info = Vehicles_from(this.vehicleid);
727 info.vr_death(info, this);
728 vehicles_setreturn(this);
732 float vehicles_crushable(entity e)
734 if(IS_PLAYER(e) && time >= e.vehicle_enter_delay)
743 void vehicles_impact(float _minspeed, float _speedfac, float _maxpain)
745 if (trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT)
748 if(self.play_time < time)
750 float wc = vlen(self.velocity - self.oldvelocity);
751 //dprint("oldvel: ", vtos(self.oldvelocity), "\n");
752 //dprint("vel: ", vtos(self.velocity), "\n");
755 float take = min(_speedfac * wc, _maxpain);
756 Damage (self, world, world, take, DEATH_FALL.m_id, self.origin, '0 0 0');
757 self.play_time = time + 0.25;
759 //dprint("wc: ", ftos(wc), "\n");
760 //dprint("take: ", ftos(take), "\n");
765 // vehicle enter/exit handling
766 vector vehicles_findgoodexit(vector prefer_spot)
771 tracebox(self.origin + '0 0 32', STAT(PL_MIN, NULL), STAT(PL_MAX, NULL), prefer_spot, MOVE_NORMAL, self.owner);
772 if(trace_fraction == 1.0 && !trace_startsolid && !trace_allsolid)
775 mysize = 1.5 * vlen(self.maxs - self.mins);
778 v2 = 0.5 * (self.absmin + self.absmax);
779 for(i = 0; i < 100; ++i)
783 v = v2 + normalize(v) * mysize;
784 tracebox(v2, STAT(PL_MIN, NULL), STAT(PL_MAX, NULL), v, MOVE_NORMAL, self.owner);
785 if(trace_fraction == 1.0 && !trace_startsolid && !trace_allsolid)
790 exitspot = (self.origin + '0 0 48') + v_forward * mysize;
791 tracebox(self.origin + '0 0 32', PL_MIN, PL_MAX, exitspot, MOVE_NORMAL, self.owner);
792 if(trace_fraction == 1.0 && !trace_startsolid && !trace_allsolid)
795 exitspot = (self.origin + '0 0 48') - v_forward * mysize;
796 tracebox(self.origin + '0 0 32', PL_MIN, PL_MAX, exitspot, MOVE_NORMAL, self.owner);
797 if(trace_fraction == 1.0 && !trace_startsolid && !trace_allsolid)
800 exitspot = (self.origin + '0 0 48') + v_right * mysize;
801 tracebox(self.origin + '0 0 32', PL_MIN, PL_MAX, exitspot, MOVE_NORMAL, self.owner);
802 if(trace_fraction == 1.0 && !trace_startsolid && !trace_allsolid)
805 exitspot = (self.origin + '0 0 48') - v_right * mysize;
806 tracebox(self.origin + '0 0 32', PL_MIN, PL_MAX, exitspot, MOVE_NORMAL, self.owner);
807 if(trace_fraction == 1.0 && !trace_startsolid && !trace_allsolid)
814 void vehicles_exit(bool eject)
819 if(vehicles_exit_running)
821 LOG_TRACE("^1vehicles_exit allready running! this is not good..\n");
825 vehicles_exit_running = true;
828 _vehicle = self.vehicle;
830 if (_vehicle.vehicle_flags & VHF_PLAYERSLOT)
832 _vehicle.vehicle_exit(eject);
834 vehicles_exit_running = false;
841 _player = _vehicle.owner;
847 if (IS_REAL_CLIENT(_player))
849 msg_entity = _player;
850 WriteByte (MSG_ONE, SVC_SETVIEWPORT);
851 WriteEntity( MSG_ONE, _player);
853 WriteByte (MSG_ONE, SVC_SETVIEWANGLES);
854 WriteAngle(MSG_ONE, 0);
855 WriteAngle(MSG_ONE, _vehicle.angles_y);
856 WriteAngle(MSG_ONE, 0);
859 setsize(_player, STAT(PL_MIN, NULL), STAT(PL_MAX, NULL));
861 _player.takedamage = DAMAGE_AIM;
862 _player.solid = SOLID_SLIDEBOX;
863 _player.movetype = MOVETYPE_WALK;
864 _player.effects &= ~EF_NODRAW;
865 _player.teleportable = TELEPORT_NORMAL;
867 _player.PlayerPhysplug = func_null;
868 _player.vehicle = world;
869 _player.view_ofs = STAT(PL_VIEW_OFS, NULL);
870 _player.event_damage = PlayerDamage;
871 _player.hud = HUD_NORMAL;
872 PS(_player).m_switchweapon = _vehicle.m_switchweapon;
873 _player.last_vehiclecheck = time + 3;
874 _player.vehicle_enter_delay = time + 2;
876 CSQCVehicleSetup(_player, HUD_NORMAL);
878 _vehicle.flags |= FL_NOTARGET;
880 if(!IS_DEAD(_vehicle))
881 _vehicle.avelocity = '0 0 0';
883 _vehicle.tur_head.nodrawtoclient = world;
888 Kill_Notification(NOTIF_ONE, _player, MSG_CENTER, CPID_VEHICLES);
889 Kill_Notification(NOTIF_ONE, _player, MSG_CENTER, CPID_VEHICLES_OTHER); // kill all vehicle notifications when exiting a vehicle?
891 WaypointSprite_Kill(_vehicle.wps_intruder);
893 MUTATOR_CALLHOOK(VehicleExit, _player, _vehicle);
895 _vehicle.team = _vehicle.tur_head.team;
897 sound (_vehicle, CH_TRIGGER_SINGLE, SND_Null, 1, ATTEN_NORM);
898 _vehicle.vehicle_hudmodel.viewmodelforclient = _vehicle;
899 _vehicle.phase = time + 1;
901 _vehicle.vehicle_exit(eject);
903 vehicles_setreturn(_vehicle);
904 vehicles_reset_colors();
905 _vehicle.owner = world;
907 CSQCMODEL_AUTOINIT(self);
910 vehicles_exit_running = false;
913 void vehicles_touch()
915 if(MUTATOR_CALLHOOK(VehicleTouch, self, other))
918 // Vehicle currently in use
921 if(!forbidWeaponUse(self.owner))
923 if((self.origin_z + self.maxs_z) > (other.origin_z))
924 if(vehicles_crushable(other))
926 if(vdist(self.velocity, >=, 30))
927 Damage(other, self, self.owner, autocvar_g_vehicles_crush_dmg, DEATH_VH_CRUSH.m_id, '0 0 0', normalize(other.origin - self.origin) * autocvar_g_vehicles_crush_force);
929 return; // Dont do selfdamage when hitting "soft targets".
932 if(self.play_time < time) {
933 Vehicle info = Vehicles_from(self.vehicleid);
934 info.vr_impact(info, self);
940 if(autocvar_g_vehicles_enter)
943 vehicles_enter(other, self);
946 bool vehicle_impulse(entity this, int imp)
948 entity v = this.vehicle;
949 if (!v) return false;
950 if (IS_DEAD(v)) return false;
951 bool(int) f = v.vehicles_impulse;
952 if (f && f(imp)) return true;
955 case IMP_weapon_drop.impulse:
957 stuffcmd(self, "\ntoggle cl_eventchase_vehicle\nset _vehicles_shownchasemessage 1\n");
964 void vehicles_enter(entity pl, entity veh)
966 // Remove this when bots know how to use vehicles
967 if((IS_BOT_CLIENT(pl) && !autocvar_g_vehicles_allow_bots))
971 || (veh.phase >= time)
972 || (pl.vehicle_enter_delay >= time)
973 || (STAT(FROZEN, pl))
978 if(autocvar_g_vehicles_enter) // vehicle's touch function should handle this if entering via use key is disabled (TODO)
979 if(veh.vehicle_flags & VHF_MULTISLOT)
983 other = pl; // TODO: fix
986 if(time >= veh.gun1.phase)
987 if(veh.gun1.vehicle_enter)
988 if(veh.gun1.vehicle_enter())
995 if(time >= veh.gun2.phase)
996 if(veh.gun2.vehicle_enter)
997 if(veh.gun2.vehicle_enter())
1008 if(DIFF_TEAM(pl, veh))
1009 if(autocvar_g_vehicles_steal)
1011 FOREACH_CLIENT(IS_PLAYER(it) && SAME_TEAM(it, veh), Send_Notification(NOTIF_ONE, it, MSG_CENTER, CENTER_VEHICLE_STEAL));
1013 Send_Notification(NOTIF_ONE, pl, MSG_CENTER, CENTER_VEHICLE_STEAL_SELF);
1015 if (autocvar_g_vehicles_steal_show_waypoint) {
1016 entity wp = WaypointSprite_Spawn(WP_VehicleIntruder, 0, 0, pl, '0 0 68', world, veh.team, veh, wps_intruder, true, RADARICON_DANGER);
1017 wp.colormod = Team_ColorRGB(pl.team);
1022 RemoveGrapplingHook(pl);
1024 veh.vehicle_ammo1 = 0;
1025 veh.vehicle_ammo2 = 0;
1026 veh.vehicle_reload1 = 0;
1027 veh.vehicle_reload2 = 0;
1028 veh.vehicle_energy = 0;
1033 // .viewmodelforclient works better.
1034 //veh.vehicle_hudmodel.drawonlytoclient = veh.owner;
1036 veh.vehicle_hudmodel.viewmodelforclient = pl;
1038 tracebox(pl.origin, STAT(PL_MIN, NULL), STAT(PL_MAX, NULL), pl.origin, false, pl);
1040 pl.view_ofs = STAT(PL_VIEW_OFS, NULL);
1041 setsize (pl, STAT(PL_MIN, NULL), STAT(PL_MAX, NULL));
1043 veh.event_damage = vehicles_damage;
1045 pl.angles = veh.angles;
1046 pl.takedamage = DAMAGE_NO;
1047 pl.solid = SOLID_NOT;
1048 pl.movetype = MOVETYPE_NOCLIP;
1049 pl.teleportable = false;
1051 pl.event_damage = func_null;
1052 pl.view_ofs = '0 0 0';
1053 veh.colormap = pl.colormap;
1055 veh.tur_head.colormap = pl.colormap;
1056 veh.m_switchweapon = PS(pl).m_switchweapon;
1057 pl.hud = veh.vehicleid;
1058 pl.PlayerPhysplug = veh.PlayerPhysplug;
1060 pl.vehicle_ammo1 = veh.vehicle_ammo1;
1061 pl.vehicle_ammo2 = veh.vehicle_ammo2;
1062 pl.vehicle_reload1 = veh.vehicle_reload1;
1063 pl.vehicle_reload2 = veh.vehicle_reload2;
1064 pl.vehicle_energy = veh.vehicle_energy;
1066 // Cant do this, hides attached objects too.
1067 //veh.exteriormodeltoclient = veh.owner;
1068 //veh.tur_head.exteriormodeltoclient = veh.owner;
1071 UNSET_ONGROUND(veh);
1074 veh.flags -= FL_NOTARGET;
1076 if (IS_REAL_CLIENT(pl))
1078 Send_Notification(NOTIF_ONE, pl, MSG_CENTER, CENTER_VEHICLE_ENTER);
1081 WriteByte (MSG_ONE, SVC_SETVIEWPORT);
1082 WriteEntity(MSG_ONE, veh.vehicle_viewport);
1084 WriteByte (MSG_ONE, SVC_SETVIEWANGLES);
1087 WriteAngle(MSG_ONE, veh.tur_head.angles_x + veh.angles_x); // tilt
1088 WriteAngle(MSG_ONE, veh.tur_head.angles_y + veh.angles_y); // yaw
1089 WriteAngle(MSG_ONE, 0); // roll
1093 WriteAngle(MSG_ONE, veh.angles_x * -1); // tilt
1094 WriteAngle(MSG_ONE, veh.angles_y); // yaw
1095 WriteAngle(MSG_ONE, 0); // roll
1099 vehicles_clearreturn(veh);
1101 CSQCVehicleSetup(pl, veh.vehicleid);
1103 MUTATOR_CALLHOOK(VehicleEnter, pl, veh);
1106 CSQCModel_UnlinkEntity(veh);
1107 Vehicle info = Vehicles_from(veh.vehicleid);
1108 info.vr_enter(info, veh);
1111 antilag_clear(pl, CS(pl));
1114 void vehicles_think()
1116 self.nextthink = time;
1119 self.owner.vehicle_weapon2mode = self.vehicle_weapon2mode;
1121 Vehicle info = Vehicles_from(self.vehicleid);
1122 info.vr_think(info, self);
1124 vehicles_painframe(self);
1126 CSQCMODEL_AUTOUPDATE(self);
1130 void vehicles_spawn()
1132 LOG_TRACE("Spawning vehicle: ", self.classname, "\n");
1135 self.vehicle_hudmodel.viewmodelforclient = self;
1138 self.touch = vehicles_touch;
1139 self.event_damage = vehicles_damage;
1140 self.iscreature = true;
1141 self.teleportable = false; // no teleporting for vehicles, too buggy
1142 self.damagedbycontents = true;
1143 self.movetype = MOVETYPE_WALK;
1144 self.solid = SOLID_SLIDEBOX;
1145 self.takedamage = DAMAGE_AIM;
1146 self.deadflag = DEAD_NO;
1147 self.bot_attack = true;
1148 self.flags = FL_NOTARGET;
1149 self.avelocity = '0 0 0';
1150 self.velocity = '0 0 0';
1151 self.think = vehicles_think;
1152 self.nextthink = time;
1155 self.lock_strength = 0;
1156 self.lock_target = world;
1157 self.misc_bulletcounter = 0;
1160 self.angles = self.pos2;
1161 setorigin(self, self.pos1);
1163 Send_Effect(EFFECT_TELEPORT, self.origin + '0 0 64', '0 0 0', 1);
1165 if(self.vehicle_controller)
1166 self.team = self.vehicle_controller.team;
1168 FOREACH_CLIENT(IS_PLAYER(it) && it.hook.aiment == self, RemoveGrapplingHook(it));
1170 vehicles_reset_colors();
1172 Vehicle info = Vehicles_from(self.vehicleid);
1173 info.vr_spawn(info, self);
1175 CSQCMODEL_AUTOINIT(self);
1178 bool vehicle_initialize(entity veh, bool nodrop)
1180 if(!autocvar_g_vehicles)
1187 Vehicle info = Vehicles_from(veh.vehicleid);
1188 info.vr_precache(info);
1191 if(self.targetname && self.targetname != "")
1193 self.vehicle_controller = find(world, target, self.targetname);
1194 if(!self.vehicle_controller)
1196 bprint("^1WARNING: ^7Vehicle with invalid .targetname\n");
1197 self.active = ACTIVE_ACTIVE;
1201 self.team = self.vehicle_controller.team;
1202 self.use = vehicle_use;
1206 if(self.vehicle_controller.team == 0)
1207 self.active = ACTIVE_NOT;
1209 self.active = ACTIVE_ACTIVE;
1213 else { self.active = ACTIVE_ACTIVE; }
1215 if(self.team && (!teamplay || !autocvar_g_vehicles_teams))
1218 if(self.mdl == "" || !self.mdl)
1219 _setmodel(self, veh.model);
1221 _setmodel(self, self.mdl);
1223 self.vehicle_flags |= VHF_ISVEHICLE;
1225 self.vehicle_viewport = new(vehicle_viewport);
1226 self.vehicle_hudmodel = new(vehicle_hudmodel);
1227 self.tur_head = new(tur_head);
1228 self.tur_head.owner = self;
1229 self.takedamage = DAMAGE_NO;
1230 self.bot_attack = true;
1231 self.iscreature = true;
1232 self.teleportable = false; // no teleporting for vehicles, too buggy
1233 self.damagedbycontents = true;
1234 self.vehicleid = veh.vehicleid;
1235 self.PlayerPhysplug = veh.PlayerPhysplug;
1236 self.event_damage = func_null;
1237 self.touch = vehicles_touch;
1238 self.think = vehicles_spawn;
1239 self.nextthink = time;
1240 self.effects = EF_NODRAW;
1241 self.dphitcontentsmask = DPCONTENTS_BODY | DPCONTENTS_SOLID;
1243 if(autocvar_g_playerclip_collisions)
1244 self.dphitcontentsmask |= DPCONTENTS_PLAYERCLIP;
1246 if(autocvar_g_nodepthtestplayers)
1247 self.effects |= EF_NODEPTHTEST;
1249 if(autocvar_g_fullbrightplayers)
1250 self.effects |= EF_FULLBRIGHT;
1252 _setmodel(self.vehicle_hudmodel, veh.hud_model);
1253 setmodel(self.vehicle_viewport, MDL_Null);
1255 if(veh.head_model != "")
1257 _setmodel(self.tur_head, veh.head_model);
1258 setattachment(self.tur_head, self, veh.tag_head);
1259 setattachment(self.vehicle_hudmodel, self.tur_head, veh.tag_hud);
1260 setattachment(self.vehicle_viewport, self.vehicle_hudmodel, veh.tag_view);
1264 setattachment(self.tur_head, self, "");
1265 setattachment(self.vehicle_hudmodel, self, veh.tag_hud);
1266 setattachment(self.vehicle_viewport, self.vehicle_hudmodel, veh.tag_view);
1269 setsize(self, veh.mins, veh.maxs);
1273 setorigin(self, self.origin);
1274 tracebox(self.origin + '0 0 100', veh.mins, veh.maxs, self.origin - '0 0 10000', MOVE_WORLDONLY, self);
1275 setorigin(self, trace_endpos);
1278 self.pos1 = self.origin;
1279 self.pos2 = self.angles;
1280 self.tur_head.team = self.team;
1282 Vehicle info = Vehicles_from(veh.vehicleid);
1283 info.vr_setup(info, veh);
1285 if(self.active == ACTIVE_NOT)
1286 self.nextthink = 0; // wait until activated
1287 else if(autocvar_g_vehicles_delayspawn)
1288 self.nextthink = time + self.respawntime + (random() * autocvar_g_vehicles_delayspawn_jitter);
1290 self.nextthink = time + game_starttime;
1292 if(MUTATOR_CALLHOOK(VehicleSpawn))