1 #include "sv_vehicles.qh"
3 bool SendAuxiliaryXhair(entity this, entity to, int sf)
5 WriteHeader(MSG_ENTITY, ENT_CLIENT_AUXILIARYXHAIR);
6 WriteByte(MSG_ENTITY, sf);
8 WriteByte(MSG_ENTITY, this.cnt);
12 WriteCoord(MSG_ENTITY, this.origin_x);
13 WriteCoord(MSG_ENTITY, this.origin_y);
14 WriteCoord(MSG_ENTITY, this.origin_z);
19 WriteByte(MSG_ENTITY, rint(this.colormod_x * 255));
20 WriteByte(MSG_ENTITY, rint(this.colormod_y * 255));
21 WriteByte(MSG_ENTITY, rint(this.colormod_z * 255));
27 bool AuxiliaryXhair_customize(entity this, entity client)
29 //entity e = WaypointSprite_getviewentity(client);
30 entity axh = client.(AuxiliaryXhair[this.cnt]);
31 return axh.owner == this.owner; // cheaply check if the client's axh owner is the same as our real owner
34 .vector axh_prevorigin;
35 .vector axh_prevcolors;
37 void UpdateAuxiliaryXhair(entity own, vector loc, vector clr, int axh_id)
39 if(!IS_REAL_CLIENT(own))
42 axh_id = bound(0, axh_id, MAX_AXH);
43 entity axh = own.(AuxiliaryXhair[axh_id]);
45 if(axh == NULL || wasfreed(axh)) // MADNESS? THIS IS QQQQCCCCCCCCC (wasfreed, why do you exsist? Mario: because of sloppy code like this)
47 axh = new(auxiliary_xhair);
49 //axh.drawonlytoclient = own; // not spectatable
50 setcefc(axh, AuxiliaryXhair_customize);
52 Net_LinkEntity(axh, false, 0, SendAuxiliaryXhair);
55 if(loc != axh.axh_prevorigin)
61 if(clr != axh.axh_prevcolors)
67 own.(AuxiliaryXhair[axh_id]) = axh; // set it anyway...?
70 void CSQCVehicleSetup(entity own, int vehicle_id)
72 if(!IS_REAL_CLIENT(own))
77 WriteHeader(MSG_ONE, TE_CSQC_VEHICLESETUP);
78 WriteByte(MSG_ONE, vehicle_id);
80 if(vehicle_id == 0 || vehicle_id == HUD_NORMAL)
82 for(int i = 0; i < MAX_AXH; ++i)
84 entity axh = own.(AuxiliaryXhair[i]);
85 own.(AuxiliaryXhair[i]) = NULL;
87 if(axh.owner == own && axh != NULL && !wasfreed(axh))
93 void vehicles_locktarget(entity this, float incr, float decr, float _lock_time)
95 if(this.lock_target && IS_DEAD(this.lock_target))
97 this.lock_target = NULL;
98 this.lock_strength = 0;
102 if(this.lock_time > time)
105 if(this.lock_soundtime < time)
107 this.lock_soundtime = time + 0.5;
108 play2(this.owner, "vehicles/locked.wav");
114 if(trace_ent != NULL)
116 if(SAME_TEAM(trace_ent, this))
119 if(IS_DEAD(trace_ent))
122 if(!(IS_VEHICLE(trace_ent) || IS_TURRET(trace_ent)))
125 if(trace_ent.alpha <= 0.5 && trace_ent.alpha != 0)
126 trace_ent = NULL; // invisible
129 if(this.lock_target == NULL && trace_ent != NULL)
130 this.lock_target = trace_ent;
132 if(this.lock_target && trace_ent == this.lock_target)
134 if(this.lock_strength != 1 && this.lock_strength + incr >= 1)
136 play2(this.owner, "vehicles/lock.wav");
137 this.lock_soundtime = time + 0.8;
139 else if (this.lock_strength != 1 && this.lock_soundtime < time)
141 play2(this.owner, "vehicles/locking.wav");
142 this.lock_soundtime = time + 0.3;
146 // Have a locking target
147 // Trace hit current target
148 if(trace_ent == this.lock_target && trace_ent != NULL)
150 this.lock_strength = min(this.lock_strength + incr, 1);
151 if(this.lock_strength == 1)
152 this.lock_time = time + _lock_time;
157 this.lock_strength = max(this.lock_strength - decr * 2, 0);
159 this.lock_strength = max(this.lock_strength - decr, 0);
161 if(this.lock_strength == 0)
162 this.lock_target = NULL;
166 float vehicle_altitude(entity this, float amax)
168 tracebox(this.origin, this.mins, this.maxs, this.origin - ('0 0 1' * amax), MOVE_WORLDONLY, this);
169 return vlen(this.origin - trace_endpos);
172 vector vehicles_force_fromtag_hover(entity this, string tag_name, float spring_length, float max_power)
174 force_fromtag_origin = gettaginfo(this, gettagindex(this, tag_name));
175 v_forward = normalize(v_forward) * -1;
176 traceline(force_fromtag_origin, force_fromtag_origin - (v_forward * spring_length), MOVE_NORMAL, this);
178 force_fromtag_power = (1 - trace_fraction) * max_power;
179 force_fromtag_normpower = force_fromtag_power / max_power;
181 return v_forward * force_fromtag_power;
184 vector vehicles_force_fromtag_maglev(entity this, string tag_name, float spring_length, float max_power)
186 force_fromtag_origin = gettaginfo(this, gettagindex(this, tag_name));
187 v_forward = normalize(v_forward) * -1;
188 traceline(force_fromtag_origin, force_fromtag_origin - (v_forward * spring_length), MOVE_NORMAL, this);
190 // TODO - this may NOT be compatible with wall/celing movement, unhardcode 0.25 (engine count multiplier)
191 if(trace_fraction == 1.0)
193 force_fromtag_normpower = -0.25;
197 force_fromtag_power = ((1 - trace_fraction) - trace_fraction) * max_power;
198 force_fromtag_normpower = force_fromtag_power / max_power;
200 return v_forward * force_fromtag_power;
203 // projectile handling
204 void vehicles_projectile_damage(entity this, entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force)
206 // Ignore damage from oterh projectiles from my owner (dont mess up volly's)
207 if(inflictor.owner == this.owner)
210 this.health -= damage;
211 this.velocity += force;
214 this.takedamage = DAMAGE_NO;
215 this.event_damage = func_null;
216 setthink(this, adaptor_think2use);
217 this.nextthink = time;
221 void vehicles_projectile_explode(entity this, entity toucher)
223 if(this.owner && toucher != NULL)
225 if(toucher == this.owner.vehicle)
228 if(toucher == this.owner.vehicle.tur_head)
232 PROJECTILE_TOUCH(this, toucher);
234 this.event_damage = func_null;
235 RadiusDamage (this, this.realowner, this.shot_dmg, 0, this.shot_radius, this, NULL, this.shot_force, this.totalfrags, toucher);
240 void vehicles_projectile_explode_think(entity this)
242 vehicles_projectile_explode(this, NULL);
245 void vehicles_projectile_explode_use(entity this, entity actor, entity trigger)
247 vehicles_projectile_explode(this, trigger);
250 entity vehicles_projectile(entity this, string _mzlfx, Sound _mzlsound,
251 vector _org, vector _vel,
252 float _dmg, float _radi, float _force, float _size,
253 int _deahtype, float _projtype, float _health,
254 bool _cull, bool _clianim, entity _owner)
256 TC(Sound, _mzlsound);
261 PROJECTILE_MAKETRIGGER(proj);
262 setorigin(proj, _org);
264 proj.shot_dmg = _dmg;
265 proj.shot_radius = _radi;
266 proj.shot_force = _force;
267 proj.totalfrags = _deahtype;
268 proj.solid = SOLID_BBOX;
269 set_movetype(proj, MOVETYPE_FLYMISSILE);
270 proj.flags = FL_PROJECTILE;
271 IL_PUSH(g_projectiles, proj);
272 IL_PUSH(g_bot_dodge, proj);
273 proj.bot_dodge = true;
274 proj.bot_dodgerating = _dmg;
275 proj.velocity = _vel;
276 settouch(proj, vehicles_projectile_explode);
277 proj.use = vehicles_projectile_explode_use;
279 proj.realowner = _owner;
280 setthink(proj, SUB_Remove);
281 proj.nextthink = time + 30;
285 proj.takedamage = DAMAGE_AIM;
286 proj.event_damage = vehicles_projectile_damage;
287 proj.health = _health;
290 proj.flags |= FL_NOTARGET;
292 if(_mzlsound != SND_Null)
293 sound (this, CH_WEAPON_A, _mzlsound, VOL_BASE, ATTEN_NORM);
296 Send_Effect_(_mzlfx, proj.origin, proj.velocity, 1);
298 setsize (proj, '-1 -1 -1' * _size, '1 1 1' * _size);
300 CSQCProjectile(proj, _clianim, _projtype, _cull);
305 void vehicles_gib_explode(entity this)
307 sound (this, CH_SHOTS, SND_ROCKET_IMPACT, VOL_BASE, ATTEN_NORM);
308 Send_Effect(EFFECT_EXPLOSION_SMALL, randomvec() * 80 + (this.origin + '0 0 100'), '0 0 0', 1);
309 Send_Effect(EFFECT_EXPLOSION_SMALL, this.wp00.origin + '0 0 64', '0 0 0', 1);
313 void vehicles_gib_touch(entity this, entity toucher)
315 vehicles_gib_explode(this);
318 void vehicles_gib_think(entity this)
324 this.nextthink = time + 0.1;
327 entity vehicle_tossgib(entity this, entity _template, vector _vel, string _tag, bool _burn, bool _explode, float _maxtime, vector _rot)
329 entity _gib = spawn();
330 _setmodel(_gib, _template.model);
331 vector org = gettaginfo(this, gettagindex(this, _tag));
332 setorigin(_gib, org);
333 _gib.velocity = _vel;
334 set_movetype(_gib, MOVETYPE_TOSS);
335 _gib.solid = SOLID_CORPSE;
336 _gib.colormod = '-0.5 -0.5 -0.5';
337 _gib.effects = EF_LOWPRECISION;
338 _gib.avelocity = _rot;
341 _gib.effects |= EF_FLAME;
345 setthink(_gib, vehicles_gib_explode);
346 _gib.nextthink = time + random() * _explode;
347 settouch(_gib, vehicles_gib_touch);
351 _gib.cnt = time + _maxtime;
352 setthink(_gib, vehicles_gib_think);
353 _gib.nextthink = time + _maxtime - 1;
359 bool vehicle_addplayerslot( entity _owner,
363 bool(entity,float) _framefunc,
364 void(entity,bool) _exitfunc, float(entity, entity) _enterfunc)
366 if(!(_owner.vehicle_flags & VHF_MULTISLOT))
367 _owner.vehicle_flags |= VHF_MULTISLOT;
369 _slot.PlayerPhysplug = _framefunc;
370 _slot.vehicle_exit = _exitfunc;
371 _slot.vehicle_enter = _enterfunc;
373 _slot.vehicle_flags = VHF_PLAYERSLOT;
374 _slot.vehicle_viewport = spawn();
375 _slot.vehicle_hudmodel = spawn();
376 _slot.vehicle_hudmodel.viewmodelforclient = _slot;
377 _slot.vehicle_viewport.effects = (EF_ADDITIVE | EF_DOUBLESIDED | EF_FULLBRIGHT | EF_NODEPTHTEST | EF_NOGUNBOB | EF_NOSHADOW | EF_LOWPRECISION | EF_SELECTABLE | EF_TELEPORT_BIT);
379 setmodel(_slot.vehicle_hudmodel, _hud_model);
380 setmodel(_slot.vehicle_viewport, MDL_Null);
382 setattachment(_slot.vehicle_hudmodel, _slot, "");
383 setattachment(_slot.vehicle_viewport, _slot.vehicle_hudmodel, "");
388 vector vehicle_aimturret(entity _vehic, vector _target, entity _turrret, string _tagname,
389 float _pichlimit_min, float _pichlimit_max,
390 float _rotlimit_min, float _rotlimit_max, float _aimspeed)
394 vtag = gettaginfo(_turrret, gettagindex(_turrret, _tagname));
395 vtmp = vectoangles(normalize(_target - vtag));
396 vtmp = AnglesTransform_ToAngles(AnglesTransform_LeftDivide(AnglesTransform_FromAngles(_vehic.angles), AnglesTransform_FromAngles(vtmp))) - _turrret.angles;
397 vtmp = AnglesTransform_Normalize(vtmp, true);
398 ftmp = _aimspeed * frametime;
399 vtmp_y = bound(-ftmp, vtmp_y, ftmp);
400 vtmp_x = bound(-ftmp, vtmp_x, ftmp);
401 _turrret.angles_y = bound(_rotlimit_min, _turrret.angles_y + vtmp_y, _rotlimit_max);
402 _turrret.angles_x = bound(_pichlimit_min, _turrret.angles_x + vtmp_x, _pichlimit_max);
406 void vehicles_reset_colors(entity this)
409 const vector cmod = '0 0 0';
410 if(this.team && teamplay)
411 cmap = 1024 + (this.team - 1) * 17;
414 if(autocvar_g_nodepthtestplayers)
415 eff |= EF_NODEPTHTEST;
416 if(autocvar_g_fullbrightplayers)
417 eff |= EF_FULLBRIGHT;
419 // Find all ents attacked to main model and setup effects, colormod etc.
420 FOREACH_ENTITY_ENT(tag_entity, this,
422 if(it != this.vehicle_shieldent)
431 // Also check head tags
432 FOREACH_ENTITY_ENT(tag_entity, this.tur_head,
434 if(it != this.vehicle_shieldent)
443 this.vehicle_hudmodel.effects = this.effects = eff; // | EF_LOWPRECISION;
444 this.vehicle_hudmodel.colormod = this.colormod = cmod;
445 this.vehicle_hudmodel.colormap = this.colormap = cmap;
446 this.vehicle_viewport.effects = (EF_ADDITIVE | EF_DOUBLESIDED | EF_FULLBRIGHT | EF_NODEPTHTEST | EF_NOGUNBOB | EF_NOSHADOW | EF_LOWPRECISION | EF_SELECTABLE | EF_TELEPORT_BIT);
449 this.avelocity = '0 0 0';
450 this.velocity = '0 0 0';
453 Vehicle info = Vehicles_from(this.vehicleid);
454 info.vr_setcolors(info, this);
457 void vehicles_clearreturn(entity veh)
459 // Remove "return helper" entities, if any.
460 IL_EACH(g_vehicle_returners, it.wp00 == veh,
463 setthink(it, SUB_Remove);
464 it.nextthink = time + 0.1;
465 IL_REMOVE(g_vehicle_returners, it);
467 if(it.waypointsprite_attached)
468 WaypointSprite_Kill(it.waypointsprite_attached);
472 void vehicles_spawn(entity this);
473 void vehicles_return(entity this)
475 Send_Effect(EFFECT_TELEPORT, this.wp00.origin + '0 0 64', '0 0 0', 1);
477 setthink(this.wp00, vehicles_spawn);
478 this.wp00.nextthink = time;
480 if(this.waypointsprite_attached)
481 WaypointSprite_Kill(this.waypointsprite_attached);
486 void vehicles_showwp_goaway(entity this)
488 if(this.waypointsprite_attached)
489 WaypointSprite_Kill(this.waypointsprite_attached);
494 void vehicles_showwp(entity this)
500 setthink(ent, vehicles_return);
501 ent.nextthink = ent.cnt;
505 setthink(ent, vehicles_return);
506 ent.nextthink = time + 1;
509 ent.team = this.wp00.team;
510 ent.wp00 = this.wp00;
511 setorigin(ent, this.wp00.pos1);
513 ent.nextthink = time + 5;
514 setthink(ent, vehicles_showwp_goaway);
518 if(teamplay && ent.team)
519 rgb = Team_ColorRGB(ent.team);
522 entity wp = WaypointSprite_Spawn(WP_Vehicle, 0, 0, ent, '0 0 64', NULL, 0, ent, waypointsprite_attached, true, RADARICON_Vehicle);
524 if(ent.waypointsprite_attached)
526 WaypointSprite_UpdateRule(ent.waypointsprite_attached, ent.wp00.team, SPRITERULE_DEFAULT);
528 WaypointSprite_UpdateBuildFinished(ent.waypointsprite_attached, ent.nextthink);
529 WaypointSprite_Ping(ent.waypointsprite_attached);
533 void vehicles_setreturn(entity veh)
535 vehicles_clearreturn(veh);
537 entity ret = new(vehicle_return);
538 IL_PUSH(g_vehicle_returners, ret);
541 setthink(ret, vehicles_showwp);
545 ret.cnt = time + veh.respawntime;
546 ret.nextthink = min(time + veh.respawntime, time + veh.respawntime - 5);
550 ret.nextthink = min(time + veh.respawntime, time + veh.respawntime - 1);
553 setorigin(ret, veh.pos1 + '0 0 96');
556 void vehicle_use(entity this, entity actor, entity trigger)
558 LOG_DEBUG("vehicle ", this.netname, " used by ", actor.classname);
560 this.tur_head.team = actor.team;
562 if(this.tur_head.team == 0)
563 this.active = ACTIVE_NOT;
565 this.active = ACTIVE_ACTIVE;
567 if(this.active == ACTIVE_ACTIVE && !IS_DEAD(this) && !game_stopped)
569 LOG_DEBUG("Respawning vehicle: ", this.netname);
570 if(this.effects & EF_NODRAW)
572 setthink(this, vehicles_spawn);
573 this.nextthink = time + 3;
577 vehicles_setreturn(this);
578 vehicles_reset_colors(this);
583 void vehicles_regen(entity this, float timer, .float regen_field, float field_max, float rpause, float regen, float delta_time, float _healthscale)
585 if(this.(regen_field) < field_max)
586 if(timer + rpause < time)
589 regen = regen * (this.vehicle_health / this.max_health);
591 this.(regen_field) = min(this.(regen_field) + regen * delta_time, field_max);
594 this.owner.(regen_field) = (this.(regen_field) / field_max) * 100;
598 void shieldhit_think(entity this)
603 // setmodel(this, MDL_Null);
605 this.effects |= EF_NODRAW;
609 this.nextthink = time + 0.1;
613 void vehicles_painframe(entity this)
615 int myhealth = ((this.owner) ? this.owner.vehicle_health : ((this.vehicle_health / this.max_health) * 100));
618 if(this.pain_frame < time)
620 float _ftmp = myhealth / 50;
621 this.pain_frame = time + max(0.1, 0.1 + (random() * 0.5 * _ftmp));
622 Send_Effect(EFFECT_SMOKE_SMALL, (this.origin + (randomvec() * 80)), '0 0 0', 1);
624 if(this.vehicle_flags & VHF_DMGSHAKE)
625 this.velocity += randomvec() * 30;
627 if(this.vehicle_flags & VHF_DMGROLL)
628 if(this.vehicle_flags & VHF_DMGHEADROLL)
629 this.tur_head.angles += randomvec();
631 this.angles += randomvec();
635 void vehicles_frame(entity this, entity actor)
637 vehicles_painframe(this);
640 void vehicles_damage(entity this, entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force)
642 this.dmg_time = time;
645 if(DEATH_ISWEAPON(deathtype, WEP_VORTEX))
646 damage *= autocvar_g_vehicles_vortex_damagerate;
647 else if(DEATH_ISWEAPON(deathtype, WEP_MACHINEGUN))
648 damage *= autocvar_g_vehicles_machinegun_damagerate;
649 else if(DEATH_ISWEAPON(deathtype, WEP_RIFLE))
650 damage *= autocvar_g_vehicles_rifle_damagerate;
651 else if(DEATH_ISWEAPON(deathtype, WEP_VAPORIZER))
652 damage *= autocvar_g_vehicles_vaporizer_damagerate;
653 else if(DEATH_ISWEAPON(deathtype, WEP_SEEKER))
654 damage *= autocvar_g_vehicles_tag_damagerate;
655 else if(DEATH_WEAPONOF(deathtype) != WEP_Null)
656 damage *= autocvar_g_vehicles_weapon_damagerate;
658 this.enemy = attacker;
660 this.pain_finished = time;
662 if((this.vehicle_flags & VHF_HASSHIELD) && (this.vehicle_shield > 0))
664 if (wasfreed(this.vehicle_shieldent) || this.vehicle_shieldent == NULL)
666 this.vehicle_shieldent = spawn();
667 this.vehicle_shieldent.effects = EF_LOWPRECISION;
669 setmodel(this.vehicle_shieldent, MDL_VEH_SHIELD);
670 setattachment(this.vehicle_shieldent, this, "");
671 setorigin(this.vehicle_shieldent, real_origin(this) - this.origin);
672 this.vehicle_shieldent.scale = 256 / vlen(this.maxs - this.mins);
673 setthink(this.vehicle_shieldent, shieldhit_think);
676 this.vehicle_shieldent.colormod = '1 1 1';
677 this.vehicle_shieldent.alpha = 0.45;
678 this.vehicle_shieldent.angles = vectoangles(normalize(hitloc - (this.origin + this.vehicle_shieldent.origin))) - this.angles;
679 this.vehicle_shieldent.nextthink = time;
680 this.vehicle_shieldent.effects &= ~EF_NODRAW;
682 this.vehicle_shield -= damage;
684 if(this.vehicle_shield < 0)
686 this.vehicle_health -= fabs(this.vehicle_shield);
687 this.vehicle_shieldent.colormod = '2 0 0';
688 this.vehicle_shield = 0;
689 this.vehicle_shieldent.alpha = 0.75;
691 if(sound_allowed(MSG_BROADCAST, attacker))
692 spamsound (this, CH_PAIN, SND_ONS_HIT2, VOL_BASE, ATTEN_NORM); // FIXME: PLACEHOLDER
695 if(sound_allowed(MSG_BROADCAST, attacker))
696 spamsound (this, CH_PAIN, SND_ONS_ELECTRICITY_EXPLODE, VOL_BASE, ATTEN_NORM); // FIXME: PLACEHOLDER
701 this.vehicle_health -= damage;
703 if(sound_allowed(MSG_BROADCAST, attacker))
704 spamsound (this, CH_PAIN, SND_ONS_HIT2, VOL_BASE, ATTEN_NORM); // FIXME: PLACEHOLDER
707 if(this.damageforcescale < 1 && this.damageforcescale > 0)
708 this.velocity += force * this.damageforcescale;
710 this.velocity += force;
712 if(this.vehicle_health <= 0)
715 if(this.vehicle_flags & VHF_DEATHEJECT)
716 vehicles_exit(this, VHEF_EJECT);
718 vehicles_exit(this, VHEF_RELEASE);
721 antilag_clear(this, this);
723 Vehicle info = Vehicles_from(this.vehicleid);
724 info.vr_death(info, this);
725 vehicles_setreturn(this);
729 bool vehicles_crushable(entity e)
731 if(IS_PLAYER(e) && time >= e.vehicle_enter_delay)
740 void vehicles_impact(entity this, float _minspeed, float _speedfac, float _maxpain)
742 if (trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT)
745 if(this.play_time < time)
747 float wc = vlen(this.velocity - this.oldvelocity);
748 //dprint("oldvel: ", vtos(this.oldvelocity), "\n");
749 //dprint("vel: ", vtos(this.velocity), "\n");
752 float take = min(_speedfac * wc, _maxpain);
753 Damage (this, NULL, NULL, take, DEATH_FALL.m_id, this.origin, '0 0 0');
754 this.play_time = time + 0.25;
756 //dprint("wc: ", ftos(wc), "\n");
757 //dprint("take: ", ftos(take), "\n");
762 // vehicle enter/exit handling
763 vector vehicles_findgoodexit(entity this, entity player, vector prefer_spot)
765 // TODO: we actually want the player's size here
766 tracebox(this.origin + '0 0 32', PL_MIN_CONST, PL_MAX_CONST, prefer_spot, MOVE_NORMAL, player);
767 if(trace_fraction == 1.0 && !trace_startsolid && !trace_allsolid)
770 float mysize = 1.5 * vlen(this.maxs - this.mins);
772 vector v2 = 0.5 * (this.absmin + this.absmax);
773 for(int i = 0; i < autocvar_g_vehicles_exit_attempts; ++i)
777 v = v2 + normalize(v) * mysize;
778 tracebox(v2, PL_MIN_CONST, PL_MAX_CONST, v, MOVE_NORMAL, player);
779 if(trace_fraction == 1.0 && !trace_startsolid && !trace_allsolid)
786 void vehicles_exit(entity vehic, bool eject)
788 entity player = vehic.owner;
790 if(vehicles_exit_running)
792 LOG_TRACE("^1vehicles_exit already running! this is not good...");
796 vehicles_exit_running = true;
798 // TODO: this was in an IS_CLIENT check, make sure it isn't actually needed!
799 if(vehic.vehicle_flags & VHF_PLAYERSLOT)
801 vehic.vehicle_exit(vehic, eject);
802 vehicles_exit_running = false;
808 if (IS_REAL_CLIENT(player))
811 WriteByte (MSG_ONE, SVC_SETVIEWPORT);
812 WriteEntity( MSG_ONE, player);
814 WriteByte (MSG_ONE, SVC_SETVIEWANGLES);
815 WriteAngle(MSG_ONE, 0);
816 WriteAngle(MSG_ONE, vehic.angles_y);
817 WriteAngle(MSG_ONE, 0);
820 setsize(player, STAT(PL_MIN, player), STAT(PL_MAX, player));
822 player.takedamage = DAMAGE_AIM;
823 player.solid = SOLID_SLIDEBOX;
824 set_movetype(player, MOVETYPE_WALK);
825 player.effects &= ~EF_NODRAW;
826 player.teleportable = TELEPORT_NORMAL;
828 player.PlayerPhysplug = func_null;
829 player.vehicle = NULL;
830 player.view_ofs = STAT(PL_VIEW_OFS, player);
831 player.event_damage = PlayerDamage;
832 player.hud = HUD_NORMAL;
833 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++ slot)
835 .entity weaponentity = weaponentities[slot];
836 player.(weaponentity).m_switchweapon = vehic.(weaponentity).m_switchweapon;
837 delete(vehic.(weaponentity)); // no longer needed
839 player.last_vehiclecheck = time + 3;
840 player.vehicle_enter_delay = time + 2;
842 CSQCVehicleSetup(player, HUD_NORMAL);
844 Kill_Notification(NOTIF_ONE, player, MSG_CENTER, CPID_VEHICLES);
845 Kill_Notification(NOTIF_ONE, player, MSG_CENTER, CPID_VEHICLES_OTHER); // kill all vehicle notifications when exiting a vehicle?
848 vehic.flags |= FL_NOTARGET;
851 vehic.avelocity = '0 0 0';
853 vehic.tur_head.nodrawtoclient = NULL;
858 WaypointSprite_Kill(vehic.wps_intruder);
860 MUTATOR_CALLHOOK(VehicleExit, player, vehic);
862 vehic.team = vehic.tur_head.team;
864 sound (vehic, CH_TRIGGER_SINGLE, SND_Null, 1, ATTEN_NORM);
865 vehic.vehicle_hudmodel.viewmodelforclient = vehic;
866 vehic.phase = time + 1;
868 vehic.vehicle_exit(vehic, eject);
870 vehicles_setreturn(vehic);
871 vehicles_reset_colors(vehic);
874 CSQCMODEL_AUTOINIT(vehic);
877 player.oldorigin = player.origin; // player's location is set by the exit functions, so we need to do this after everything
879 vehicles_exit_running = false;
882 void vehicles_touch(entity this, entity toucher)
884 if(MUTATOR_CALLHOOK(VehicleTouch, this, toucher))
887 // Vehicle currently in use
890 if(!forbidWeaponUse(this.owner))
892 if((this.origin_z + this.maxs_z) > (toucher.origin_z))
893 if(vehicles_crushable(toucher))
895 if(vdist(this.velocity, >=, 30))
896 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);
898 return; // Dont do selfdamage when hitting "soft targets".
901 if(this.play_time < time) {
902 Vehicle info = Vehicles_from(this.vehicleid);
903 info.vr_impact(info, this);
909 if(autocvar_g_vehicles_enter)
912 vehicles_enter(toucher, this);
915 bool vehicle_impulse(entity this, int imp)
917 entity v = this.vehicle;
918 if (!v) return false;
919 if (IS_DEAD(v)) return false;
920 bool(entity,int) f = v.vehicles_impulse;
921 if (f && f(this,imp)) return true;
924 case IMP_weapon_drop.impulse:
926 stuffcmd(this, "\ntoggle cl_eventchase_vehicle\nset _vehicles_shownchasemessage 1\n");
933 void vehicles_enter(entity pl, entity veh)
935 // Remove this when bots know how to use vehicles
936 if((IS_BOT_CLIENT(pl) && !autocvar_g_vehicles_allow_bots))
940 || (veh.phase >= time)
941 || (pl.vehicle_enter_delay >= time)
942 || (STAT(FROZEN, pl))
947 Vehicle info = Vehicles_from(veh.vehicleid);
949 if(autocvar_g_vehicles_enter) // vehicle's touch function should handle this if entering via use key is disabled (TODO)
950 if(veh.vehicle_flags & VHF_MULTISLOT)
951 if(veh.owner && SAME_TEAM(pl, veh))
953 // we don't need a return value or anything here
954 // if successful the owner check below will prevent anything weird
955 info.vr_gunner_enter(info, veh, pl);
959 return; // got here and didn't enter the gunner, return
963 if(DIFF_TEAM(pl, veh))
964 if(autocvar_g_vehicles_steal)
966 FOREACH_CLIENT(IS_PLAYER(it) && SAME_TEAM(it, veh), Send_Notification(NOTIF_ONE, it, MSG_CENTER, CENTER_VEHICLE_STEAL));
968 Send_Notification(NOTIF_ONE, pl, MSG_CENTER, CENTER_VEHICLE_STEAL_SELF);
970 if (autocvar_g_vehicles_steal_show_waypoint) {
971 entity wp = WaypointSprite_Spawn(WP_VehicleIntruder, 0, 0, pl, '0 0 68', NULL, veh.team, veh, wps_intruder, true, RADARICON_DANGER);
972 wp.colormod = Team_ColorRGB(pl.team);
977 RemoveGrapplingHooks(pl);
979 veh.vehicle_ammo1 = 0;
980 veh.vehicle_ammo2 = 0;
981 veh.vehicle_reload1 = 0;
982 veh.vehicle_reload2 = 0;
983 veh.vehicle_energy = 0;
988 // .viewmodelforclient works better.
989 //veh.vehicle_hudmodel.drawonlytoclient = veh.owner;
991 veh.vehicle_hudmodel.viewmodelforclient = pl;
994 pl.view_ofs = STAT(PL_VIEW_OFS, pl);
995 setsize(pl, STAT(PL_MIN, pl), STAT(PL_MAX, pl));
997 veh.event_damage = vehicles_damage;
999 pl.items &= ~IT_USING_JETPACK;
1000 pl.angles = veh.angles;
1001 pl.takedamage = DAMAGE_NO;
1002 pl.solid = SOLID_NOT;
1003 pl.disableclientprediction = 1; // physics is no longer run, so this won't be reset
1004 set_movetype(pl, MOVETYPE_NOCLIP);
1005 pl.teleportable = false;
1007 pl.event_damage = func_null;
1008 pl.view_ofs = '0 0 0';
1009 veh.colormap = pl.colormap;
1011 veh.tur_head.colormap = pl.colormap;
1012 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
1014 .entity weaponentity = weaponentities[slot];
1015 veh.(weaponentity) = new(temp_wepent);
1016 veh.(weaponentity).m_switchweapon = pl.(weaponentity).m_switchweapon;
1018 pl.hud = veh.vehicleid;
1019 pl.PlayerPhysplug = veh.PlayerPhysplug;
1021 pl.vehicle_ammo1 = veh.vehicle_ammo1;
1022 pl.vehicle_ammo2 = veh.vehicle_ammo2;
1023 pl.vehicle_reload1 = veh.vehicle_reload1;
1024 pl.vehicle_reload2 = veh.vehicle_reload2;
1025 pl.vehicle_energy = veh.vehicle_energy;
1027 // Cant do this, hides attached objects too.
1028 //veh.exteriormodeltoclient = veh.owner;
1029 //veh.tur_head.exteriormodeltoclient = veh.owner;
1032 UNSET_ONGROUND(veh);
1035 veh.flags -= FL_NOTARGET;
1037 if (IS_REAL_CLIENT(pl))
1039 Send_Notification(NOTIF_ONE, pl, MSG_CENTER, CENTER_VEHICLE_ENTER);
1042 WriteByte (MSG_ONE, SVC_SETVIEWPORT);
1043 WriteEntity(MSG_ONE, veh.vehicle_viewport);
1045 WriteByte (MSG_ONE, SVC_SETVIEWANGLES);
1048 WriteAngle(MSG_ONE, veh.tur_head.angles_x + veh.angles_x); // tilt
1049 WriteAngle(MSG_ONE, veh.tur_head.angles_y + veh.angles_y); // yaw
1050 WriteAngle(MSG_ONE, 0); // roll
1054 WriteAngle(MSG_ONE, veh.angles_x * -1); // tilt
1055 WriteAngle(MSG_ONE, veh.angles_y); // yaw
1056 WriteAngle(MSG_ONE, 0); // roll
1060 vehicles_clearreturn(veh);
1062 CSQCVehicleSetup(pl, veh.vehicleid);
1064 MUTATOR_CALLHOOK(VehicleEnter, pl, veh);
1066 CSQCModel_UnlinkEntity(veh);
1067 info.vr_enter(info, veh);
1069 antilag_clear(pl, CS(pl));
1072 void vehicles_think(entity this)
1074 this.nextthink = time + autocvar_g_vehicles_thinkrate;
1077 this.owner.vehicle_weapon2mode = this.vehicle_weapon2mode;
1079 Vehicle info = Vehicles_from(this.vehicleid);
1080 info.vr_think(info, this);
1082 vehicles_painframe(this);
1084 CSQCMODEL_AUTOUPDATE(this);
1087 void vehicles_reset(entity this)
1090 vehicles_exit(this, VHEF_RELEASE);
1092 vehicles_clearreturn(this);
1094 if(this.active != ACTIVE_NOT)
1095 vehicles_spawn(this);
1099 void vehicles_spawn(entity this)
1101 LOG_DEBUG("Spawning vehicle: ", this.classname);
1104 this.vehicle_hudmodel.viewmodelforclient = this;
1107 settouch(this, vehicles_touch);
1108 this.event_damage = vehicles_damage;
1109 this.reset = vehicles_reset;
1110 this.iscreature = true;
1111 this.teleportable = false; // no teleporting for vehicles, too buggy
1112 this.damagedbycontents = true;
1113 set_movetype(this, MOVETYPE_WALK);
1114 this.solid = SOLID_SLIDEBOX;
1115 this.takedamage = DAMAGE_AIM;
1116 this.deadflag = DEAD_NO;
1117 if(!this.bot_attack)
1118 IL_PUSH(g_bot_targets, this);
1119 this.bot_attack = true;
1120 this.flags = FL_NOTARGET;
1121 this.avelocity = '0 0 0';
1122 this.velocity = '0 0 0';
1123 setthink(this, vehicles_think);
1124 this.nextthink = time;
1127 this.lock_strength = 0;
1128 this.lock_target = NULL;
1129 this.misc_bulletcounter = 0;
1132 this.angles = this.pos2;
1133 setorigin(this, this.pos1);
1135 Send_Effect(EFFECT_TELEPORT, this.origin + '0 0 64', '0 0 0', 1);
1137 if(this.vehicle_controller)
1138 this.team = this.vehicle_controller.team;
1140 FOREACH_CLIENT(IS_PLAYER(it),
1142 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
1144 .entity weaponentity = weaponentities[slot];
1145 if(it.(weaponentity).hook.aiment == this)
1146 RemoveHook(it.(weaponentity).hook);
1150 vehicles_reset_colors(this);
1152 Vehicle info = Vehicles_from(this.vehicleid);
1153 info.vr_spawn(info, this);
1155 CSQCMODEL_AUTOINIT(this);
1158 bool vehicle_initialize(entity this, Vehicle info, bool nodrop)
1160 if(!autocvar_g_vehicles)
1168 info.vr_precache(info);
1169 IL_PUSH(g_vehicles, this);
1172 if(this.targetname && this.targetname != "")
1174 this.vehicle_controller = find(NULL, target, this.targetname);
1175 if(!this.vehicle_controller)
1177 LOG_DEBUG("^1WARNING: ^7Vehicle with invalid .targetname");
1178 this.active = ACTIVE_ACTIVE;
1182 this.team = this.vehicle_controller.team;
1183 this.use = vehicle_use;
1187 if(this.vehicle_controller.team == 0)
1188 this.active = ACTIVE_NOT;
1190 this.active = ACTIVE_ACTIVE;
1194 else { this.active = ACTIVE_ACTIVE; }
1196 if(this.team && (!teamplay || !autocvar_g_vehicles_teams))
1199 if(this.mdl == "" || !this.mdl)
1200 _setmodel(this, info.model);
1202 _setmodel(this, this.mdl);
1204 this.vehicle_flags |= VHF_ISVEHICLE;
1206 this.vehicle_viewport = new(vehicle_viewport);
1207 this.vehicle_hudmodel = new(vehicle_hudmodel);
1208 this.tur_head = new(tur_head);
1209 this.tur_head.owner = this;
1210 this.takedamage = DAMAGE_NO;
1211 this.bot_attack = true;
1212 IL_PUSH(g_bot_targets, this);
1213 this.iscreature = true;
1214 this.teleportable = false; // no teleporting for vehicles, too buggy
1215 this.damagedbycontents = true;
1216 IL_PUSH(g_damagedbycontents, this);
1217 this.vehicleid = info.vehicleid;
1218 this.PlayerPhysplug = info.PlayerPhysplug;
1219 this.event_damage = func_null;
1220 settouch(this, vehicles_touch);
1221 setthink(this, vehicles_spawn);
1222 this.nextthink = time;
1223 this.effects = EF_NODRAW;
1224 this.dphitcontentsmask = DPCONTENTS_BODY | DPCONTENTS_SOLID;
1226 if(autocvar_g_playerclip_collisions)
1227 this.dphitcontentsmask |= DPCONTENTS_PLAYERCLIP;
1229 if(autocvar_g_nodepthtestplayers)
1230 this.effects |= EF_NODEPTHTEST;
1232 if(autocvar_g_fullbrightplayers)
1233 this.effects |= EF_FULLBRIGHT;
1235 _setmodel(this.vehicle_hudmodel, info.hud_model);
1236 setmodel(this.vehicle_viewport, MDL_Null);
1238 if(info.head_model != "")
1240 _setmodel(this.tur_head, info.head_model);
1241 setattachment(this.tur_head, this, info.tag_head);
1242 setattachment(this.vehicle_hudmodel, this.tur_head, info.tag_hud);
1243 setattachment(this.vehicle_viewport, this.vehicle_hudmodel, info.tag_view);
1247 setattachment(this.tur_head, this, "");
1248 setattachment(this.vehicle_hudmodel, this, info.tag_hud);
1249 setattachment(this.vehicle_viewport, this.vehicle_hudmodel, info.tag_view);
1252 setsize(this, info.m_mins, info.m_maxs);
1254 info.vr_setup(info, this);
1258 setorigin(this, this.origin);
1259 tracebox(this.origin + '0 0 100', info.m_mins, info.m_maxs, this.origin - '0 0 10000', MOVE_WORLDONLY, this);
1260 setorigin(this, trace_endpos);
1263 this.pos1 = this.origin;
1264 this.pos2 = this.angles;
1265 this.tur_head.team = this.team;
1267 if(this.active == ACTIVE_NOT)
1268 this.nextthink = 0; // wait until activated
1269 else if(autocvar_g_vehicles_delayspawn)
1270 this.nextthink = time + this.respawntime + (random() * autocvar_g_vehicles_delayspawn_jitter);
1272 this.nextthink = time + game_starttime;
1274 if(MUTATOR_CALLHOOK(VehicleInit, this))