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)
458 // Remove "return helper", if any.
459 for (entity ret = findchain(classname, "vehicle_return"); ret; ret = ret.chain)
464 ret.think = SUB_Remove;
465 ret.nextthink = time + 0.1;
467 if(ret.waypointsprite_attached)
468 WaypointSprite_Kill(ret.waypointsprite_attached);
475 void vehicles_spawn();
476 void vehicles_return()
478 Send_Effect(EFFECT_TELEPORT, self.wp00.origin + '0 0 64', '0 0 0', 1);
480 self.wp00.think = vehicles_spawn;
481 self.wp00.nextthink = time;
483 if(self.waypointsprite_attached)
484 WaypointSprite_Kill(self.waypointsprite_attached);
489 void vehicles_showwp_goaway()
491 if(self.waypointsprite_attached)
492 WaypointSprite_Kill(self.waypointsprite_attached);
498 void vehicles_showwp()
500 entity oldself = world;
505 self.think = vehicles_return;
506 self.nextthink = self.cnt;
510 self.think = vehicles_return;
511 self.nextthink = time +1;
515 setmodel(self, MDL_Null);
516 self.team = oldself.wp00.team;
517 self.wp00 = oldself.wp00;
518 setorigin(self, oldself.wp00.pos1);
520 self.nextthink = time + 5;
521 self.think = vehicles_showwp_goaway;
524 if(teamplay && self.team)
525 rgb = Team_ColorRGB(self.team);
528 entity wp = WaypointSprite_Spawn(WP_Vehicle, 0, 0, self, '0 0 64', world, 0, self, waypointsprite_attached, true, RADARICON_Vehicle);
530 if(self.waypointsprite_attached)
532 WaypointSprite_UpdateRule(self.waypointsprite_attached, self.wp00.team, SPRITERULE_DEFAULT);
534 WaypointSprite_UpdateBuildFinished(self.waypointsprite_attached, self.nextthink);
535 WaypointSprite_Ping(self.waypointsprite_attached);
542 void vehicles_setreturn(entity veh)
546 vehicles_clearreturn(veh);
548 ret = new(vehicle_return);
551 ret.think = vehicles_showwp;
553 if(veh.deadflag != DEAD_NO)
555 ret.cnt = time + veh.respawntime;
556 ret.nextthink = min(time + veh.respawntime, time + veh.respawntime - 5);
560 ret.nextthink = min(time + veh.respawntime, time + veh.respawntime - 1);
563 setmodel(ret, MDL_Null);
564 setorigin(ret, veh.pos1 + '0 0 96');
570 LOG_TRACE("vehicle ",self.netname, " used by ", activator.classname, "\n");
572 self.tur_head.team = activator.team;
574 if(self.tur_head.team == 0)
575 self.active = ACTIVE_NOT;
577 self.active = ACTIVE_ACTIVE;
579 if(self.active == ACTIVE_ACTIVE && self.deadflag == DEAD_NO && !gameover)
581 LOG_TRACE("Respawning vehicle: ", self.netname, "\n");
582 if(self.effects & EF_NODRAW)
584 self.think = vehicles_spawn;
585 self.nextthink = time + 3;
589 vehicles_setreturn(self);
590 vehicles_reset_colors();
595 void vehicles_regen(float timer, .float regen_field, float field_max, float rpause, float regen, float delta_time, float _healthscale)
597 if(self.(regen_field) < field_max)
598 if(timer + rpause < time)
601 regen = regen * (self.vehicle_health / self.max_health);
603 self.(regen_field) = min(self.(regen_field) + regen * delta_time, field_max);
606 self.owner.(regen_field) = (self.(regen_field) / field_max) * 100;
610 void shieldhit_think()
615 // setmodel(self, MDL_Null);
617 self.effects |= EF_NODRAW;
621 self.nextthink = time + 0.1;
625 void vehicles_painframe()
627 if(self.owner.vehicle_health <= 50)
628 if(self.pain_frame < time)
631 _ftmp = self.owner.vehicle_health / 50;
632 self.pain_frame = time + 0.1 + (random() * 0.5 * _ftmp);
633 pointparticles(EFFECT_SMOKE_SMALL, (self.origin + (randomvec() * 80)), '0 0 0', 1);
635 if(self.vehicle_flags & VHF_DMGSHAKE)
636 self.velocity += randomvec() * 30;
638 if(self.vehicle_flags & VHF_DMGROLL)
639 if(self.vehicle_flags & VHF_DMGHEADROLL)
640 self.tur_head.angles += randomvec();
642 self.angles += randomvec();
647 void vehicles_damage(entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force)
649 self.dmg_time = time;
652 if(DEATH_ISWEAPON(deathtype, WEP_VORTEX))
653 damage *= autocvar_g_vehicles_vortex_damagerate;
655 if(DEATH_ISWEAPON(deathtype, WEP_MACHINEGUN))
656 damage *= autocvar_g_vehicles_machinegun_damagerate;
658 if(DEATH_ISWEAPON(deathtype, WEP_RIFLE))
659 damage *= autocvar_g_vehicles_rifle_damagerate;
661 if(DEATH_ISWEAPON(deathtype, WEP_VAPORIZER))
662 damage *= autocvar_g_vehicles_vaporizer_damagerate;
664 if(DEATH_ISWEAPON(deathtype, WEP_SEEKER))
665 damage *= autocvar_g_vehicles_tag_damagerate;
667 if(DEATH_WEAPONOF(deathtype) != WEP_Null)
668 damage *= autocvar_g_vehicles_weapon_damagerate;
670 self.enemy = attacker;
672 self.pain_finished = time;
674 if((self.vehicle_flags & VHF_HASSHIELD) && (self.vehicle_shield > 0))
676 if (wasfreed(self.vehicle_shieldent) || self.vehicle_shieldent == world)
678 self.vehicle_shieldent = spawn();
679 self.vehicle_shieldent.effects = EF_LOWPRECISION;
681 setmodel(self.vehicle_shieldent, MDL_VEH_SHIELD);
682 setattachment(self.vehicle_shieldent, self, "");
683 setorigin(self.vehicle_shieldent, real_origin(self) - self.origin);
684 self.vehicle_shieldent.scale = 256 / vlen(self.maxs - self.mins);
685 self.vehicle_shieldent.think = shieldhit_think;
688 self.vehicle_shieldent.colormod = '1 1 1';
689 self.vehicle_shieldent.alpha = 0.45;
690 self.vehicle_shieldent.angles = vectoangles(normalize(hitloc - (self.origin + self.vehicle_shieldent.origin))) - self.angles;
691 self.vehicle_shieldent.nextthink = time;
692 self.vehicle_shieldent.effects &= ~EF_NODRAW;
694 self.vehicle_shield -= damage;
696 if(self.vehicle_shield < 0)
698 self.vehicle_health -= fabs(self.vehicle_shield);
699 self.vehicle_shieldent.colormod = '2 0 0';
700 self.vehicle_shield = 0;
701 self.vehicle_shieldent.alpha = 0.75;
703 if(sound_allowed(MSG_BROADCAST, attacker))
704 spamsound (self, CH_PAIN, "onslaught/ons_hit2.wav", VOL_BASE, ATTEN_NORM); // FIXME: PLACEHOLDER
707 if(sound_allowed(MSG_BROADCAST, attacker))
708 spamsound (self, CH_PAIN, "onslaught/electricity_explode.wav", VOL_BASE, ATTEN_NORM); // FIXME: PLACEHOLDER
713 self.vehicle_health -= damage;
715 if(sound_allowed(MSG_BROADCAST, attacker))
716 spamsound (self, CH_PAIN, "onslaught/ons_hit2.wav", VOL_BASE, ATTEN_NORM); // FIXME: PLACEHOLDER
719 if(self.damageforcescale < 1 && self.damageforcescale > 0)
720 self.velocity += force * self.damageforcescale;
722 self.velocity += force;
724 if(self.vehicle_health <= 0)
727 if(self.vehicle_flags & VHF_DEATHEJECT)
728 vehicles_exit(VHEF_EJECT);
730 vehicles_exit(VHEF_RELEASE);
735 Vehicle info = get_vehicleinfo(self.vehicleid);
737 vehicles_setreturn(self);
741 float vehicles_crushable(entity e)
743 if(IS_PLAYER(e) && time >= e.vehicle_enter_delay)
752 void vehicles_impact(float _minspeed, float _speedfac, float _maxpain)
754 if (trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT)
757 if(self.play_time < time)
759 float wc = vlen(self.velocity - self.oldvelocity);
760 //dprint("oldvel: ", vtos(self.oldvelocity), "\n");
761 //dprint("vel: ", vtos(self.velocity), "\n");
764 float take = min(_speedfac * wc, _maxpain);
765 Damage (self, world, world, take, DEATH_FALL.m_id, self.origin, '0 0 0');
766 self.play_time = time + 0.25;
768 //dprint("wc: ", ftos(wc), "\n");
769 //dprint("take: ", ftos(take), "\n");
774 // vehicle enter/exit handling
775 vector vehicles_findgoodexit(vector prefer_spot)
780 tracebox(self.origin + '0 0 32', PL_MIN, PL_MAX, prefer_spot, MOVE_NORMAL, self.owner);
781 if(trace_fraction == 1.0 && !trace_startsolid && !trace_allsolid)
784 mysize = 1.5 * vlen(self.maxs - self.mins);
787 v2 = 0.5 * (self.absmin + self.absmax);
788 for(i = 0; i < 100; ++i)
792 v = v2 + normalize(v) * mysize;
793 tracebox(v2, PL_MIN, PL_MAX, v, MOVE_NORMAL, self.owner);
794 if(trace_fraction == 1.0 && !trace_startsolid && !trace_allsolid)
799 exitspot = (self.origin + '0 0 48') + v_forward * mysize;
800 tracebox(self.origin + '0 0 32', PL_MIN, PL_MAX, exitspot, MOVE_NORMAL, self.owner);
801 if(trace_fraction == 1.0 && !trace_startsolid && !trace_allsolid)
804 exitspot = (self.origin + '0 0 48') - v_forward * mysize;
805 tracebox(self.origin + '0 0 32', PL_MIN, PL_MAX, exitspot, MOVE_NORMAL, self.owner);
806 if(trace_fraction == 1.0 && !trace_startsolid && !trace_allsolid)
809 exitspot = (self.origin + '0 0 48') + v_right * mysize;
810 tracebox(self.origin + '0 0 32', PL_MIN, PL_MAX, exitspot, MOVE_NORMAL, self.owner);
811 if(trace_fraction == 1.0 && !trace_startsolid && !trace_allsolid)
814 exitspot = (self.origin + '0 0 48') - v_right * mysize;
815 tracebox(self.origin + '0 0 32', PL_MIN, PL_MAX, exitspot, MOVE_NORMAL, self.owner);
816 if(trace_fraction == 1.0 && !trace_startsolid && !trace_allsolid)
823 void vehicles_exit(bool eject)
828 if(vehicles_exit_running)
830 LOG_TRACE("^1vehicles_exit allready running! this is not good..\n");
834 vehicles_exit_running = true;
837 _vehicle = self.vehicle;
839 if (_vehicle.vehicle_flags & VHF_PLAYERSLOT)
841 _vehicle.vehicle_exit(eject);
843 vehicles_exit_running = false;
850 _player = _vehicle.owner;
856 if (IS_REAL_CLIENT(_player))
858 msg_entity = _player;
859 WriteByte (MSG_ONE, SVC_SETVIEWPORT);
860 WriteEntity( MSG_ONE, _player);
862 WriteByte (MSG_ONE, SVC_SETVIEWANGLES);
863 WriteAngle(MSG_ONE, 0);
864 WriteAngle(MSG_ONE, _vehicle.angles_y);
865 WriteAngle(MSG_ONE, 0);
868 setsize(_player, PL_MIN,PL_MAX);
870 _player.takedamage = DAMAGE_AIM;
871 _player.solid = SOLID_SLIDEBOX;
872 _player.movetype = MOVETYPE_WALK;
873 _player.effects &= ~EF_NODRAW;
874 _player.teleportable = TELEPORT_NORMAL;
876 _player.PlayerPhysplug = func_null;
877 _player.vehicle = world;
878 _player.view_ofs = PL_VIEW_OFS;
879 _player.event_damage = PlayerDamage;
880 _player.hud = HUD_NORMAL;
881 _player.switchweapon = _vehicle.switchweapon;
882 _player.last_vehiclecheck = time + 3;
883 _player.vehicle_enter_delay = time + 2;
885 CSQCVehicleSetup(_player, HUD_NORMAL);
887 _vehicle.flags |= FL_NOTARGET;
889 if(_vehicle.deadflag == DEAD_NO)
890 _vehicle.avelocity = '0 0 0';
892 _vehicle.tur_head.nodrawtoclient = world;
897 Kill_Notification(NOTIF_ONE, _player, MSG_CENTER_CPID, CPID_VEHICLES);
898 Kill_Notification(NOTIF_ONE, _player, MSG_CENTER_CPID, CPID_VEHICLES_OTHER); // kill all vehicle notifications when exiting a vehicle?
900 WaypointSprite_Kill(_vehicle.wps_intruder);
902 MUTATOR_CALLHOOK(VehicleExit, _player, _vehicle);
904 _vehicle.team = _vehicle.tur_head.team;
906 sound (_vehicle, CH_TRIGGER_SINGLE, SND_Null, 1, ATTEN_NORM);
907 _vehicle.vehicle_hudmodel.viewmodelforclient = _vehicle;
908 _vehicle.phase = time + 1;
910 _vehicle.vehicle_exit(eject);
912 vehicles_setreturn(_vehicle);
913 vehicles_reset_colors();
914 _vehicle.owner = world;
916 CSQCMODEL_AUTOINIT(self);
919 vehicles_exit_running = false;
922 void vehicles_touch()
924 if(MUTATOR_CALLHOOK(VehicleTouch, self, other))
927 // Vehicle currently in use
930 if(!forbidWeaponUse(self.owner))
932 if((self.origin_z + self.maxs_z) > (other.origin_z))
933 if(vehicles_crushable(other))
935 if(vlen(self.velocity) >= 30)
936 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);
938 return; // Dont do selfdamage when hitting "soft targets".
941 if(self.play_time < time) {
942 Vehicle info = get_vehicleinfo(self.vehicleid);
943 info.vr_impact(info);
949 if(autocvar_g_vehicles_enter)
952 vehicles_enter(other, self);
955 bool vehicle_impulse(int imp)
961 stuffcmd(self, "\ntoggle cl_eventchase_vehicle\nset _vehicles_shownchasemessage 1\n");
969 void vehicles_enter(entity pl, entity veh)
971 // Remove this when bots know how to use vehicles
972 if((IS_BOT_CLIENT(pl) && !autocvar_g_vehicles_allow_bots))
976 || (veh.phase >= time)
977 || (pl.vehicle_enter_delay >= time)
979 || (pl.deadflag != DEAD_NO)
983 if(autocvar_g_vehicles_enter) // vehicle's touch function should handle this if entering via use key is disabled (TODO)
984 if(veh.vehicle_flags & VHF_MULTISLOT)
988 other = pl; // TODO: fix
991 if(time >= veh.gun1.phase)
992 if(veh.gun1.vehicle_enter)
993 if(veh.gun1.vehicle_enter())
1000 if(time >= veh.gun2.phase)
1001 if(veh.gun2.vehicle_enter)
1002 if(veh.gun2.vehicle_enter())
1013 if(DIFF_TEAM(pl, veh))
1014 if(autocvar_g_vehicles_steal)
1017 FOR_EACH_PLAYER(head) if(SAME_TEAM(head, veh))
1018 Send_Notification(NOTIF_ONE, head, MSG_CENTER, CENTER_VEHICLE_STEAL);
1020 Send_Notification(NOTIF_ONE, pl, MSG_CENTER, CENTER_VEHICLE_STEAL_SELF);
1022 if (autocvar_g_vehicles_steal_show_waypoint) {
1023 entity wp = WaypointSprite_Spawn(WP_VehicleIntruder, 0, 0, pl, '0 0 68', world, veh.team, veh, wps_intruder, true, RADARICON_DANGER);
1024 wp.colormod = Team_ColorRGB(pl.team);
1029 RemoveGrapplingHook(pl);
1031 veh.vehicle_ammo1 = 0;
1032 veh.vehicle_ammo2 = 0;
1033 veh.vehicle_reload1 = 0;
1034 veh.vehicle_reload2 = 0;
1035 veh.vehicle_energy = 0;
1040 // .viewmodelforclient works better.
1041 //veh.vehicle_hudmodel.drawonlytoclient = veh.owner;
1043 veh.vehicle_hudmodel.viewmodelforclient = pl;
1045 tracebox(pl.origin, PL_MIN, PL_MAX, pl.origin, false, pl);
1047 pl.view_ofs = PL_VIEW_OFS;
1048 setsize (pl, PL_MIN, PL_MAX);
1050 veh.event_damage = vehicles_damage;
1052 pl.angles = veh.angles;
1053 pl.takedamage = DAMAGE_NO;
1054 pl.solid = SOLID_NOT;
1055 pl.movetype = MOVETYPE_NOCLIP;
1056 pl.teleportable = false;
1058 pl.event_damage = func_null;
1059 pl.view_ofs = '0 0 0';
1060 veh.colormap = pl.colormap;
1062 veh.tur_head.colormap = pl.colormap;
1063 veh.switchweapon = pl.switchweapon;
1064 pl.hud = veh.vehicleid;
1065 pl.PlayerPhysplug = veh.PlayerPhysplug;
1067 pl.vehicle_ammo1 = veh.vehicle_ammo1;
1068 pl.vehicle_ammo2 = veh.vehicle_ammo2;
1069 pl.vehicle_reload1 = veh.vehicle_reload1;
1070 pl.vehicle_reload2 = veh.vehicle_reload2;
1071 pl.vehicle_energy = veh.vehicle_energy;
1073 // Cant do this, hides attached objects too.
1074 //veh.exteriormodeltoclient = veh.owner;
1075 //veh.tur_head.exteriormodeltoclient = veh.owner;
1077 pl.flags &= ~FL_ONGROUND;
1078 veh.flags &= ~FL_ONGROUND;
1081 veh.flags -= FL_NOTARGET;
1083 if (IS_REAL_CLIENT(pl))
1085 Send_Notification(NOTIF_ONE, pl, MSG_CENTER, CENTER_VEHICLE_ENTER);
1088 WriteByte (MSG_ONE, SVC_SETVIEWPORT);
1089 WriteEntity(MSG_ONE, veh.vehicle_viewport);
1091 WriteByte (MSG_ONE, SVC_SETVIEWANGLES);
1094 WriteAngle(MSG_ONE, veh.tur_head.angles_x + veh.angles_x); // tilt
1095 WriteAngle(MSG_ONE, veh.tur_head.angles_y + veh.angles_y); // yaw
1096 WriteAngle(MSG_ONE, 0); // roll
1100 WriteAngle(MSG_ONE, veh.angles_x * -1); // tilt
1101 WriteAngle(MSG_ONE, veh.angles_y); // yaw
1102 WriteAngle(MSG_ONE, 0); // roll
1106 vehicles_clearreturn(veh);
1108 CSQCVehicleSetup(pl, veh.vehicleid);
1110 MUTATOR_CALLHOOK(VehicleEnter, pl, veh);
1113 CSQCModel_UnlinkEntity(veh);
1114 Vehicle info = get_vehicleinfo(veh.vehicleid);
1115 info.vr_enter(info);
1121 void vehicles_think()
1123 self.nextthink = time;
1126 self.owner.vehicle_weapon2mode = self.vehicle_weapon2mode;
1128 Vehicle info = get_vehicleinfo(self.vehicleid);
1129 info.vr_think(info);
1131 CSQCMODEL_AUTOUPDATE(self);
1135 void vehicles_spawn()
1137 LOG_TRACE("Spawning vehicle: ", self.classname, "\n");
1140 self.vehicle_hudmodel.viewmodelforclient = self;
1143 self.touch = vehicles_touch;
1144 self.event_damage = vehicles_damage;
1145 self.iscreature = true;
1146 self.teleportable = false; // no teleporting for vehicles, too buggy
1147 self.damagedbycontents = true;
1148 self.movetype = MOVETYPE_WALK;
1149 self.solid = SOLID_SLIDEBOX;
1150 self.takedamage = DAMAGE_AIM;
1151 self.deadflag = DEAD_NO;
1152 self.bot_attack = true;
1153 self.flags = FL_NOTARGET;
1154 self.avelocity = '0 0 0';
1155 self.velocity = '0 0 0';
1156 self.think = vehicles_think;
1157 self.nextthink = time;
1160 self.lock_strength = 0;
1161 self.lock_target = world;
1162 self.misc_bulletcounter = 0;
1165 self.angles = self.pos2;
1166 setorigin(self, self.pos1);
1168 Send_Effect(EFFECT_TELEPORT, self.origin + '0 0 64', '0 0 0', 1);
1170 if(self.vehicle_controller)
1171 self.team = self.vehicle_controller.team;
1173 entity head; // remove hooks (if any)
1174 FOR_EACH_PLAYER(head)
1175 if(head.hook.aiment == self)
1176 RemoveGrapplingHook(head);
1178 vehicles_reset_colors();
1180 Vehicle info = get_vehicleinfo(self.vehicleid);
1181 info.vr_spawn(info);
1183 CSQCMODEL_AUTOINIT(self);
1186 bool vehicle_initialize(entity veh, bool nodrop)
1188 if(!autocvar_g_vehicles)
1195 Vehicle info = get_vehicleinfo(veh.vehicleid);
1196 info.vr_precache(info);
1199 if(self.targetname && self.targetname != "")
1201 self.vehicle_controller = find(world, target, self.targetname);
1202 if(!self.vehicle_controller)
1204 bprint("^1WARNING: ^7Vehicle with invalid .targetname\n");
1205 self.active = ACTIVE_ACTIVE;
1209 self.team = self.vehicle_controller.team;
1210 self.use = vehicle_use;
1214 if(self.vehicle_controller.team == 0)
1215 self.active = ACTIVE_NOT;
1217 self.active = ACTIVE_ACTIVE;
1221 else { self.active = ACTIVE_ACTIVE; }
1223 if(self.team && (!teamplay || !autocvar_g_vehicles_teams))
1226 if(self.mdl == "" || !self.mdl)
1227 _setmodel(self, veh.model);
1229 _setmodel(self, self.mdl);
1231 self.vehicle_flags |= VHF_ISVEHICLE;
1233 self.vehicle_viewport = new(vehicle_viewport);
1234 self.vehicle_hudmodel = new(vehicle_hudmodel);
1235 self.tur_head = new(tur_head);
1236 self.tur_head.owner = self;
1237 self.takedamage = DAMAGE_NO;
1238 self.bot_attack = true;
1239 self.iscreature = true;
1240 self.teleportable = false; // no teleporting for vehicles, too buggy
1241 self.damagedbycontents = true;
1242 self.vehicleid = veh.vehicleid;
1243 self.PlayerPhysplug = veh.PlayerPhysplug;
1244 self.event_damage = func_null;
1245 self.touch = vehicles_touch;
1246 self.think = vehicles_spawn;
1247 self.nextthink = time;
1248 self.effects = EF_NODRAW;
1249 self.dphitcontentsmask = DPCONTENTS_BODY | DPCONTENTS_SOLID;
1251 if(autocvar_g_playerclip_collisions)
1252 self.dphitcontentsmask |= DPCONTENTS_PLAYERCLIP;
1254 if(autocvar_g_nodepthtestplayers)
1255 self.effects |= EF_NODEPTHTEST;
1257 if(autocvar_g_fullbrightplayers)
1258 self.effects |= EF_FULLBRIGHT;
1260 _setmodel(self.vehicle_hudmodel, veh.hud_model);
1261 setmodel(self.vehicle_viewport, MDL_Null);
1263 if(veh.head_model != "")
1265 _setmodel(self.tur_head, veh.head_model);
1266 setattachment(self.tur_head, self, veh.tag_head);
1267 setattachment(self.vehicle_hudmodel, self.tur_head, veh.tag_hud);
1268 setattachment(self.vehicle_viewport, self.vehicle_hudmodel, veh.tag_view);
1272 setattachment(self.tur_head, self, "");
1273 setattachment(self.vehicle_hudmodel, self, veh.tag_hud);
1274 setattachment(self.vehicle_viewport, self.vehicle_hudmodel, veh.tag_view);
1277 setsize(self, veh.mins, veh.maxs);
1281 setorigin(self, self.origin);
1282 tracebox(self.origin + '0 0 100', veh.mins, veh.maxs, self.origin - '0 0 10000', MOVE_WORLDONLY, self);
1283 setorigin(self, trace_endpos);
1286 self.pos1 = self.origin;
1287 self.pos2 = self.angles;
1288 self.tur_head.team = self.team;
1290 Vehicle info = get_vehicleinfo(veh.vehicleid);
1291 info.vr_setup(info);
1293 if(self.active == ACTIVE_NOT)
1294 self.nextthink = 0; // wait until activated
1295 else if(autocvar_g_vehicles_delayspawn)
1296 self.nextthink = time + self.respawntime + (random() * autocvar_g_vehicles_delayspawn_jitter);
1298 self.nextthink = time + game_starttime;
1300 if(MUTATOR_CALLHOOK(VehicleSpawn))