1 #include "../effects.qh"
3 #include "sv_vehicles.qh"
6 bool vehicle_send(entity to, int sf)
8 WriteByte(MSG_ENTITY, ENT_CLIENT_VEHICLE);
9 WriteByte(MSG_ENTITY, sf);
13 WriteByte(MSG_ENTITY, self.vehicleid);
23 // player handles the .vehicle stuff, we need only set ourselves up for driving
42 bool SendAuxiliaryXhair(entity to, int sf)
45 WriteByte(MSG_ENTITY, ENT_CLIENT_AUXILIARYXHAIR);
47 WriteByte(MSG_ENTITY, self.cnt);
49 WriteCoord(MSG_ENTITY, self.origin_x);
50 WriteCoord(MSG_ENTITY, self.origin_y);
51 WriteCoord(MSG_ENTITY, self.origin_z);
53 WriteByte(MSG_ENTITY, rint(self.colormod_x * 255));
54 WriteByte(MSG_ENTITY, rint(self.colormod_y * 255));
55 WriteByte(MSG_ENTITY, rint(self.colormod_z * 255));
60 void UpdateAuxiliaryXhair(entity own, vector loc, vector clr, int axh_id)
62 if(!IS_REAL_CLIENT(own))
67 axh_id = bound(0, axh_id, MAX_AXH);
68 axh = own.(AuxiliaryXhair[axh_id]);
70 if(axh == world || wasfreed(axh)) // MADNESS? THIS IS QQQQCCCCCCCCC (wasfreed, why do you exsist?)
74 axh.drawonlytoclient = own;
76 Net_LinkEntity(axh, false, 0, SendAuxiliaryXhair);
82 own.(AuxiliaryXhair[axh_id]) = axh;
85 void CSQCVehicleSetup(entity own, int vehicle_id)
87 if(!IS_REAL_CLIENT(own))
92 WriteByte(MSG_ONE, SVC_TEMPENTITY);
93 WriteByte(MSG_ONE, TE_CSQC_VEHICLESETUP);
94 WriteByte(MSG_ONE, vehicle_id);
97 vector targetdrone_getnewspot()
101 for(i = 0; i < 100; ++i)
103 spot = self.origin + randomvec() * 1024;
104 tracebox(spot, self.mins, self.maxs, spot, MOVE_NORMAL, self);
105 if(trace_fraction == 1.0 && trace_startsolid == 0 && trace_allsolid == 0)
111 void vehicles_locktarget(float incr, float decr, float _lock_time)
113 if(self.lock_target && self.lock_target.deadflag != DEAD_NO)
115 self.lock_target = world;
116 self.lock_strength = 0;
120 if(self.lock_time > time)
123 if(self.lock_soundtime < time)
125 self.lock_soundtime = time + 0.5;
126 play2(self.owner, "vehicles/locked.wav");
132 if(trace_ent != world)
134 if(SAME_TEAM(trace_ent, self))
137 if(trace_ent.deadflag != DEAD_NO)
140 if(!(IS_VEHICLE(trace_ent) || IS_TURRET(trace_ent)))
143 if(trace_ent.alpha <= 0.5 && trace_ent.alpha != 0)
144 trace_ent = world; // invisible
147 if(self.lock_target == world && trace_ent != world)
148 self.lock_target = trace_ent;
150 if(self.lock_target && trace_ent == self.lock_target)
152 if(self.lock_strength != 1 && self.lock_strength + incr >= 1)
154 play2(self.owner, "vehicles/lock.wav");
155 self.lock_soundtime = time + 0.8;
157 else if (self.lock_strength != 1 && self.lock_soundtime < time)
159 play2(self.owner, "vehicles/locking.wav");
160 self.lock_soundtime = time + 0.3;
164 // Have a locking target
165 // Trace hit current target
166 if(trace_ent == self.lock_target && trace_ent != world)
168 self.lock_strength = min(self.lock_strength + incr, 1);
169 if(self.lock_strength == 1)
170 self.lock_time = time + _lock_time;
175 self.lock_strength = max(self.lock_strength - decr * 2, 0);
177 self.lock_strength = max(self.lock_strength - decr, 0);
179 if(self.lock_strength == 0)
180 self.lock_target = world;
184 vector vehicles_force_fromtag_hover(string tag_name, float spring_length, float max_power)
186 force_fromtag_origin = gettaginfo(self, gettagindex(self, tag_name));
187 v_forward = normalize(v_forward) * -1;
188 traceline(force_fromtag_origin, force_fromtag_origin - (v_forward * spring_length), MOVE_NORMAL, self);
190 force_fromtag_power = (1 - trace_fraction) * max_power;
191 force_fromtag_normpower = force_fromtag_power / max_power;
193 return v_forward * force_fromtag_power;
196 vector vehicles_force_fromtag_maglev(string tag_name, float spring_length, float max_power)
199 force_fromtag_origin = gettaginfo(self, gettagindex(self, tag_name));
200 v_forward = normalize(v_forward) * -1;
201 traceline(force_fromtag_origin, force_fromtag_origin - (v_forward * spring_length), MOVE_NORMAL, self);
203 // TODO - this may NOT be compatible with wall/celing movement, unhardcode 0.25 (engine count multiplier)
204 if(trace_fraction == 1.0)
206 force_fromtag_normpower = -0.25;
210 force_fromtag_power = ((1 - trace_fraction) - trace_fraction) * max_power;
211 force_fromtag_normpower = force_fromtag_power / max_power;
213 return v_forward * force_fromtag_power;
216 // projectile handling
217 void vehicles_projectile_damage(entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force)
219 // Ignore damage from oterh projectiles from my owner (dont mess up volly's)
220 if(inflictor.owner == self.owner)
223 self.health -= damage;
224 self.velocity += force;
227 self.takedamage = DAMAGE_NO;
228 self.event_damage = func_null;
229 self.think = self.use;
230 self.nextthink = time;
234 void vehicles_projectile_explode()
236 if(self.owner && other != world)
238 if(other == self.owner.vehicle)
241 if(other == self.owner.vehicle.tur_head)
247 self.event_damage = func_null;
248 RadiusDamage (self, self.realowner, self.shot_dmg, 0, self.shot_radius, self, world, self.shot_force, self.totalfrags, other);
253 entity vehicles_projectile(string _mzlfx, string _mzlsound,
254 vector _org, vector _vel,
255 float _dmg, float _radi, float _force, float _size,
256 int _deahtype, float _projtype, float _health,
257 bool _cull, bool _clianim, entity _owner)
263 PROJECTILE_MAKETRIGGER(proj);
264 setorigin(proj, _org);
266 proj.shot_dmg = _dmg;
267 proj.shot_radius = _radi;
268 proj.shot_force = _force;
269 proj.totalfrags = _deahtype;
270 proj.solid = SOLID_BBOX;
271 proj.movetype = MOVETYPE_FLYMISSILE;
272 proj.flags = FL_PROJECTILE;
273 proj.bot_dodge = true;
274 proj.bot_dodgerating = _dmg;
275 proj.velocity = _vel;
276 proj.touch = vehicles_projectile_explode;
277 proj.use = vehicles_projectile_explode;
279 proj.realowner = _owner;
280 proj.think = SUB_Remove;
281 proj.nextthink = time + 30;
285 proj.takedamage = DAMAGE_AIM;
286 proj.event_damage = vehicles_projectile_damage;
287 proj.health = _health;
290 proj.flags = FL_PROJECTILE | FL_NOTARGET;
293 sound (self, CH_WEAPON_A, _mzlsound, VOL_BASE, ATTEN_NORM);
296 Send_Effect(_mzlfx, proj.origin, proj.velocity, 1);
298 setsize (proj, '-1 -1 -1' * _size, '1 1 1' * _size);
300 CSQCProjectile(proj, _clianim, _projtype, _cull);
305 void vehicles_gib_explode()
307 sound (self, CH_SHOTS, "weapons/rocket_impact.wav", VOL_BASE, ATTEN_NORM);
308 Send_Effect("explosion_small", randomvec() * 80 + (self.origin + '0 0 100'), '0 0 0', 1);
309 Send_Effect("explosion_small", self.wp00.origin + '0 0 64', '0 0 0', 1);
313 void vehicles_gib_think()
319 self.nextthink = time + 0.1;
322 entity vehicle_tossgib(entity _template, vector _vel, string _tag, bool _burn, bool _explode, float _maxtime, vector _rot)
324 entity _gib = spawn();
325 setmodel(_gib, _template.model);
326 setorigin(_gib, gettaginfo(self, gettagindex(self, _tag)));
327 _gib.velocity = _vel;
328 _gib.movetype = MOVETYPE_TOSS;
329 _gib.solid = SOLID_CORPSE;
330 _gib.colormod = '-0.5 -0.5 -0.5';
331 _gib.effects = EF_LOWPRECISION;
332 _gib.avelocity = _rot;
335 _gib.effects |= EF_FLAME;
339 _gib.think = vehicles_gib_explode;
340 _gib.nextthink = time + random() * _explode;
341 _gib.touch = vehicles_gib_explode;
345 _gib.cnt = time + _maxtime;
346 _gib.think = vehicles_gib_think;
347 _gib.nextthink = time + _maxtime - 1;
353 bool vehicle_addplayerslot( entity _owner,
358 void(bool) _exitfunc, float() _enterfunc)
360 if(!(_owner.vehicle_flags & VHF_MULTISLOT))
361 _owner.vehicle_flags |= VHF_MULTISLOT;
363 _slot.PlayerPhysplug = _framefunc;
364 _slot.vehicle_exit = _exitfunc;
365 _slot.vehicle_enter = _enterfunc;
367 _slot.vehicle_flags = VHF_PLAYERSLOT;
368 _slot.vehicle_viewport = spawn();
369 _slot.vehicle_hudmodel = spawn();
370 _slot.vehicle_hudmodel.viewmodelforclient = _slot;
371 _slot.vehicle_viewport.effects = (EF_ADDITIVE | EF_DOUBLESIDED | EF_FULLBRIGHT | EF_NODEPTHTEST | EF_NOGUNBOB | EF_NOSHADOW | EF_LOWPRECISION | EF_SELECTABLE | EF_TELEPORT_BIT);
373 setmodel(_slot.vehicle_hudmodel, _hud_model);
374 setmodel(_slot.vehicle_viewport, "null");
376 setattachment(_slot.vehicle_hudmodel, _slot, "");
377 setattachment(_slot.vehicle_viewport, _slot.vehicle_hudmodel, "");
382 vector vehicle_aimturret(entity _vehic, vector _target, entity _turrret, string _tagname,
383 float _pichlimit_min, float _pichlimit_max,
384 float _rotlimit_min, float _rotlimit_max, float _aimspeed)
388 vtag = gettaginfo(_turrret, gettagindex(_turrret, _tagname));
389 vtmp = vectoangles(normalize(_target - vtag));
390 vtmp = AnglesTransform_ToAngles(AnglesTransform_LeftDivide(AnglesTransform_FromAngles(_vehic.angles), AnglesTransform_FromAngles(vtmp))) - _turrret.angles;
391 vtmp = AnglesTransform_Normalize(vtmp, true);
392 ftmp = _aimspeed * frametime;
393 vtmp_y = bound(-ftmp, vtmp_y, ftmp);
394 vtmp_x = bound(-ftmp, vtmp_x, ftmp);
395 _turrret.angles_y = bound(_rotlimit_min, _turrret.angles_y + vtmp_y, _rotlimit_max);
396 _turrret.angles_x = bound(_pichlimit_min, _turrret.angles_x + vtmp_x, _pichlimit_max);
400 void vehicles_reset_colors()
403 float _effects = 0, _colormap;
404 vector _glowmod, _colormod;
406 if(autocvar_g_nodepthtestplayers)
407 _effects |= EF_NODEPTHTEST;
409 if(autocvar_g_fullbrightplayers)
410 _effects |= EF_FULLBRIGHT;
413 _colormap = 1024 + (self.team - 1) * 17;
420 // Find all ents attacked to main model and setup effects, colormod etc.
421 e = findchainentity(tag_entity, self);
424 if(e != self.vehicle_shieldent)
426 e.effects = _effects; // | EF_LOWPRECISION;
427 e.colormod = _colormod;
428 e.colormap = _colormap;
433 // Also check head tags
434 e = findchainentity(tag_entity, self.tur_head);
437 if(e != self.vehicle_shieldent)
439 e.effects = _effects; // | EF_LOWPRECISION;
440 e.colormod = _colormod;
441 e.colormap = _colormap;
447 self.vehicle_hudmodel.effects = self.effects = _effects; // | EF_LOWPRECISION;
448 self.vehicle_hudmodel.colormod = self.colormod = _colormod;
449 self.vehicle_hudmodel.colormap = self.colormap = _colormap;
450 self.vehicle_viewport.effects = (EF_ADDITIVE | EF_DOUBLESIDED | EF_FULLBRIGHT | EF_NODEPTHTEST | EF_NOGUNBOB | EF_NOSHADOW | EF_LOWPRECISION | EF_SELECTABLE | EF_TELEPORT_BIT);
453 self.avelocity = '0 0 0';
454 self.velocity = '0 0 0';
455 self.effects = _effects;
458 void vehicles_clearreturn(entity veh)
461 // Remove "return helper", if any.
462 ret = findchain(classname, "vehicle_return");
468 ret.think = SUB_Remove;
469 ret.nextthink = time + 0.1;
471 if(ret.waypointsprite_attached)
472 WaypointSprite_Kill(ret.waypointsprite_attached);
480 void vehicles_spawn();
481 void vehicles_return()
483 Send_Effect("teleport", self.wp00.origin + '0 0 64', '0 0 0', 1);
485 self.wp00.think = vehicles_spawn;
486 self.wp00.nextthink = time;
488 if(self.waypointsprite_attached)
489 WaypointSprite_Kill(self.waypointsprite_attached);
494 void vehicles_showwp_goaway()
496 if(self.waypointsprite_attached)
497 WaypointSprite_Kill(self.waypointsprite_attached);
503 void vehicles_showwp()
505 entity oldself = world;
510 self.think = vehicles_return;
511 self.nextthink = self.cnt;
515 self.think = vehicles_return;
516 self.nextthink = time +1;
520 setmodel(self, "null");
521 self.team = oldself.wp00.team;
522 self.wp00 = oldself.wp00;
523 setorigin(self, oldself.wp00.pos1);
525 self.nextthink = time + 5;
526 self.think = vehicles_showwp_goaway;
529 if(teamplay && self.team)
530 rgb = Team_ColorRGB(self.team);
533 WaypointSprite_Spawn("vehicle", 0, 0, self, '0 0 64', world, 0, self, waypointsprite_attached, true, RADARICON_POWERUP, rgb);
534 if(self.waypointsprite_attached)
536 WaypointSprite_UpdateRule(self.waypointsprite_attached, self.wp00.team, SPRITERULE_DEFAULT);
538 WaypointSprite_UpdateBuildFinished(self.waypointsprite_attached, self.nextthink);
539 WaypointSprite_Ping(self.waypointsprite_attached);
546 void vehicles_setreturn(entity veh)
550 vehicles_clearreturn(veh);
553 ret.classname = "vehicle_return";
556 ret.think = vehicles_showwp;
558 if(veh.deadflag != DEAD_NO)
560 ret.cnt = time + veh.respawntime;
561 ret.nextthink = min(time + veh.respawntime, time + veh.respawntime - 5);
565 ret.nextthink = min(time + veh.respawntime, time + veh.respawntime - 1);
568 setmodel(ret, "null");
569 setorigin(ret, veh.pos1 + '0 0 96');
575 dprint("vehicle ",self.netname, " used by ", activator.classname, "\n");
577 self.tur_head.team = activator.team;
579 if(self.tur_head.team == 0)
580 self.active = ACTIVE_NOT;
582 self.active = ACTIVE_ACTIVE;
584 if(self.active == ACTIVE_ACTIVE && self.deadflag == DEAD_NO && !gameover)
586 dprint("Respawning vehicle: ", self.netname, "\n");
587 if(self.effects & EF_NODRAW)
589 self.think = vehicles_spawn;
590 self.nextthink = time + 3;
594 vehicles_setreturn(self);
595 vehicles_reset_colors();
600 void vehicles_regen(float timer, .float regen_field, float field_max, float rpause, float regen, float delta_time, float _healthscale)
602 if(self.regen_field < field_max)
603 if(timer + rpause < time)
606 regen = regen * (self.vehicle_health / self.max_health);
608 self.regen_field = min(self.regen_field + regen * delta_time, field_max);
611 self.owner.regen_field = (self.regen_field / field_max) * 100;
615 void shieldhit_think()
620 //setmodel(self, "");
622 self.effects |= EF_NODRAW;
626 self.nextthink = time + 0.1;
630 void vehicles_painframe()
632 if(self.owner.vehicle_health <= 50)
633 if(self.pain_frame < time)
636 _ftmp = self.owner.vehicle_health / 50;
637 self.pain_frame = time + 0.1 + (random() * 0.5 * _ftmp);
638 pointparticles(particleeffectnum("smoke_small"), (self.origin + (randomvec() * 80)), '0 0 0', 1);
640 if(self.vehicle_flags & VHF_DMGSHAKE)
641 self.velocity += randomvec() * 30;
643 if(self.vehicle_flags & VHF_DMGROLL)
644 if(self.vehicle_flags & VHF_DMGHEADROLL)
645 self.tur_head.angles += randomvec();
647 self.angles += randomvec();
652 void vehicles_damage(entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force)
654 self.dmg_time = time;
657 if(DEATH_ISWEAPON(deathtype, WEP_VORTEX.m_id))
658 damage *= autocvar_g_vehicles_vortex_damagerate;
660 if(DEATH_ISWEAPON(deathtype, WEP_MACHINEGUN.m_id))
661 damage *= autocvar_g_vehicles_machinegun_damagerate;
663 if(DEATH_ISWEAPON(deathtype, WEP_RIFLE.m_id))
664 damage *= autocvar_g_vehicles_rifle_damagerate;
666 if(DEATH_ISWEAPON(deathtype, WEP_VAPORIZER.m_id))
667 damage *= autocvar_g_vehicles_vaporizer_damagerate;
669 if(DEATH_ISWEAPON(deathtype, WEP_SEEKER.m_id))
670 damage *= autocvar_g_vehicles_tag_damagerate;
672 if(DEATH_WEAPONOFWEAPONDEATH(deathtype))
673 damage *= autocvar_g_vehicles_weapon_damagerate;
675 self.enemy = attacker;
677 self.pain_finished = time;
679 if((self.vehicle_flags & VHF_HASSHIELD) && (self.vehicle_shield > 0))
681 if (wasfreed(self.vehicle_shieldent) || self.vehicle_shieldent == world)
683 self.vehicle_shieldent = spawn();
684 self.vehicle_shieldent.effects = EF_LOWPRECISION;
686 setmodel(self.vehicle_shieldent, "models/vhshield.md3");
687 setattachment(self.vehicle_shieldent, self, "");
688 setorigin(self.vehicle_shieldent, real_origin(self) - self.origin);
689 self.vehicle_shieldent.scale = 256 / vlen(self.maxs - self.mins);
690 self.vehicle_shieldent.think = shieldhit_think;
693 self.vehicle_shieldent.colormod = '1 1 1';
694 self.vehicle_shieldent.alpha = 0.45;
695 self.vehicle_shieldent.angles = vectoangles(normalize(hitloc - (self.origin + self.vehicle_shieldent.origin))) - self.angles;
696 self.vehicle_shieldent.nextthink = time;
697 self.vehicle_shieldent.effects &= ~EF_NODRAW;
699 self.vehicle_shield -= damage;
701 if(self.vehicle_shield < 0)
703 self.vehicle_health -= fabs(self.vehicle_shield);
704 self.vehicle_shieldent.colormod = '2 0 0';
705 self.vehicle_shield = 0;
706 self.vehicle_shieldent.alpha = 0.75;
708 if(sound_allowed(MSG_BROADCAST, attacker))
709 spamsound (self, CH_PAIN, "onslaught/ons_hit2.wav", VOL_BASE, ATTEN_NORM); // FIXME: PLACEHOLDER
712 if(sound_allowed(MSG_BROADCAST, attacker))
713 spamsound (self, CH_PAIN, "onslaught/electricity_explode.wav", VOL_BASE, ATTEN_NORM); // FIXME: PLACEHOLDER
718 self.vehicle_health -= damage;
720 if(sound_allowed(MSG_BROADCAST, attacker))
721 spamsound (self, CH_PAIN, "onslaught/ons_hit2.wav", VOL_BASE, ATTEN_NORM); // FIXME: PLACEHOLDER
724 if(self.damageforcescale < 1 && self.damageforcescale > 0)
725 self.velocity += force * self.damageforcescale;
727 self.velocity += force;
729 if(self.vehicle_health <= 0)
732 if(self.vehicle_flags & VHF_DEATHEJECT)
733 vehicles_exit(VHEF_EJECT);
735 vehicles_exit(VHEF_RELEASE);
740 VEH_ACTION(self.vehicleid, VR_DEATH);
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)
831 entity _oldself = self;
833 if(vehicles_exit_running)
835 dprint("^1vehicles_exit allready running! this is not good..\n");
839 vehicles_exit_running = true;
842 _vehicle = self.vehicle;
844 if (_vehicle.vehicle_flags & VHF_PLAYERSLOT)
846 _vehicle.vehicle_exit(eject);
848 vehicles_exit_running = false;
855 _player = _vehicle.owner;
861 if (IS_REAL_CLIENT(_player))
863 msg_entity = _player;
864 WriteByte (MSG_ONE, SVC_SETVIEWPORT);
865 WriteEntity( MSG_ONE, _player);
867 WriteByte (MSG_ONE, SVC_SETVIEWANGLES);
868 WriteAngle(MSG_ONE, 0);
869 WriteAngle(MSG_ONE, _vehicle.angles_y);
870 WriteAngle(MSG_ONE, 0);
873 setsize(_player, PL_MIN,PL_MAX);
875 _player.takedamage = DAMAGE_AIM;
876 _player.solid = SOLID_SLIDEBOX;
877 _player.movetype = MOVETYPE_WALK;
878 _player.effects &= ~EF_NODRAW;
879 _player.teleportable = TELEPORT_NORMAL;
881 _player.PlayerPhysplug = func_null;
882 _player.vehicle = world;
883 _player.view_ofs = PL_VIEW_OFS;
884 _player.event_damage = PlayerDamage;
885 _player.hud = HUD_NORMAL;
886 _player.switchweapon = _vehicle.switchweapon;
887 _player.last_vehiclecheck = time + 3;
888 _player.vehicle_enter_delay = time + 2;
890 CSQCVehicleSetup(_player, HUD_NORMAL);
892 _vehicle.flags |= FL_NOTARGET;
894 if(_vehicle.deadflag == DEAD_NO)
895 _vehicle.avelocity = '0 0 0';
897 _vehicle.tur_head.nodrawtoclient = world;
902 Kill_Notification(NOTIF_ONE, _player, MSG_CENTER_CPID, CPID_VEHICLES);
903 Kill_Notification(NOTIF_ONE, _player, MSG_CENTER_CPID, CPID_VEHICLES_OTHER); // kill all vehicle notifications when exiting a vehicle?
905 WaypointSprite_Kill(_vehicle.wps_intruder);
907 MUTATOR_CALLHOOK(VehicleExit, _player, _vehicle);
909 _vehicle.team = _vehicle.tur_head.team;
911 sound (_vehicle, CH_TRIGGER_SINGLE, "misc/null.wav", 1, ATTEN_NORM);
912 _vehicle.vehicle_hudmodel.viewmodelforclient = _vehicle;
913 _vehicle.phase = time + 1;
915 _vehicle.vehicle_exit(eject);
917 vehicles_setreturn(_vehicle);
918 vehicles_reset_colors();
919 _vehicle.owner = world;
921 CSQCMODEL_AUTOINIT();
925 vehicles_exit_running = false;
928 void vehicles_touch()
930 if(MUTATOR_CALLHOOK(VehicleTouch, self, other))
933 // Vehicle currently in use
936 if(!forbidWeaponUse(self.owner))
938 if((self.origin_z + self.maxs_z) > (other.origin_z))
939 if(vehicles_crushable(other))
941 if(vlen(self.velocity) >= 30)
942 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);
944 return; // Dont do selfdamage when hitting "soft targets".
947 if(self.play_time < time)
948 VEH_ACTION(self.vehicleid, VR_IMPACT);
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)
991 entity oldself = self;
993 other = pl; // TODO: fix
996 if(time >= veh.gun1.phase)
997 if(veh.gun1.vehicle_enter)
998 if(veh.gun1.vehicle_enter())
1005 if(time >= veh.gun2.phase)
1006 if(veh.gun2.vehicle_enter)
1007 if(veh.gun2.vehicle_enter())
1018 if(DIFF_TEAM(pl, veh))
1019 if(autocvar_g_vehicles_steal)
1022 FOR_EACH_PLAYER(head) if(SAME_TEAM(head, veh))
1023 Send_Notification(NOTIF_ONE, head, MSG_CENTER, CENTER_VEHICLE_STEAL);
1025 Send_Notification(NOTIF_ONE, pl, MSG_CENTER, CENTER_VEHICLE_STEAL_SELF);
1027 if(autocvar_g_vehicles_steal_show_waypoint)
1028 WaypointSprite_Spawn("intruder", 0, 0, pl, '0 0 68', world, veh.team, veh, wps_intruder, true, RADARICON_DANGER, Team_ColorRGB(pl.team));
1032 RemoveGrapplingHook(pl);
1034 veh.vehicle_ammo1 = 0;
1035 veh.vehicle_ammo2 = 0;
1036 veh.vehicle_reload1 = 0;
1037 veh.vehicle_reload2 = 0;
1038 veh.vehicle_energy = 0;
1043 // .viewmodelforclient works better.
1044 //veh.vehicle_hudmodel.drawonlytoclient = veh.owner;
1046 veh.vehicle_hudmodel.viewmodelforclient = pl;
1048 tracebox(pl.origin, PL_MIN, PL_MAX, pl.origin, false, pl);
1050 pl.view_ofs = PL_VIEW_OFS;
1051 setsize (pl, PL_MIN, PL_MAX);
1053 veh.event_damage = vehicles_damage;
1055 pl.angles = veh.angles;
1056 pl.takedamage = DAMAGE_NO;
1057 pl.solid = SOLID_NOT;
1058 pl.movetype = MOVETYPE_NOCLIP;
1059 pl.teleportable = false;
1061 pl.event_damage = func_null;
1062 pl.view_ofs = '0 0 0';
1063 veh.colormap = pl.colormap;
1065 veh.tur_head.colormap = pl.colormap;
1066 veh.switchweapon = pl.switchweapon;
1067 pl.hud = veh.vehicleid;
1068 pl.PlayerPhysplug = veh.PlayerPhysplug;
1070 pl.vehicle_ammo1 = veh.vehicle_ammo1;
1071 pl.vehicle_ammo2 = veh.vehicle_ammo2;
1072 pl.vehicle_reload1 = veh.vehicle_reload1;
1073 pl.vehicle_reload2 = veh.vehicle_reload2;
1074 pl.vehicle_energy = veh.vehicle_energy;
1076 // Cant do this, hides attached objects too.
1077 //veh.exteriormodeltoclient = veh.owner;
1078 //veh.tur_head.exteriormodeltoclient = veh.owner;
1080 pl.flags &= ~FL_ONGROUND;
1081 veh.flags &= ~FL_ONGROUND;
1084 veh.flags -= FL_NOTARGET;
1086 if (IS_REAL_CLIENT(pl))
1088 Send_Notification(NOTIF_ONE, pl, MSG_CENTER, CENTER_VEHICLE_ENTER);
1091 WriteByte (MSG_ONE, SVC_SETVIEWPORT);
1092 WriteEntity(MSG_ONE, veh.vehicle_viewport);
1094 WriteByte (MSG_ONE, SVC_SETVIEWANGLES);
1097 WriteAngle(MSG_ONE, veh.tur_head.angles_x + veh.angles_x); // tilt
1098 WriteAngle(MSG_ONE, veh.tur_head.angles_y + veh.angles_y); // yaw
1099 WriteAngle(MSG_ONE, 0); // roll
1103 WriteAngle(MSG_ONE, veh.angles_x * -1); // tilt
1104 WriteAngle(MSG_ONE, veh.angles_y); // yaw
1105 WriteAngle(MSG_ONE, 0); // roll
1109 vehicles_clearreturn(veh);
1111 CSQCVehicleSetup(pl, veh.vehicleid);
1113 MUTATOR_CALLHOOK(VehicleEnter, pl, veh);
1115 entity oldself = self;
1117 CSQCModel_UnlinkEntity();
1118 VEH_ACTION(veh.vehicleid, VR_ENTER);
1124 void vehicles_think()
1126 self.nextthink = time;
1129 self.owner.vehicle_weapon2mode = self.vehicle_weapon2mode;
1131 VEH_ACTION(self.vehicleid, VR_THINK);
1133 CSQCMODEL_AUTOUPDATE();
1137 void vehicles_spawn()
1139 dprint("Spawning vehicle: ", self.classname, "\n");
1142 self.vehicle_hudmodel.viewmodelforclient = self;
1145 self.touch = vehicles_touch;
1146 self.event_damage = vehicles_damage;
1147 self.iscreature = true;
1148 self.teleportable = false; // no teleporting for vehicles, too buggy
1149 self.damagedbycontents = true;
1150 self.movetype = MOVETYPE_WALK;
1151 self.solid = SOLID_SLIDEBOX;
1152 self.takedamage = DAMAGE_AIM;
1153 self.deadflag = DEAD_NO;
1154 self.bot_attack = true;
1155 self.flags = FL_NOTARGET;
1156 self.avelocity = '0 0 0';
1157 self.velocity = '0 0 0';
1158 self.think = vehicles_think;
1159 self.nextthink = time;
1162 self.lock_strength = 0;
1163 self.lock_target = world;
1164 self.misc_bulletcounter = 0;
1167 self.angles = self.pos2;
1168 setorigin(self, self.pos1);
1170 Send_Effect("teleport", self.origin + '0 0 64', '0 0 0', 1);
1172 if(self.vehicle_controller)
1173 self.team = self.vehicle_controller.team;
1175 entity head; // remove hooks (if any)
1176 FOR_EACH_PLAYER(head)
1177 if(head.hook.aiment == self)
1178 RemoveGrapplingHook(head);
1180 vehicles_reset_colors();
1182 VEH_ACTION(self.vehicleid, VR_SPAWN);
1184 CSQCMODEL_AUTOINIT();
1187 bool vehicle_initialize(int vehicle_id, bool nodrop)
1189 if(!autocvar_g_vehicles)
1192 entity veh = get_vehicleinfo(vehicle_id);
1197 if(!veh.tur_head) { VEH_ACTION(vehicle_id, VR_PRECACHE); }
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 = spawn();
1234 self.vehicle_hudmodel = spawn();
1235 self.tur_head = spawn();
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 = vehicle_id;
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, "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 VEH_ACTION(vehicle_id, VR_SETUP);
1292 if(self.active == ACTIVE_NOT)
1293 self.nextthink = 0; // wait until activated
1294 else if(autocvar_g_vehicles_delayspawn)
1295 self.nextthink = time + self.respawntime + (random() * autocvar_g_vehicles_delayspawn_jitter);
1297 self.nextthink = time + game_starttime;
1299 if(MUTATOR_CALLHOOK(VehicleSpawn))