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, entity toucher)
184 if(this.owner && toucher != NULL)
186 if(toucher == this.owner.vehicle)
189 if(toucher == this.owner.vehicle.tur_head)
193 PROJECTILE_TOUCH(this, toucher);
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, toucher);
201 void vehicles_projectile_explode_think(entity this)
203 vehicles_projectile_explode(this, NULL);
206 void vehicles_projectile_explode_use(entity this, entity actor, entity trigger)
208 vehicles_projectile_explode(this, trigger);
211 entity vehicles_projectile(entity this, string _mzlfx, Sound _mzlsound,
212 vector _org, vector _vel,
213 float _dmg, float _radi, float _force, float _size,
214 int _deahtype, float _projtype, float _health,
215 bool _cull, bool _clianim, entity _owner)
217 TC(Sound, _mzlsound);
222 PROJECTILE_MAKETRIGGER(proj);
223 setorigin(proj, _org);
225 proj.shot_dmg = _dmg;
226 proj.shot_radius = _radi;
227 proj.shot_force = _force;
228 proj.totalfrags = _deahtype;
229 proj.solid = SOLID_BBOX;
230 set_movetype(proj, MOVETYPE_FLYMISSILE);
231 proj.flags = FL_PROJECTILE;
232 proj.bot_dodge = true;
233 proj.bot_dodgerating = _dmg;
234 proj.velocity = _vel;
235 settouch(proj, vehicles_projectile_explode);
236 proj.use = vehicles_projectile_explode_use;
238 proj.realowner = _owner;
239 setthink(proj, SUB_Remove);
240 proj.nextthink = time + 30;
244 proj.takedamage = DAMAGE_AIM;
245 proj.event_damage = vehicles_projectile_damage;
246 proj.health = _health;
249 proj.flags = FL_PROJECTILE | FL_NOTARGET;
251 if(_mzlsound != SND_Null)
252 sound (this, CH_WEAPON_A, _mzlsound, VOL_BASE, ATTEN_NORM);
255 Send_Effect_(_mzlfx, proj.origin, proj.velocity, 1);
257 setsize (proj, '-1 -1 -1' * _size, '1 1 1' * _size);
259 CSQCProjectile(proj, _clianim, _projtype, _cull);
264 void vehicles_gib_explode(entity this)
266 sound (this, CH_SHOTS, SND_ROCKET_IMPACT, VOL_BASE, ATTEN_NORM);
267 Send_Effect(EFFECT_EXPLOSION_SMALL, randomvec() * 80 + (this.origin + '0 0 100'), '0 0 0', 1);
268 Send_Effect(EFFECT_EXPLOSION_SMALL, this.wp00.origin + '0 0 64', '0 0 0', 1);
272 void vehicles_gib_touch(entity this, entity toucher)
274 vehicles_gib_explode(this);
277 void vehicles_gib_think(entity this)
283 this.nextthink = time + 0.1;
286 entity vehicle_tossgib(entity this, entity _template, vector _vel, string _tag, bool _burn, bool _explode, float _maxtime, vector _rot)
288 entity _gib = spawn();
289 _setmodel(_gib, _template.model);
290 vector org = gettaginfo(this, gettagindex(this, _tag));
291 setorigin(_gib, org);
292 _gib.velocity = _vel;
293 set_movetype(_gib, MOVETYPE_TOSS);
294 _gib.solid = SOLID_CORPSE;
295 _gib.colormod = '-0.5 -0.5 -0.5';
296 _gib.effects = EF_LOWPRECISION;
297 _gib.avelocity = _rot;
300 _gib.effects |= EF_FLAME;
304 setthink(_gib, vehicles_gib_explode);
305 _gib.nextthink = time + random() * _explode;
306 settouch(_gib, vehicles_gib_touch);
310 _gib.cnt = time + _maxtime;
311 setthink(_gib, vehicles_gib_think);
312 _gib.nextthink = time + _maxtime - 1;
318 bool vehicle_addplayerslot( entity _owner,
322 bool(entity) _framefunc,
323 void(entity,bool) _exitfunc, float(entity, entity) _enterfunc)
325 if(!(_owner.vehicle_flags & VHF_MULTISLOT))
326 _owner.vehicle_flags |= VHF_MULTISLOT;
328 _slot.PlayerPhysplug = _framefunc;
329 _slot.vehicle_exit = _exitfunc;
330 _slot.vehicle_enter = _enterfunc;
332 _slot.vehicle_flags = VHF_PLAYERSLOT;
333 _slot.vehicle_viewport = spawn();
334 _slot.vehicle_hudmodel = spawn();
335 _slot.vehicle_hudmodel.viewmodelforclient = _slot;
336 _slot.vehicle_viewport.effects = (EF_ADDITIVE | EF_DOUBLESIDED | EF_FULLBRIGHT | EF_NODEPTHTEST | EF_NOGUNBOB | EF_NOSHADOW | EF_LOWPRECISION | EF_SELECTABLE | EF_TELEPORT_BIT);
338 setmodel(_slot.vehicle_hudmodel, _hud_model);
339 setmodel(_slot.vehicle_viewport, MDL_Null);
341 setattachment(_slot.vehicle_hudmodel, _slot, "");
342 setattachment(_slot.vehicle_viewport, _slot.vehicle_hudmodel, "");
347 vector vehicle_aimturret(entity _vehic, vector _target, entity _turrret, string _tagname,
348 float _pichlimit_min, float _pichlimit_max,
349 float _rotlimit_min, float _rotlimit_max, float _aimspeed)
353 vtag = gettaginfo(_turrret, gettagindex(_turrret, _tagname));
354 vtmp = vectoangles(normalize(_target - vtag));
355 vtmp = AnglesTransform_ToAngles(AnglesTransform_LeftDivide(AnglesTransform_FromAngles(_vehic.angles), AnglesTransform_FromAngles(vtmp))) - _turrret.angles;
356 vtmp = AnglesTransform_Normalize(vtmp, true);
357 ftmp = _aimspeed * frametime;
358 vtmp_y = bound(-ftmp, vtmp_y, ftmp);
359 vtmp_x = bound(-ftmp, vtmp_x, ftmp);
360 _turrret.angles_y = bound(_rotlimit_min, _turrret.angles_y + vtmp_y, _rotlimit_max);
361 _turrret.angles_x = bound(_pichlimit_min, _turrret.angles_x + vtmp_x, _pichlimit_max);
365 void vehicles_reset_colors(entity this)
368 const vector cmod = '0 0 0';
369 if(this.team && teamplay)
370 cmap = 1024 + (this.team - 1) * 17;
373 if(autocvar_g_nodepthtestplayers)
374 eff |= EF_NODEPTHTEST;
375 if(autocvar_g_fullbrightplayers)
376 eff |= EF_FULLBRIGHT;
378 // Find all ents attacked to main model and setup effects, colormod etc.
379 FOREACH_ENTITY_ENT(tag_entity, this,
381 if(it != this.vehicle_shieldent)
390 // Also check head tags
391 FOREACH_ENTITY_ENT(tag_entity, this.tur_head,
393 if(it != this.vehicle_shieldent)
402 this.vehicle_hudmodel.effects = this.effects = eff; // | EF_LOWPRECISION;
403 this.vehicle_hudmodel.colormod = this.colormod = cmod;
404 this.vehicle_hudmodel.colormap = this.colormap = cmap;
405 this.vehicle_viewport.effects = (EF_ADDITIVE | EF_DOUBLESIDED | EF_FULLBRIGHT | EF_NODEPTHTEST | EF_NOGUNBOB | EF_NOSHADOW | EF_LOWPRECISION | EF_SELECTABLE | EF_TELEPORT_BIT);
408 this.avelocity = '0 0 0';
409 this.velocity = '0 0 0';
413 void vehicles_clearreturn(entity veh)
415 // Remove "return helper" entities, if any.
416 FOREACH_ENTITY_ENT(wp00, veh,
418 if(it.classname == "vehicle_return")
421 setthink(it, SUB_Remove);
422 it.nextthink = time + 0.1;
424 if(it.waypointsprite_attached)
425 WaypointSprite_Kill(it.waypointsprite_attached);
430 void vehicles_spawn(entity this);
431 void vehicles_return(entity this)
433 Send_Effect(EFFECT_TELEPORT, this.wp00.origin + '0 0 64', '0 0 0', 1);
435 setthink(this.wp00, vehicles_spawn);
436 this.wp00.nextthink = time;
438 if(this.waypointsprite_attached)
439 WaypointSprite_Kill(this.waypointsprite_attached);
444 void vehicles_showwp_goaway(entity this)
446 if(this.waypointsprite_attached)
447 WaypointSprite_Kill(this.waypointsprite_attached);
452 void vehicles_showwp(entity this)
458 setthink(ent, vehicles_return);
459 ent.nextthink = ent.cnt;
463 setthink(ent, vehicles_return);
464 ent.nextthink = time + 1;
467 ent.team = this.wp00.team;
468 ent.wp00 = this.wp00;
469 setorigin(ent, this.wp00.pos1);
471 ent.nextthink = time + 5;
472 setthink(ent, vehicles_showwp_goaway);
476 if(teamplay && ent.team)
477 rgb = Team_ColorRGB(ent.team);
480 entity wp = WaypointSprite_Spawn(WP_Vehicle, 0, 0, ent, '0 0 64', NULL, 0, ent, waypointsprite_attached, true, RADARICON_Vehicle);
482 if(ent.waypointsprite_attached)
484 WaypointSprite_UpdateRule(ent.waypointsprite_attached, ent.wp00.team, SPRITERULE_DEFAULT);
486 WaypointSprite_UpdateBuildFinished(ent.waypointsprite_attached, ent.nextthink);
487 WaypointSprite_Ping(ent.waypointsprite_attached);
491 void vehicles_setreturn(entity veh)
493 vehicles_clearreturn(veh);
495 entity ret = new(vehicle_return);
498 setthink(ret, vehicles_showwp);
502 ret.cnt = time + veh.respawntime;
503 ret.nextthink = min(time + veh.respawntime, time + veh.respawntime - 5);
507 ret.nextthink = min(time + veh.respawntime, time + veh.respawntime - 1);
510 setorigin(ret, veh.pos1 + '0 0 96');
513 void vehicle_use(entity this, entity actor, entity trigger)
515 LOG_DEBUG("vehicle ", this.netname, " used by ", actor.classname, "\n");
517 this.tur_head.team = actor.team;
519 if(this.tur_head.team == 0)
520 this.active = ACTIVE_NOT;
522 this.active = ACTIVE_ACTIVE;
524 if(this.active == ACTIVE_ACTIVE && !IS_DEAD(this) && !gameover)
526 LOG_DEBUG("Respawning vehicle: ", this.netname, "\n");
527 if(this.effects & EF_NODRAW)
529 setthink(this, vehicles_spawn);
530 this.nextthink = time + 3;
534 vehicles_setreturn(this);
535 vehicles_reset_colors(this);
540 void vehicles_regen(entity this, float timer, .float regen_field, float field_max, float rpause, float regen, float delta_time, float _healthscale)
542 if(this.(regen_field) < field_max)
543 if(timer + rpause < time)
546 regen = regen * (this.vehicle_health / this.max_health);
548 this.(regen_field) = min(this.(regen_field) + regen * delta_time, field_max);
551 this.owner.(regen_field) = (this.(regen_field) / field_max) * 100;
555 void shieldhit_think(entity this)
560 // setmodel(this, MDL_Null);
562 this.effects |= EF_NODRAW;
566 this.nextthink = time + 0.1;
570 void vehicles_painframe(entity this)
572 int myhealth = ((this.owner) ? this.owner.vehicle_health : ((this.vehicle_health / this.max_health) * 100));
575 if(this.pain_frame < time)
577 float _ftmp = myhealth / 50;
578 this.pain_frame = time + max(0.1, 0.1 + (random() * 0.5 * _ftmp));
579 Send_Effect(EFFECT_SMOKE_SMALL, (this.origin + (randomvec() * 80)), '0 0 0', 1);
581 if(this.vehicle_flags & VHF_DMGSHAKE)
582 this.velocity += randomvec() * 30;
584 if(this.vehicle_flags & VHF_DMGROLL)
585 if(this.vehicle_flags & VHF_DMGHEADROLL)
586 this.tur_head.angles += randomvec();
588 this.angles += randomvec();
592 void vehicles_frame(entity this, entity actor)
594 vehicles_painframe(this);
597 void vehicles_damage(entity this, entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force)
599 this.dmg_time = time;
602 if(DEATH_ISWEAPON(deathtype, WEP_VORTEX))
603 damage *= autocvar_g_vehicles_vortex_damagerate;
604 else if(DEATH_ISWEAPON(deathtype, WEP_MACHINEGUN))
605 damage *= autocvar_g_vehicles_machinegun_damagerate;
606 else if(DEATH_ISWEAPON(deathtype, WEP_RIFLE))
607 damage *= autocvar_g_vehicles_rifle_damagerate;
608 else if(DEATH_ISWEAPON(deathtype, WEP_VAPORIZER))
609 damage *= autocvar_g_vehicles_vaporizer_damagerate;
610 else if(DEATH_ISWEAPON(deathtype, WEP_SEEKER))
611 damage *= autocvar_g_vehicles_tag_damagerate;
612 else if(DEATH_WEAPONOF(deathtype) != WEP_Null)
613 damage *= autocvar_g_vehicles_weapon_damagerate;
615 this.enemy = attacker;
617 this.pain_finished = time;
619 if((this.vehicle_flags & VHF_HASSHIELD) && (this.vehicle_shield > 0))
621 if (wasfreed(this.vehicle_shieldent) || this.vehicle_shieldent == NULL)
623 this.vehicle_shieldent = spawn();
624 this.vehicle_shieldent.effects = EF_LOWPRECISION;
626 setmodel(this.vehicle_shieldent, MDL_VEH_SHIELD);
627 setattachment(this.vehicle_shieldent, this, "");
628 setorigin(this.vehicle_shieldent, real_origin(this) - this.origin);
629 this.vehicle_shieldent.scale = 256 / vlen(this.maxs - this.mins);
630 setthink(this.vehicle_shieldent, shieldhit_think);
633 this.vehicle_shieldent.colormod = '1 1 1';
634 this.vehicle_shieldent.alpha = 0.45;
635 this.vehicle_shieldent.angles = vectoangles(normalize(hitloc - (this.origin + this.vehicle_shieldent.origin))) - this.angles;
636 this.vehicle_shieldent.nextthink = time;
637 this.vehicle_shieldent.effects &= ~EF_NODRAW;
639 this.vehicle_shield -= damage;
641 if(this.vehicle_shield < 0)
643 this.vehicle_health -= fabs(this.vehicle_shield);
644 this.vehicle_shieldent.colormod = '2 0 0';
645 this.vehicle_shield = 0;
646 this.vehicle_shieldent.alpha = 0.75;
648 if(sound_allowed(MSG_BROADCAST, attacker))
649 spamsound (this, CH_PAIN, "onslaught/ons_hit2.wav", VOL_BASE, ATTEN_NORM); // FIXME: PLACEHOLDER
652 if(sound_allowed(MSG_BROADCAST, attacker))
653 spamsound (this, CH_PAIN, "onslaught/electricity_explode.wav", VOL_BASE, ATTEN_NORM); // FIXME: PLACEHOLDER
658 this.vehicle_health -= damage;
660 if(sound_allowed(MSG_BROADCAST, attacker))
661 spamsound (this, CH_PAIN, "onslaught/ons_hit2.wav", VOL_BASE, ATTEN_NORM); // FIXME: PLACEHOLDER
664 if(this.damageforcescale < 1 && this.damageforcescale > 0)
665 this.velocity += force * this.damageforcescale;
667 this.velocity += force;
669 if(this.vehicle_health <= 0)
672 if(this.vehicle_flags & VHF_DEATHEJECT)
673 vehicles_exit(this, VHEF_EJECT);
675 vehicles_exit(this, VHEF_RELEASE);
678 antilag_clear(this, this);
680 Vehicle info = Vehicles_from(this.vehicleid);
681 info.vr_death(info, this);
682 vehicles_setreturn(this);
686 bool vehicles_crushable(entity e)
688 if(IS_PLAYER(e) && time >= e.vehicle_enter_delay)
697 void vehicles_impact(entity this, float _minspeed, float _speedfac, float _maxpain)
699 if (trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT)
702 if(this.play_time < time)
704 float wc = vlen(this.velocity - this.oldvelocity);
705 //dprint("oldvel: ", vtos(this.oldvelocity), "\n");
706 //dprint("vel: ", vtos(this.velocity), "\n");
709 float take = min(_speedfac * wc, _maxpain);
710 Damage (this, NULL, NULL, take, DEATH_FALL.m_id, this.origin, '0 0 0');
711 this.play_time = time + 0.25;
713 //dprint("wc: ", ftos(wc), "\n");
714 //dprint("take: ", ftos(take), "\n");
719 // vehicle enter/exit handling
720 vector vehicles_findgoodexit(entity this, vector prefer_spot)
722 tracebox(this.origin + '0 0 32', STAT(PL_MIN, NULL), STAT(PL_MAX, NULL), prefer_spot, MOVE_NORMAL, this.owner);
723 if(trace_fraction == 1.0 && !trace_startsolid && !trace_allsolid)
726 float mysize = 1.5 * vlen(this.maxs - this.mins);
728 vector v2 = 0.5 * (this.absmin + this.absmax);
729 for(int i = 0; i < autocvar_g_vehicles_exit_attempts; ++i)
733 v = v2 + normalize(v) * mysize;
734 tracebox(v2, STAT(PL_MIN, NULL), STAT(PL_MAX, NULL), v, MOVE_NORMAL, this.owner);
735 if(trace_fraction == 1.0 && !trace_startsolid && !trace_allsolid)
742 void vehicles_exit(entity vehic, bool eject)
744 entity player = vehic.owner;
746 if(vehicles_exit_running)
748 LOG_TRACE("^1vehicles_exit already running! this is not good...\n");
752 vehicles_exit_running = true;
754 // TODO: this was in an IS_CLIENT check, make sure it isn't actually needed!
755 if(vehic.vehicle_flags & VHF_PLAYERSLOT)
757 vehic.vehicle_exit(vehic, eject);
758 vehicles_exit_running = false;
764 if (IS_REAL_CLIENT(player))
767 WriteByte (MSG_ONE, SVC_SETVIEWPORT);
768 WriteEntity( MSG_ONE, player);
770 WriteByte (MSG_ONE, SVC_SETVIEWANGLES);
771 WriteAngle(MSG_ONE, 0);
772 WriteAngle(MSG_ONE, vehic.angles_y);
773 WriteAngle(MSG_ONE, 0);
776 setsize(player, STAT(PL_MIN, NULL), STAT(PL_MAX, NULL));
778 player.takedamage = DAMAGE_AIM;
779 player.solid = SOLID_SLIDEBOX;
780 set_movetype(player, MOVETYPE_WALK);
781 player.effects &= ~EF_NODRAW;
782 player.teleportable = TELEPORT_NORMAL;
784 player.PlayerPhysplug = func_null;
785 player.vehicle = NULL;
786 player.view_ofs = STAT(PL_VIEW_OFS, NULL);
787 player.event_damage = PlayerDamage;
788 player.hud = HUD_NORMAL;
789 PS(player).m_switchweapon = vehic.m_switchweapon;
790 player.last_vehiclecheck = time + 3;
791 player.vehicle_enter_delay = time + 2;
793 CSQCVehicleSetup(player, HUD_NORMAL);
795 Kill_Notification(NOTIF_ONE, player, MSG_CENTER, CPID_VEHICLES);
796 Kill_Notification(NOTIF_ONE, player, MSG_CENTER, CPID_VEHICLES_OTHER); // kill all vehicle notifications when exiting a vehicle?
799 vehic.flags |= FL_NOTARGET;
802 vehic.avelocity = '0 0 0';
804 vehic.tur_head.nodrawtoclient = NULL;
809 WaypointSprite_Kill(vehic.wps_intruder);
811 MUTATOR_CALLHOOK(VehicleExit, player, vehic);
813 vehic.team = vehic.tur_head.team;
815 sound (vehic, CH_TRIGGER_SINGLE, SND_Null, 1, ATTEN_NORM);
816 vehic.vehicle_hudmodel.viewmodelforclient = vehic;
817 vehic.phase = time + 1;
819 vehic.vehicle_exit(vehic, eject);
821 vehicles_setreturn(vehic);
822 vehicles_reset_colors(vehic);
825 CSQCMODEL_AUTOINIT(vehic);
827 vehicles_exit_running = false;
830 void vehicles_touch(entity this, entity toucher)
832 if(MUTATOR_CALLHOOK(VehicleTouch, this, toucher))
835 // Vehicle currently in use
838 if(!forbidWeaponUse(this.owner))
840 if((this.origin_z + this.maxs_z) > (toucher.origin_z))
841 if(vehicles_crushable(toucher))
843 if(vdist(this.velocity, >=, 30))
844 Damage(toucher, this, this.owner, autocvar_g_vehicles_crush_dmg, DEATH_VH_CRUSH.m_id, '0 0 0', normalize(toucher.origin - this.origin) * autocvar_g_vehicles_crush_force);
846 return; // Dont do selfdamage when hitting "soft targets".
849 if(this.play_time < time) {
850 Vehicle info = Vehicles_from(this.vehicleid);
851 info.vr_impact(info, this);
857 if(autocvar_g_vehicles_enter)
860 vehicles_enter(toucher, this);
863 bool vehicle_impulse(entity this, int imp)
865 entity v = this.vehicle;
866 if (!v) return false;
867 if (IS_DEAD(v)) return false;
868 bool(entity,int) f = v.vehicles_impulse;
869 if (f && f(this,imp)) return true;
872 case IMP_weapon_drop.impulse:
874 stuffcmd(this, "\ntoggle cl_eventchase_vehicle\nset _vehicles_shownchasemessage 1\n");
881 void vehicles_enter(entity pl, entity veh)
883 // Remove this when bots know how to use vehicles
884 if((IS_BOT_CLIENT(pl) && !autocvar_g_vehicles_allow_bots))
888 || (veh.phase >= time)
889 || (pl.vehicle_enter_delay >= time)
890 || (STAT(FROZEN, pl))
895 Vehicle info = Vehicles_from(veh.vehicleid);
897 if(autocvar_g_vehicles_enter) // vehicle's touch function should handle this if entering via use key is disabled (TODO)
898 if(veh.vehicle_flags & VHF_MULTISLOT)
899 if(veh.owner && SAME_TEAM(pl, veh))
901 // we don't need a return value or anything here
902 // if successful the owner check below will prevent anything weird
903 info.vr_gunner_enter(info, veh, pl);
907 return; // got here and didn't enter the gunner, return
911 if(DIFF_TEAM(pl, veh))
912 if(autocvar_g_vehicles_steal)
914 FOREACH_CLIENT(IS_PLAYER(it) && SAME_TEAM(it, veh), Send_Notification(NOTIF_ONE, it, MSG_CENTER, CENTER_VEHICLE_STEAL));
916 Send_Notification(NOTIF_ONE, pl, MSG_CENTER, CENTER_VEHICLE_STEAL_SELF);
918 if (autocvar_g_vehicles_steal_show_waypoint) {
919 entity wp = WaypointSprite_Spawn(WP_VehicleIntruder, 0, 0, pl, '0 0 68', NULL, veh.team, veh, wps_intruder, true, RADARICON_DANGER);
920 wp.colormod = Team_ColorRGB(pl.team);
925 RemoveGrapplingHook(pl);
927 veh.vehicle_ammo1 = 0;
928 veh.vehicle_ammo2 = 0;
929 veh.vehicle_reload1 = 0;
930 veh.vehicle_reload2 = 0;
931 veh.vehicle_energy = 0;
936 // .viewmodelforclient works better.
937 //veh.vehicle_hudmodel.drawonlytoclient = veh.owner;
939 veh.vehicle_hudmodel.viewmodelforclient = pl;
942 pl.view_ofs = STAT(PL_VIEW_OFS, NULL);
943 setsize (pl, STAT(PL_MIN, NULL), STAT(PL_MAX, NULL));
945 veh.event_damage = vehicles_damage;
947 pl.angles = veh.angles;
948 pl.takedamage = DAMAGE_NO;
949 pl.solid = SOLID_NOT;
950 pl.disableclientprediction = 1; // physics is no longer run, so this won't be reset
951 set_movetype(pl, MOVETYPE_NOCLIP);
952 pl.teleportable = false;
954 pl.event_damage = func_null;
955 pl.view_ofs = '0 0 0';
956 veh.colormap = pl.colormap;
958 veh.tur_head.colormap = pl.colormap;
959 veh.m_switchweapon = PS(pl).m_switchweapon;
960 pl.hud = veh.vehicleid;
961 pl.PlayerPhysplug = veh.PlayerPhysplug;
963 pl.vehicle_ammo1 = veh.vehicle_ammo1;
964 pl.vehicle_ammo2 = veh.vehicle_ammo2;
965 pl.vehicle_reload1 = veh.vehicle_reload1;
966 pl.vehicle_reload2 = veh.vehicle_reload2;
967 pl.vehicle_energy = veh.vehicle_energy;
969 // Cant do this, hides attached objects too.
970 //veh.exteriormodeltoclient = veh.owner;
971 //veh.tur_head.exteriormodeltoclient = veh.owner;
977 veh.flags -= FL_NOTARGET;
979 if (IS_REAL_CLIENT(pl))
981 Send_Notification(NOTIF_ONE, pl, MSG_CENTER, CENTER_VEHICLE_ENTER);
984 WriteByte (MSG_ONE, SVC_SETVIEWPORT);
985 WriteEntity(MSG_ONE, veh.vehicle_viewport);
987 WriteByte (MSG_ONE, SVC_SETVIEWANGLES);
990 WriteAngle(MSG_ONE, veh.tur_head.angles_x + veh.angles_x); // tilt
991 WriteAngle(MSG_ONE, veh.tur_head.angles_y + veh.angles_y); // yaw
992 WriteAngle(MSG_ONE, 0); // roll
996 WriteAngle(MSG_ONE, veh.angles_x * -1); // tilt
997 WriteAngle(MSG_ONE, veh.angles_y); // yaw
998 WriteAngle(MSG_ONE, 0); // roll
1002 vehicles_clearreturn(veh);
1004 CSQCVehicleSetup(pl, veh.vehicleid);
1006 MUTATOR_CALLHOOK(VehicleEnter, pl, veh);
1008 CSQCModel_UnlinkEntity(veh);
1009 info.vr_enter(info, veh);
1011 antilag_clear(pl, CS(pl));
1014 void vehicles_think(entity this)
1016 this.nextthink = time + autocvar_g_vehicles_thinkrate;
1019 this.owner.vehicle_weapon2mode = this.vehicle_weapon2mode;
1021 Vehicle info = Vehicles_from(this.vehicleid);
1022 info.vr_think(info, this);
1024 vehicles_painframe(this);
1026 CSQCMODEL_AUTOUPDATE(this);
1029 void vehicles_reset(entity this)
1032 vehicles_exit(this, VHEF_RELEASE);
1034 vehicles_clearreturn(this);
1036 if(this.active != ACTIVE_NOT)
1037 vehicles_spawn(this);
1041 void vehicles_spawn(entity this)
1043 LOG_DEBUG("Spawning vehicle: ", this.classname, "\n");
1046 this.vehicle_hudmodel.viewmodelforclient = this;
1049 settouch(this, vehicles_touch);
1050 this.event_damage = vehicles_damage;
1051 this.reset = vehicles_reset;
1052 this.iscreature = true;
1053 this.teleportable = false; // no teleporting for vehicles, too buggy
1054 this.damagedbycontents = true;
1055 set_movetype(this, MOVETYPE_WALK);
1056 this.solid = SOLID_SLIDEBOX;
1057 this.takedamage = DAMAGE_AIM;
1058 this.deadflag = DEAD_NO;
1059 this.bot_attack = true;
1060 this.flags = FL_NOTARGET;
1061 this.avelocity = '0 0 0';
1062 this.velocity = '0 0 0';
1063 setthink(this, vehicles_think);
1064 this.nextthink = time;
1067 this.lock_strength = 0;
1068 this.lock_target = NULL;
1069 this.misc_bulletcounter = 0;
1072 this.angles = this.pos2;
1073 setorigin(this, this.pos1);
1075 Send_Effect(EFFECT_TELEPORT, this.origin + '0 0 64', '0 0 0', 1);
1077 if(this.vehicle_controller)
1078 this.team = this.vehicle_controller.team;
1080 FOREACH_CLIENT(IS_PLAYER(it) && it.hook.aiment == this, RemoveGrapplingHook(it));
1082 vehicles_reset_colors(this);
1084 Vehicle info = Vehicles_from(this.vehicleid);
1085 info.vr_spawn(info, this);
1087 CSQCMODEL_AUTOINIT(this);
1090 bool vehicle_initialize(entity this, Vehicle info, bool nodrop)
1092 if(!autocvar_g_vehicles)
1100 info.vr_precache(info);
1101 IL_PUSH(g_vehicles, this);
1104 if(this.targetname && this.targetname != "")
1106 this.vehicle_controller = find(NULL, target, this.targetname);
1107 if(!this.vehicle_controller)
1109 LOG_DEBUG("^1WARNING: ^7Vehicle with invalid .targetname\n");
1110 this.active = ACTIVE_ACTIVE;
1114 this.team = this.vehicle_controller.team;
1115 this.use = vehicle_use;
1119 if(this.vehicle_controller.team == 0)
1120 this.active = ACTIVE_NOT;
1122 this.active = ACTIVE_ACTIVE;
1126 else { this.active = ACTIVE_ACTIVE; }
1128 if(this.team && (!teamplay || !autocvar_g_vehicles_teams))
1131 if(this.mdl == "" || !this.mdl)
1132 _setmodel(this, info.model);
1134 _setmodel(this, this.mdl);
1136 this.vehicle_flags |= VHF_ISVEHICLE;
1138 this.vehicle_viewport = new(vehicle_viewport);
1139 this.vehicle_hudmodel = new(vehicle_hudmodel);
1140 this.tur_head = new(tur_head);
1141 this.tur_head.owner = this;
1142 this.takedamage = DAMAGE_NO;
1143 this.bot_attack = true;
1144 this.iscreature = true;
1145 this.teleportable = false; // no teleporting for vehicles, too buggy
1146 this.damagedbycontents = true;
1147 this.vehicleid = info.vehicleid;
1148 this.PlayerPhysplug = info.PlayerPhysplug;
1149 this.event_damage = func_null;
1150 settouch(this, vehicles_touch);
1151 setthink(this, vehicles_spawn);
1152 this.nextthink = time;
1153 this.effects = EF_NODRAW;
1154 this.dphitcontentsmask = DPCONTENTS_BODY | DPCONTENTS_SOLID;
1156 if(autocvar_g_playerclip_collisions)
1157 this.dphitcontentsmask |= DPCONTENTS_PLAYERCLIP;
1159 if(autocvar_g_nodepthtestplayers)
1160 this.effects |= EF_NODEPTHTEST;
1162 if(autocvar_g_fullbrightplayers)
1163 this.effects |= EF_FULLBRIGHT;
1165 _setmodel(this.vehicle_hudmodel, info.hud_model);
1166 setmodel(this.vehicle_viewport, MDL_Null);
1168 if(info.head_model != "")
1170 _setmodel(this.tur_head, info.head_model);
1171 setattachment(this.tur_head, this, info.tag_head);
1172 setattachment(this.vehicle_hudmodel, this.tur_head, info.tag_hud);
1173 setattachment(this.vehicle_viewport, this.vehicle_hudmodel, info.tag_view);
1177 setattachment(this.tur_head, this, "");
1178 setattachment(this.vehicle_hudmodel, this, info.tag_hud);
1179 setattachment(this.vehicle_viewport, this.vehicle_hudmodel, info.tag_view);
1182 setsize(this, info.mins, info.maxs);
1184 info.vr_setup(info, this);
1188 setorigin(this, this.origin);
1189 tracebox(this.origin + '0 0 100', info.mins, info.maxs, this.origin - '0 0 10000', MOVE_WORLDONLY, this);
1190 setorigin(this, trace_endpos);
1193 this.pos1 = this.origin;
1194 this.pos2 = this.angles;
1195 this.tur_head.team = this.team;
1197 if(this.active == ACTIVE_NOT)
1198 this.nextthink = 0; // wait until activated
1199 else if(autocvar_g_vehicles_delayspawn)
1200 this.nextthink = time + this.respawntime + (random() * autocvar_g_vehicles_delayspawn_jitter);
1202 this.nextthink = time + game_starttime;
1204 if(MUTATOR_CALLHOOK(VehicleSpawn, this))