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, 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 WriteHeader(MSG_ONE, TE_CSQC_VEHICLESETUP);
91 WriteByte(MSG_ONE, vehicle_id);
94 vector targetdrone_getnewspot()
98 for(i = 0; i < 100; ++i)
100 spot = self.origin + randomvec() * 1024;
101 tracebox(spot, self.mins, self.maxs, spot, MOVE_NORMAL, self);
102 if(trace_fraction == 1.0 && trace_startsolid == 0 && trace_allsolid == 0)
108 void vehicles_locktarget(float incr, float decr, float _lock_time)
110 if(self.lock_target && self.lock_target.deadflag != DEAD_NO)
112 self.lock_target = world;
113 self.lock_strength = 0;
117 if(self.lock_time > time)
120 if(self.lock_soundtime < time)
122 self.lock_soundtime = time + 0.5;
123 play2(self.owner, "vehicles/locked.wav");
129 if(trace_ent != world)
131 if(SAME_TEAM(trace_ent, self))
134 if(trace_ent.deadflag != DEAD_NO)
137 if(!(IS_VEHICLE(trace_ent) || IS_TURRET(trace_ent)))
140 if(trace_ent.alpha <= 0.5 && trace_ent.alpha != 0)
141 trace_ent = world; // invisible
144 if(self.lock_target == world && trace_ent != world)
145 self.lock_target = trace_ent;
147 if(self.lock_target && trace_ent == self.lock_target)
149 if(self.lock_strength != 1 && self.lock_strength + incr >= 1)
151 play2(self.owner, "vehicles/lock.wav");
152 self.lock_soundtime = time + 0.8;
154 else if (self.lock_strength != 1 && self.lock_soundtime < time)
156 play2(self.owner, "vehicles/locking.wav");
157 self.lock_soundtime = time + 0.3;
161 // Have a locking target
162 // Trace hit current target
163 if(trace_ent == self.lock_target && trace_ent != world)
165 self.lock_strength = min(self.lock_strength + incr, 1);
166 if(self.lock_strength == 1)
167 self.lock_time = time + _lock_time;
172 self.lock_strength = max(self.lock_strength - decr * 2, 0);
174 self.lock_strength = max(self.lock_strength - decr, 0);
176 if(self.lock_strength == 0)
177 self.lock_target = world;
181 vector vehicles_force_fromtag_hover(string tag_name, float spring_length, float max_power)
183 force_fromtag_origin = gettaginfo(self, gettagindex(self, tag_name));
184 v_forward = normalize(v_forward) * -1;
185 traceline(force_fromtag_origin, force_fromtag_origin - (v_forward * spring_length), MOVE_NORMAL, self);
187 force_fromtag_power = (1 - trace_fraction) * max_power;
188 force_fromtag_normpower = force_fromtag_power / max_power;
190 return v_forward * force_fromtag_power;
193 vector vehicles_force_fromtag_maglev(string tag_name, float spring_length, float max_power)
196 force_fromtag_origin = gettaginfo(self, gettagindex(self, tag_name));
197 v_forward = normalize(v_forward) * -1;
198 traceline(force_fromtag_origin, force_fromtag_origin - (v_forward * spring_length), MOVE_NORMAL, self);
200 // TODO - this may NOT be compatible with wall/celing movement, unhardcode 0.25 (engine count multiplier)
201 if(trace_fraction == 1.0)
203 force_fromtag_normpower = -0.25;
207 force_fromtag_power = ((1 - trace_fraction) - trace_fraction) * max_power;
208 force_fromtag_normpower = force_fromtag_power / max_power;
210 return v_forward * force_fromtag_power;
213 // projectile handling
214 void vehicles_projectile_damage(entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force)
216 // Ignore damage from oterh projectiles from my owner (dont mess up volly's)
217 if(inflictor.owner == self.owner)
220 self.health -= damage;
221 self.velocity += force;
224 self.takedamage = DAMAGE_NO;
225 self.event_damage = func_null;
226 self.think = self.use;
227 self.nextthink = time;
231 void vehicles_projectile_explode()
233 if(self.owner && other != world)
235 if(other == self.owner.vehicle)
238 if(other == self.owner.vehicle.tur_head)
244 self.event_damage = func_null;
245 RadiusDamage (self, self.realowner, self.shot_dmg, 0, self.shot_radius, self, world, self.shot_force, self.totalfrags, other);
250 entity vehicles_projectile(string _mzlfx, string _mzlsound,
251 vector _org, vector _vel,
252 float _dmg, float _radi, float _force, float _size,
253 int _deahtype, float _projtype, float _health,
254 bool _cull, bool _clianim, entity _owner)
260 PROJECTILE_MAKETRIGGER(proj);
261 setorigin(proj, _org);
263 proj.shot_dmg = _dmg;
264 proj.shot_radius = _radi;
265 proj.shot_force = _force;
266 proj.totalfrags = _deahtype;
267 proj.solid = SOLID_BBOX;
268 proj.movetype = MOVETYPE_FLYMISSILE;
269 proj.flags = FL_PROJECTILE;
270 proj.bot_dodge = true;
271 proj.bot_dodgerating = _dmg;
272 proj.velocity = _vel;
273 proj.touch = vehicles_projectile_explode;
274 proj.use = vehicles_projectile_explode;
276 proj.realowner = _owner;
277 proj.think = SUB_Remove_self;
278 proj.nextthink = time + 30;
282 proj.takedamage = DAMAGE_AIM;
283 proj.event_damage = vehicles_projectile_damage;
284 proj.health = _health;
287 proj.flags = FL_PROJECTILE | FL_NOTARGET;
290 _sound (self, CH_WEAPON_A, _mzlsound, VOL_BASE, ATTEN_NORM);
293 Send_Effect_(_mzlfx, proj.origin, proj.velocity, 1);
295 setsize (proj, '-1 -1 -1' * _size, '1 1 1' * _size);
297 CSQCProjectile(proj, _clianim, _projtype, _cull);
302 void vehicles_gib_explode()
304 sound (self, CH_SHOTS, SND_ROCKET_IMPACT, VOL_BASE, ATTEN_NORM);
305 Send_Effect(EFFECT_EXPLOSION_SMALL, randomvec() * 80 + (self.origin + '0 0 100'), '0 0 0', 1);
306 Send_Effect(EFFECT_EXPLOSION_SMALL, self.wp00.origin + '0 0 64', '0 0 0', 1);
310 void vehicles_gib_think()
316 self.nextthink = time + 0.1;
319 entity vehicle_tossgib(entity _template, vector _vel, string _tag, bool _burn, bool _explode, float _maxtime, vector _rot)
321 entity _gib = spawn();
322 _setmodel(_gib, _template.model);
323 setorigin(_gib, gettaginfo(self, gettagindex(self, _tag)));
324 _gib.velocity = _vel;
325 _gib.movetype = MOVETYPE_TOSS;
326 _gib.solid = SOLID_CORPSE;
327 _gib.colormod = '-0.5 -0.5 -0.5';
328 _gib.effects = EF_LOWPRECISION;
329 _gib.avelocity = _rot;
332 _gib.effects |= EF_FLAME;
336 _gib.think = vehicles_gib_explode;
337 _gib.nextthink = time + random() * _explode;
338 _gib.touch = vehicles_gib_explode;
342 _gib.cnt = time + _maxtime;
343 _gib.think = vehicles_gib_think;
344 _gib.nextthink = time + _maxtime - 1;
350 bool vehicle_addplayerslot( entity _owner,
355 void(bool) _exitfunc, float() _enterfunc)
357 if(!(_owner.vehicle_flags & VHF_MULTISLOT))
358 _owner.vehicle_flags |= VHF_MULTISLOT;
360 _slot.PlayerPhysplug = _framefunc;
361 _slot.vehicle_exit = _exitfunc;
362 _slot.vehicle_enter = _enterfunc;
364 _slot.vehicle_flags = VHF_PLAYERSLOT;
365 _slot.vehicle_viewport = spawn();
366 _slot.vehicle_hudmodel = spawn();
367 _slot.vehicle_hudmodel.viewmodelforclient = _slot;
368 _slot.vehicle_viewport.effects = (EF_ADDITIVE | EF_DOUBLESIDED | EF_FULLBRIGHT | EF_NODEPTHTEST | EF_NOGUNBOB | EF_NOSHADOW | EF_LOWPRECISION | EF_SELECTABLE | EF_TELEPORT_BIT);
370 _setmodel(_slot.vehicle_hudmodel, _hud_model);
371 setmodel(_slot.vehicle_viewport, MDL_Null);
373 setattachment(_slot.vehicle_hudmodel, _slot, "");
374 setattachment(_slot.vehicle_viewport, _slot.vehicle_hudmodel, "");
379 vector vehicle_aimturret(entity _vehic, vector _target, entity _turrret, string _tagname,
380 float _pichlimit_min, float _pichlimit_max,
381 float _rotlimit_min, float _rotlimit_max, float _aimspeed)
385 vtag = gettaginfo(_turrret, gettagindex(_turrret, _tagname));
386 vtmp = vectoangles(normalize(_target - vtag));
387 vtmp = AnglesTransform_ToAngles(AnglesTransform_LeftDivide(AnglesTransform_FromAngles(_vehic.angles), AnglesTransform_FromAngles(vtmp))) - _turrret.angles;
388 vtmp = AnglesTransform_Normalize(vtmp, true);
389 ftmp = _aimspeed * frametime;
390 vtmp_y = bound(-ftmp, vtmp_y, ftmp);
391 vtmp_x = bound(-ftmp, vtmp_x, ftmp);
392 _turrret.angles_y = bound(_rotlimit_min, _turrret.angles_y + vtmp_y, _rotlimit_max);
393 _turrret.angles_x = bound(_pichlimit_min, _turrret.angles_x + vtmp_x, _pichlimit_max);
397 void vehicles_reset_colors()
400 float _effects = 0, _colormap;
401 vector _glowmod, _colormod;
403 if(autocvar_g_nodepthtestplayers)
404 _effects |= EF_NODEPTHTEST;
406 if(autocvar_g_fullbrightplayers)
407 _effects |= EF_FULLBRIGHT;
410 _colormap = 1024 + (self.team - 1) * 17;
417 // Find all ents attacked to main model and setup effects, colormod etc.
418 e = findchainentity(tag_entity, self);
421 if(e != self.vehicle_shieldent)
423 e.effects = _effects; // | EF_LOWPRECISION;
424 e.colormod = _colormod;
425 e.colormap = _colormap;
430 // Also check head tags
431 e = findchainentity(tag_entity, self.tur_head);
434 if(e != self.vehicle_shieldent)
436 e.effects = _effects; // | EF_LOWPRECISION;
437 e.colormod = _colormod;
438 e.colormap = _colormap;
444 self.vehicle_hudmodel.effects = self.effects = _effects; // | EF_LOWPRECISION;
445 self.vehicle_hudmodel.colormod = self.colormod = _colormod;
446 self.vehicle_hudmodel.colormap = self.colormap = _colormap;
447 self.vehicle_viewport.effects = (EF_ADDITIVE | EF_DOUBLESIDED | EF_FULLBRIGHT | EF_NODEPTHTEST | EF_NOGUNBOB | EF_NOSHADOW | EF_LOWPRECISION | EF_SELECTABLE | EF_TELEPORT_BIT);
450 self.avelocity = '0 0 0';
451 self.velocity = '0 0 0';
452 self.effects = _effects;
455 void vehicles_clearreturn(entity veh)
457 // Remove "return helper", if any.
458 for (entity ret = findchain(classname, "vehicle_return"); ret; ret = ret.chain)
463 ret.think = SUB_Remove_self;
464 ret.nextthink = time + 0.1;
466 if(ret.waypointsprite_attached)
467 WaypointSprite_Kill(ret.waypointsprite_attached);
474 void vehicles_spawn();
475 void vehicles_return()
477 Send_Effect(EFFECT_TELEPORT, self.wp00.origin + '0 0 64', '0 0 0', 1);
479 self.wp00.think = vehicles_spawn;
480 self.wp00.nextthink = time;
482 if(self.waypointsprite_attached)
483 WaypointSprite_Kill(self.waypointsprite_attached);
488 void vehicles_showwp_goaway()
490 if(self.waypointsprite_attached)
491 WaypointSprite_Kill(self.waypointsprite_attached);
497 void vehicles_showwp()
499 entity oldself = world;
504 self.think = vehicles_return;
505 self.nextthink = self.cnt;
509 self.think = vehicles_return;
510 self.nextthink = time +1;
514 setmodel(self, MDL_Null);
515 self.team = oldself.wp00.team;
516 self.wp00 = oldself.wp00;
517 setorigin(self, oldself.wp00.pos1);
519 self.nextthink = time + 5;
520 self.think = vehicles_showwp_goaway;
523 if(teamplay && self.team)
524 rgb = Team_ColorRGB(self.team);
527 entity wp = WaypointSprite_Spawn(WP_Vehicle, 0, 0, self, '0 0 64', world, 0, self, waypointsprite_attached, true, RADARICON_Vehicle);
529 if(self.waypointsprite_attached)
531 WaypointSprite_UpdateRule(self.waypointsprite_attached, self.wp00.team, SPRITERULE_DEFAULT);
533 WaypointSprite_UpdateBuildFinished(self.waypointsprite_attached, self.nextthink);
534 WaypointSprite_Ping(self.waypointsprite_attached);
541 void vehicles_setreturn(entity veh)
545 vehicles_clearreturn(veh);
547 ret = new(vehicle_return);
550 ret.think = vehicles_showwp;
552 if(veh.deadflag != DEAD_NO)
554 ret.cnt = time + veh.respawntime;
555 ret.nextthink = min(time + veh.respawntime, time + veh.respawntime - 5);
559 ret.nextthink = min(time + veh.respawntime, time + veh.respawntime - 1);
562 setmodel(ret, MDL_Null);
563 setorigin(ret, veh.pos1 + '0 0 96');
569 LOG_TRACE("vehicle ",self.netname, " used by ", activator.classname, "\n");
571 self.tur_head.team = activator.team;
573 if(self.tur_head.team == 0)
574 self.active = ACTIVE_NOT;
576 self.active = ACTIVE_ACTIVE;
578 if(self.active == ACTIVE_ACTIVE && self.deadflag == DEAD_NO && !gameover)
580 LOG_TRACE("Respawning vehicle: ", self.netname, "\n");
581 if(self.effects & EF_NODRAW)
583 self.think = vehicles_spawn;
584 self.nextthink = time + 3;
588 vehicles_setreturn(self);
589 vehicles_reset_colors();
594 void vehicles_regen(float timer, .float regen_field, float field_max, float rpause, float regen, float delta_time, float _healthscale)
596 if(self.(regen_field) < field_max)
597 if(timer + rpause < time)
600 regen = regen * (self.vehicle_health / self.max_health);
602 self.(regen_field) = min(self.(regen_field) + regen * delta_time, field_max);
605 self.owner.(regen_field) = (self.(regen_field) / field_max) * 100;
609 void shieldhit_think()
614 // setmodel(self, MDL_Null);
616 self.effects |= EF_NODRAW;
620 self.nextthink = time + 0.1;
624 void vehicles_painframe()
626 if(self.owner.vehicle_health <= 50)
627 if(self.pain_frame < time)
630 _ftmp = self.owner.vehicle_health / 50;
631 self.pain_frame = time + 0.1 + (random() * 0.5 * _ftmp);
632 pointparticles(EFFECT_SMOKE_SMALL, (self.origin + (randomvec() * 80)), '0 0 0', 1);
634 if(self.vehicle_flags & VHF_DMGSHAKE)
635 self.velocity += randomvec() * 30;
637 if(self.vehicle_flags & VHF_DMGROLL)
638 if(self.vehicle_flags & VHF_DMGHEADROLL)
639 self.tur_head.angles += randomvec();
641 self.angles += randomvec();
646 void vehicles_damage(entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force)
648 self.dmg_time = time;
651 if(DEATH_ISWEAPON(deathtype, WEP_VORTEX))
652 damage *= autocvar_g_vehicles_vortex_damagerate;
654 if(DEATH_ISWEAPON(deathtype, WEP_MACHINEGUN))
655 damage *= autocvar_g_vehicles_machinegun_damagerate;
657 if(DEATH_ISWEAPON(deathtype, WEP_RIFLE))
658 damage *= autocvar_g_vehicles_rifle_damagerate;
660 if(DEATH_ISWEAPON(deathtype, WEP_VAPORIZER))
661 damage *= autocvar_g_vehicles_vaporizer_damagerate;
663 if(DEATH_ISWEAPON(deathtype, WEP_SEEKER))
664 damage *= autocvar_g_vehicles_tag_damagerate;
666 if(DEATH_WEAPONOF(deathtype) != WEP_Null)
667 damage *= autocvar_g_vehicles_weapon_damagerate;
669 self.enemy = attacker;
671 self.pain_finished = time;
673 if((self.vehicle_flags & VHF_HASSHIELD) && (self.vehicle_shield > 0))
675 if (wasfreed(self.vehicle_shieldent) || self.vehicle_shieldent == world)
677 self.vehicle_shieldent = spawn();
678 self.vehicle_shieldent.effects = EF_LOWPRECISION;
680 setmodel(self.vehicle_shieldent, MDL_VEH_SHIELD);
681 setattachment(self.vehicle_shieldent, self, "");
682 setorigin(self.vehicle_shieldent, real_origin(self) - self.origin);
683 self.vehicle_shieldent.scale = 256 / vlen(self.maxs - self.mins);
684 self.vehicle_shieldent.think = shieldhit_think;
687 self.vehicle_shieldent.colormod = '1 1 1';
688 self.vehicle_shieldent.alpha = 0.45;
689 self.vehicle_shieldent.angles = vectoangles(normalize(hitloc - (self.origin + self.vehicle_shieldent.origin))) - self.angles;
690 self.vehicle_shieldent.nextthink = time;
691 self.vehicle_shieldent.effects &= ~EF_NODRAW;
693 self.vehicle_shield -= damage;
695 if(self.vehicle_shield < 0)
697 self.vehicle_health -= fabs(self.vehicle_shield);
698 self.vehicle_shieldent.colormod = '2 0 0';
699 self.vehicle_shield = 0;
700 self.vehicle_shieldent.alpha = 0.75;
702 if(sound_allowed(MSG_BROADCAST, attacker))
703 spamsound (self, CH_PAIN, "onslaught/ons_hit2.wav", VOL_BASE, ATTEN_NORM); // FIXME: PLACEHOLDER
706 if(sound_allowed(MSG_BROADCAST, attacker))
707 spamsound (self, CH_PAIN, "onslaught/electricity_explode.wav", VOL_BASE, ATTEN_NORM); // FIXME: PLACEHOLDER
712 self.vehicle_health -= damage;
714 if(sound_allowed(MSG_BROADCAST, attacker))
715 spamsound (self, CH_PAIN, "onslaught/ons_hit2.wav", VOL_BASE, ATTEN_NORM); // FIXME: PLACEHOLDER
718 if(self.damageforcescale < 1 && self.damageforcescale > 0)
719 self.velocity += force * self.damageforcescale;
721 self.velocity += force;
723 if(self.vehicle_health <= 0)
726 if(self.vehicle_flags & VHF_DEATHEJECT)
727 vehicles_exit(VHEF_EJECT);
729 vehicles_exit(VHEF_RELEASE);
734 Vehicle info = get_vehicleinfo(self.vehicleid);
736 vehicles_setreturn(self);
740 float vehicles_crushable(entity e)
742 if(IS_PLAYER(e) && time >= e.vehicle_enter_delay)
751 void vehicles_impact(float _minspeed, float _speedfac, float _maxpain)
753 if (trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT)
756 if(self.play_time < time)
758 float wc = vlen(self.velocity - self.oldvelocity);
759 //dprint("oldvel: ", vtos(self.oldvelocity), "\n");
760 //dprint("vel: ", vtos(self.velocity), "\n");
763 float take = min(_speedfac * wc, _maxpain);
764 Damage (self, world, world, take, DEATH_FALL.m_id, self.origin, '0 0 0');
765 self.play_time = time + 0.25;
767 //dprint("wc: ", ftos(wc), "\n");
768 //dprint("take: ", ftos(take), "\n");
773 // vehicle enter/exit handling
774 vector vehicles_findgoodexit(vector prefer_spot)
779 tracebox(self.origin + '0 0 32', PL_MIN, PL_MAX, prefer_spot, MOVE_NORMAL, self.owner);
780 if(trace_fraction == 1.0 && !trace_startsolid && !trace_allsolid)
783 mysize = 1.5 * vlen(self.maxs - self.mins);
786 v2 = 0.5 * (self.absmin + self.absmax);
787 for(i = 0; i < 100; ++i)
791 v = v2 + normalize(v) * mysize;
792 tracebox(v2, PL_MIN, PL_MAX, v, MOVE_NORMAL, self.owner);
793 if(trace_fraction == 1.0 && !trace_startsolid && !trace_allsolid)
798 exitspot = (self.origin + '0 0 48') + v_forward * mysize;
799 tracebox(self.origin + '0 0 32', PL_MIN, PL_MAX, exitspot, MOVE_NORMAL, self.owner);
800 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_right * 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)
822 void vehicles_exit(bool eject)
827 if(vehicles_exit_running)
829 LOG_TRACE("^1vehicles_exit allready running! this is not good..\n");
833 vehicles_exit_running = true;
836 _vehicle = self.vehicle;
838 if (_vehicle.vehicle_flags & VHF_PLAYERSLOT)
840 _vehicle.vehicle_exit(eject);
842 vehicles_exit_running = false;
849 _player = _vehicle.owner;
855 if (IS_REAL_CLIENT(_player))
857 msg_entity = _player;
858 WriteByte (MSG_ONE, SVC_SETVIEWPORT);
859 WriteEntity( MSG_ONE, _player);
861 WriteByte (MSG_ONE, SVC_SETVIEWANGLES);
862 WriteAngle(MSG_ONE, 0);
863 WriteAngle(MSG_ONE, _vehicle.angles_y);
864 WriteAngle(MSG_ONE, 0);
867 setsize(_player, PL_MIN,PL_MAX);
869 _player.takedamage = DAMAGE_AIM;
870 _player.solid = SOLID_SLIDEBOX;
871 _player.movetype = MOVETYPE_WALK;
872 _player.effects &= ~EF_NODRAW;
873 _player.teleportable = TELEPORT_NORMAL;
875 _player.PlayerPhysplug = func_null;
876 _player.vehicle = world;
877 _player.view_ofs = PL_VIEW_OFS;
878 _player.event_damage = PlayerDamage;
879 _player.hud = HUD_NORMAL;
880 PS(_player).m_switchweapon = _vehicle.m_switchweapon;
881 _player.last_vehiclecheck = time + 3;
882 _player.vehicle_enter_delay = time + 2;
884 CSQCVehicleSetup(_player, HUD_NORMAL);
886 _vehicle.flags |= FL_NOTARGET;
888 if(_vehicle.deadflag == DEAD_NO)
889 _vehicle.avelocity = '0 0 0';
891 _vehicle.tur_head.nodrawtoclient = world;
896 Kill_Notification(NOTIF_ONE, _player, MSG_CENTER_CPID, CPID_VEHICLES);
897 Kill_Notification(NOTIF_ONE, _player, MSG_CENTER_CPID, CPID_VEHICLES_OTHER); // kill all vehicle notifications when exiting a vehicle?
899 WaypointSprite_Kill(_vehicle.wps_intruder);
901 MUTATOR_CALLHOOK(VehicleExit, _player, _vehicle);
903 _vehicle.team = _vehicle.tur_head.team;
905 sound (_vehicle, CH_TRIGGER_SINGLE, SND_Null, 1, ATTEN_NORM);
906 _vehicle.vehicle_hudmodel.viewmodelforclient = _vehicle;
907 _vehicle.phase = time + 1;
909 _vehicle.vehicle_exit(eject);
911 vehicles_setreturn(_vehicle);
912 vehicles_reset_colors();
913 _vehicle.owner = world;
915 CSQCMODEL_AUTOINIT(self);
918 vehicles_exit_running = false;
921 void vehicles_touch()
923 if(MUTATOR_CALLHOOK(VehicleTouch, self, other))
926 // Vehicle currently in use
929 if(!forbidWeaponUse(self.owner))
931 if((self.origin_z + self.maxs_z) > (other.origin_z))
932 if(vehicles_crushable(other))
934 if(vlen(self.velocity) >= 30)
935 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);
937 return; // Dont do selfdamage when hitting "soft targets".
940 if(self.play_time < time) {
941 Vehicle info = get_vehicleinfo(self.vehicleid);
942 info.vr_impact(info);
948 if(autocvar_g_vehicles_enter)
951 vehicles_enter(other, self);
954 bool vehicle_impulse(entity this, int imp)
956 entity v = this.vehicle;
957 if (!v) return false;
958 if (v.deadflag != DEAD_NO) return false;
959 bool(int) f = v.vehicles_impulse;
960 if (f && f(imp)) return true;
963 case IMP_weapon_drop.impulse:
965 stuffcmd(self, "\ntoggle cl_eventchase_vehicle\nset _vehicles_shownchasemessage 1\n");
972 void vehicles_enter(entity pl, entity veh)
974 // Remove this when bots know how to use vehicles
975 if((IS_BOT_CLIENT(pl) && !autocvar_g_vehicles_allow_bots))
979 || (veh.phase >= time)
980 || (pl.vehicle_enter_delay >= time)
982 || (pl.deadflag != DEAD_NO)
986 if(autocvar_g_vehicles_enter) // vehicle's touch function should handle this if entering via use key is disabled (TODO)
987 if(veh.vehicle_flags & VHF_MULTISLOT)
991 other = pl; // TODO: fix
994 if(time >= veh.gun1.phase)
995 if(veh.gun1.vehicle_enter)
996 if(veh.gun1.vehicle_enter())
1003 if(time >= veh.gun2.phase)
1004 if(veh.gun2.vehicle_enter)
1005 if(veh.gun2.vehicle_enter())
1016 if(DIFF_TEAM(pl, veh))
1017 if(autocvar_g_vehicles_steal)
1019 FOREACH_CLIENT(IS_PLAYER(it) && SAME_TEAM(it, veh), LAMBDA(Send_Notification(NOTIF_ONE, it, MSG_CENTER, CENTER_VEHICLE_STEAL)));
1021 Send_Notification(NOTIF_ONE, pl, MSG_CENTER, CENTER_VEHICLE_STEAL_SELF);
1023 if (autocvar_g_vehicles_steal_show_waypoint) {
1024 entity wp = WaypointSprite_Spawn(WP_VehicleIntruder, 0, 0, pl, '0 0 68', world, veh.team, veh, wps_intruder, true, RADARICON_DANGER);
1025 wp.colormod = Team_ColorRGB(pl.team);
1030 RemoveGrapplingHook(pl);
1032 veh.vehicle_ammo1 = 0;
1033 veh.vehicle_ammo2 = 0;
1034 veh.vehicle_reload1 = 0;
1035 veh.vehicle_reload2 = 0;
1036 veh.vehicle_energy = 0;
1041 // .viewmodelforclient works better.
1042 //veh.vehicle_hudmodel.drawonlytoclient = veh.owner;
1044 veh.vehicle_hudmodel.viewmodelforclient = pl;
1046 tracebox(pl.origin, PL_MIN, PL_MAX, pl.origin, false, pl);
1048 pl.view_ofs = PL_VIEW_OFS;
1049 setsize (pl, PL_MIN, PL_MAX);
1051 veh.event_damage = vehicles_damage;
1053 pl.angles = veh.angles;
1054 pl.takedamage = DAMAGE_NO;
1055 pl.solid = SOLID_NOT;
1056 pl.movetype = MOVETYPE_NOCLIP;
1057 pl.teleportable = false;
1059 pl.event_damage = func_null;
1060 pl.view_ofs = '0 0 0';
1061 veh.colormap = pl.colormap;
1063 veh.tur_head.colormap = pl.colormap;
1064 veh.m_switchweapon = PS(pl).m_switchweapon;
1065 pl.hud = veh.vehicleid;
1066 pl.PlayerPhysplug = veh.PlayerPhysplug;
1068 pl.vehicle_ammo1 = veh.vehicle_ammo1;
1069 pl.vehicle_ammo2 = veh.vehicle_ammo2;
1070 pl.vehicle_reload1 = veh.vehicle_reload1;
1071 pl.vehicle_reload2 = veh.vehicle_reload2;
1072 pl.vehicle_energy = veh.vehicle_energy;
1074 // Cant do this, hides attached objects too.
1075 //veh.exteriormodeltoclient = veh.owner;
1076 //veh.tur_head.exteriormodeltoclient = veh.owner;
1078 pl.flags &= ~FL_ONGROUND;
1079 veh.flags &= ~FL_ONGROUND;
1082 veh.flags -= FL_NOTARGET;
1084 if (IS_REAL_CLIENT(pl))
1086 Send_Notification(NOTIF_ONE, pl, MSG_CENTER, CENTER_VEHICLE_ENTER);
1089 WriteByte (MSG_ONE, SVC_SETVIEWPORT);
1090 WriteEntity(MSG_ONE, veh.vehicle_viewport);
1092 WriteByte (MSG_ONE, SVC_SETVIEWANGLES);
1095 WriteAngle(MSG_ONE, veh.tur_head.angles_x + veh.angles_x); // tilt
1096 WriteAngle(MSG_ONE, veh.tur_head.angles_y + veh.angles_y); // yaw
1097 WriteAngle(MSG_ONE, 0); // roll
1101 WriteAngle(MSG_ONE, veh.angles_x * -1); // tilt
1102 WriteAngle(MSG_ONE, veh.angles_y); // yaw
1103 WriteAngle(MSG_ONE, 0); // roll
1107 vehicles_clearreturn(veh);
1109 CSQCVehicleSetup(pl, veh.vehicleid);
1111 MUTATOR_CALLHOOK(VehicleEnter, pl, veh);
1114 CSQCModel_UnlinkEntity(veh);
1115 Vehicle info = get_vehicleinfo(veh.vehicleid);
1116 info.vr_enter(info);
1122 void vehicles_think()
1124 self.nextthink = time;
1127 self.owner.vehicle_weapon2mode = self.vehicle_weapon2mode;
1129 Vehicle info = get_vehicleinfo(self.vehicleid);
1130 info.vr_think(info);
1132 CSQCMODEL_AUTOUPDATE(self);
1136 void vehicles_spawn()
1138 LOG_TRACE("Spawning vehicle: ", self.classname, "\n");
1141 self.vehicle_hudmodel.viewmodelforclient = self;
1144 self.touch = vehicles_touch;
1145 self.event_damage = vehicles_damage;
1146 self.iscreature = true;
1147 self.teleportable = false; // no teleporting for vehicles, too buggy
1148 self.damagedbycontents = true;
1149 self.movetype = MOVETYPE_WALK;
1150 self.solid = SOLID_SLIDEBOX;
1151 self.takedamage = DAMAGE_AIM;
1152 self.deadflag = DEAD_NO;
1153 self.bot_attack = true;
1154 self.flags = FL_NOTARGET;
1155 self.avelocity = '0 0 0';
1156 self.velocity = '0 0 0';
1157 self.think = vehicles_think;
1158 self.nextthink = time;
1161 self.lock_strength = 0;
1162 self.lock_target = world;
1163 self.misc_bulletcounter = 0;
1166 self.angles = self.pos2;
1167 setorigin(self, self.pos1);
1169 Send_Effect(EFFECT_TELEPORT, self.origin + '0 0 64', '0 0 0', 1);
1171 if(self.vehicle_controller)
1172 self.team = self.vehicle_controller.team;
1174 FOREACH_CLIENT(IS_PLAYER(it) && it.hook.aiment == self, LAMBDA(RemoveGrapplingHook(it)));
1176 vehicles_reset_colors();
1178 Vehicle info = get_vehicleinfo(self.vehicleid);
1179 info.vr_spawn(info);
1181 CSQCMODEL_AUTOINIT(self);
1184 bool vehicle_initialize(entity veh, bool nodrop)
1186 if(!autocvar_g_vehicles)
1193 Vehicle info = get_vehicleinfo(veh.vehicleid);
1194 info.vr_precache(info);
1197 if(self.targetname && self.targetname != "")
1199 self.vehicle_controller = find(world, target, self.targetname);
1200 if(!self.vehicle_controller)
1202 bprint("^1WARNING: ^7Vehicle with invalid .targetname\n");
1203 self.active = ACTIVE_ACTIVE;
1207 self.team = self.vehicle_controller.team;
1208 self.use = vehicle_use;
1212 if(self.vehicle_controller.team == 0)
1213 self.active = ACTIVE_NOT;
1215 self.active = ACTIVE_ACTIVE;
1219 else { self.active = ACTIVE_ACTIVE; }
1221 if(self.team && (!teamplay || !autocvar_g_vehicles_teams))
1224 if(self.mdl == "" || !self.mdl)
1225 _setmodel(self, veh.model);
1227 _setmodel(self, self.mdl);
1229 self.vehicle_flags |= VHF_ISVEHICLE;
1231 self.vehicle_viewport = new(vehicle_viewport);
1232 self.vehicle_hudmodel = new(vehicle_hudmodel);
1233 self.tur_head = new(tur_head);
1234 self.tur_head.owner = self;
1235 self.takedamage = DAMAGE_NO;
1236 self.bot_attack = true;
1237 self.iscreature = true;
1238 self.teleportable = false; // no teleporting for vehicles, too buggy
1239 self.damagedbycontents = true;
1240 self.vehicleid = veh.vehicleid;
1241 self.PlayerPhysplug = veh.PlayerPhysplug;
1242 self.event_damage = func_null;
1243 self.touch = vehicles_touch;
1244 self.think = vehicles_spawn;
1245 self.nextthink = time;
1246 self.effects = EF_NODRAW;
1247 self.dphitcontentsmask = DPCONTENTS_BODY | DPCONTENTS_SOLID;
1249 if(autocvar_g_playerclip_collisions)
1250 self.dphitcontentsmask |= DPCONTENTS_PLAYERCLIP;
1252 if(autocvar_g_nodepthtestplayers)
1253 self.effects |= EF_NODEPTHTEST;
1255 if(autocvar_g_fullbrightplayers)
1256 self.effects |= EF_FULLBRIGHT;
1258 _setmodel(self.vehicle_hudmodel, veh.hud_model);
1259 setmodel(self.vehicle_viewport, MDL_Null);
1261 if(veh.head_model != "")
1263 _setmodel(self.tur_head, veh.head_model);
1264 setattachment(self.tur_head, self, veh.tag_head);
1265 setattachment(self.vehicle_hudmodel, self.tur_head, veh.tag_hud);
1266 setattachment(self.vehicle_viewport, self.vehicle_hudmodel, veh.tag_view);
1270 setattachment(self.tur_head, self, "");
1271 setattachment(self.vehicle_hudmodel, self, veh.tag_hud);
1272 setattachment(self.vehicle_viewport, self.vehicle_hudmodel, veh.tag_view);
1275 setsize(self, veh.mins, veh.maxs);
1279 setorigin(self, self.origin);
1280 tracebox(self.origin + '0 0 100', veh.mins, veh.maxs, self.origin - '0 0 10000', MOVE_WORLDONLY, self);
1281 setorigin(self, trace_endpos);
1284 self.pos1 = self.origin;
1285 self.pos2 = self.angles;
1286 self.tur_head.team = self.team;
1288 Vehicle info = get_vehicleinfo(veh.vehicleid);
1289 info.vr_setup(info);
1291 if(self.active == ACTIVE_NOT)
1292 self.nextthink = 0; // wait until activated
1293 else if(autocvar_g_vehicles_delayspawn)
1294 self.nextthink = time + self.respawntime + (random() * autocvar_g_vehicles_delayspawn_jitter);
1296 self.nextthink = time + game_starttime;
1298 if(MUTATOR_CALLHOOK(VehicleSpawn))