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 WriteByte(MSG_ENTITY, ENT_CLIENT_AUXILIARYXHAIR);
45 WriteByte(MSG_ENTITY, self.cnt);
47 WriteCoord(MSG_ENTITY, self.origin_x);
48 WriteCoord(MSG_ENTITY, self.origin_y);
49 WriteCoord(MSG_ENTITY, self.origin_z);
51 WriteByte(MSG_ENTITY, rint(self.colormod_x * 255));
52 WriteByte(MSG_ENTITY, rint(self.colormod_y * 255));
53 WriteByte(MSG_ENTITY, rint(self.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 WriteByte(MSG_ONE, SVC_TEMPENTITY);
91 WriteByte(MSG_ONE, TE_CSQC_VEHICLESETUP);
92 WriteByte(MSG_ONE, vehicle_id);
95 vector targetdrone_getnewspot()
99 for(i = 0; i < 100; ++i)
101 spot = self.origin + randomvec() * 1024;
102 tracebox(spot, self.mins, self.maxs, spot, MOVE_NORMAL, self);
103 if(trace_fraction == 1.0 && trace_startsolid == 0 && trace_allsolid == 0)
109 void vehicles_locktarget(float incr, float decr, float _lock_time)
111 if(self.lock_target && self.lock_target.deadflag != DEAD_NO)
113 self.lock_target = world;
114 self.lock_strength = 0;
118 if(self.lock_time > time)
121 if(self.lock_soundtime < time)
123 self.lock_soundtime = time + 0.5;
124 play2(self.owner, "vehicles/locked.wav");
130 if(trace_ent != world)
132 if(SAME_TEAM(trace_ent, self))
135 if(trace_ent.deadflag != DEAD_NO)
138 if(!(IS_VEHICLE(trace_ent) || IS_TURRET(trace_ent)))
141 if(trace_ent.alpha <= 0.5 && trace_ent.alpha != 0)
142 trace_ent = world; // invisible
145 if(self.lock_target == world && trace_ent != world)
146 self.lock_target = trace_ent;
148 if(self.lock_target && trace_ent == self.lock_target)
150 if(self.lock_strength != 1 && self.lock_strength + incr >= 1)
152 play2(self.owner, "vehicles/lock.wav");
153 self.lock_soundtime = time + 0.8;
155 else if (self.lock_strength != 1 && self.lock_soundtime < time)
157 play2(self.owner, "vehicles/locking.wav");
158 self.lock_soundtime = time + 0.3;
162 // Have a locking target
163 // Trace hit current target
164 if(trace_ent == self.lock_target && trace_ent != world)
166 self.lock_strength = min(self.lock_strength + incr, 1);
167 if(self.lock_strength == 1)
168 self.lock_time = time + _lock_time;
173 self.lock_strength = max(self.lock_strength - decr * 2, 0);
175 self.lock_strength = max(self.lock_strength - decr, 0);
177 if(self.lock_strength == 0)
178 self.lock_target = world;
182 vector vehicles_force_fromtag_hover(string tag_name, float spring_length, float max_power)
184 force_fromtag_origin = gettaginfo(self, gettagindex(self, tag_name));
185 v_forward = normalize(v_forward) * -1;
186 traceline(force_fromtag_origin, force_fromtag_origin - (v_forward * spring_length), MOVE_NORMAL, self);
188 force_fromtag_power = (1 - trace_fraction) * max_power;
189 force_fromtag_normpower = force_fromtag_power / max_power;
191 return v_forward * force_fromtag_power;
194 vector vehicles_force_fromtag_maglev(string tag_name, float spring_length, float max_power)
197 force_fromtag_origin = gettaginfo(self, gettagindex(self, tag_name));
198 v_forward = normalize(v_forward) * -1;
199 traceline(force_fromtag_origin, force_fromtag_origin - (v_forward * spring_length), MOVE_NORMAL, self);
201 // TODO - this may NOT be compatible with wall/celing movement, unhardcode 0.25 (engine count multiplier)
202 if(trace_fraction == 1.0)
204 force_fromtag_normpower = -0.25;
208 force_fromtag_power = ((1 - trace_fraction) - trace_fraction) * max_power;
209 force_fromtag_normpower = force_fromtag_power / max_power;
211 return v_forward * force_fromtag_power;
214 // projectile handling
215 void vehicles_projectile_damage(entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force)
217 // Ignore damage from oterh projectiles from my owner (dont mess up volly's)
218 if(inflictor.owner == self.owner)
221 self.health -= damage;
222 self.velocity += force;
225 self.takedamage = DAMAGE_NO;
226 self.event_damage = func_null;
227 self.think = self.use;
228 self.nextthink = time;
232 void vehicles_projectile_explode()
234 if(self.owner && other != world)
236 if(other == self.owner.vehicle)
239 if(other == self.owner.vehicle.tur_head)
245 self.event_damage = func_null;
246 RadiusDamage (self, self.realowner, self.shot_dmg, 0, self.shot_radius, self, world, self.shot_force, self.totalfrags, other);
251 entity vehicles_projectile(string _mzlfx, string _mzlsound,
252 vector _org, vector _vel,
253 float _dmg, float _radi, float _force, float _size,
254 int _deahtype, float _projtype, float _health,
255 bool _cull, bool _clianim, entity _owner)
261 PROJECTILE_MAKETRIGGER(proj);
262 setorigin(proj, _org);
264 proj.shot_dmg = _dmg;
265 proj.shot_radius = _radi;
266 proj.shot_force = _force;
267 proj.totalfrags = _deahtype;
268 proj.solid = SOLID_BBOX;
269 proj.movetype = MOVETYPE_FLYMISSILE;
270 proj.flags = FL_PROJECTILE;
271 proj.bot_dodge = true;
272 proj.bot_dodgerating = _dmg;
273 proj.velocity = _vel;
274 proj.touch = vehicles_projectile_explode;
275 proj.use = vehicles_projectile_explode;
277 proj.realowner = _owner;
278 proj.think = SUB_Remove;
279 proj.nextthink = time + 30;
283 proj.takedamage = DAMAGE_AIM;
284 proj.event_damage = vehicles_projectile_damage;
285 proj.health = _health;
288 proj.flags = FL_PROJECTILE | FL_NOTARGET;
291 _sound (self, CH_WEAPON_A, _mzlsound, VOL_BASE, ATTEN_NORM);
294 Send_Effect_(_mzlfx, proj.origin, proj.velocity, 1);
296 setsize (proj, '-1 -1 -1' * _size, '1 1 1' * _size);
298 CSQCProjectile(proj, _clianim, _projtype, _cull);
303 void vehicles_gib_explode()
305 sound (self, CH_SHOTS, SND_ROCKET_IMPACT, VOL_BASE, ATTEN_NORM);
306 Send_Effect(EFFECT_EXPLOSION_SMALL, randomvec() * 80 + (self.origin + '0 0 100'), '0 0 0', 1);
307 Send_Effect(EFFECT_EXPLOSION_SMALL, self.wp00.origin + '0 0 64', '0 0 0', 1);
311 void vehicles_gib_think()
317 self.nextthink = time + 0.1;
320 entity vehicle_tossgib(entity _template, vector _vel, string _tag, bool _burn, bool _explode, float _maxtime, vector _rot)
322 entity _gib = spawn();
323 _setmodel(_gib, _template.model);
324 setorigin(_gib, gettaginfo(self, gettagindex(self, _tag)));
325 _gib.velocity = _vel;
326 _gib.movetype = MOVETYPE_TOSS;
327 _gib.solid = SOLID_CORPSE;
328 _gib.colormod = '-0.5 -0.5 -0.5';
329 _gib.effects = EF_LOWPRECISION;
330 _gib.avelocity = _rot;
333 _gib.effects |= EF_FLAME;
337 _gib.think = vehicles_gib_explode;
338 _gib.nextthink = time + random() * _explode;
339 _gib.touch = vehicles_gib_explode;
343 _gib.cnt = time + _maxtime;
344 _gib.think = vehicles_gib_think;
345 _gib.nextthink = time + _maxtime - 1;
351 bool vehicle_addplayerslot( entity _owner,
356 void(bool) _exitfunc, float() _enterfunc)
358 if(!(_owner.vehicle_flags & VHF_MULTISLOT))
359 _owner.vehicle_flags |= VHF_MULTISLOT;
361 _slot.PlayerPhysplug = _framefunc;
362 _slot.vehicle_exit = _exitfunc;
363 _slot.vehicle_enter = _enterfunc;
365 _slot.vehicle_flags = VHF_PLAYERSLOT;
366 _slot.vehicle_viewport = spawn();
367 _slot.vehicle_hudmodel = spawn();
368 _slot.vehicle_hudmodel.viewmodelforclient = _slot;
369 _slot.vehicle_viewport.effects = (EF_ADDITIVE | EF_DOUBLESIDED | EF_FULLBRIGHT | EF_NODEPTHTEST | EF_NOGUNBOB | EF_NOSHADOW | EF_LOWPRECISION | EF_SELECTABLE | EF_TELEPORT_BIT);
371 _setmodel(_slot.vehicle_hudmodel, _hud_model);
372 setmodel(_slot.vehicle_viewport, MDL_Null);
374 setattachment(_slot.vehicle_hudmodel, _slot, "");
375 setattachment(_slot.vehicle_viewport, _slot.vehicle_hudmodel, "");
380 vector vehicle_aimturret(entity _vehic, vector _target, entity _turrret, string _tagname,
381 float _pichlimit_min, float _pichlimit_max,
382 float _rotlimit_min, float _rotlimit_max, float _aimspeed)
386 vtag = gettaginfo(_turrret, gettagindex(_turrret, _tagname));
387 vtmp = vectoangles(normalize(_target - vtag));
388 vtmp = AnglesTransform_ToAngles(AnglesTransform_LeftDivide(AnglesTransform_FromAngles(_vehic.angles), AnglesTransform_FromAngles(vtmp))) - _turrret.angles;
389 vtmp = AnglesTransform_Normalize(vtmp, true);
390 ftmp = _aimspeed * frametime;
391 vtmp_y = bound(-ftmp, vtmp_y, ftmp);
392 vtmp_x = bound(-ftmp, vtmp_x, ftmp);
393 _turrret.angles_y = bound(_rotlimit_min, _turrret.angles_y + vtmp_y, _rotlimit_max);
394 _turrret.angles_x = bound(_pichlimit_min, _turrret.angles_x + vtmp_x, _pichlimit_max);
398 void vehicles_reset_colors()
401 float _effects = 0, _colormap;
402 vector _glowmod, _colormod;
404 if(autocvar_g_nodepthtestplayers)
405 _effects |= EF_NODEPTHTEST;
407 if(autocvar_g_fullbrightplayers)
408 _effects |= EF_FULLBRIGHT;
411 _colormap = 1024 + (self.team - 1) * 17;
418 // Find all ents attacked to main model and setup effects, colormod etc.
419 e = findchainentity(tag_entity, self);
422 if(e != self.vehicle_shieldent)
424 e.effects = _effects; // | EF_LOWPRECISION;
425 e.colormod = _colormod;
426 e.colormap = _colormap;
431 // Also check head tags
432 e = findchainentity(tag_entity, self.tur_head);
435 if(e != self.vehicle_shieldent)
437 e.effects = _effects; // | EF_LOWPRECISION;
438 e.colormod = _colormod;
439 e.colormap = _colormap;
445 self.vehicle_hudmodel.effects = self.effects = _effects; // | EF_LOWPRECISION;
446 self.vehicle_hudmodel.colormod = self.colormod = _colormod;
447 self.vehicle_hudmodel.colormap = self.colormap = _colormap;
448 self.vehicle_viewport.effects = (EF_ADDITIVE | EF_DOUBLESIDED | EF_FULLBRIGHT | EF_NODEPTHTEST | EF_NOGUNBOB | EF_NOSHADOW | EF_LOWPRECISION | EF_SELECTABLE | EF_TELEPORT_BIT);
451 self.avelocity = '0 0 0';
452 self.velocity = '0 0 0';
453 self.effects = _effects;
456 void vehicles_clearreturn(entity veh)
459 // Remove "return helper", if any.
460 ret = findchain(classname, "vehicle_return");
466 ret.think = SUB_Remove;
467 ret.nextthink = time + 0.1;
469 if(ret.waypointsprite_attached)
470 WaypointSprite_Kill(ret.waypointsprite_attached);
478 void vehicles_spawn();
479 void vehicles_return()
481 Send_Effect(EFFECT_TELEPORT, self.wp00.origin + '0 0 64', '0 0 0', 1);
483 self.wp00.think = vehicles_spawn;
484 self.wp00.nextthink = time;
486 if(self.waypointsprite_attached)
487 WaypointSprite_Kill(self.waypointsprite_attached);
492 void vehicles_showwp_goaway()
494 if(self.waypointsprite_attached)
495 WaypointSprite_Kill(self.waypointsprite_attached);
501 void vehicles_showwp()
503 entity oldself = world;
508 self.think = vehicles_return;
509 self.nextthink = self.cnt;
513 self.think = vehicles_return;
514 self.nextthink = time +1;
518 setmodel(self, MDL_Null);
519 self.team = oldself.wp00.team;
520 self.wp00 = oldself.wp00;
521 setorigin(self, oldself.wp00.pos1);
523 self.nextthink = time + 5;
524 self.think = vehicles_showwp_goaway;
527 if(teamplay && self.team)
528 rgb = Team_ColorRGB(self.team);
531 entity wp = WaypointSprite_Spawn(WP_Vehicle, 0, 0, self, '0 0 64', world, 0, self, waypointsprite_attached, true, RADARICON_Vehicle);
533 if(self.waypointsprite_attached)
535 WaypointSprite_UpdateRule(self.waypointsprite_attached, self.wp00.team, SPRITERULE_DEFAULT);
537 WaypointSprite_UpdateBuildFinished(self.waypointsprite_attached, self.nextthink);
538 WaypointSprite_Ping(self.waypointsprite_attached);
545 void vehicles_setreturn(entity veh)
549 vehicles_clearreturn(veh);
552 ret.classname = "vehicle_return";
555 ret.think = vehicles_showwp;
557 if(veh.deadflag != DEAD_NO)
559 ret.cnt = time + veh.respawntime;
560 ret.nextthink = min(time + veh.respawntime, time + veh.respawntime - 5);
564 ret.nextthink = min(time + veh.respawntime, time + veh.respawntime - 1);
567 setmodel(ret, MDL_Null);
568 setorigin(ret, veh.pos1 + '0 0 96');
574 LOG_TRACE("vehicle ",self.netname, " used by ", activator.classname, "\n");
576 self.tur_head.team = activator.team;
578 if(self.tur_head.team == 0)
579 self.active = ACTIVE_NOT;
581 self.active = ACTIVE_ACTIVE;
583 if(self.active == ACTIVE_ACTIVE && self.deadflag == DEAD_NO && !gameover)
585 LOG_TRACE("Respawning vehicle: ", self.netname, "\n");
586 if(self.effects & EF_NODRAW)
588 self.think = vehicles_spawn;
589 self.nextthink = time + 3;
593 vehicles_setreturn(self);
594 vehicles_reset_colors();
599 void vehicles_regen(float timer, .float regen_field, float field_max, float rpause, float regen, float delta_time, float _healthscale)
601 if(self.(regen_field) < field_max)
602 if(timer + rpause < time)
605 regen = regen * (self.vehicle_health / self.max_health);
607 self.(regen_field) = min(self.(regen_field) + regen * delta_time, field_max);
610 self.owner.(regen_field) = (self.(regen_field) / field_max) * 100;
614 void shieldhit_think()
619 // setmodel(self, MDL_Null);
621 self.effects |= EF_NODRAW;
625 self.nextthink = time + 0.1;
629 void vehicles_painframe()
631 if(self.owner.vehicle_health <= 50)
632 if(self.pain_frame < time)
635 _ftmp = self.owner.vehicle_health / 50;
636 self.pain_frame = time + 0.1 + (random() * 0.5 * _ftmp);
637 pointparticles(particleeffectnum(EFFECT_SMOKE_SMALL), (self.origin + (randomvec() * 80)), '0 0 0', 1);
639 if(self.vehicle_flags & VHF_DMGSHAKE)
640 self.velocity += randomvec() * 30;
642 if(self.vehicle_flags & VHF_DMGROLL)
643 if(self.vehicle_flags & VHF_DMGHEADROLL)
644 self.tur_head.angles += randomvec();
646 self.angles += randomvec();
651 void vehicles_damage(entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force)
653 self.dmg_time = time;
656 if(DEATH_ISWEAPON(deathtype, WEP_VORTEX.m_id))
657 damage *= autocvar_g_vehicles_vortex_damagerate;
659 if(DEATH_ISWEAPON(deathtype, WEP_MACHINEGUN.m_id))
660 damage *= autocvar_g_vehicles_machinegun_damagerate;
662 if(DEATH_ISWEAPON(deathtype, WEP_RIFLE.m_id))
663 damage *= autocvar_g_vehicles_rifle_damagerate;
665 if(DEATH_ISWEAPON(deathtype, WEP_VAPORIZER.m_id))
666 damage *= autocvar_g_vehicles_vaporizer_damagerate;
668 if(DEATH_ISWEAPON(deathtype, WEP_SEEKER.m_id))
669 damage *= autocvar_g_vehicles_tag_damagerate;
671 if(DEATH_WEAPONOFWEAPONDEATH(deathtype))
672 damage *= autocvar_g_vehicles_weapon_damagerate;
674 self.enemy = attacker;
676 self.pain_finished = time;
678 if((self.vehicle_flags & VHF_HASSHIELD) && (self.vehicle_shield > 0))
680 if (wasfreed(self.vehicle_shieldent) || self.vehicle_shieldent == world)
682 self.vehicle_shieldent = spawn();
683 self.vehicle_shieldent.effects = EF_LOWPRECISION;
685 setmodel(self.vehicle_shieldent, MDL_VEH_SHIELD);
686 setattachment(self.vehicle_shieldent, self, "");
687 setorigin(self.vehicle_shieldent, real_origin(self) - self.origin);
688 self.vehicle_shieldent.scale = 256 / vlen(self.maxs - self.mins);
689 self.vehicle_shieldent.think = shieldhit_think;
692 self.vehicle_shieldent.colormod = '1 1 1';
693 self.vehicle_shieldent.alpha = 0.45;
694 self.vehicle_shieldent.angles = vectoangles(normalize(hitloc - (self.origin + self.vehicle_shieldent.origin))) - self.angles;
695 self.vehicle_shieldent.nextthink = time;
696 self.vehicle_shieldent.effects &= ~EF_NODRAW;
698 self.vehicle_shield -= damage;
700 if(self.vehicle_shield < 0)
702 self.vehicle_health -= fabs(self.vehicle_shield);
703 self.vehicle_shieldent.colormod = '2 0 0';
704 self.vehicle_shield = 0;
705 self.vehicle_shieldent.alpha = 0.75;
707 if(sound_allowed(MSG_BROADCAST, attacker))
708 spamsound (self, CH_PAIN, "onslaught/ons_hit2.wav", VOL_BASE, ATTEN_NORM); // FIXME: PLACEHOLDER
711 if(sound_allowed(MSG_BROADCAST, attacker))
712 spamsound (self, CH_PAIN, "onslaught/electricity_explode.wav", VOL_BASE, ATTEN_NORM); // FIXME: PLACEHOLDER
717 self.vehicle_health -= damage;
719 if(sound_allowed(MSG_BROADCAST, attacker))
720 spamsound (self, CH_PAIN, "onslaught/ons_hit2.wav", VOL_BASE, ATTEN_NORM); // FIXME: PLACEHOLDER
723 if(self.damageforcescale < 1 && self.damageforcescale > 0)
724 self.velocity += force * self.damageforcescale;
726 self.velocity += force;
728 if(self.vehicle_health <= 0)
731 if(self.vehicle_flags & VHF_DEATHEJECT)
732 vehicles_exit(VHEF_EJECT);
734 vehicles_exit(VHEF_RELEASE);
739 Vehicle info = get_vehicleinfo(self.vehicleid);
741 vehicles_setreturn(self);
745 float vehicles_crushable(entity e)
747 if(IS_PLAYER(e) && time >= e.vehicle_enter_delay)
756 void vehicles_impact(float _minspeed, float _speedfac, float _maxpain)
758 if (trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT)
761 if(self.play_time < time)
763 float wc = vlen(self.velocity - self.oldvelocity);
764 //dprint("oldvel: ", vtos(self.oldvelocity), "\n");
765 //dprint("vel: ", vtos(self.velocity), "\n");
768 float take = min(_speedfac * wc, _maxpain);
769 Damage (self, world, world, take, DEATH_FALL, self.origin, '0 0 0');
770 self.play_time = time + 0.25;
772 //dprint("wc: ", ftos(wc), "\n");
773 //dprint("take: ", ftos(take), "\n");
778 // vehicle enter/exit handling
779 vector vehicles_findgoodexit(vector prefer_spot)
784 tracebox(self.origin + '0 0 32', PL_MIN, PL_MAX, prefer_spot, MOVE_NORMAL, self.owner);
785 if(trace_fraction == 1.0 && !trace_startsolid && !trace_allsolid)
788 mysize = 1.5 * vlen(self.maxs - self.mins);
791 v2 = 0.5 * (self.absmin + self.absmax);
792 for(i = 0; i < 100; ++i)
796 v = v2 + normalize(v) * mysize;
797 tracebox(v2, PL_MIN, PL_MAX, v, MOVE_NORMAL, self.owner);
798 if(trace_fraction == 1.0 && !trace_startsolid && !trace_allsolid)
803 exitspot = (self.origin + '0 0 48') + v_forward * mysize;
804 tracebox(self.origin + '0 0 32', PL_MIN, PL_MAX, exitspot, MOVE_NORMAL, self.owner);
805 if(trace_fraction == 1.0 && !trace_startsolid && !trace_allsolid)
808 exitspot = (self.origin + '0 0 48') - v_forward * mysize;
809 tracebox(self.origin + '0 0 32', PL_MIN, PL_MAX, exitspot, MOVE_NORMAL, self.owner);
810 if(trace_fraction == 1.0 && !trace_startsolid && !trace_allsolid)
813 exitspot = (self.origin + '0 0 48') + v_right * mysize;
814 tracebox(self.origin + '0 0 32', PL_MIN, PL_MAX, exitspot, MOVE_NORMAL, self.owner);
815 if(trace_fraction == 1.0 && !trace_startsolid && !trace_allsolid)
818 exitspot = (self.origin + '0 0 48') - v_right * mysize;
819 tracebox(self.origin + '0 0 32', PL_MIN, PL_MAX, exitspot, MOVE_NORMAL, self.owner);
820 if(trace_fraction == 1.0 && !trace_startsolid && !trace_allsolid)
827 void vehicles_exit(bool eject)
832 if(vehicles_exit_running)
834 LOG_TRACE("^1vehicles_exit allready running! this is not good..\n");
838 vehicles_exit_running = true;
841 _vehicle = self.vehicle;
843 if (_vehicle.vehicle_flags & VHF_PLAYERSLOT)
845 _vehicle.vehicle_exit(eject);
847 vehicles_exit_running = false;
854 _player = _vehicle.owner;
860 if (IS_REAL_CLIENT(_player))
862 msg_entity = _player;
863 WriteByte (MSG_ONE, SVC_SETVIEWPORT);
864 WriteEntity( MSG_ONE, _player);
866 WriteByte (MSG_ONE, SVC_SETVIEWANGLES);
867 WriteAngle(MSG_ONE, 0);
868 WriteAngle(MSG_ONE, _vehicle.angles_y);
869 WriteAngle(MSG_ONE, 0);
872 setsize(_player, PL_MIN,PL_MAX);
874 _player.takedamage = DAMAGE_AIM;
875 _player.solid = SOLID_SLIDEBOX;
876 _player.movetype = MOVETYPE_WALK;
877 _player.effects &= ~EF_NODRAW;
878 _player.teleportable = TELEPORT_NORMAL;
880 _player.PlayerPhysplug = func_null;
881 _player.vehicle = world;
882 _player.view_ofs = PL_VIEW_OFS;
883 _player.event_damage = PlayerDamage;
884 _player.hud = HUD_NORMAL;
885 _player.switchweapon = _vehicle.switchweapon;
886 _player.last_vehiclecheck = time + 3;
887 _player.vehicle_enter_delay = time + 2;
889 CSQCVehicleSetup(_player, HUD_NORMAL);
891 _vehicle.flags |= FL_NOTARGET;
893 if(_vehicle.deadflag == DEAD_NO)
894 _vehicle.avelocity = '0 0 0';
896 _vehicle.tur_head.nodrawtoclient = world;
901 Kill_Notification(NOTIF_ONE, _player, MSG_CENTER_CPID, CPID_VEHICLES);
902 Kill_Notification(NOTIF_ONE, _player, MSG_CENTER_CPID, CPID_VEHICLES_OTHER); // kill all vehicle notifications when exiting a vehicle?
904 WaypointSprite_Kill(_vehicle.wps_intruder);
906 MUTATOR_CALLHOOK(VehicleExit, _player, _vehicle);
908 _vehicle.team = _vehicle.tur_head.team;
910 sound (_vehicle, CH_TRIGGER_SINGLE, SND_Null, 1, ATTEN_NORM);
911 _vehicle.vehicle_hudmodel.viewmodelforclient = _vehicle;
912 _vehicle.phase = time + 1;
914 _vehicle.vehicle_exit(eject);
916 vehicles_setreturn(_vehicle);
917 vehicles_reset_colors();
918 _vehicle.owner = world;
920 CSQCMODEL_AUTOINIT(self);
923 vehicles_exit_running = false;
926 void vehicles_touch()
928 if(MUTATOR_CALLHOOK(VehicleTouch, self, other))
931 // Vehicle currently in use
934 if(!forbidWeaponUse(self.owner))
936 if((self.origin_z + self.maxs_z) > (other.origin_z))
937 if(vehicles_crushable(other))
939 if(vlen(self.velocity) >= 30)
940 Damage(other, self, self.owner, autocvar_g_vehicles_crush_dmg, DEATH_VH_CRUSH, '0 0 0', normalize(other.origin - self.origin) * autocvar_g_vehicles_crush_force);
942 return; // Dont do selfdamage when hitting "soft targets".
945 if(self.play_time < time) {
946 Vehicle info = get_vehicleinfo(self.vehicleid);
947 info.vr_impact(info);
953 if(autocvar_g_vehicles_enter)
956 vehicles_enter(other, self);
959 bool vehicle_impulse(int imp)
965 stuffcmd(self, "\ntoggle cl_eventchase_vehicle\nset _vehicles_shownchasemessage 1\n");
973 void vehicles_enter(entity pl, entity veh)
975 // Remove this when bots know how to use vehicles
976 if((IS_BOT_CLIENT(pl) && !autocvar_g_vehicles_allow_bots))
980 || (veh.phase >= time)
981 || (pl.vehicle_enter_delay >= time)
983 || (pl.deadflag != DEAD_NO)
987 if(autocvar_g_vehicles_enter) // vehicle's touch function should handle this if entering via use key is disabled (TODO)
988 if(veh.vehicle_flags & VHF_MULTISLOT)
992 other = pl; // TODO: fix
995 if(time >= veh.gun1.phase)
996 if(veh.gun1.vehicle_enter)
997 if(veh.gun1.vehicle_enter())
1004 if(time >= veh.gun2.phase)
1005 if(veh.gun2.vehicle_enter)
1006 if(veh.gun2.vehicle_enter())
1017 if(DIFF_TEAM(pl, veh))
1018 if(autocvar_g_vehicles_steal)
1021 FOR_EACH_PLAYER(head) if(SAME_TEAM(head, veh))
1022 Send_Notification(NOTIF_ONE, head, MSG_CENTER, CENTER_VEHICLE_STEAL);
1024 Send_Notification(NOTIF_ONE, pl, MSG_CENTER, CENTER_VEHICLE_STEAL_SELF);
1026 if (autocvar_g_vehicles_steal_show_waypoint) {
1027 entity wp = WaypointSprite_Spawn(WP_VehicleIntruder, 0, 0, pl, '0 0 68', world, veh.team, veh, wps_intruder, true, RADARICON_DANGER);
1028 wp.colormod = Team_ColorRGB(pl.team);
1033 RemoveGrapplingHook(pl);
1035 veh.vehicle_ammo1 = 0;
1036 veh.vehicle_ammo2 = 0;
1037 veh.vehicle_reload1 = 0;
1038 veh.vehicle_reload2 = 0;
1039 veh.vehicle_energy = 0;
1044 // .viewmodelforclient works better.
1045 //veh.vehicle_hudmodel.drawonlytoclient = veh.owner;
1047 veh.vehicle_hudmodel.viewmodelforclient = pl;
1049 tracebox(pl.origin, PL_MIN, PL_MAX, pl.origin, false, pl);
1051 pl.view_ofs = PL_VIEW_OFS;
1052 setsize (pl, PL_MIN, PL_MAX);
1054 veh.event_damage = vehicles_damage;
1056 pl.angles = veh.angles;
1057 pl.takedamage = DAMAGE_NO;
1058 pl.solid = SOLID_NOT;
1059 pl.movetype = MOVETYPE_NOCLIP;
1060 pl.teleportable = false;
1062 pl.event_damage = func_null;
1063 pl.view_ofs = '0 0 0';
1064 veh.colormap = pl.colormap;
1066 veh.tur_head.colormap = pl.colormap;
1067 veh.switchweapon = pl.switchweapon;
1068 pl.hud = veh.vehicleid;
1069 pl.PlayerPhysplug = veh.PlayerPhysplug;
1071 pl.vehicle_ammo1 = veh.vehicle_ammo1;
1072 pl.vehicle_ammo2 = veh.vehicle_ammo2;
1073 pl.vehicle_reload1 = veh.vehicle_reload1;
1074 pl.vehicle_reload2 = veh.vehicle_reload2;
1075 pl.vehicle_energy = veh.vehicle_energy;
1077 // Cant do this, hides attached objects too.
1078 //veh.exteriormodeltoclient = veh.owner;
1079 //veh.tur_head.exteriormodeltoclient = veh.owner;
1081 pl.flags &= ~FL_ONGROUND;
1082 veh.flags &= ~FL_ONGROUND;
1085 veh.flags -= FL_NOTARGET;
1087 if (IS_REAL_CLIENT(pl))
1089 Send_Notification(NOTIF_ONE, pl, MSG_CENTER, CENTER_VEHICLE_ENTER);
1092 WriteByte (MSG_ONE, SVC_SETVIEWPORT);
1093 WriteEntity(MSG_ONE, veh.vehicle_viewport);
1095 WriteByte (MSG_ONE, SVC_SETVIEWANGLES);
1098 WriteAngle(MSG_ONE, veh.tur_head.angles_x + veh.angles_x); // tilt
1099 WriteAngle(MSG_ONE, veh.tur_head.angles_y + veh.angles_y); // yaw
1100 WriteAngle(MSG_ONE, 0); // roll
1104 WriteAngle(MSG_ONE, veh.angles_x * -1); // tilt
1105 WriteAngle(MSG_ONE, veh.angles_y); // yaw
1106 WriteAngle(MSG_ONE, 0); // roll
1110 vehicles_clearreturn(veh);
1112 CSQCVehicleSetup(pl, veh.vehicleid);
1114 MUTATOR_CALLHOOK(VehicleEnter, pl, veh);
1117 CSQCModel_UnlinkEntity(veh);
1118 Vehicle info = get_vehicleinfo(veh.vehicleid);
1119 info.vr_enter(info);
1125 void vehicles_think()
1127 self.nextthink = time;
1130 self.owner.vehicle_weapon2mode = self.vehicle_weapon2mode;
1132 Vehicle info = get_vehicleinfo(self.vehicleid);
1133 info.vr_think(info);
1135 CSQCMODEL_AUTOUPDATE(self);
1139 void vehicles_spawn()
1141 LOG_TRACE("Spawning vehicle: ", self.classname, "\n");
1144 self.vehicle_hudmodel.viewmodelforclient = self;
1147 self.touch = vehicles_touch;
1148 self.event_damage = vehicles_damage;
1149 self.iscreature = true;
1150 self.teleportable = false; // no teleporting for vehicles, too buggy
1151 self.damagedbycontents = true;
1152 self.movetype = MOVETYPE_WALK;
1153 self.solid = SOLID_SLIDEBOX;
1154 self.takedamage = DAMAGE_AIM;
1155 self.deadflag = DEAD_NO;
1156 self.bot_attack = true;
1157 self.flags = FL_NOTARGET;
1158 self.avelocity = '0 0 0';
1159 self.velocity = '0 0 0';
1160 self.think = vehicles_think;
1161 self.nextthink = time;
1164 self.lock_strength = 0;
1165 self.lock_target = world;
1166 self.misc_bulletcounter = 0;
1169 self.angles = self.pos2;
1170 setorigin(self, self.pos1);
1172 Send_Effect(EFFECT_TELEPORT, self.origin + '0 0 64', '0 0 0', 1);
1174 if(self.vehicle_controller)
1175 self.team = self.vehicle_controller.team;
1177 entity head; // remove hooks (if any)
1178 FOR_EACH_PLAYER(head)
1179 if(head.hook.aiment == self)
1180 RemoveGrapplingHook(head);
1182 vehicles_reset_colors();
1184 Vehicle info = get_vehicleinfo(self.vehicleid);
1185 info.vr_spawn(info);
1187 CSQCMODEL_AUTOINIT(self);
1190 bool vehicle_initialize(entity veh, bool nodrop)
1192 if(!autocvar_g_vehicles)
1199 Vehicle info = get_vehicleinfo(veh.vehicleid);
1200 info.vr_precache(info);
1203 if(self.targetname && self.targetname != "")
1205 self.vehicle_controller = find(world, target, self.targetname);
1206 if(!self.vehicle_controller)
1208 bprint("^1WARNING: ^7Vehicle with invalid .targetname\n");
1209 self.active = ACTIVE_ACTIVE;
1213 self.team = self.vehicle_controller.team;
1214 self.use = vehicle_use;
1218 if(self.vehicle_controller.team == 0)
1219 self.active = ACTIVE_NOT;
1221 self.active = ACTIVE_ACTIVE;
1225 else { self.active = ACTIVE_ACTIVE; }
1227 if(self.team && (!teamplay || !autocvar_g_vehicles_teams))
1230 if(self.mdl == "" || !self.mdl)
1231 _setmodel(self, veh.model);
1233 _setmodel(self, self.mdl);
1235 self.vehicle_flags |= VHF_ISVEHICLE;
1237 self.vehicle_viewport = spawn();
1238 self.vehicle_hudmodel = spawn();
1239 self.tur_head = spawn();
1240 self.tur_head.owner = self;
1241 self.takedamage = DAMAGE_NO;
1242 self.bot_attack = true;
1243 self.iscreature = true;
1244 self.teleportable = false; // no teleporting for vehicles, too buggy
1245 self.damagedbycontents = true;
1246 self.vehicleid = veh.vehicleid;
1247 self.PlayerPhysplug = veh.PlayerPhysplug;
1248 self.event_damage = func_null;
1249 self.touch = vehicles_touch;
1250 self.think = vehicles_spawn;
1251 self.nextthink = time;
1252 self.effects = EF_NODRAW;
1253 self.dphitcontentsmask = DPCONTENTS_BODY | DPCONTENTS_SOLID;
1255 if(autocvar_g_playerclip_collisions)
1256 self.dphitcontentsmask |= DPCONTENTS_PLAYERCLIP;
1258 if(autocvar_g_nodepthtestplayers)
1259 self.effects |= EF_NODEPTHTEST;
1261 if(autocvar_g_fullbrightplayers)
1262 self.effects |= EF_FULLBRIGHT;
1264 _setmodel(self.vehicle_hudmodel, veh.hud_model);
1265 setmodel(self.vehicle_viewport, MDL_Null);
1267 if(veh.head_model != "")
1269 _setmodel(self.tur_head, veh.head_model);
1270 setattachment(self.tur_head, self, veh.tag_head);
1271 setattachment(self.vehicle_hudmodel, self.tur_head, veh.tag_hud);
1272 setattachment(self.vehicle_viewport, self.vehicle_hudmodel, veh.tag_view);
1276 setattachment(self.tur_head, self, "");
1277 setattachment(self.vehicle_hudmodel, self, veh.tag_hud);
1278 setattachment(self.vehicle_viewport, self.vehicle_hudmodel, veh.tag_view);
1281 setsize(self, veh.mins, veh.maxs);
1285 setorigin(self, self.origin);
1286 tracebox(self.origin + '0 0 100', veh.mins, veh.maxs, self.origin - '0 0 10000', MOVE_WORLDONLY, self);
1287 setorigin(self, trace_endpos);
1290 self.pos1 = self.origin;
1291 self.pos2 = self.angles;
1292 self.tur_head.team = self.team;
1294 Vehicle info = get_vehicleinfo(veh.vehicleid);
1295 info.vr_setup(info);
1297 if(self.active == ACTIVE_NOT)
1298 self.nextthink = 0; // wait until activated
1299 else if(autocvar_g_vehicles_delayspawn)
1300 self.nextthink = time + self.respawntime + (random() * autocvar_g_vehicles_delayspawn_jitter);
1302 self.nextthink = time + game_starttime;
1304 if(MUTATOR_CALLHOOK(VehicleSpawn))