1 #include "sv_vehicles.qh"
2 #include "../effects.qh"
5 bool vehicle_send(entity to, int sf)
7 WriteByte(MSG_ENTITY, ENT_CLIENT_VEHICLE);
8 WriteByte(MSG_ENTITY, sf);
12 WriteByte(MSG_ENTITY, self.vehicleid);
22 // player handles the .vehicle stuff, we need only set ourselves up for driving
41 bool SendAuxiliaryXhair(entity to, int sf)
44 WriteByte(MSG_ENTITY, ENT_CLIENT_AUXILIARYXHAIR);
46 WriteByte(MSG_ENTITY, self.cnt);
48 WriteCoord(MSG_ENTITY, self.origin_x);
49 WriteCoord(MSG_ENTITY, self.origin_y);
50 WriteCoord(MSG_ENTITY, self.origin_z);
52 WriteByte(MSG_ENTITY, rint(self.colormod_x * 255));
53 WriteByte(MSG_ENTITY, rint(self.colormod_y * 255));
54 WriteByte(MSG_ENTITY, rint(self.colormod_z * 255));
59 void UpdateAuxiliaryXhair(entity own, vector loc, vector clr, int axh_id)
61 if(!IS_REAL_CLIENT(own))
66 axh_id = bound(0, axh_id, MAX_AXH);
67 axh = own.(AuxiliaryXhair[axh_id]);
69 if(axh == world || wasfreed(axh)) // MADNESS? THIS IS QQQQCCCCCCCCC (wasfreed, why do you exsist?)
73 axh.drawonlytoclient = own;
75 Net_LinkEntity(axh, false, 0, SendAuxiliaryXhair);
81 own.(AuxiliaryXhair[axh_id]) = axh;
84 void CSQCVehicleSetup(entity own, int vehicle_id)
86 if(!IS_REAL_CLIENT(own))
91 WriteByte(MSG_ONE, SVC_TEMPENTITY);
92 WriteByte(MSG_ONE, TE_CSQC_VEHICLESETUP);
93 WriteByte(MSG_ONE, vehicle_id);
96 vector targetdrone_getnewspot()
100 for(i = 0; i < 100; ++i)
102 spot = self.origin + randomvec() * 1024;
103 tracebox(spot, self.mins, self.maxs, spot, MOVE_NORMAL, self);
104 if(trace_fraction == 1.0 && trace_startsolid == 0 && trace_allsolid == 0)
110 void vehicles_locktarget(float incr, float decr, float _lock_time)
112 if(self.lock_target && self.lock_target.deadflag != DEAD_NO)
114 self.lock_target = world;
115 self.lock_strength = 0;
119 if(self.lock_time > time)
122 if(self.lock_soundtime < time)
124 self.lock_soundtime = time + 0.5;
125 play2(self.owner, "vehicles/locked.wav");
131 if(trace_ent != world)
133 if(SAME_TEAM(trace_ent, self))
136 if(trace_ent.deadflag != DEAD_NO)
139 if(!(IS_VEHICLE(trace_ent) || IS_TURRET(trace_ent)))
142 if(trace_ent.alpha <= 0.5 && trace_ent.alpha != 0)
143 trace_ent = world; // invisible
146 if(self.lock_target == world && trace_ent != world)
147 self.lock_target = trace_ent;
149 if(self.lock_target && trace_ent == self.lock_target)
151 if(self.lock_strength != 1 && self.lock_strength + incr >= 1)
153 play2(self.owner, "vehicles/lock.wav");
154 self.lock_soundtime = time + 0.8;
156 else if (self.lock_strength != 1 && self.lock_soundtime < time)
158 play2(self.owner, "vehicles/locking.wav");
159 self.lock_soundtime = time + 0.3;
163 // Have a locking target
164 // Trace hit current target
165 if(trace_ent == self.lock_target && trace_ent != world)
167 self.lock_strength = min(self.lock_strength + incr, 1);
168 if(self.lock_strength == 1)
169 self.lock_time = time + _lock_time;
174 self.lock_strength = max(self.lock_strength - decr * 2, 0);
176 self.lock_strength = max(self.lock_strength - decr, 0);
178 if(self.lock_strength == 0)
179 self.lock_target = world;
183 vector vehicles_force_fromtag_hover(string tag_name, float spring_length, float max_power)
185 force_fromtag_origin = gettaginfo(self, gettagindex(self, tag_name));
186 v_forward = normalize(v_forward) * -1;
187 traceline(force_fromtag_origin, force_fromtag_origin - (v_forward * spring_length), MOVE_NORMAL, self);
189 force_fromtag_power = (1 - trace_fraction) * max_power;
190 force_fromtag_normpower = force_fromtag_power / max_power;
192 return v_forward * force_fromtag_power;
195 vector vehicles_force_fromtag_maglev(string tag_name, float spring_length, float max_power)
198 force_fromtag_origin = gettaginfo(self, gettagindex(self, tag_name));
199 v_forward = normalize(v_forward) * -1;
200 traceline(force_fromtag_origin, force_fromtag_origin - (v_forward * spring_length), MOVE_NORMAL, self);
202 // TODO - this may NOT be compatible with wall/celing movement, unhardcode 0.25 (engine count multiplier)
203 if(trace_fraction == 1.0)
205 force_fromtag_normpower = -0.25;
209 force_fromtag_power = ((1 - trace_fraction) - trace_fraction) * max_power;
210 force_fromtag_normpower = force_fromtag_power / max_power;
212 return v_forward * force_fromtag_power;
215 // projectile handling
216 void vehicles_projectile_damage(entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force)
218 // Ignore damage from oterh projectiles from my owner (dont mess up volly's)
219 if(inflictor.owner == self.owner)
222 self.health -= damage;
223 self.velocity += force;
226 self.takedamage = DAMAGE_NO;
227 self.event_damage = func_null;
228 self.think = self.use;
229 self.nextthink = time;
233 void vehicles_projectile_explode()
235 if(self.owner && other != world)
237 if(other == self.owner.vehicle)
240 if(other == self.owner.vehicle.tur_head)
246 self.event_damage = func_null;
247 RadiusDamage (self, self.realowner, self.shot_dmg, 0, self.shot_radius, self, world, self.shot_force, self.totalfrags, other);
252 entity vehicles_projectile(string _mzlfx, string _mzlsound,
253 vector _org, vector _vel,
254 float _dmg, float _radi, float _force, float _size,
255 int _deahtype, float _projtype, float _health,
256 bool _cull, bool _clianim, entity _owner)
262 PROJECTILE_MAKETRIGGER(proj);
263 setorigin(proj, _org);
265 proj.shot_dmg = _dmg;
266 proj.shot_radius = _radi;
267 proj.shot_force = _force;
268 proj.totalfrags = _deahtype;
269 proj.solid = SOLID_BBOX;
270 proj.movetype = MOVETYPE_FLYMISSILE;
271 proj.flags = FL_PROJECTILE;
272 proj.bot_dodge = true;
273 proj.bot_dodgerating = _dmg;
274 proj.velocity = _vel;
275 proj.touch = vehicles_projectile_explode;
276 proj.use = vehicles_projectile_explode;
278 proj.realowner = _owner;
279 proj.think = SUB_Remove;
280 proj.nextthink = time + 30;
284 proj.takedamage = DAMAGE_AIM;
285 proj.event_damage = vehicles_projectile_damage;
286 proj.health = _health;
289 proj.flags = FL_PROJECTILE | FL_NOTARGET;
292 sound (self, CH_WEAPON_A, _mzlsound, VOL_BASE, ATTEN_NORM);
295 Send_Effect_(_mzlfx, proj.origin, proj.velocity, 1);
297 setsize (proj, '-1 -1 -1' * _size, '1 1 1' * _size);
299 CSQCProjectile(proj, _clianim, _projtype, _cull);
304 void vehicles_gib_explode()
306 sound (self, CH_SHOTS, W_Sound("rocket_impact"), VOL_BASE, ATTEN_NORM);
307 Send_Effect(EFFECT_EXPLOSION_SMALL, randomvec() * 80 + (self.origin + '0 0 100'), '0 0 0', 1);
308 Send_Effect(EFFECT_EXPLOSION_SMALL, self.wp00.origin + '0 0 64', '0 0 0', 1);
312 void vehicles_gib_think()
318 self.nextthink = time + 0.1;
321 entity vehicle_tossgib(entity _template, vector _vel, string _tag, bool _burn, bool _explode, float _maxtime, vector _rot)
323 entity _gib = spawn();
324 setmodel(_gib, _template.model);
325 setorigin(_gib, gettaginfo(self, gettagindex(self, _tag)));
326 _gib.velocity = _vel;
327 _gib.movetype = MOVETYPE_TOSS;
328 _gib.solid = SOLID_CORPSE;
329 _gib.colormod = '-0.5 -0.5 -0.5';
330 _gib.effects = EF_LOWPRECISION;
331 _gib.avelocity = _rot;
334 _gib.effects |= EF_FLAME;
338 _gib.think = vehicles_gib_explode;
339 _gib.nextthink = time + random() * _explode;
340 _gib.touch = vehicles_gib_explode;
344 _gib.cnt = time + _maxtime;
345 _gib.think = vehicles_gib_think;
346 _gib.nextthink = time + _maxtime - 1;
352 bool vehicle_addplayerslot( entity _owner,
357 void(bool) _exitfunc, float() _enterfunc)
359 if(!(_owner.vehicle_flags & VHF_MULTISLOT))
360 _owner.vehicle_flags |= VHF_MULTISLOT;
362 _slot.PlayerPhysplug = _framefunc;
363 _slot.vehicle_exit = _exitfunc;
364 _slot.vehicle_enter = _enterfunc;
366 _slot.vehicle_flags = VHF_PLAYERSLOT;
367 _slot.vehicle_viewport = spawn();
368 _slot.vehicle_hudmodel = spawn();
369 _slot.vehicle_hudmodel.viewmodelforclient = _slot;
370 _slot.vehicle_viewport.effects = (EF_ADDITIVE | EF_DOUBLESIDED | EF_FULLBRIGHT | EF_NODEPTHTEST | EF_NOGUNBOB | EF_NOSHADOW | EF_LOWPRECISION | EF_SELECTABLE | EF_TELEPORT_BIT);
372 setmodel(_slot.vehicle_hudmodel, _hud_model);
373 setmodel(_slot.vehicle_viewport, "null");
375 setattachment(_slot.vehicle_hudmodel, _slot, "");
376 setattachment(_slot.vehicle_viewport, _slot.vehicle_hudmodel, "");
381 vector vehicle_aimturret(entity _vehic, vector _target, entity _turrret, string _tagname,
382 float _pichlimit_min, float _pichlimit_max,
383 float _rotlimit_min, float _rotlimit_max, float _aimspeed)
387 vtag = gettaginfo(_turrret, gettagindex(_turrret, _tagname));
388 vtmp = vectoangles(normalize(_target - vtag));
389 vtmp = AnglesTransform_ToAngles(AnglesTransform_LeftDivide(AnglesTransform_FromAngles(_vehic.angles), AnglesTransform_FromAngles(vtmp))) - _turrret.angles;
390 vtmp = AnglesTransform_Normalize(vtmp, true);
391 ftmp = _aimspeed * frametime;
392 vtmp_y = bound(-ftmp, vtmp_y, ftmp);
393 vtmp_x = bound(-ftmp, vtmp_x, ftmp);
394 _turrret.angles_y = bound(_rotlimit_min, _turrret.angles_y + vtmp_y, _rotlimit_max);
395 _turrret.angles_x = bound(_pichlimit_min, _turrret.angles_x + vtmp_x, _pichlimit_max);
399 void vehicles_reset_colors()
402 float _effects = 0, _colormap;
403 vector _glowmod, _colormod;
405 if(autocvar_g_nodepthtestplayers)
406 _effects |= EF_NODEPTHTEST;
408 if(autocvar_g_fullbrightplayers)
409 _effects |= EF_FULLBRIGHT;
412 _colormap = 1024 + (self.team - 1) * 17;
419 // Find all ents attacked to main model and setup effects, colormod etc.
420 e = findchainentity(tag_entity, self);
423 if(e != self.vehicle_shieldent)
425 e.effects = _effects; // | EF_LOWPRECISION;
426 e.colormod = _colormod;
427 e.colormap = _colormap;
432 // Also check head tags
433 e = findchainentity(tag_entity, self.tur_head);
436 if(e != self.vehicle_shieldent)
438 e.effects = _effects; // | EF_LOWPRECISION;
439 e.colormod = _colormod;
440 e.colormap = _colormap;
446 self.vehicle_hudmodel.effects = self.effects = _effects; // | EF_LOWPRECISION;
447 self.vehicle_hudmodel.colormod = self.colormod = _colormod;
448 self.vehicle_hudmodel.colormap = self.colormap = _colormap;
449 self.vehicle_viewport.effects = (EF_ADDITIVE | EF_DOUBLESIDED | EF_FULLBRIGHT | EF_NODEPTHTEST | EF_NOGUNBOB | EF_NOSHADOW | EF_LOWPRECISION | EF_SELECTABLE | EF_TELEPORT_BIT);
452 self.avelocity = '0 0 0';
453 self.velocity = '0 0 0';
454 self.effects = _effects;
457 void vehicles_clearreturn(entity veh)
460 // Remove "return helper", if any.
461 ret = findchain(classname, "vehicle_return");
467 ret.think = SUB_Remove;
468 ret.nextthink = time + 0.1;
470 if(ret.waypointsprite_attached)
471 WaypointSprite_Kill(ret.waypointsprite_attached);
479 void vehicles_spawn();
480 void vehicles_return()
482 Send_Effect(EFFECT_TELEPORT, self.wp00.origin + '0 0 64', '0 0 0', 1);
484 self.wp00.think = vehicles_spawn;
485 self.wp00.nextthink = time;
487 if(self.waypointsprite_attached)
488 WaypointSprite_Kill(self.waypointsprite_attached);
493 void vehicles_showwp_goaway()
495 if(self.waypointsprite_attached)
496 WaypointSprite_Kill(self.waypointsprite_attached);
502 void vehicles_showwp()
504 entity oldself = world;
509 self.think = vehicles_return;
510 self.nextthink = self.cnt;
514 self.think = vehicles_return;
515 self.nextthink = time +1;
519 setmodel(self, "null");
520 self.team = oldself.wp00.team;
521 self.wp00 = oldself.wp00;
522 setorigin(self, oldself.wp00.pos1);
524 self.nextthink = time + 5;
525 self.think = vehicles_showwp_goaway;
528 if(teamplay && self.team)
529 rgb = Team_ColorRGB(self.team);
532 entity wp = WaypointSprite_Spawn(WP_Vehicle, 0, 0, self, '0 0 64', world, 0, self, waypointsprite_attached, true, RADARICON_POWERUP);
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 LOG_TRACE("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 LOG_TRACE("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(EFFECT_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)
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, "misc/null.wav", 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 VEH_ACTION(self.vehicleid, VR_IMPACT);
951 if(autocvar_g_vehicles_enter)
954 vehicles_enter(other, self);
957 bool vehicle_impulse(int imp)
963 stuffcmd(self, "\ntoggle cl_eventchase_vehicle\nset _vehicles_shownchasemessage 1\n");
971 void vehicles_enter(entity pl, entity veh)
973 // Remove this when bots know how to use vehicles
974 if((IS_BOT_CLIENT(pl) && !autocvar_g_vehicles_allow_bots))
978 || (veh.phase >= time)
979 || (pl.vehicle_enter_delay >= time)
981 || (pl.deadflag != DEAD_NO)
985 if(autocvar_g_vehicles_enter) // vehicle's touch function should handle this if entering via use key is disabled (TODO)
986 if(veh.vehicle_flags & VHF_MULTISLOT)
990 other = pl; // TODO: fix
993 if(time >= veh.gun1.phase)
994 if(veh.gun1.vehicle_enter)
995 if(veh.gun1.vehicle_enter())
1002 if(time >= veh.gun2.phase)
1003 if(veh.gun2.vehicle_enter)
1004 if(veh.gun2.vehicle_enter())
1015 if(DIFF_TEAM(pl, veh))
1016 if(autocvar_g_vehicles_steal)
1019 FOR_EACH_PLAYER(head) if(SAME_TEAM(head, veh))
1020 Send_Notification(NOTIF_ONE, head, MSG_CENTER, CENTER_VEHICLE_STEAL);
1022 Send_Notification(NOTIF_ONE, pl, MSG_CENTER, CENTER_VEHICLE_STEAL_SELF);
1024 if (autocvar_g_vehicles_steal_show_waypoint) {
1025 entity wp = WaypointSprite_Spawn(WP_VehicleIntruder, 0, 0, pl, '0 0 68', world, veh.team, veh, wps_intruder, true, RADARICON_DANGER);
1026 wp.colormod = Team_ColorRGB(pl.team);
1031 RemoveGrapplingHook(pl);
1033 veh.vehicle_ammo1 = 0;
1034 veh.vehicle_ammo2 = 0;
1035 veh.vehicle_reload1 = 0;
1036 veh.vehicle_reload2 = 0;
1037 veh.vehicle_energy = 0;
1042 // .viewmodelforclient works better.
1043 //veh.vehicle_hudmodel.drawonlytoclient = veh.owner;
1045 veh.vehicle_hudmodel.viewmodelforclient = pl;
1047 tracebox(pl.origin, PL_MIN, PL_MAX, pl.origin, false, pl);
1049 pl.view_ofs = PL_VIEW_OFS;
1050 setsize (pl, PL_MIN, PL_MAX);
1052 veh.event_damage = vehicles_damage;
1054 pl.angles = veh.angles;
1055 pl.takedamage = DAMAGE_NO;
1056 pl.solid = SOLID_NOT;
1057 pl.movetype = MOVETYPE_NOCLIP;
1058 pl.teleportable = false;
1060 pl.event_damage = func_null;
1061 pl.view_ofs = '0 0 0';
1062 veh.colormap = pl.colormap;
1064 veh.tur_head.colormap = pl.colormap;
1065 veh.switchweapon = pl.switchweapon;
1066 pl.hud = veh.vehicleid;
1067 pl.PlayerPhysplug = veh.PlayerPhysplug;
1069 pl.vehicle_ammo1 = veh.vehicle_ammo1;
1070 pl.vehicle_ammo2 = veh.vehicle_ammo2;
1071 pl.vehicle_reload1 = veh.vehicle_reload1;
1072 pl.vehicle_reload2 = veh.vehicle_reload2;
1073 pl.vehicle_energy = veh.vehicle_energy;
1075 // Cant do this, hides attached objects too.
1076 //veh.exteriormodeltoclient = veh.owner;
1077 //veh.tur_head.exteriormodeltoclient = veh.owner;
1079 pl.flags &= ~FL_ONGROUND;
1080 veh.flags &= ~FL_ONGROUND;
1083 veh.flags -= FL_NOTARGET;
1085 if (IS_REAL_CLIENT(pl))
1087 Send_Notification(NOTIF_ONE, pl, MSG_CENTER, CENTER_VEHICLE_ENTER);
1090 WriteByte (MSG_ONE, SVC_SETVIEWPORT);
1091 WriteEntity(MSG_ONE, veh.vehicle_viewport);
1093 WriteByte (MSG_ONE, SVC_SETVIEWANGLES);
1096 WriteAngle(MSG_ONE, veh.tur_head.angles_x + veh.angles_x); // tilt
1097 WriteAngle(MSG_ONE, veh.tur_head.angles_y + veh.angles_y); // yaw
1098 WriteAngle(MSG_ONE, 0); // roll
1102 WriteAngle(MSG_ONE, veh.angles_x * -1); // tilt
1103 WriteAngle(MSG_ONE, veh.angles_y); // yaw
1104 WriteAngle(MSG_ONE, 0); // roll
1108 vehicles_clearreturn(veh);
1110 CSQCVehicleSetup(pl, veh.vehicleid);
1112 MUTATOR_CALLHOOK(VehicleEnter, pl, veh);
1115 CSQCModel_UnlinkEntity();
1116 VEH_ACTION(veh.vehicleid, VR_ENTER);
1122 void vehicles_think()
1124 self.nextthink = time;
1127 self.owner.vehicle_weapon2mode = self.vehicle_weapon2mode;
1129 VEH_ACTION(self.vehicleid, VR_THINK);
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 VEH_ACTION(self.vehicleid, VR_SPAWN);
1182 CSQCMODEL_AUTOINIT(self);
1185 bool vehicle_initialize(entity veh, bool nodrop)
1187 if(!autocvar_g_vehicles)
1193 if(!veh.tur_head) { VEH_ACTION(veh.vehicleid, VR_PRECACHE); }
1195 if(self.targetname && self.targetname != "")
1197 self.vehicle_controller = find(world, target, self.targetname);
1198 if(!self.vehicle_controller)
1200 bprint("^1WARNING: ^7Vehicle with invalid .targetname\n");
1201 self.active = ACTIVE_ACTIVE;
1205 self.team = self.vehicle_controller.team;
1206 self.use = vehicle_use;
1210 if(self.vehicle_controller.team == 0)
1211 self.active = ACTIVE_NOT;
1213 self.active = ACTIVE_ACTIVE;
1217 else { self.active = ACTIVE_ACTIVE; }
1219 if(self.team && (!teamplay || !autocvar_g_vehicles_teams))
1222 if(self.mdl == "" || !self.mdl)
1223 setmodel(self, veh.model);
1225 setmodel(self, self.mdl);
1227 self.vehicle_flags |= VHF_ISVEHICLE;
1229 self.vehicle_viewport = spawn();
1230 self.vehicle_hudmodel = spawn();
1231 self.tur_head = spawn();
1232 self.tur_head.owner = self;
1233 self.takedamage = DAMAGE_NO;
1234 self.bot_attack = true;
1235 self.iscreature = true;
1236 self.teleportable = false; // no teleporting for vehicles, too buggy
1237 self.damagedbycontents = true;
1238 self.vehicleid = veh.vehicleid;
1239 self.PlayerPhysplug = veh.PlayerPhysplug;
1240 self.event_damage = func_null;
1241 self.touch = vehicles_touch;
1242 self.think = vehicles_spawn;
1243 self.nextthink = time;
1244 self.effects = EF_NODRAW;
1245 self.dphitcontentsmask = DPCONTENTS_BODY | DPCONTENTS_SOLID;
1247 if(autocvar_g_playerclip_collisions)
1248 self.dphitcontentsmask |= DPCONTENTS_PLAYERCLIP;
1250 if(autocvar_g_nodepthtestplayers)
1251 self.effects |= EF_NODEPTHTEST;
1253 if(autocvar_g_fullbrightplayers)
1254 self.effects |= EF_FULLBRIGHT;
1256 setmodel(self.vehicle_hudmodel, veh.hud_model);
1257 setmodel(self.vehicle_viewport, "null");
1259 if(veh.head_model != "")
1261 setmodel(self.tur_head, veh.head_model);
1262 setattachment(self.tur_head, self, veh.tag_head);
1263 setattachment(self.vehicle_hudmodel, self.tur_head, veh.tag_hud);
1264 setattachment(self.vehicle_viewport, self.vehicle_hudmodel, veh.tag_view);
1268 setattachment(self.tur_head, self, "");
1269 setattachment(self.vehicle_hudmodel, self, veh.tag_hud);
1270 setattachment(self.vehicle_viewport, self.vehicle_hudmodel, veh.tag_view);
1273 setsize(self, veh.mins, veh.maxs);
1277 setorigin(self, self.origin);
1278 tracebox(self.origin + '0 0 100', veh.mins, veh.maxs, self.origin - '0 0 10000', MOVE_WORLDONLY, self);
1279 setorigin(self, trace_endpos);
1282 self.pos1 = self.origin;
1283 self.pos2 = self.angles;
1284 self.tur_head.team = self.team;
1286 VEH_ACTION(veh.vehicleid, VR_SETUP);
1288 if(self.active == ACTIVE_NOT)
1289 self.nextthink = 0; // wait until activated
1290 else if(autocvar_g_vehicles_delayspawn)
1291 self.nextthink = time + self.respawntime + (random() * autocvar_g_vehicles_delayspawn_jitter);
1293 self.nextthink = time + game_starttime;
1295 if(MUTATOR_CALLHOOK(VehicleSpawn))