1 #include "sv_vehicles.qh"
3 bool SendAuxiliaryXhair(entity this, entity to, int sf)
5 WriteHeader(MSG_ENTITY, ENT_CLIENT_AUXILIARYXHAIR);
7 WriteByte(MSG_ENTITY, this.cnt);
9 WriteCoord(MSG_ENTITY, this.origin_x);
10 WriteCoord(MSG_ENTITY, this.origin_y);
11 WriteCoord(MSG_ENTITY, this.origin_z);
13 WriteByte(MSG_ENTITY, rint(this.colormod_x * 255));
14 WriteByte(MSG_ENTITY, rint(this.colormod_y * 255));
15 WriteByte(MSG_ENTITY, rint(this.colormod_z * 255));
20 void UpdateAuxiliaryXhair(entity own, vector loc, vector clr, int axh_id)
22 if(!IS_REAL_CLIENT(own))
25 axh_id = bound(0, axh_id, MAX_AXH);
26 entity axh = own.(AuxiliaryXhair[axh_id]);
28 if(axh == NULL || wasfreed(axh)) // MADNESS? THIS IS QQQQCCCCCCCCC (wasfreed, why do you exsist? Mario: because of sloppy code like this)
32 axh.drawonlytoclient = own;
34 Net_LinkEntity(axh, false, 0, SendAuxiliaryXhair);
40 own.(AuxiliaryXhair[axh_id]) = axh;
43 void CSQCVehicleSetup(entity own, int vehicle_id)
45 if(!IS_REAL_CLIENT(own))
50 WriteHeader(MSG_ONE, TE_CSQC_VEHICLESETUP);
51 WriteByte(MSG_ONE, vehicle_id);
54 void vehicles_locktarget(entity this, float incr, float decr, float _lock_time)
56 if(this.lock_target && IS_DEAD(this.lock_target))
58 this.lock_target = NULL;
59 this.lock_strength = 0;
63 if(this.lock_time > time)
66 if(this.lock_soundtime < time)
68 this.lock_soundtime = time + 0.5;
69 play2(this.owner, "vehicles/locked.wav");
77 if(SAME_TEAM(trace_ent, this))
80 if(IS_DEAD(trace_ent))
83 if(!(IS_VEHICLE(trace_ent) || IS_TURRET(trace_ent)))
86 if(trace_ent.alpha <= 0.5 && trace_ent.alpha != 0)
87 trace_ent = NULL; // invisible
90 if(this.lock_target == NULL && trace_ent != NULL)
91 this.lock_target = trace_ent;
93 if(this.lock_target && trace_ent == this.lock_target)
95 if(this.lock_strength != 1 && this.lock_strength + incr >= 1)
97 play2(this.owner, "vehicles/lock.wav");
98 this.lock_soundtime = time + 0.8;
100 else if (this.lock_strength != 1 && this.lock_soundtime < time)
102 play2(this.owner, "vehicles/locking.wav");
103 this.lock_soundtime = time + 0.3;
107 // Have a locking target
108 // Trace hit current target
109 if(trace_ent == this.lock_target && trace_ent != NULL)
111 this.lock_strength = min(this.lock_strength + incr, 1);
112 if(this.lock_strength == 1)
113 this.lock_time = time + _lock_time;
118 this.lock_strength = max(this.lock_strength - decr * 2, 0);
120 this.lock_strength = max(this.lock_strength - decr, 0);
122 if(this.lock_strength == 0)
123 this.lock_target = NULL;
127 float vehicle_altitude(entity this, float amax)
129 tracebox(this.origin, this.mins, this.maxs, this.origin - ('0 0 1' * amax), MOVE_WORLDONLY, this);
130 return vlen(this.origin - trace_endpos);
133 vector vehicles_force_fromtag_hover(entity this, string tag_name, float spring_length, float max_power)
135 force_fromtag_origin = gettaginfo(this, gettagindex(this, tag_name));
136 v_forward = normalize(v_forward) * -1;
137 traceline(force_fromtag_origin, force_fromtag_origin - (v_forward * spring_length), MOVE_NORMAL, this);
139 force_fromtag_power = (1 - trace_fraction) * max_power;
140 force_fromtag_normpower = force_fromtag_power / max_power;
142 return v_forward * force_fromtag_power;
145 vector vehicles_force_fromtag_maglev(entity this, string tag_name, float spring_length, float max_power)
147 force_fromtag_origin = gettaginfo(this, gettagindex(this, tag_name));
148 v_forward = normalize(v_forward) * -1;
149 traceline(force_fromtag_origin, force_fromtag_origin - (v_forward * spring_length), MOVE_NORMAL, this);
151 // TODO - this may NOT be compatible with wall/celing movement, unhardcode 0.25 (engine count multiplier)
152 if(trace_fraction == 1.0)
154 force_fromtag_normpower = -0.25;
158 force_fromtag_power = ((1 - trace_fraction) - trace_fraction) * max_power;
159 force_fromtag_normpower = force_fromtag_power / max_power;
161 return v_forward * force_fromtag_power;
164 // projectile handling
165 void vehicles_projectile_damage(entity this, entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force)
167 // Ignore damage from oterh projectiles from my owner (dont mess up volly's)
168 if(inflictor.owner == this.owner)
171 this.health -= damage;
172 this.velocity += force;
175 this.takedamage = DAMAGE_NO;
176 this.event_damage = func_null;
177 setthink(this, adaptor_think2use);
178 this.nextthink = time;
182 void vehicles_projectile_explode(entity this)
184 if(this.owner && other != NULL)
186 if(other == this.owner.vehicle)
189 if(other == this.owner.vehicle.tur_head)
193 PROJECTILE_TOUCH(this);
195 this.event_damage = func_null;
196 RadiusDamage (this, this.realowner, this.shot_dmg, 0, this.shot_radius, this, NULL, this.shot_force, this.totalfrags, other);
201 void vehicles_projectile_explode_use(entity this, entity actor, entity trigger)
203 vehicles_projectile_explode(this);
206 entity vehicles_projectile(entity this, string _mzlfx, Sound _mzlsound,
207 vector _org, vector _vel,
208 float _dmg, float _radi, float _force, float _size,
209 int _deahtype, float _projtype, float _health,
210 bool _cull, bool _clianim, entity _owner)
212 TC(Sound, _mzlsound);
217 PROJECTILE_MAKETRIGGER(proj);
218 setorigin(proj, _org);
220 proj.shot_dmg = _dmg;
221 proj.shot_radius = _radi;
222 proj.shot_force = _force;
223 proj.totalfrags = _deahtype;
224 proj.solid = SOLID_BBOX;
225 proj.movetype = MOVETYPE_FLYMISSILE;
226 proj.flags = FL_PROJECTILE;
227 proj.bot_dodge = true;
228 proj.bot_dodgerating = _dmg;
229 proj.velocity = _vel;
230 settouch(proj, vehicles_projectile_explode);
231 proj.use = vehicles_projectile_explode_use;
233 proj.realowner = _owner;
234 setthink(proj, SUB_Remove);
235 proj.nextthink = time + 30;
239 proj.takedamage = DAMAGE_AIM;
240 proj.event_damage = vehicles_projectile_damage;
241 proj.health = _health;
244 proj.flags = FL_PROJECTILE | FL_NOTARGET;
246 if(_mzlsound != SND_Null)
247 sound (this, CH_WEAPON_A, _mzlsound, VOL_BASE, ATTEN_NORM);
250 Send_Effect_(_mzlfx, proj.origin, proj.velocity, 1);
252 setsize (proj, '-1 -1 -1' * _size, '1 1 1' * _size);
254 CSQCProjectile(proj, _clianim, _projtype, _cull);
259 void vehicles_gib_explode(entity this)
261 sound (this, CH_SHOTS, SND_ROCKET_IMPACT, VOL_BASE, ATTEN_NORM);
262 Send_Effect(EFFECT_EXPLOSION_SMALL, randomvec() * 80 + (this.origin + '0 0 100'), '0 0 0', 1);
263 Send_Effect(EFFECT_EXPLOSION_SMALL, this.wp00.origin + '0 0 64', '0 0 0', 1);
267 void vehicles_gib_think(entity this)
273 this.nextthink = time + 0.1;
276 entity vehicle_tossgib(entity this, entity _template, vector _vel, string _tag, bool _burn, bool _explode, float _maxtime, vector _rot)
278 entity _gib = spawn();
279 _setmodel(_gib, _template.model);
280 vector org = gettaginfo(this, gettagindex(this, _tag));
281 setorigin(_gib, org);
282 _gib.velocity = _vel;
283 _gib.movetype = MOVETYPE_TOSS;
284 _gib.solid = SOLID_CORPSE;
285 _gib.colormod = '-0.5 -0.5 -0.5';
286 _gib.effects = EF_LOWPRECISION;
287 _gib.avelocity = _rot;
290 _gib.effects |= EF_FLAME;
294 setthink(_gib, vehicles_gib_explode);
295 _gib.nextthink = time + random() * _explode;
296 settouch(_gib, vehicles_gib_explode);
300 _gib.cnt = time + _maxtime;
301 setthink(_gib, vehicles_gib_think);
302 _gib.nextthink = time + _maxtime - 1;
308 bool vehicle_addplayerslot( entity _owner,
312 bool(entity) _framefunc,
313 void(entity,bool) _exitfunc, float(entity, entity) _enterfunc)
315 if(!(_owner.vehicle_flags & VHF_MULTISLOT))
316 _owner.vehicle_flags |= VHF_MULTISLOT;
318 _slot.PlayerPhysplug = _framefunc;
319 _slot.vehicle_exit = _exitfunc;
320 _slot.vehicle_enter = _enterfunc;
322 _slot.vehicle_flags = VHF_PLAYERSLOT;
323 _slot.vehicle_viewport = spawn();
324 _slot.vehicle_hudmodel = spawn();
325 _slot.vehicle_hudmodel.viewmodelforclient = _slot;
326 _slot.vehicle_viewport.effects = (EF_ADDITIVE | EF_DOUBLESIDED | EF_FULLBRIGHT | EF_NODEPTHTEST | EF_NOGUNBOB | EF_NOSHADOW | EF_LOWPRECISION | EF_SELECTABLE | EF_TELEPORT_BIT);
328 setmodel(_slot.vehicle_hudmodel, _hud_model);
329 setmodel(_slot.vehicle_viewport, MDL_Null);
331 setattachment(_slot.vehicle_hudmodel, _slot, "");
332 setattachment(_slot.vehicle_viewport, _slot.vehicle_hudmodel, "");
337 vector vehicle_aimturret(entity _vehic, vector _target, entity _turrret, string _tagname,
338 float _pichlimit_min, float _pichlimit_max,
339 float _rotlimit_min, float _rotlimit_max, float _aimspeed)
343 vtag = gettaginfo(_turrret, gettagindex(_turrret, _tagname));
344 vtmp = vectoangles(normalize(_target - vtag));
345 vtmp = AnglesTransform_ToAngles(AnglesTransform_LeftDivide(AnglesTransform_FromAngles(_vehic.angles), AnglesTransform_FromAngles(vtmp))) - _turrret.angles;
346 vtmp = AnglesTransform_Normalize(vtmp, true);
347 ftmp = _aimspeed * frametime;
348 vtmp_y = bound(-ftmp, vtmp_y, ftmp);
349 vtmp_x = bound(-ftmp, vtmp_x, ftmp);
350 _turrret.angles_y = bound(_rotlimit_min, _turrret.angles_y + vtmp_y, _rotlimit_max);
351 _turrret.angles_x = bound(_pichlimit_min, _turrret.angles_x + vtmp_x, _pichlimit_max);
355 void vehicles_reset_colors(entity this)
358 const vector cmod = '0 0 0';
359 if(this.team && teamplay)
360 cmap = 1024 + (this.team - 1) * 17;
363 if(autocvar_g_nodepthtestplayers)
364 eff |= EF_NODEPTHTEST;
365 if(autocvar_g_fullbrightplayers)
366 eff |= EF_FULLBRIGHT;
368 // Find all ents attacked to main model and setup effects, colormod etc.
369 FOREACH_ENTITY_ENT(tag_entity, this,
371 if(it != this.vehicle_shieldent)
380 // Also check head tags
381 FOREACH_ENTITY_ENT(tag_entity, this.tur_head,
383 if(it != this.vehicle_shieldent)
392 this.vehicle_hudmodel.effects = this.effects = eff; // | EF_LOWPRECISION;
393 this.vehicle_hudmodel.colormod = this.colormod = cmod;
394 this.vehicle_hudmodel.colormap = this.colormap = cmap;
395 this.vehicle_viewport.effects = (EF_ADDITIVE | EF_DOUBLESIDED | EF_FULLBRIGHT | EF_NODEPTHTEST | EF_NOGUNBOB | EF_NOSHADOW | EF_LOWPRECISION | EF_SELECTABLE | EF_TELEPORT_BIT);
398 this.avelocity = '0 0 0';
399 this.velocity = '0 0 0';
403 void vehicles_clearreturn(entity veh)
405 // Remove "return helper" entities, if any.
406 FOREACH_ENTITY_ENT(wp00, veh,
408 if(it.classname == "vehicle_return")
411 setthink(it, SUB_Remove);
412 it.nextthink = time + 0.1;
414 if(it.waypointsprite_attached)
415 WaypointSprite_Kill(it.waypointsprite_attached);
420 void vehicles_spawn(entity this);
421 void vehicles_return(entity this)
423 Send_Effect(EFFECT_TELEPORT, this.wp00.origin + '0 0 64', '0 0 0', 1);
425 setthink(this.wp00, vehicles_spawn);
426 this.wp00.nextthink = time;
428 if(this.waypointsprite_attached)
429 WaypointSprite_Kill(this.waypointsprite_attached);
434 void vehicles_showwp_goaway(entity this)
436 if(this.waypointsprite_attached)
437 WaypointSprite_Kill(this.waypointsprite_attached);
442 void vehicles_showwp(entity this)
448 setthink(ent, vehicles_return);
449 ent.nextthink = ent.cnt;
453 setthink(ent, vehicles_return);
454 ent.nextthink = time + 1;
457 ent.team = this.wp00.team;
458 ent.wp00 = this.wp00;
459 setorigin(ent, this.wp00.pos1);
461 ent.nextthink = time + 5;
462 setthink(ent, vehicles_showwp_goaway);
466 if(teamplay && ent.team)
467 rgb = Team_ColorRGB(ent.team);
470 entity wp = WaypointSprite_Spawn(WP_Vehicle, 0, 0, ent, '0 0 64', NULL, 0, ent, waypointsprite_attached, true, RADARICON_Vehicle);
472 if(ent.waypointsprite_attached)
474 WaypointSprite_UpdateRule(ent.waypointsprite_attached, ent.wp00.team, SPRITERULE_DEFAULT);
476 WaypointSprite_UpdateBuildFinished(ent.waypointsprite_attached, ent.nextthink);
477 WaypointSprite_Ping(ent.waypointsprite_attached);
481 void vehicles_setreturn(entity veh)
483 vehicles_clearreturn(veh);
485 entity ret = new(vehicle_return);
488 setthink(ret, vehicles_showwp);
492 ret.cnt = time + veh.respawntime;
493 ret.nextthink = min(time + veh.respawntime, time + veh.respawntime - 5);
497 ret.nextthink = min(time + veh.respawntime, time + veh.respawntime - 1);
500 setorigin(ret, veh.pos1 + '0 0 96');
503 void vehicle_use(entity this, entity actor, entity trigger)
505 LOG_DEBUG("vehicle ", this.netname, " used by ", actor.classname, "\n");
507 this.tur_head.team = actor.team;
509 if(this.tur_head.team == 0)
510 this.active = ACTIVE_NOT;
512 this.active = ACTIVE_ACTIVE;
514 if(this.active == ACTIVE_ACTIVE && !IS_DEAD(this) && !gameover)
516 LOG_DEBUG("Respawning vehicle: ", this.netname, "\n");
517 if(this.effects & EF_NODRAW)
519 setthink(this, vehicles_spawn);
520 this.nextthink = time + 3;
524 vehicles_setreturn(this);
525 vehicles_reset_colors(this);
530 void vehicles_regen(entity this, float timer, .float regen_field, float field_max, float rpause, float regen, float delta_time, float _healthscale)
532 if(this.(regen_field) < field_max)
533 if(timer + rpause < time)
536 regen = regen * (this.vehicle_health / this.max_health);
538 this.(regen_field) = min(this.(regen_field) + regen * delta_time, field_max);
541 this.owner.(regen_field) = (this.(regen_field) / field_max) * 100;
545 void shieldhit_think(entity this)
550 // setmodel(this, MDL_Null);
552 this.effects |= EF_NODRAW;
556 this.nextthink = time + 0.1;
560 void vehicles_painframe(entity this)
562 int myhealth = ((this.owner) ? this.owner.vehicle_health : ((this.vehicle_health / this.max_health) * 100));
565 if(this.pain_frame < time)
567 float _ftmp = myhealth / 50;
568 this.pain_frame = time + max(0.1, 0.1 + (random() * 0.5 * _ftmp));
569 Send_Effect(EFFECT_SMOKE_SMALL, (this.origin + (randomvec() * 80)), '0 0 0', 1);
571 if(this.vehicle_flags & VHF_DMGSHAKE)
572 this.velocity += randomvec() * 30;
574 if(this.vehicle_flags & VHF_DMGROLL)
575 if(this.vehicle_flags & VHF_DMGHEADROLL)
576 this.tur_head.angles += randomvec();
578 this.angles += randomvec();
582 void vehicles_frame(entity this, entity actor)
584 vehicles_painframe(this);
587 void vehicles_damage(entity this, entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force)
589 this.dmg_time = time;
592 if(DEATH_ISWEAPON(deathtype, WEP_VORTEX))
593 damage *= autocvar_g_vehicles_vortex_damagerate;
595 if(DEATH_ISWEAPON(deathtype, WEP_MACHINEGUN))
596 damage *= autocvar_g_vehicles_machinegun_damagerate;
598 if(DEATH_ISWEAPON(deathtype, WEP_RIFLE))
599 damage *= autocvar_g_vehicles_rifle_damagerate;
601 if(DEATH_ISWEAPON(deathtype, WEP_VAPORIZER))
602 damage *= autocvar_g_vehicles_vaporizer_damagerate;
604 if(DEATH_ISWEAPON(deathtype, WEP_SEEKER))
605 damage *= autocvar_g_vehicles_tag_damagerate;
607 if(DEATH_WEAPONOF(deathtype) != WEP_Null)
608 damage *= autocvar_g_vehicles_weapon_damagerate;
610 this.enemy = attacker;
612 this.pain_finished = time;
614 if((this.vehicle_flags & VHF_HASSHIELD) && (this.vehicle_shield > 0))
616 if (wasfreed(this.vehicle_shieldent) || this.vehicle_shieldent == NULL)
618 this.vehicle_shieldent = spawn();
619 this.vehicle_shieldent.effects = EF_LOWPRECISION;
621 setmodel(this.vehicle_shieldent, MDL_VEH_SHIELD);
622 setattachment(this.vehicle_shieldent, this, "");
623 setorigin(this.vehicle_shieldent, real_origin(this) - this.origin);
624 this.vehicle_shieldent.scale = 256 / vlen(this.maxs - this.mins);
625 setthink(this.vehicle_shieldent, shieldhit_think);
628 this.vehicle_shieldent.colormod = '1 1 1';
629 this.vehicle_shieldent.alpha = 0.45;
630 this.vehicle_shieldent.angles = vectoangles(normalize(hitloc - (this.origin + this.vehicle_shieldent.origin))) - this.angles;
631 this.vehicle_shieldent.nextthink = time;
632 this.vehicle_shieldent.effects &= ~EF_NODRAW;
634 this.vehicle_shield -= damage;
636 if(this.vehicle_shield < 0)
638 this.vehicle_health -= fabs(this.vehicle_shield);
639 this.vehicle_shieldent.colormod = '2 0 0';
640 this.vehicle_shield = 0;
641 this.vehicle_shieldent.alpha = 0.75;
643 if(sound_allowed(MSG_BROADCAST, attacker))
644 spamsound (this, CH_PAIN, "onslaught/ons_hit2.wav", VOL_BASE, ATTEN_NORM); // FIXME: PLACEHOLDER
647 if(sound_allowed(MSG_BROADCAST, attacker))
648 spamsound (this, CH_PAIN, "onslaught/electricity_explode.wav", VOL_BASE, ATTEN_NORM); // FIXME: PLACEHOLDER
653 this.vehicle_health -= damage;
655 if(sound_allowed(MSG_BROADCAST, attacker))
656 spamsound (this, CH_PAIN, "onslaught/ons_hit2.wav", VOL_BASE, ATTEN_NORM); // FIXME: PLACEHOLDER
659 if(this.damageforcescale < 1 && this.damageforcescale > 0)
660 this.velocity += force * this.damageforcescale;
662 this.velocity += force;
664 if(this.vehicle_health <= 0)
667 if(this.vehicle_flags & VHF_DEATHEJECT)
668 vehicles_exit(this, VHEF_EJECT);
670 vehicles_exit(this, VHEF_RELEASE);
673 antilag_clear(this, this);
675 Vehicle info = Vehicles_from(this.vehicleid);
676 info.vr_death(info, this);
677 vehicles_setreturn(this);
681 bool vehicles_crushable(entity e)
683 if(IS_PLAYER(e) && time >= e.vehicle_enter_delay)
692 void vehicles_impact(entity this, float _minspeed, float _speedfac, float _maxpain)
694 if (trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT)
697 if(this.play_time < time)
699 float wc = vlen(this.velocity - this.oldvelocity);
700 //dprint("oldvel: ", vtos(this.oldvelocity), "\n");
701 //dprint("vel: ", vtos(this.velocity), "\n");
704 float take = min(_speedfac * wc, _maxpain);
705 Damage (this, NULL, NULL, take, DEATH_FALL.m_id, this.origin, '0 0 0');
706 this.play_time = time + 0.25;
708 //dprint("wc: ", ftos(wc), "\n");
709 //dprint("take: ", ftos(take), "\n");
714 // vehicle enter/exit handling
715 vector vehicles_findgoodexit(entity this, vector prefer_spot)
717 tracebox(this.origin + '0 0 32', STAT(PL_MIN, NULL), STAT(PL_MAX, NULL), prefer_spot, MOVE_NORMAL, this.owner);
718 if(trace_fraction == 1.0 && !trace_startsolid && !trace_allsolid)
721 float mysize = 1.5 * vlen(this.maxs - this.mins);
723 vector v2 = 0.5 * (this.absmin + this.absmax);
724 for(int i = 0; i < autocvar_g_vehicles_exit_attempts; ++i)
728 v = v2 + normalize(v) * mysize;
729 tracebox(v2, STAT(PL_MIN, NULL), STAT(PL_MAX, NULL), v, MOVE_NORMAL, this.owner);
730 if(trace_fraction == 1.0 && !trace_startsolid && !trace_allsolid)
737 void vehicles_exit(entity vehic, bool eject)
739 entity player = vehic.owner;
741 if(vehicles_exit_running)
743 LOG_TRACE("^1vehicles_exit already running! this is not good...\n");
747 vehicles_exit_running = true;
749 // TODO: this was in an IS_CLIENT check, make sure it isn't actually needed!
750 if(vehic.vehicle_flags & VHF_PLAYERSLOT)
752 vehic.vehicle_exit(vehic, eject);
753 vehicles_exit_running = false;
759 if (IS_REAL_CLIENT(player))
762 WriteByte (MSG_ONE, SVC_SETVIEWPORT);
763 WriteEntity( MSG_ONE, player);
765 WriteByte (MSG_ONE, SVC_SETVIEWANGLES);
766 WriteAngle(MSG_ONE, 0);
767 WriteAngle(MSG_ONE, vehic.angles_y);
768 WriteAngle(MSG_ONE, 0);
771 setsize(player, STAT(PL_MIN, NULL), STAT(PL_MAX, NULL));
773 player.takedamage = DAMAGE_AIM;
774 player.solid = SOLID_SLIDEBOX;
775 player.movetype = MOVETYPE_WALK;
776 player.effects &= ~EF_NODRAW;
777 player.teleportable = TELEPORT_NORMAL;
779 player.PlayerPhysplug = func_null;
780 player.vehicle = NULL;
781 player.view_ofs = STAT(PL_VIEW_OFS, NULL);
782 player.event_damage = PlayerDamage;
783 player.hud = HUD_NORMAL;
784 PS(player).m_switchweapon = vehic.m_switchweapon;
785 player.last_vehiclecheck = time + 3;
786 player.vehicle_enter_delay = time + 2;
788 CSQCVehicleSetup(player, HUD_NORMAL);
790 Kill_Notification(NOTIF_ONE, player, MSG_CENTER, CPID_VEHICLES);
791 Kill_Notification(NOTIF_ONE, player, MSG_CENTER, CPID_VEHICLES_OTHER); // kill all vehicle notifications when exiting a vehicle?
794 vehic.flags |= FL_NOTARGET;
797 vehic.avelocity = '0 0 0';
799 vehic.tur_head.nodrawtoclient = NULL;
804 WaypointSprite_Kill(vehic.wps_intruder);
806 MUTATOR_CALLHOOK(VehicleExit, player, vehic);
808 vehic.team = vehic.tur_head.team;
810 sound (vehic, CH_TRIGGER_SINGLE, SND_Null, 1, ATTEN_NORM);
811 vehic.vehicle_hudmodel.viewmodelforclient = vehic;
812 vehic.phase = time + 1;
814 vehic.vehicle_exit(vehic, eject);
816 vehicles_setreturn(vehic);
817 vehicles_reset_colors(vehic);
820 CSQCMODEL_AUTOINIT(vehic);
822 vehicles_exit_running = false;
825 void vehicles_touch(entity this)
827 if(MUTATOR_CALLHOOK(VehicleTouch, this, other))
830 // Vehicle currently in use
833 if(!forbidWeaponUse(this.owner))
835 if((this.origin_z + this.maxs_z) > (other.origin_z))
836 if(vehicles_crushable(other))
838 if(vdist(this.velocity, >=, 30))
839 Damage(other, this, this.owner, autocvar_g_vehicles_crush_dmg, DEATH_VH_CRUSH.m_id, '0 0 0', normalize(other.origin - this.origin) * autocvar_g_vehicles_crush_force);
841 return; // Dont do selfdamage when hitting "soft targets".
844 if(this.play_time < time) {
845 Vehicle info = Vehicles_from(this.vehicleid);
846 info.vr_impact(info, this);
852 if(autocvar_g_vehicles_enter)
855 vehicles_enter(other, this);
858 bool vehicle_impulse(entity this, int imp)
860 entity v = this.vehicle;
861 if (!v) return false;
862 if (IS_DEAD(v)) return false;
863 bool(entity,int) f = v.vehicles_impulse;
864 if (f && f(this,imp)) return true;
867 case IMP_weapon_drop.impulse:
869 stuffcmd(this, "\ntoggle cl_eventchase_vehicle\nset _vehicles_shownchasemessage 1\n");
876 void vehicles_enter(entity pl, entity veh)
878 // Remove this when bots know how to use vehicles
879 if((IS_BOT_CLIENT(pl) && !autocvar_g_vehicles_allow_bots))
883 || (veh.phase >= time)
884 || (pl.vehicle_enter_delay >= time)
885 || (STAT(FROZEN, pl))
890 if(autocvar_g_vehicles_enter) // vehicle's touch function should handle this if entering via use key is disabled (TODO)
891 if(veh.vehicle_flags & VHF_MULTISLOT)
895 if(time >= veh.gun1.phase)
896 if(veh.gun1.vehicle_enter)
897 if(veh.gun1.vehicle_enter(veh, pl))
901 if(time >= veh.gun2.phase)
902 if(veh.gun2.vehicle_enter)
903 if(veh.gun2.vehicle_enter(veh, pl))
909 if(DIFF_TEAM(pl, veh))
910 if(autocvar_g_vehicles_steal)
912 FOREACH_CLIENT(IS_PLAYER(it) && SAME_TEAM(it, veh), Send_Notification(NOTIF_ONE, it, MSG_CENTER, CENTER_VEHICLE_STEAL));
914 Send_Notification(NOTIF_ONE, pl, MSG_CENTER, CENTER_VEHICLE_STEAL_SELF);
916 if (autocvar_g_vehicles_steal_show_waypoint) {
917 entity wp = WaypointSprite_Spawn(WP_VehicleIntruder, 0, 0, pl, '0 0 68', NULL, veh.team, veh, wps_intruder, true, RADARICON_DANGER);
918 wp.colormod = Team_ColorRGB(pl.team);
923 RemoveGrapplingHook(pl);
925 veh.vehicle_ammo1 = 0;
926 veh.vehicle_ammo2 = 0;
927 veh.vehicle_reload1 = 0;
928 veh.vehicle_reload2 = 0;
929 veh.vehicle_energy = 0;
934 // .viewmodelforclient works better.
935 //veh.vehicle_hudmodel.drawonlytoclient = veh.owner;
937 veh.vehicle_hudmodel.viewmodelforclient = pl;
940 pl.view_ofs = STAT(PL_VIEW_OFS, NULL);
941 setsize (pl, STAT(PL_MIN, NULL), STAT(PL_MAX, NULL));
943 veh.event_damage = vehicles_damage;
945 pl.angles = veh.angles;
946 pl.takedamage = DAMAGE_NO;
947 pl.solid = SOLID_NOT;
948 pl.movetype = MOVETYPE_NOCLIP;
949 pl.teleportable = false;
951 pl.event_damage = func_null;
952 pl.view_ofs = '0 0 0';
953 veh.colormap = pl.colormap;
955 veh.tur_head.colormap = pl.colormap;
956 veh.m_switchweapon = PS(pl).m_switchweapon;
957 pl.hud = veh.vehicleid;
958 pl.PlayerPhysplug = veh.PlayerPhysplug;
960 pl.vehicle_ammo1 = veh.vehicle_ammo1;
961 pl.vehicle_ammo2 = veh.vehicle_ammo2;
962 pl.vehicle_reload1 = veh.vehicle_reload1;
963 pl.vehicle_reload2 = veh.vehicle_reload2;
964 pl.vehicle_energy = veh.vehicle_energy;
966 // Cant do this, hides attached objects too.
967 //veh.exteriormodeltoclient = veh.owner;
968 //veh.tur_head.exteriormodeltoclient = veh.owner;
974 veh.flags -= FL_NOTARGET;
976 if (IS_REAL_CLIENT(pl))
978 Send_Notification(NOTIF_ONE, pl, MSG_CENTER, CENTER_VEHICLE_ENTER);
981 WriteByte (MSG_ONE, SVC_SETVIEWPORT);
982 WriteEntity(MSG_ONE, veh.vehicle_viewport);
984 WriteByte (MSG_ONE, SVC_SETVIEWANGLES);
987 WriteAngle(MSG_ONE, veh.tur_head.angles_x + veh.angles_x); // tilt
988 WriteAngle(MSG_ONE, veh.tur_head.angles_y + veh.angles_y); // yaw
989 WriteAngle(MSG_ONE, 0); // roll
993 WriteAngle(MSG_ONE, veh.angles_x * -1); // tilt
994 WriteAngle(MSG_ONE, veh.angles_y); // yaw
995 WriteAngle(MSG_ONE, 0); // roll
999 vehicles_clearreturn(veh);
1001 CSQCVehicleSetup(pl, veh.vehicleid);
1003 MUTATOR_CALLHOOK(VehicleEnter, pl, veh);
1005 CSQCModel_UnlinkEntity(veh);
1006 Vehicle info = Vehicles_from(veh.vehicleid);
1007 info.vr_enter(info, veh);
1009 antilag_clear(pl, CS(pl));
1012 void vehicles_think(entity this)
1014 this.nextthink = time;
1017 this.owner.vehicle_weapon2mode = this.vehicle_weapon2mode;
1019 Vehicle info = Vehicles_from(this.vehicleid);
1020 info.vr_think(info, this);
1022 vehicles_painframe(this);
1024 CSQCMODEL_AUTOUPDATE(this);
1028 void vehicles_spawn(entity this)
1030 LOG_DEBUG("Spawning vehicle: ", this.classname, "\n");
1033 this.vehicle_hudmodel.viewmodelforclient = this;
1036 settouch(this, vehicles_touch);
1037 this.event_damage = vehicles_damage;
1038 this.iscreature = true;
1039 this.teleportable = false; // no teleporting for vehicles, too buggy
1040 this.damagedbycontents = true;
1041 this.movetype = MOVETYPE_WALK;
1042 this.solid = SOLID_SLIDEBOX;
1043 this.takedamage = DAMAGE_AIM;
1044 this.deadflag = DEAD_NO;
1045 this.bot_attack = true;
1046 this.flags = FL_NOTARGET;
1047 this.avelocity = '0 0 0';
1048 this.velocity = '0 0 0';
1049 setthink(this, vehicles_think);
1050 this.nextthink = time;
1053 this.lock_strength = 0;
1054 this.lock_target = NULL;
1055 this.misc_bulletcounter = 0;
1058 this.angles = this.pos2;
1059 setorigin(this, this.pos1);
1061 Send_Effect(EFFECT_TELEPORT, this.origin + '0 0 64', '0 0 0', 1);
1063 if(this.vehicle_controller)
1064 this.team = this.vehicle_controller.team;
1066 FOREACH_CLIENT(IS_PLAYER(it) && it.hook.aiment == this, RemoveGrapplingHook(it));
1068 vehicles_reset_colors(this);
1070 Vehicle info = Vehicles_from(this.vehicleid);
1071 info.vr_spawn(info, this);
1073 CSQCMODEL_AUTOINIT(this);
1076 bool vehicle_initialize(entity this, Vehicle info, bool nodrop)
1078 if(!autocvar_g_vehicles)
1085 info.vr_precache(info);
1087 if(this.targetname && this.targetname != "")
1089 this.vehicle_controller = find(NULL, target, this.targetname);
1090 if(!this.vehicle_controller)
1092 LOG_DEBUG("^1WARNING: ^7Vehicle with invalid .targetname\n");
1093 this.active = ACTIVE_ACTIVE;
1097 this.team = this.vehicle_controller.team;
1098 this.use = vehicle_use;
1102 if(this.vehicle_controller.team == 0)
1103 this.active = ACTIVE_NOT;
1105 this.active = ACTIVE_ACTIVE;
1109 else { this.active = ACTIVE_ACTIVE; }
1111 if(this.team && (!teamplay || !autocvar_g_vehicles_teams))
1114 if(this.mdl == "" || !this.mdl)
1115 _setmodel(this, info.model);
1117 _setmodel(this, this.mdl);
1119 this.vehicle_flags |= VHF_ISVEHICLE;
1121 this.vehicle_viewport = new(vehicle_viewport);
1122 this.vehicle_hudmodel = new(vehicle_hudmodel);
1123 this.tur_head = new(tur_head);
1124 this.tur_head.owner = this;
1125 this.takedamage = DAMAGE_NO;
1126 this.bot_attack = true;
1127 this.iscreature = true;
1128 this.teleportable = false; // no teleporting for vehicles, too buggy
1129 this.damagedbycontents = true;
1130 this.vehicleid = info.vehicleid;
1131 this.PlayerPhysplug = info.PlayerPhysplug;
1132 this.event_damage = func_null;
1133 settouch(this, vehicles_touch);
1134 setthink(this, vehicles_spawn);
1135 this.nextthink = time;
1136 this.effects = EF_NODRAW;
1137 this.dphitcontentsmask = DPCONTENTS_BODY | DPCONTENTS_SOLID;
1139 if(autocvar_g_playerclip_collisions)
1140 this.dphitcontentsmask |= DPCONTENTS_PLAYERCLIP;
1142 if(autocvar_g_nodepthtestplayers)
1143 this.effects |= EF_NODEPTHTEST;
1145 if(autocvar_g_fullbrightplayers)
1146 this.effects |= EF_FULLBRIGHT;
1148 _setmodel(this.vehicle_hudmodel, info.hud_model);
1149 setmodel(this.vehicle_viewport, MDL_Null);
1151 if(info.head_model != "")
1153 _setmodel(this.tur_head, info.head_model);
1154 setattachment(this.tur_head, this, info.tag_head);
1155 setattachment(this.vehicle_hudmodel, this.tur_head, info.tag_hud);
1156 setattachment(this.vehicle_viewport, this.vehicle_hudmodel, info.tag_view);
1160 setattachment(this.tur_head, this, "");
1161 setattachment(this.vehicle_hudmodel, this, info.tag_hud);
1162 setattachment(this.vehicle_viewport, this.vehicle_hudmodel, info.tag_view);
1165 setsize(this, info.mins, info.maxs);
1169 setorigin(this, this.origin);
1170 tracebox(this.origin + '0 0 100', info.mins, info.maxs, this.origin - '0 0 10000', MOVE_WORLDONLY, this);
1171 setorigin(this, trace_endpos);
1174 this.pos1 = this.origin;
1175 this.pos2 = this.angles;
1176 this.tur_head.team = this.team;
1178 info.vr_setup(info, this);
1180 if(this.active == ACTIVE_NOT)
1181 this.nextthink = 0; // wait until activated
1182 else if(autocvar_g_vehicles_delayspawn)
1183 this.nextthink = time + this.respawntime + (random() * autocvar_g_vehicles_delayspawn_jitter);
1185 this.nextthink = time + game_starttime;
1187 if(MUTATOR_CALLHOOK(VehicleSpawn, this))