1 // =========================
2 // SVQC Vehicle Properties
3 // =========================
6 float SendAuxiliaryXhair(entity to, float sf)
9 WriteByte(MSG_ENTITY, ENT_CLIENT_AUXILIARYXHAIR);
11 WriteByte(MSG_ENTITY, self.cnt);
13 WriteCoord(MSG_ENTITY, self.origin_x);
14 WriteCoord(MSG_ENTITY, self.origin_y);
15 WriteCoord(MSG_ENTITY, self.origin_z);
17 WriteByte(MSG_ENTITY, rint(self.colormod_x * 255));
18 WriteByte(MSG_ENTITY, rint(self.colormod_y * 255));
19 WriteByte(MSG_ENTITY, rint(self.colormod_z * 255));
24 void UpdateAuxiliaryXhair(entity own, vector loc, vector clr, float axh_id)
26 if(!IS_REAL_CLIENT(own))
31 axh_id = bound(0, axh_id, MAX_AXH);
32 axh = own.(AuxiliaryXhair[axh_id]);
34 if(axh == world || wasfreed(axh)) // MADNESS? THIS IS QQQQCCCCCCCCC (wasfreed, why do you exsist?)
38 axh.drawonlytoclient = own;
40 Net_LinkEntity(axh, FALSE, 0, SendAuxiliaryXhair);
46 own.(AuxiliaryXhair[axh_id]) = axh;
49 void CSQCVehicleSetup(entity own, float vehicle_id)
51 if(!IS_REAL_CLIENT(own))
56 WriteByte(MSG_ONE, SVC_TEMPENTITY);
57 WriteByte(MSG_ONE, TE_CSQC_VEHICLESETUP);
58 WriteByte(MSG_ONE, vehicle_id);
61 vector targetdrone_getnewspot()
65 for(i = 0; i < 100; ++i)
67 spot = self.origin + randomvec() * 1024;
68 tracebox(spot, self.mins, self.maxs, spot, MOVE_NORMAL, self);
69 if(trace_fraction == 1.0 && trace_startsolid == 0 && trace_allsolid == 0)
75 void vehicles_locktarget(float incr, float decr, float _lock_time)
77 if(self.lock_target && self.lock_target.deadflag != DEAD_NO)
79 self.lock_target = world;
80 self.lock_strength = 0;
84 if(self.lock_time > time)
87 if(self.lock_soundtime < time)
89 self.lock_soundtime = time + 0.5;
90 play2(self.owner, "vehicles/locked.wav");
96 if(trace_ent != world)
98 if(SAME_TEAM(trace_ent, self))
101 if(trace_ent.deadflag != DEAD_NO)
104 if(!((trace_ent.vehicle_flags & VHF_ISVEHICLE) || (trace_ent.turrcaps_flags & TFL_TURRCAPS_ISTURRET)))
107 if(trace_ent.alpha <= 0.5)
108 trace_ent = world; // invisible
111 if(self.lock_target == world && trace_ent != world)
112 self.lock_target = trace_ent;
114 if(self.lock_target && trace_ent == self.lock_target)
116 if(self.lock_strength != 1 && self.lock_strength + incr >= 1)
118 play2(self.owner, "vehicles/lock.wav");
119 self.lock_soundtime = time + 0.8;
121 else if (self.lock_strength != 1 && self.lock_soundtime < time)
123 play2(self.owner, "vehicles/locking.wav");
124 self.lock_soundtime = time + 0.3;
128 // Have a locking target
129 // Trace hit current target
130 if(trace_ent == self.lock_target && trace_ent != world)
132 self.lock_strength = min(self.lock_strength + incr, 1);
133 if(self.lock_strength == 1)
134 self.lock_time = time + _lock_time;
139 self.lock_strength = max(self.lock_strength - decr * 2, 0);
141 self.lock_strength = max(self.lock_strength - decr, 0);
143 if(self.lock_strength == 0)
144 self.lock_target = world;
148 vector vehicles_force_fromtag_hover(string tag_name, float spring_length, float max_power)
150 force_fromtag_origin = gettaginfo(self, gettagindex(self, tag_name));
151 v_forward = normalize(v_forward) * -1;
152 traceline(force_fromtag_origin, force_fromtag_origin - (v_forward * spring_length), MOVE_NORMAL, self);
154 force_fromtag_power = (1 - trace_fraction) * max_power;
155 force_fromtag_normpower = force_fromtag_power / max_power;
157 return v_forward * force_fromtag_power;
160 vector vehicles_force_fromtag_maglev(string tag_name, float spring_length, float max_power)
163 force_fromtag_origin = gettaginfo(self, gettagindex(self, tag_name));
164 v_forward = normalize(v_forward) * -1;
165 traceline(force_fromtag_origin, force_fromtag_origin - (v_forward * spring_length), MOVE_NORMAL, self);
167 // TODO - this may NOT be compatible with wall/celing movement, unhardcode 0.25 (engine count multiplier)
168 if(trace_fraction == 1.0)
170 force_fromtag_normpower = -0.25;
174 force_fromtag_power = ((1 - trace_fraction) - trace_fraction) * max_power;
175 force_fromtag_normpower = force_fromtag_power / max_power;
177 return v_forward * force_fromtag_power;
180 // projectile handling
181 void vehicles_projectile_damage(entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
183 // Ignore damage from oterh projectiles from my owner (dont mess up volly's)
184 if(inflictor.owner == self.owner)
187 self.health -= damage;
188 self.velocity += force;
191 self.takedamage = DAMAGE_NO;
192 self.event_damage = func_null;
193 self.think = self.use;
194 self.nextthink = time;
198 void vehicles_projectile_explode()
200 if(self.owner && other != world)
202 if(other == self.owner.vehicle)
205 if(other == self.owner.vehicle.tur_head)
211 self.event_damage = func_null;
212 RadiusDamage (self, self.realowner, self.shot_dmg, 0, self.shot_radius, self, self.shot_force, self.totalfrags, other);
217 entity vehicles_projectile(string _mzlfx, string _mzlsound,
218 vector _org, vector _vel,
219 float _dmg, float _radi, float _force, float _size,
220 float _deahtype, float _projtype, float _health,
221 float _cull, float _clianim, entity _owner)
227 PROJECTILE_MAKETRIGGER(proj);
228 setorigin(proj, _org);
230 proj.shot_dmg = _dmg;
231 proj.shot_radius = _radi;
232 proj.shot_force = _force;
233 proj.totalfrags = _deahtype;
234 proj.solid = SOLID_BBOX;
235 proj.movetype = MOVETYPE_FLYMISSILE;
236 proj.flags = FL_PROJECTILE;
237 proj.bot_dodge = TRUE;
238 proj.bot_dodgerating = _dmg;
239 proj.velocity = _vel;
240 proj.touch = vehicles_projectile_explode;
241 proj.use = vehicles_projectile_explode;
243 proj.realowner = _owner;
244 proj.think = SUB_Remove;
245 proj.nextthink = time + 30;
249 proj.takedamage = DAMAGE_AIM;
250 proj.event_damage = vehicles_projectile_damage;
251 proj.health = _health;
254 proj.flags = FL_PROJECTILE | FL_NOTARGET;
257 sound (self, CH_WEAPON_A, _mzlsound, VOL_BASE, ATTEN_NORM);
260 pointparticles(particleeffectnum(_mzlfx), proj.origin, proj.velocity, 1);
263 setsize (proj, '-1 -1 -1' * _size, '1 1 1' * _size);
265 CSQCProjectile(proj, _clianim, _projtype, _cull);
270 void vehicles_gib_explode()
272 sound (self, CH_SHOTS, "weapons/rocket_impact.wav", VOL_BASE, ATTEN_NORM);
273 pointparticles(particleeffectnum("explosion_small"), randomvec() * 80 + (self.origin + '0 0 100'), '0 0 0', 1);
277 void vehicles_gib_think()
283 self.nextthink = time + 0.1;
286 entity vehicle_tossgib(entity _template, vector _vel, string _tag, float _burn, float _explode, float _maxtime, vector _rot)
288 entity _gib = spawn();
289 setmodel(_gib, _template.model);
290 setorigin(_gib, gettaginfo(self, gettagindex(self, _tag)));
291 _gib.velocity = _vel;
292 _gib.movetype = MOVETYPE_TOSS;
293 _gib.solid = SOLID_CORPSE;
294 _gib.colormod = '-0.5 -0.5 -0.5';
295 _gib.effects = EF_LOWPRECISION;
296 _gib.avelocity = _rot;
299 _gib.effects |= EF_FLAME;
303 _gib.think = vehicles_gib_explode;
304 _gib.nextthink = time + random() * _explode;
305 _gib.touch = vehicles_gib_explode;
309 _gib.cnt = time + _maxtime;
310 _gib.think = vehicles_gib_think;
311 _gib.nextthink = time + _maxtime - 1;
317 float vehicle_addplayerslot( entity _owner,
322 void(float) _exitfunc, float() _enterfunc)
324 if(!(_owner.vehicle_flags & VHF_MULTISLOT))
325 _owner.vehicle_flags |= VHF_MULTISLOT;
327 _slot.PlayerPhysplug = _framefunc;
328 _slot.vehicle_exit = _exitfunc;
329 _slot.vehicle_enter = _enterfunc;
331 _slot.vehicle_flags = VHF_PLAYERSLOT;
332 _slot.vehicle_viewport = spawn();
333 _slot.vehicle_hudmodel = spawn();
334 _slot.vehicle_hudmodel.viewmodelforclient = _slot;
335 _slot.vehicle_viewport.effects = (EF_ADDITIVE | EF_DOUBLESIDED | EF_FULLBRIGHT | EF_NODEPTHTEST | EF_NOGUNBOB | EF_NOSHADOW | EF_LOWPRECISION | EF_SELECTABLE | EF_TELEPORT_BIT);
337 setmodel(_slot.vehicle_hudmodel, _hud_model);
338 setmodel(_slot.vehicle_viewport, "null");
340 setattachment(_slot.vehicle_hudmodel, _slot, "");
341 setattachment(_slot.vehicle_viewport, _slot.vehicle_hudmodel, "");
346 vector vehicle_aimturret(entity _vehic, vector _target, entity _turrret, string _tagname,
347 float _pichlimit_min, float _pichlimit_max,
348 float _rotlimit_min, float _rotlimit_max, float _aimspeed)
352 vtag = gettaginfo(_turrret, gettagindex(_turrret, _tagname));
353 vtmp = vectoangles(normalize(_target - vtag));
354 vtmp = AnglesTransform_ToAngles(AnglesTransform_LeftDivide(AnglesTransform_FromAngles(_vehic.angles), AnglesTransform_FromAngles(vtmp))) - _turrret.angles;
355 vtmp = AnglesTransform_Normalize(vtmp, TRUE);
356 ftmp = _aimspeed * frametime;
357 vtmp_y = bound(-ftmp, vtmp_y, ftmp);
358 vtmp_x = bound(-ftmp, vtmp_x, ftmp);
359 _turrret.angles_y = bound(_rotlimit_min, _turrret.angles_y + vtmp_y, _rotlimit_max);
360 _turrret.angles_x = bound(_pichlimit_min, _turrret.angles_x + vtmp_x, _pichlimit_max);
364 void vehicles_reset_colors()
367 float _effects = 0, _colormap;
368 vector _glowmod, _colormod;
370 if(autocvar_g_nodepthtestplayers)
371 _effects |= EF_NODEPTHTEST;
373 if(autocvar_g_fullbrightplayers)
374 _effects |= EF_FULLBRIGHT;
377 _colormap = 1024 + (self.team - 1) * 17;
384 // Find all ents attacked to main model and setup effects, colormod etc.
385 e = findchainentity(tag_entity, self);
388 if(e != self.vehicle_shieldent)
390 e.effects = _effects; // | EF_LOWPRECISION;
391 e.colormod = _colormod;
392 e.colormap = _colormap;
397 // Also check head tags
398 e = findchainentity(tag_entity, self.tur_head);
401 if(e != self.vehicle_shieldent)
403 e.effects = _effects; // | EF_LOWPRECISION;
404 e.colormod = _colormod;
405 e.colormap = _colormap;
411 self.vehicle_hudmodel.effects = self.effects = _effects; // | EF_LOWPRECISION;
412 self.vehicle_hudmodel.colormod = self.colormod = _colormod;
413 self.vehicle_hudmodel.colormap = self.colormap = _colormap;
414 self.vehicle_viewport.effects = (EF_ADDITIVE | EF_DOUBLESIDED | EF_FULLBRIGHT | EF_NODEPTHTEST | EF_NOGUNBOB | EF_NOSHADOW | EF_LOWPRECISION | EF_SELECTABLE | EF_TELEPORT_BIT);
417 self.avelocity = '0 0 0';
418 self.velocity = '0 0 0';
419 self.effects = _effects;
422 void vehicles_clearreturn(entity veh)
425 // Remove "return helper", if any.
426 ret = findchain(classname, "vehicle_return");
432 ret.think = SUB_Remove;
433 ret.nextthink = time + 0.1;
435 if(ret.waypointsprite_attached)
436 WaypointSprite_Kill(ret.waypointsprite_attached);
444 void vehicles_spawn();
445 void vehicles_return()
447 pointparticles(particleeffectnum("teleport"), self.wp00.origin + '0 0 64', '0 0 0', 1);
449 self.wp00.think = vehicles_spawn;
450 self.wp00.nextthink = time;
452 if(self.waypointsprite_attached)
453 WaypointSprite_Kill(self.waypointsprite_attached);
458 void vehicles_showwp_goaway()
460 if(self.waypointsprite_attached)
461 WaypointSprite_Kill(self.waypointsprite_attached);
467 void vehicles_showwp()
469 entity oldself = world;
474 self.think = vehicles_return;
475 self.nextthink = self.cnt;
479 self.think = vehicles_return;
480 self.nextthink = time +1;
484 setmodel(self, "null");
485 self.team = oldself.wp00.team;
486 self.wp00 = oldself.wp00;
487 setorigin(self, oldself.wp00.pos1);
489 self.nextthink = time + 5;
490 self.think = vehicles_showwp_goaway;
493 if(teamplay && self.team)
494 rgb = Team_ColorRGB(self.team);
497 WaypointSprite_Spawn("vehicle", 0, 0, self, '0 0 64', world, 0, self, waypointsprite_attached, TRUE, RADARICON_POWERUP, rgb);
498 if(self.waypointsprite_attached)
500 WaypointSprite_UpdateRule(self.waypointsprite_attached, self.wp00.team, SPRITERULE_DEFAULT);
502 WaypointSprite_UpdateBuildFinished(self.waypointsprite_attached, self.nextthink);
503 WaypointSprite_Ping(self.waypointsprite_attached);
510 void vehicles_setreturn(entity veh)
514 vehicles_clearreturn(veh);
517 ret.classname = "vehicle_return";
520 ret.think = vehicles_showwp;
522 if(veh.deadflag != DEAD_NO)
524 ret.cnt = time + veh.respawntime;
525 ret.nextthink = min(time + veh.respawntime, time + veh.respawntime - 5);
529 ret.nextthink = min(time + veh.respawntime, time + veh.respawntime - 1);
532 setmodel(ret, "null");
533 setorigin(ret, veh.pos1 + '0 0 96');
539 dprint("vehicle ",self.netname, " used by ", activator.classname, "\n");
541 self.tur_head.team = activator.team;
543 if(self.tur_head.team == 0)
544 self.active = ACTIVE_NOT;
546 self.active = ACTIVE_ACTIVE;
548 if(self.active == ACTIVE_ACTIVE && self.deadflag == DEAD_NO && !gameover)
550 dprint("Respawning vehicle: ", self.netname, "\n");
551 vehicles_setreturn(self);
552 vehicles_reset_colors();
556 void vehicles_regen(float timer, .float regen_field, float field_max, float rpause, float regen, float delta_time, float _healthscale)
558 if(self.regen_field < field_max)
559 if(timer + rpause < time)
562 regen = regen * (self.vehicle_health / self.max_health);
564 self.regen_field = min(self.regen_field + regen * delta_time, field_max);
567 self.owner.regen_field = (self.regen_field / field_max) * 100;
571 void shieldhit_think()
576 //setmodel(self, "");
578 self.effects |= EF_NODRAW;
582 self.nextthink = time + 0.1;
586 void vehicles_painframe()
588 if(self.owner.vehicle_health <= 50)
589 if(self.pain_frame < time)
592 _ftmp = self.owner.vehicle_health / 50;
593 self.pain_frame = time + 0.1 + (random() * 0.5 * _ftmp);
594 pointparticles(particleeffectnum("smoke_small"), (self.origin + (randomvec() * 80)), '0 0 0', 1);
596 if(self.vehicle_flags & VHF_DMGSHAKE)
597 self.velocity += randomvec() * 30;
599 if(self.vehicle_flags & VHF_DMGROLL)
600 if(self.vehicle_flags & VHF_DMGHEADROLL)
601 self.tur_head.angles += randomvec();
603 self.angles += randomvec();
608 void vehicles_damage(entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
610 self.dmg_time = time;
612 if(DEATH_ISWEAPON(deathtype, WEP_NEX))
613 damage *= autocvar_g_vehicles_nex_damagerate;
615 if(DEATH_ISWEAPON(deathtype, WEP_UZI))
616 damage *= autocvar_g_vehicles_uzi_damagerate;
618 if(DEATH_ISWEAPON(deathtype, WEP_RIFLE))
619 damage *= autocvar_g_vehicles_rifle_damagerate;
621 if(DEATH_ISWEAPON(deathtype, WEP_MINSTANEX))
622 damage *= autocvar_g_vehicles_minstanex_damagerate;
624 if(DEATH_ISWEAPON(deathtype, WEP_SEEKER))
625 damage *= autocvar_g_vehicles_tag_damagerate;
627 self.enemy = attacker;
629 self.pain_finished = time;
631 if((self.vehicle_flags & VHF_HASSHIELD) && (self.vehicle_shield > 0))
633 if (wasfreed(self.vehicle_shieldent) || self.vehicle_shieldent == world)
635 self.vehicle_shieldent = spawn();
636 self.vehicle_shieldent.effects = EF_LOWPRECISION;
638 setmodel(self.vehicle_shieldent, "models/vhshield.md3");
639 setattachment(self.vehicle_shieldent, self, "");
640 setorigin(self.vehicle_shieldent, real_origin(self) - self.origin);
641 self.vehicle_shieldent.scale = 256 / vlen(self.maxs - self.mins);
642 self.vehicle_shieldent.think = shieldhit_think;
645 self.vehicle_shieldent.colormod = '1 1 1';
646 self.vehicle_shieldent.alpha = 0.45;
647 self.vehicle_shieldent.angles = vectoangles(normalize(hitloc - (self.origin + self.vehicle_shieldent.origin))) - self.angles;
648 self.vehicle_shieldent.nextthink = time;
649 self.vehicle_shieldent.effects &= ~EF_NODRAW;
651 self.vehicle_shield -= damage;
653 if(self.vehicle_shield < 0)
655 self.vehicle_health -= fabs(self.vehicle_shield);
656 self.vehicle_shieldent.colormod = '2 0 0';
657 self.vehicle_shield = 0;
658 self.vehicle_shieldent.alpha = 0.75;
660 if(sound_allowed(MSG_BROADCAST, attacker))
661 spamsound (self, CH_PAIN, "onslaught/ons_hit2.wav", VOL_BASE, ATTEN_NORM); // FIXME: PLACEHOLDER
664 if(sound_allowed(MSG_BROADCAST, attacker))
665 spamsound (self, CH_PAIN, "onslaught/electricity_explode.wav", VOL_BASE, ATTEN_NORM); // FIXME: PLACEHOLDER
670 self.vehicle_health -= damage;
672 if(sound_allowed(MSG_BROADCAST, attacker))
673 spamsound (self, CH_PAIN, "onslaught/ons_hit2.wav", VOL_BASE, ATTEN_NORM); // FIXME: PLACEHOLDER
676 if(self.damageforcescale < 1 && self.damageforcescale > 0)
677 self.velocity += force * self.damageforcescale;
679 self.velocity += force;
681 if(self.vehicle_health <= 0)
684 if(self.vehicle_flags & VHF_DEATHEJECT)
685 vehicles_exit(VHEF_EJECT);
687 vehicles_exit(VHEF_RELEASE);
692 VEH_ACTION(self.vehicleid, VR_DEATH);
693 vehicles_setreturn(self);
697 float vehicles_crushable(entity e)
702 if(e.flags & FL_MONSTER)
708 void vehicles_impact(float _minspeed, float _speedfac, float _maxpain)
710 if (trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT)
713 if(self.play_time < time)
715 float wc = vlen(self.velocity - self.oldvelocity);
716 //dprint("oldvel: ", vtos(self.oldvelocity), "\n");
717 //dprint("vel: ", vtos(self.velocity), "\n");
720 float take = min(_speedfac * wc, _maxpain);
721 Damage (self, world, world, take, DEATH_FALL, self.origin, '0 0 0');
722 self.play_time = time + 0.25;
724 //dprint("wc: ", ftos(wc), "\n");
725 //dprint("take: ", ftos(take), "\n");
730 // vehicle enter/exit handling
731 vector vehicles_findgoodexit(vector prefer_spot)
736 tracebox(self.origin + '0 0 32', PL_MIN, PL_MAX, prefer_spot, MOVE_NORMAL, self.owner);
737 if(trace_fraction == 1.0 && !trace_startsolid && !trace_allsolid)
740 mysize = 1.5 * vlen(self.maxs - self.mins);
743 v2 = 0.5 * (self.absmin + self.absmax);
744 for(i = 0; i < 100; ++i)
748 v = v2 + normalize(v) * mysize;
749 tracebox(v2, PL_MIN, PL_MAX, v, MOVE_NORMAL, self.owner);
750 if(trace_fraction == 1.0 && !trace_startsolid && !trace_allsolid)
755 exitspot = (self.origin + '0 0 48') + v_forward * mysize;
756 tracebox(self.origin + '0 0 32', PL_MIN, PL_MAX, exitspot, MOVE_NORMAL, self.owner);
757 if(trace_fraction == 1.0 && !trace_startsolid && !trace_allsolid)
760 exitspot = (self.origin + '0 0 48') - v_forward * mysize;
761 tracebox(self.origin + '0 0 32', PL_MIN, PL_MAX, exitspot, MOVE_NORMAL, self.owner);
762 if(trace_fraction == 1.0 && !trace_startsolid && !trace_allsolid)
765 exitspot = (self.origin + '0 0 48') + v_right * mysize;
766 tracebox(self.origin + '0 0 32', PL_MIN, PL_MAX, exitspot, MOVE_NORMAL, self.owner);
767 if(trace_fraction == 1.0 && !trace_startsolid && !trace_allsolid)
770 exitspot = (self.origin + '0 0 48') - v_right * mysize;
771 tracebox(self.origin + '0 0 32', PL_MIN, PL_MAX, exitspot, MOVE_NORMAL, self.owner);
772 if(trace_fraction == 1.0 && !trace_startsolid && !trace_allsolid)
779 void vehicles_exit(float eject)
783 entity _oldself = self;
785 if(vehicles_exit_running)
787 dprint("^1vehicles_exit allready running! this is not good..\n");
791 vehicles_exit_running = TRUE;
794 _vehicle = self.vehicle;
796 if (_vehicle.vehicle_flags & VHF_PLAYERSLOT)
798 _vehicle.vehicle_exit(eject);
800 vehicles_exit_running = FALSE;
807 _player = _vehicle.owner;
813 if (IS_REAL_CLIENT(_player))
815 msg_entity = _player;
816 WriteByte (MSG_ONE, SVC_SETVIEWPORT);
817 WriteEntity( MSG_ONE, _player);
819 WriteByte (MSG_ONE, SVC_SETVIEWANGLES);
820 WriteAngle(MSG_ONE, 0);
821 WriteAngle(MSG_ONE, _vehicle.angles_y);
822 WriteAngle(MSG_ONE, 0);
825 setsize(_player, PL_MIN,PL_MAX);
827 _player.takedamage = DAMAGE_AIM;
828 _player.solid = SOLID_SLIDEBOX;
829 _player.movetype = MOVETYPE_WALK;
830 _player.effects &= ~EF_NODRAW;
831 _player.teleportable = TELEPORT_NORMAL;
833 _player.PlayerPhysplug = func_null;
834 _player.vehicle = world;
835 _player.view_ofs = PL_VIEW_OFS;
836 _player.event_damage = PlayerDamage;
837 _player.hud = HUD_NORMAL;
838 _player.switchweapon = _vehicle.switchweapon;
839 _player.last_vehiclecheck = time + 3;
841 CSQCVehicleSetup(_player, HUD_NORMAL);
843 _vehicle.flags |= FL_NOTARGET;
845 if(_vehicle.deadflag == DEAD_NO)
846 _vehicle.avelocity = '0 0 0';
848 _vehicle.tur_head.nodrawtoclient = world;
853 Kill_Notification(NOTIF_ONE, _player, MSG_CENTER_CPID, CPID_VEHICLES);
854 Kill_Notification(NOTIF_ONE, _player, MSG_CENTER_CPID, CPID_VEHICLES_OTHER); // kill all vehicle notifications when exiting a vehicle?
856 WaypointSprite_Kill(_vehicle.wps_intruder);
859 vh_vehicle = _vehicle;
860 MUTATOR_CALLHOOK(VehicleExit);
862 _vehicle = vh_vehicle;
864 _vehicle.team = _vehicle.tur_head.team;
866 sound (_vehicle, CH_TRIGGER_SINGLE, "misc/null.wav", 1, ATTEN_NORM);
867 _vehicle.vehicle_hudmodel.viewmodelforclient = _vehicle;
868 _vehicle.phase = time + 1;
870 _vehicle.vehicle_exit(eject);
872 vehicles_setreturn(_vehicle);
873 vehicles_reset_colors();
874 _vehicle.owner = world;
876 CSQCMODEL_AUTOINIT();
880 vehicles_exit_running = FALSE;
883 void vehicles_touch()
885 if(MUTATOR_CALLHOOK(VehicleTouch))
888 // Vehicle currently in use
891 if(!forbidWeaponUse(self.owner))
893 if((self.origin_z + self.maxs_z) > (other.origin_z))
894 if(vehicles_crushable(other))
896 if(vlen(self.velocity) != 0)
897 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);
899 return; // Dont do selfdamage when hitting "soft targets".
902 if(self.play_time < time)
903 VEH_ACTION(self.vehicleid, VR_IMPACT);
908 if(autocvar_g_vehicles_enter)
911 vehicles_enter(other, self);
914 void vehicles_enter(entity pl, entity veh)
916 // Remove this when bots know how to use vehicles
917 if (IS_BOT_CLIENT(pl))
918 if (autocvar_g_vehicles_allow_bots)
919 dprint("Bot enters vehicle\n"); // This is where we need to disconnect (some, all?) normal bot AI and hand over to vehicle's _aiframe()
932 if(pl.deadflag != DEAD_NO)
938 if(autocvar_g_vehicles_enter) // skip if we're using regular touch code
939 if(veh.vehicle_flags & VHF_MULTISLOT)
942 entity oldself = self;
944 other = pl; // TODO: fix
947 if(veh.gun1.phase <= time)
948 if(veh.gun1.vehicle_enter)
949 if(veh.gun1.vehicle_enter())
956 if(veh.gun2.phase <= time)
957 if(veh.gun2.vehicle_enter)
958 if(veh.gun2.vehicle_enter())
969 if(DIFF_TEAM(pl, veh))
970 if(autocvar_g_vehicles_steal)
973 FOR_EACH_PLAYER(head) if(SAME_TEAM(head, veh))
974 Send_Notification(NOTIF_ONE, head, MSG_CENTER, CENTER_VEHICLE_STEAL);
976 Send_Notification(NOTIF_ONE, pl, MSG_CENTER, CENTER_VEHICLE_STEAL_SELF);
978 if(autocvar_g_vehicles_steal_show_waypoint)
979 WaypointSprite_Spawn("intruder", 0, 0, pl, '0 0 68', world, veh.team, veh, wps_intruder, TRUE, RADARICON_DANGER, Team_ColorRGB(pl.team));
983 RemoveGrapplingHook(pl);
985 veh.vehicle_ammo1 = 0;
986 veh.vehicle_ammo2 = 0;
987 veh.vehicle_reload1 = 0;
988 veh.vehicle_reload2 = 0;
989 veh.vehicle_energy = 0;
994 // .viewmodelforclient works better.
995 //veh.vehicle_hudmodel.drawonlytoclient = veh.owner;
997 veh.vehicle_hudmodel.viewmodelforclient = pl;
1000 pl.view_ofs = PL_VIEW_OFS;
1001 setsize (pl, PL_MIN, PL_MAX);
1003 veh.event_damage = vehicles_damage;
1005 pl.angles = veh.angles;
1006 pl.takedamage = DAMAGE_NO;
1007 pl.solid = SOLID_NOT;
1008 pl.movetype = MOVETYPE_NOCLIP;
1009 pl.teleportable = FALSE;
1011 pl.event_damage = func_null;
1012 pl.view_ofs = '0 0 0';
1013 veh.colormap = pl.colormap;
1015 veh.tur_head.colormap = pl.colormap;
1016 veh.switchweapon = pl.switchweapon;
1017 pl.hud = veh.vehicleid;
1018 pl.PlayerPhysplug = veh.PlayerPhysplug;
1020 pl.vehicle_ammo1 = veh.vehicle_ammo1;
1021 pl.vehicle_ammo2 = veh.vehicle_ammo2;
1022 pl.vehicle_reload1 = veh.vehicle_reload1;
1023 pl.vehicle_reload2 = veh.vehicle_reload2;
1025 // Cant do this, hides attached objects too.
1026 //veh.exteriormodeltoclient = veh.owner;
1027 //veh.tur_head.exteriormodeltoclient = veh.owner;
1029 pl.flags &= ~FL_ONGROUND;
1030 veh.flags &= ~FL_ONGROUND;
1033 veh.flags -= FL_NOTARGET;
1035 if (IS_REAL_CLIENT(pl))
1037 Send_Notification(NOTIF_ONE, pl, MSG_CENTER, CENTER_VEHICLE_ENTER);
1040 WriteByte (MSG_ONE, SVC_SETVIEWPORT);
1041 WriteEntity(MSG_ONE, veh.vehicle_viewport);
1043 WriteByte (MSG_ONE, SVC_SETVIEWANGLES);
1046 WriteAngle(MSG_ONE, veh.tur_head.angles_x + veh.angles_x); // tilt
1047 WriteAngle(MSG_ONE, veh.tur_head.angles_y + veh.angles_y); // yaw
1048 WriteAngle(MSG_ONE, 0); // roll
1052 WriteAngle(MSG_ONE, veh.angles_x * -1); // tilt
1053 WriteAngle(MSG_ONE, veh.angles_y); // yaw
1054 WriteAngle(MSG_ONE, 0); // roll
1058 vehicles_clearreturn(veh);
1060 CSQCVehicleSetup(pl, veh.vehicleid);
1064 MUTATOR_CALLHOOK(VehicleEnter);
1066 entity oldself = self;
1068 CSQCModel_UnlinkEntity();
1069 VEH_ACTION(veh.vehicleid, VR_ENTER);
1075 void vehicles_think()
1077 self.nextthink = time;
1080 self.owner.vehicle_weapon2mode = self.vehicle_weapon2mode;
1082 VEH_ACTION(self.vehicleid, VR_THINK);
1084 CSQCMODEL_AUTOUPDATE();
1088 void vehicles_spawn()
1090 dprint("Spawning vehicle: ", self.classname, "\n");
1093 self.vehicle_hudmodel.viewmodelforclient = self;
1096 self.touch = vehicles_touch;
1097 self.event_damage = vehicles_damage;
1098 self.iscreature = TRUE;
1099 self.teleportable = FALSE; // no teleporting for vehicles, too buggy
1100 self.damagedbycontents = TRUE;
1101 self.movetype = MOVETYPE_WALK;
1102 self.solid = SOLID_SLIDEBOX;
1103 self.takedamage = DAMAGE_AIM;
1104 self.deadflag = DEAD_NO;
1105 self.bot_attack = TRUE;
1106 self.flags = FL_NOTARGET;
1107 self.avelocity = '0 0 0';
1108 self.velocity = '0 0 0';
1109 self.think = vehicles_think;
1110 self.nextthink = time;
1113 self.lock_strength = 0;
1114 self.lock_target = world;
1115 self.misc_bulletcounter = 0;
1118 self.angles = self.pos2;
1119 setorigin(self, self.pos1);
1121 pointparticles(particleeffectnum("teleport"), self.origin + '0 0 64', '0 0 0', 1);
1123 if(self.vehicle_controller)
1124 self.team = self.vehicle_controller.team;
1126 entity head; // remove hooks (if any)
1127 FOR_EACH_PLAYER(head)
1128 if(head.hook.aiment == self)
1129 RemoveGrapplingHook(head);
1131 vehicles_reset_colors();
1133 VEH_ACTION(self.vehicleid, VR_SPAWN);
1135 CSQCMODEL_AUTOINIT();
1138 float vehicle_initialize(float vehicle_id, float nodrop)
1140 if(!autocvar_g_vehicles)
1143 entity veh = get_vehicleinfo(vehicle_id);
1150 self.vehicle_controller = find(world, target, self.targetname);
1151 if(!self.vehicle_controller)
1153 bprint("^1WARNING: ^7Vehicle with invalid .targetname\n");
1157 self.team = self.vehicle_controller.team;
1158 self.use = vehicle_use;
1162 if(self.vehicle_controller.team == 0)
1163 self.active = ACTIVE_NOT;
1165 self.active = ACTIVE_ACTIVE;
1170 if(self.team && (!teamplay || !autocvar_g_vehicles_teams))
1173 self.vehicle_flags |= VHF_ISVEHICLE;
1175 setmodel(self, veh.model);
1177 self.vehicle_viewport = spawn();
1178 self.vehicle_hudmodel = spawn();
1179 self.tur_head = spawn();
1180 self.tur_head.owner = self;
1181 self.takedamage = DAMAGE_NO;
1182 self.bot_attack = TRUE;
1183 self.iscreature = TRUE;
1184 self.teleportable = FALSE; // no teleporting for vehicles, too buggy
1185 self.damagedbycontents = TRUE;
1186 self.vehicleid = vehicle_id;
1187 self.PlayerPhysplug = veh.PlayerPhysplug;
1188 self.event_damage = func_null;
1189 self.touch = vehicles_touch;
1190 self.think = vehicles_spawn;
1191 self.nextthink = time;
1192 self.effects = EF_NODRAW;
1193 self.dphitcontentsmask = DPCONTENTS_BODY | DPCONTENTS_SOLID;
1195 if(autocvar_g_playerclip_collisions)
1196 self.dphitcontentsmask |= DPCONTENTS_PLAYERCLIP;
1198 if(autocvar_g_nodepthtestplayers)
1199 self.effects |= EF_NODEPTHTEST;
1201 if(autocvar_g_fullbrightplayers)
1202 self.effects |= EF_FULLBRIGHT;
1204 setmodel(self.vehicle_hudmodel, veh.hud_model);
1205 setmodel(self.vehicle_viewport, "null");
1207 if(veh.head_model != "")
1209 setmodel(self.tur_head, veh.head_model);
1210 setattachment(self.tur_head, self, veh.tag_head);
1211 setattachment(self.vehicle_hudmodel, self.tur_head, veh.tag_hud);
1212 setattachment(self.vehicle_viewport, self.vehicle_hudmodel, veh.tag_view);
1216 setattachment(self.tur_head, self, "");
1217 setattachment(self.vehicle_hudmodel, self, veh.tag_hud);
1218 setattachment(self.vehicle_viewport, self.vehicle_hudmodel, veh.tag_view);
1221 setsize(self, veh.mins, veh.maxs);
1225 setorigin(self, self.origin);
1226 tracebox(self.origin + '0 0 100', veh.mins, veh.maxs, self.origin - '0 0 10000', MOVE_WORLDONLY, self);
1227 setorigin(self, trace_endpos);
1230 self.pos1 = self.origin;
1231 self.pos2 = self.angles;
1232 self.tur_head.team = self.team;
1234 VEH_ACTION(vehicle_id, VR_SETUP);
1236 if(autocvar_g_vehicles_delayspawn)
1237 self.nextthink = time + self.respawntime + (random() * autocvar_g_vehicles_delayspawn_jitter);
1239 self.nextthink = time + game_starttime;
1241 if(MUTATOR_CALLHOOK(VehicleSpawn))