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 IL_PUSH(g_projectiles, proj);
233 proj.bot_dodge = true;
234 proj.bot_dodgerating = _dmg;
235 proj.velocity = _vel;
236 settouch(proj, vehicles_projectile_explode);
237 proj.use = vehicles_projectile_explode_use;
239 proj.realowner = _owner;
240 setthink(proj, SUB_Remove);
241 proj.nextthink = time + 30;
245 proj.takedamage = DAMAGE_AIM;
246 proj.event_damage = vehicles_projectile_damage;
247 proj.health = _health;
250 proj.flags |= FL_NOTARGET;
252 if(_mzlsound != SND_Null)
253 sound (this, CH_WEAPON_A, _mzlsound, VOL_BASE, ATTEN_NORM);
256 Send_Effect_(_mzlfx, proj.origin, proj.velocity, 1);
258 setsize (proj, '-1 -1 -1' * _size, '1 1 1' * _size);
260 CSQCProjectile(proj, _clianim, _projtype, _cull);
265 void vehicles_gib_explode(entity this)
267 sound (this, CH_SHOTS, SND_ROCKET_IMPACT, VOL_BASE, ATTEN_NORM);
268 Send_Effect(EFFECT_EXPLOSION_SMALL, randomvec() * 80 + (this.origin + '0 0 100'), '0 0 0', 1);
269 Send_Effect(EFFECT_EXPLOSION_SMALL, this.wp00.origin + '0 0 64', '0 0 0', 1);
273 void vehicles_gib_touch(entity this, entity toucher)
275 vehicles_gib_explode(this);
278 void vehicles_gib_think(entity this)
284 this.nextthink = time + 0.1;
287 entity vehicle_tossgib(entity this, entity _template, vector _vel, string _tag, bool _burn, bool _explode, float _maxtime, vector _rot)
289 entity _gib = spawn();
290 _setmodel(_gib, _template.model);
291 vector org = gettaginfo(this, gettagindex(this, _tag));
292 setorigin(_gib, org);
293 _gib.velocity = _vel;
294 set_movetype(_gib, MOVETYPE_TOSS);
295 _gib.solid = SOLID_CORPSE;
296 _gib.colormod = '-0.5 -0.5 -0.5';
297 _gib.effects = EF_LOWPRECISION;
298 _gib.avelocity = _rot;
301 _gib.effects |= EF_FLAME;
305 setthink(_gib, vehicles_gib_explode);
306 _gib.nextthink = time + random() * _explode;
307 settouch(_gib, vehicles_gib_touch);
311 _gib.cnt = time + _maxtime;
312 setthink(_gib, vehicles_gib_think);
313 _gib.nextthink = time + _maxtime - 1;
319 bool vehicle_addplayerslot( entity _owner,
323 bool(entity) _framefunc,
324 void(entity,bool) _exitfunc, float(entity, entity) _enterfunc)
326 if(!(_owner.vehicle_flags & VHF_MULTISLOT))
327 _owner.vehicle_flags |= VHF_MULTISLOT;
329 _slot.PlayerPhysplug = _framefunc;
330 _slot.vehicle_exit = _exitfunc;
331 _slot.vehicle_enter = _enterfunc;
333 _slot.vehicle_flags = VHF_PLAYERSLOT;
334 _slot.vehicle_viewport = spawn();
335 _slot.vehicle_hudmodel = spawn();
336 _slot.vehicle_hudmodel.viewmodelforclient = _slot;
337 _slot.vehicle_viewport.effects = (EF_ADDITIVE | EF_DOUBLESIDED | EF_FULLBRIGHT | EF_NODEPTHTEST | EF_NOGUNBOB | EF_NOSHADOW | EF_LOWPRECISION | EF_SELECTABLE | EF_TELEPORT_BIT);
339 setmodel(_slot.vehicle_hudmodel, _hud_model);
340 setmodel(_slot.vehicle_viewport, MDL_Null);
342 setattachment(_slot.vehicle_hudmodel, _slot, "");
343 setattachment(_slot.vehicle_viewport, _slot.vehicle_hudmodel, "");
348 vector vehicle_aimturret(entity _vehic, vector _target, entity _turrret, string _tagname,
349 float _pichlimit_min, float _pichlimit_max,
350 float _rotlimit_min, float _rotlimit_max, float _aimspeed)
354 vtag = gettaginfo(_turrret, gettagindex(_turrret, _tagname));
355 vtmp = vectoangles(normalize(_target - vtag));
356 vtmp = AnglesTransform_ToAngles(AnglesTransform_LeftDivide(AnglesTransform_FromAngles(_vehic.angles), AnglesTransform_FromAngles(vtmp))) - _turrret.angles;
357 vtmp = AnglesTransform_Normalize(vtmp, true);
358 ftmp = _aimspeed * frametime;
359 vtmp_y = bound(-ftmp, vtmp_y, ftmp);
360 vtmp_x = bound(-ftmp, vtmp_x, ftmp);
361 _turrret.angles_y = bound(_rotlimit_min, _turrret.angles_y + vtmp_y, _rotlimit_max);
362 _turrret.angles_x = bound(_pichlimit_min, _turrret.angles_x + vtmp_x, _pichlimit_max);
366 void vehicles_reset_colors(entity this)
369 const vector cmod = '0 0 0';
370 if(this.team && teamplay)
371 cmap = 1024 + (this.team - 1) * 17;
374 if(autocvar_g_nodepthtestplayers)
375 eff |= EF_NODEPTHTEST;
376 if(autocvar_g_fullbrightplayers)
377 eff |= EF_FULLBRIGHT;
379 // Find all ents attacked to main model and setup effects, colormod etc.
380 FOREACH_ENTITY_ENT(tag_entity, this,
382 if(it != this.vehicle_shieldent)
391 // Also check head tags
392 FOREACH_ENTITY_ENT(tag_entity, this.tur_head,
394 if(it != this.vehicle_shieldent)
403 this.vehicle_hudmodel.effects = this.effects = eff; // | EF_LOWPRECISION;
404 this.vehicle_hudmodel.colormod = this.colormod = cmod;
405 this.vehicle_hudmodel.colormap = this.colormap = cmap;
406 this.vehicle_viewport.effects = (EF_ADDITIVE | EF_DOUBLESIDED | EF_FULLBRIGHT | EF_NODEPTHTEST | EF_NOGUNBOB | EF_NOSHADOW | EF_LOWPRECISION | EF_SELECTABLE | EF_TELEPORT_BIT);
409 this.avelocity = '0 0 0';
410 this.velocity = '0 0 0';
414 void vehicles_clearreturn(entity veh)
416 // Remove "return helper" entities, if any.
417 FOREACH_ENTITY_ENT(wp00, veh,
419 if(it.classname == "vehicle_return")
422 setthink(it, SUB_Remove);
423 it.nextthink = time + 0.1;
425 if(it.waypointsprite_attached)
426 WaypointSprite_Kill(it.waypointsprite_attached);
431 void vehicles_spawn(entity this);
432 void vehicles_return(entity this)
434 Send_Effect(EFFECT_TELEPORT, this.wp00.origin + '0 0 64', '0 0 0', 1);
436 setthink(this.wp00, vehicles_spawn);
437 this.wp00.nextthink = time;
439 if(this.waypointsprite_attached)
440 WaypointSprite_Kill(this.waypointsprite_attached);
445 void vehicles_showwp_goaway(entity this)
447 if(this.waypointsprite_attached)
448 WaypointSprite_Kill(this.waypointsprite_attached);
453 void vehicles_showwp(entity this)
459 setthink(ent, vehicles_return);
460 ent.nextthink = ent.cnt;
464 setthink(ent, vehicles_return);
465 ent.nextthink = time + 1;
468 ent.team = this.wp00.team;
469 ent.wp00 = this.wp00;
470 setorigin(ent, this.wp00.pos1);
472 ent.nextthink = time + 5;
473 setthink(ent, vehicles_showwp_goaway);
477 if(teamplay && ent.team)
478 rgb = Team_ColorRGB(ent.team);
481 entity wp = WaypointSprite_Spawn(WP_Vehicle, 0, 0, ent, '0 0 64', NULL, 0, ent, waypointsprite_attached, true, RADARICON_Vehicle);
483 if(ent.waypointsprite_attached)
485 WaypointSprite_UpdateRule(ent.waypointsprite_attached, ent.wp00.team, SPRITERULE_DEFAULT);
487 WaypointSprite_UpdateBuildFinished(ent.waypointsprite_attached, ent.nextthink);
488 WaypointSprite_Ping(ent.waypointsprite_attached);
492 void vehicles_setreturn(entity veh)
494 vehicles_clearreturn(veh);
496 entity ret = new(vehicle_return);
499 setthink(ret, vehicles_showwp);
503 ret.cnt = time + veh.respawntime;
504 ret.nextthink = min(time + veh.respawntime, time + veh.respawntime - 5);
508 ret.nextthink = min(time + veh.respawntime, time + veh.respawntime - 1);
511 setorigin(ret, veh.pos1 + '0 0 96');
514 void vehicle_use(entity this, entity actor, entity trigger)
516 LOG_DEBUG("vehicle ", this.netname, " used by ", actor.classname, "\n");
518 this.tur_head.team = actor.team;
520 if(this.tur_head.team == 0)
521 this.active = ACTIVE_NOT;
523 this.active = ACTIVE_ACTIVE;
525 if(this.active == ACTIVE_ACTIVE && !IS_DEAD(this) && !gameover)
527 LOG_DEBUG("Respawning vehicle: ", this.netname, "\n");
528 if(this.effects & EF_NODRAW)
530 setthink(this, vehicles_spawn);
531 this.nextthink = time + 3;
535 vehicles_setreturn(this);
536 vehicles_reset_colors(this);
541 void vehicles_regen(entity this, float timer, .float regen_field, float field_max, float rpause, float regen, float delta_time, float _healthscale)
543 if(this.(regen_field) < field_max)
544 if(timer + rpause < time)
547 regen = regen * (this.vehicle_health / this.max_health);
549 this.(regen_field) = min(this.(regen_field) + regen * delta_time, field_max);
552 this.owner.(regen_field) = (this.(regen_field) / field_max) * 100;
556 void shieldhit_think(entity this)
561 // setmodel(this, MDL_Null);
563 this.effects |= EF_NODRAW;
567 this.nextthink = time + 0.1;
571 void vehicles_painframe(entity this)
573 int myhealth = ((this.owner) ? this.owner.vehicle_health : ((this.vehicle_health / this.max_health) * 100));
576 if(this.pain_frame < time)
578 float _ftmp = myhealth / 50;
579 this.pain_frame = time + max(0.1, 0.1 + (random() * 0.5 * _ftmp));
580 Send_Effect(EFFECT_SMOKE_SMALL, (this.origin + (randomvec() * 80)), '0 0 0', 1);
582 if(this.vehicle_flags & VHF_DMGSHAKE)
583 this.velocity += randomvec() * 30;
585 if(this.vehicle_flags & VHF_DMGROLL)
586 if(this.vehicle_flags & VHF_DMGHEADROLL)
587 this.tur_head.angles += randomvec();
589 this.angles += randomvec();
593 void vehicles_frame(entity this, entity actor)
595 vehicles_painframe(this);
598 void vehicles_damage(entity this, entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force)
600 this.dmg_time = time;
603 if(DEATH_ISWEAPON(deathtype, WEP_VORTEX))
604 damage *= autocvar_g_vehicles_vortex_damagerate;
605 else if(DEATH_ISWEAPON(deathtype, WEP_MACHINEGUN))
606 damage *= autocvar_g_vehicles_machinegun_damagerate;
607 else if(DEATH_ISWEAPON(deathtype, WEP_RIFLE))
608 damage *= autocvar_g_vehicles_rifle_damagerate;
609 else if(DEATH_ISWEAPON(deathtype, WEP_VAPORIZER))
610 damage *= autocvar_g_vehicles_vaporizer_damagerate;
611 else if(DEATH_ISWEAPON(deathtype, WEP_SEEKER))
612 damage *= autocvar_g_vehicles_tag_damagerate;
613 else if(DEATH_WEAPONOF(deathtype) != WEP_Null)
614 damage *= autocvar_g_vehicles_weapon_damagerate;
616 this.enemy = attacker;
618 this.pain_finished = time;
620 if((this.vehicle_flags & VHF_HASSHIELD) && (this.vehicle_shield > 0))
622 if (wasfreed(this.vehicle_shieldent) || this.vehicle_shieldent == NULL)
624 this.vehicle_shieldent = spawn();
625 this.vehicle_shieldent.effects = EF_LOWPRECISION;
627 setmodel(this.vehicle_shieldent, MDL_VEH_SHIELD);
628 setattachment(this.vehicle_shieldent, this, "");
629 setorigin(this.vehicle_shieldent, real_origin(this) - this.origin);
630 this.vehicle_shieldent.scale = 256 / vlen(this.maxs - this.mins);
631 setthink(this.vehicle_shieldent, shieldhit_think);
634 this.vehicle_shieldent.colormod = '1 1 1';
635 this.vehicle_shieldent.alpha = 0.45;
636 this.vehicle_shieldent.angles = vectoangles(normalize(hitloc - (this.origin + this.vehicle_shieldent.origin))) - this.angles;
637 this.vehicle_shieldent.nextthink = time;
638 this.vehicle_shieldent.effects &= ~EF_NODRAW;
640 this.vehicle_shield -= damage;
642 if(this.vehicle_shield < 0)
644 this.vehicle_health -= fabs(this.vehicle_shield);
645 this.vehicle_shieldent.colormod = '2 0 0';
646 this.vehicle_shield = 0;
647 this.vehicle_shieldent.alpha = 0.75;
649 if(sound_allowed(MSG_BROADCAST, attacker))
650 spamsound (this, CH_PAIN, "onslaught/ons_hit2.wav", VOL_BASE, ATTEN_NORM); // FIXME: PLACEHOLDER
653 if(sound_allowed(MSG_BROADCAST, attacker))
654 spamsound (this, CH_PAIN, "onslaught/electricity_explode.wav", VOL_BASE, ATTEN_NORM); // FIXME: PLACEHOLDER
659 this.vehicle_health -= damage;
661 if(sound_allowed(MSG_BROADCAST, attacker))
662 spamsound (this, CH_PAIN, "onslaught/ons_hit2.wav", VOL_BASE, ATTEN_NORM); // FIXME: PLACEHOLDER
665 if(this.damageforcescale < 1 && this.damageforcescale > 0)
666 this.velocity += force * this.damageforcescale;
668 this.velocity += force;
670 if(this.vehicle_health <= 0)
673 if(this.vehicle_flags & VHF_DEATHEJECT)
674 vehicles_exit(this, VHEF_EJECT);
676 vehicles_exit(this, VHEF_RELEASE);
679 antilag_clear(this, this);
681 Vehicle info = Vehicles_from(this.vehicleid);
682 info.vr_death(info, this);
683 vehicles_setreturn(this);
687 bool vehicles_crushable(entity e)
689 if(IS_PLAYER(e) && time >= e.vehicle_enter_delay)
698 void vehicles_impact(entity this, float _minspeed, float _speedfac, float _maxpain)
700 if (trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT)
703 if(this.play_time < time)
705 float wc = vlen(this.velocity - this.oldvelocity);
706 //dprint("oldvel: ", vtos(this.oldvelocity), "\n");
707 //dprint("vel: ", vtos(this.velocity), "\n");
710 float take = min(_speedfac * wc, _maxpain);
711 Damage (this, NULL, NULL, take, DEATH_FALL.m_id, this.origin, '0 0 0');
712 this.play_time = time + 0.25;
714 //dprint("wc: ", ftos(wc), "\n");
715 //dprint("take: ", ftos(take), "\n");
720 // vehicle enter/exit handling
721 vector vehicles_findgoodexit(entity this, vector prefer_spot)
723 tracebox(this.origin + '0 0 32', STAT(PL_MIN, NULL), STAT(PL_MAX, NULL), prefer_spot, MOVE_NORMAL, this.owner);
724 if(trace_fraction == 1.0 && !trace_startsolid && !trace_allsolid)
727 float mysize = 1.5 * vlen(this.maxs - this.mins);
729 vector v2 = 0.5 * (this.absmin + this.absmax);
730 for(int i = 0; i < autocvar_g_vehicles_exit_attempts; ++i)
734 v = v2 + normalize(v) * mysize;
735 tracebox(v2, STAT(PL_MIN, NULL), STAT(PL_MAX, NULL), v, MOVE_NORMAL, this.owner);
736 if(trace_fraction == 1.0 && !trace_startsolid && !trace_allsolid)
743 void vehicles_exit(entity vehic, bool eject)
745 entity player = vehic.owner;
747 if(vehicles_exit_running)
749 LOG_TRACE("^1vehicles_exit already running! this is not good...\n");
753 vehicles_exit_running = true;
755 // TODO: this was in an IS_CLIENT check, make sure it isn't actually needed!
756 if(vehic.vehicle_flags & VHF_PLAYERSLOT)
758 vehic.vehicle_exit(vehic, eject);
759 vehicles_exit_running = false;
765 if (IS_REAL_CLIENT(player))
768 WriteByte (MSG_ONE, SVC_SETVIEWPORT);
769 WriteEntity( MSG_ONE, player);
771 WriteByte (MSG_ONE, SVC_SETVIEWANGLES);
772 WriteAngle(MSG_ONE, 0);
773 WriteAngle(MSG_ONE, vehic.angles_y);
774 WriteAngle(MSG_ONE, 0);
777 setsize(player, STAT(PL_MIN, NULL), STAT(PL_MAX, NULL));
779 player.takedamage = DAMAGE_AIM;
780 player.solid = SOLID_SLIDEBOX;
781 set_movetype(player, MOVETYPE_WALK);
782 player.effects &= ~EF_NODRAW;
783 player.teleportable = TELEPORT_NORMAL;
785 player.PlayerPhysplug = func_null;
786 player.vehicle = NULL;
787 player.view_ofs = STAT(PL_VIEW_OFS, NULL);
788 player.event_damage = PlayerDamage;
789 player.hud = HUD_NORMAL;
790 PS(player).m_switchweapon = vehic.m_switchweapon;
791 player.last_vehiclecheck = time + 3;
792 player.vehicle_enter_delay = time + 2;
794 CSQCVehicleSetup(player, HUD_NORMAL);
796 Kill_Notification(NOTIF_ONE, player, MSG_CENTER, CPID_VEHICLES);
797 Kill_Notification(NOTIF_ONE, player, MSG_CENTER, CPID_VEHICLES_OTHER); // kill all vehicle notifications when exiting a vehicle?
800 vehic.flags |= FL_NOTARGET;
803 vehic.avelocity = '0 0 0';
805 vehic.tur_head.nodrawtoclient = NULL;
810 WaypointSprite_Kill(vehic.wps_intruder);
812 MUTATOR_CALLHOOK(VehicleExit, player, vehic);
814 vehic.team = vehic.tur_head.team;
816 sound (vehic, CH_TRIGGER_SINGLE, SND_Null, 1, ATTEN_NORM);
817 vehic.vehicle_hudmodel.viewmodelforclient = vehic;
818 vehic.phase = time + 1;
820 vehic.vehicle_exit(vehic, eject);
822 vehicles_setreturn(vehic);
823 vehicles_reset_colors(vehic);
826 CSQCMODEL_AUTOINIT(vehic);
828 vehicles_exit_running = false;
831 void vehicles_touch(entity this, entity toucher)
833 if(MUTATOR_CALLHOOK(VehicleTouch, this, toucher))
836 // Vehicle currently in use
839 if(!forbidWeaponUse(this.owner))
841 if((this.origin_z + this.maxs_z) > (toucher.origin_z))
842 if(vehicles_crushable(toucher))
844 if(vdist(this.velocity, >=, 30))
845 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);
847 return; // Dont do selfdamage when hitting "soft targets".
850 if(this.play_time < time) {
851 Vehicle info = Vehicles_from(this.vehicleid);
852 info.vr_impact(info, this);
858 if(autocvar_g_vehicles_enter)
861 vehicles_enter(toucher, this);
864 bool vehicle_impulse(entity this, int imp)
866 entity v = this.vehicle;
867 if (!v) return false;
868 if (IS_DEAD(v)) return false;
869 bool(entity,int) f = v.vehicles_impulse;
870 if (f && f(this,imp)) return true;
873 case IMP_weapon_drop.impulse:
875 stuffcmd(this, "\ntoggle cl_eventchase_vehicle\nset _vehicles_shownchasemessage 1\n");
882 void vehicles_enter(entity pl, entity veh)
884 // Remove this when bots know how to use vehicles
885 if((IS_BOT_CLIENT(pl) && !autocvar_g_vehicles_allow_bots))
889 || (veh.phase >= time)
890 || (pl.vehicle_enter_delay >= time)
891 || (STAT(FROZEN, pl))
896 Vehicle info = Vehicles_from(veh.vehicleid);
898 if(autocvar_g_vehicles_enter) // vehicle's touch function should handle this if entering via use key is disabled (TODO)
899 if(veh.vehicle_flags & VHF_MULTISLOT)
900 if(veh.owner && SAME_TEAM(pl, veh))
902 // we don't need a return value or anything here
903 // if successful the owner check below will prevent anything weird
904 info.vr_gunner_enter(info, veh, pl);
908 return; // got here and didn't enter the gunner, return
912 if(DIFF_TEAM(pl, veh))
913 if(autocvar_g_vehicles_steal)
915 FOREACH_CLIENT(IS_PLAYER(it) && SAME_TEAM(it, veh), Send_Notification(NOTIF_ONE, it, MSG_CENTER, CENTER_VEHICLE_STEAL));
917 Send_Notification(NOTIF_ONE, pl, MSG_CENTER, CENTER_VEHICLE_STEAL_SELF);
919 if (autocvar_g_vehicles_steal_show_waypoint) {
920 entity wp = WaypointSprite_Spawn(WP_VehicleIntruder, 0, 0, pl, '0 0 68', NULL, veh.team, veh, wps_intruder, true, RADARICON_DANGER);
921 wp.colormod = Team_ColorRGB(pl.team);
926 RemoveGrapplingHook(pl);
928 veh.vehicle_ammo1 = 0;
929 veh.vehicle_ammo2 = 0;
930 veh.vehicle_reload1 = 0;
931 veh.vehicle_reload2 = 0;
932 veh.vehicle_energy = 0;
937 // .viewmodelforclient works better.
938 //veh.vehicle_hudmodel.drawonlytoclient = veh.owner;
940 veh.vehicle_hudmodel.viewmodelforclient = pl;
943 pl.view_ofs = STAT(PL_VIEW_OFS, NULL);
944 setsize (pl, STAT(PL_MIN, NULL), STAT(PL_MAX, NULL));
946 veh.event_damage = vehicles_damage;
948 pl.angles = veh.angles;
949 pl.takedamage = DAMAGE_NO;
950 pl.solid = SOLID_NOT;
951 pl.disableclientprediction = 1; // physics is no longer run, so this won't be reset
952 set_movetype(pl, MOVETYPE_NOCLIP);
953 pl.teleportable = false;
955 pl.event_damage = func_null;
956 pl.view_ofs = '0 0 0';
957 veh.colormap = pl.colormap;
959 veh.tur_head.colormap = pl.colormap;
960 veh.m_switchweapon = PS(pl).m_switchweapon;
961 pl.hud = veh.vehicleid;
962 pl.PlayerPhysplug = veh.PlayerPhysplug;
964 pl.vehicle_ammo1 = veh.vehicle_ammo1;
965 pl.vehicle_ammo2 = veh.vehicle_ammo2;
966 pl.vehicle_reload1 = veh.vehicle_reload1;
967 pl.vehicle_reload2 = veh.vehicle_reload2;
968 pl.vehicle_energy = veh.vehicle_energy;
970 // Cant do this, hides attached objects too.
971 //veh.exteriormodeltoclient = veh.owner;
972 //veh.tur_head.exteriormodeltoclient = veh.owner;
978 veh.flags -= FL_NOTARGET;
980 if (IS_REAL_CLIENT(pl))
982 Send_Notification(NOTIF_ONE, pl, MSG_CENTER, CENTER_VEHICLE_ENTER);
985 WriteByte (MSG_ONE, SVC_SETVIEWPORT);
986 WriteEntity(MSG_ONE, veh.vehicle_viewport);
988 WriteByte (MSG_ONE, SVC_SETVIEWANGLES);
991 WriteAngle(MSG_ONE, veh.tur_head.angles_x + veh.angles_x); // tilt
992 WriteAngle(MSG_ONE, veh.tur_head.angles_y + veh.angles_y); // yaw
993 WriteAngle(MSG_ONE, 0); // roll
997 WriteAngle(MSG_ONE, veh.angles_x * -1); // tilt
998 WriteAngle(MSG_ONE, veh.angles_y); // yaw
999 WriteAngle(MSG_ONE, 0); // roll
1003 vehicles_clearreturn(veh);
1005 CSQCVehicleSetup(pl, veh.vehicleid);
1007 MUTATOR_CALLHOOK(VehicleEnter, pl, veh);
1009 CSQCModel_UnlinkEntity(veh);
1010 info.vr_enter(info, veh);
1012 antilag_clear(pl, CS(pl));
1015 void vehicles_think(entity this)
1017 this.nextthink = time + autocvar_g_vehicles_thinkrate;
1020 this.owner.vehicle_weapon2mode = this.vehicle_weapon2mode;
1022 Vehicle info = Vehicles_from(this.vehicleid);
1023 info.vr_think(info, this);
1025 vehicles_painframe(this);
1027 CSQCMODEL_AUTOUPDATE(this);
1030 void vehicles_reset(entity this)
1033 vehicles_exit(this, VHEF_RELEASE);
1035 vehicles_clearreturn(this);
1037 if(this.active != ACTIVE_NOT)
1038 vehicles_spawn(this);
1042 void vehicles_spawn(entity this)
1044 LOG_DEBUG("Spawning vehicle: ", this.classname, "\n");
1047 this.vehicle_hudmodel.viewmodelforclient = this;
1050 settouch(this, vehicles_touch);
1051 this.event_damage = vehicles_damage;
1052 this.reset = vehicles_reset;
1053 this.iscreature = true;
1054 this.teleportable = false; // no teleporting for vehicles, too buggy
1055 this.damagedbycontents = true;
1056 set_movetype(this, MOVETYPE_WALK);
1057 this.solid = SOLID_SLIDEBOX;
1058 this.takedamage = DAMAGE_AIM;
1059 this.deadflag = DEAD_NO;
1060 this.bot_attack = true;
1061 this.flags = FL_NOTARGET;
1062 this.avelocity = '0 0 0';
1063 this.velocity = '0 0 0';
1064 setthink(this, vehicles_think);
1065 this.nextthink = time;
1068 this.lock_strength = 0;
1069 this.lock_target = NULL;
1070 this.misc_bulletcounter = 0;
1073 this.angles = this.pos2;
1074 setorigin(this, this.pos1);
1076 Send_Effect(EFFECT_TELEPORT, this.origin + '0 0 64', '0 0 0', 1);
1078 if(this.vehicle_controller)
1079 this.team = this.vehicle_controller.team;
1081 FOREACH_CLIENT(IS_PLAYER(it) && it.hook.aiment == this, RemoveGrapplingHook(it));
1083 vehicles_reset_colors(this);
1085 Vehicle info = Vehicles_from(this.vehicleid);
1086 info.vr_spawn(info, this);
1088 CSQCMODEL_AUTOINIT(this);
1091 bool vehicle_initialize(entity this, Vehicle info, bool nodrop)
1093 if(!autocvar_g_vehicles)
1101 info.vr_precache(info);
1102 IL_PUSH(g_vehicles, this);
1105 if(this.targetname && this.targetname != "")
1107 this.vehicle_controller = find(NULL, target, this.targetname);
1108 if(!this.vehicle_controller)
1110 LOG_DEBUG("^1WARNING: ^7Vehicle with invalid .targetname\n");
1111 this.active = ACTIVE_ACTIVE;
1115 this.team = this.vehicle_controller.team;
1116 this.use = vehicle_use;
1120 if(this.vehicle_controller.team == 0)
1121 this.active = ACTIVE_NOT;
1123 this.active = ACTIVE_ACTIVE;
1127 else { this.active = ACTIVE_ACTIVE; }
1129 if(this.team && (!teamplay || !autocvar_g_vehicles_teams))
1132 if(this.mdl == "" || !this.mdl)
1133 _setmodel(this, info.model);
1135 _setmodel(this, this.mdl);
1137 this.vehicle_flags |= VHF_ISVEHICLE;
1139 this.vehicle_viewport = new(vehicle_viewport);
1140 this.vehicle_hudmodel = new(vehicle_hudmodel);
1141 this.tur_head = new(tur_head);
1142 this.tur_head.owner = this;
1143 this.takedamage = DAMAGE_NO;
1144 this.bot_attack = true;
1145 this.iscreature = true;
1146 this.teleportable = false; // no teleporting for vehicles, too buggy
1147 this.damagedbycontents = true;
1148 this.vehicleid = info.vehicleid;
1149 this.PlayerPhysplug = info.PlayerPhysplug;
1150 this.event_damage = func_null;
1151 settouch(this, vehicles_touch);
1152 setthink(this, vehicles_spawn);
1153 this.nextthink = time;
1154 this.effects = EF_NODRAW;
1155 this.dphitcontentsmask = DPCONTENTS_BODY | DPCONTENTS_SOLID;
1157 if(autocvar_g_playerclip_collisions)
1158 this.dphitcontentsmask |= DPCONTENTS_PLAYERCLIP;
1160 if(autocvar_g_nodepthtestplayers)
1161 this.effects |= EF_NODEPTHTEST;
1163 if(autocvar_g_fullbrightplayers)
1164 this.effects |= EF_FULLBRIGHT;
1166 _setmodel(this.vehicle_hudmodel, info.hud_model);
1167 setmodel(this.vehicle_viewport, MDL_Null);
1169 if(info.head_model != "")
1171 _setmodel(this.tur_head, info.head_model);
1172 setattachment(this.tur_head, this, info.tag_head);
1173 setattachment(this.vehicle_hudmodel, this.tur_head, info.tag_hud);
1174 setattachment(this.vehicle_viewport, this.vehicle_hudmodel, info.tag_view);
1178 setattachment(this.tur_head, this, "");
1179 setattachment(this.vehicle_hudmodel, this, info.tag_hud);
1180 setattachment(this.vehicle_viewport, this.vehicle_hudmodel, info.tag_view);
1183 setsize(this, info.mins, info.maxs);
1185 info.vr_setup(info, this);
1189 setorigin(this, this.origin);
1190 tracebox(this.origin + '0 0 100', info.mins, info.maxs, this.origin - '0 0 10000', MOVE_WORLDONLY, this);
1191 setorigin(this, trace_endpos);
1194 this.pos1 = this.origin;
1195 this.pos2 = this.angles;
1196 this.tur_head.team = this.team;
1198 if(this.active == ACTIVE_NOT)
1199 this.nextthink = 0; // wait until activated
1200 else if(autocvar_g_vehicles_delayspawn)
1201 this.nextthink = time + this.respawntime + (random() * autocvar_g_vehicles_delayspawn_jitter);
1203 this.nextthink = time + game_starttime;
1205 if(MUTATOR_CALLHOOK(VehicleSpawn, this))