1 float autocvar_g_vehicles_crush_dmg;
2 float autocvar_g_vehicles_crush_force;
3 float autocvar_g_vehicles_delayspawn;
4 float autocvar_g_vehicles_delayspawn_jitter;
5 float autocvar_g_vehicles_allow_flagcarry;
7 float autocvar_g_vehicles_nex_damagerate = 0.5;
8 float autocvar_g_vehicles_uzi_damagerate = 0.5;
9 float autocvar_g_vehicles_rifle_damagerate = 0.75;
10 float autocvar_g_vehicles_minstanex_damagerate = 0.001;
13 void vehicles_damage(entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force);
14 void vehicles_return();
15 void vehicles_enter();
16 void vehicles_touch();
17 void vehicles_reset_colors();
18 void vehicles_clearrturn();
19 void vehicles_setreturn();
23 Send additional points of interest to be drawn, to vehicle owner
26 .entity AuxiliaryXhair[MAX_AXH];
28 float SendAuxiliaryXhair(entity to, float sf)
31 WriteByte(MSG_ENTITY, ENT_CLIENT_AUXILIARYXHAIR);
33 WriteByte(MSG_ENTITY, self.cnt);
35 WriteCoord(MSG_ENTITY, self.origin_x);
36 WriteCoord(MSG_ENTITY, self.origin_y);
37 WriteCoord(MSG_ENTITY, self.origin_z);
39 WriteByte(MSG_ENTITY, rint(self.colormod_x * 255));
40 WriteByte(MSG_ENTITY, rint(self.colormod_y * 255));
41 WriteByte(MSG_ENTITY, rint(self.colormod_z * 255));
46 void UpdateAuxiliaryXhair(entity own, vector loc, vector clr, float axh_id)
50 axh_id = bound(0, axh_id, MAX_AXH);
51 axh = own.(AuxiliaryXhair[axh_id]);
53 if(axh == world || wasfreed(axh)) // MADNESS? THIS IS QQQQCCCCCCCCC (wasfreed, why do you exsist?)
57 axh.drawonlytoclient = own;
59 Net_LinkEntity(axh, FALSE, 0, SendAuxiliaryXhair);
65 own.(AuxiliaryXhair[axh_id]) = axh;
69 // SVC_TEMPENTITY based, horrible with even 50 ping. hm.
70 // WriteByte(MSG_ONE, SVC_TEMPENTITY) uses reliable messagess, never use for thinsg that need continous updates.
71 void SendAuxiliaryXhair2(entity own, vector loc, vector clr, float axh_id)
75 WriteByte(MSG_ONE, SVC_TEMPENTITY);
76 WriteByte(MSG_ONE, TE_CSQC_AUXILIARYXHAIR);
78 WriteByte(MSG_ONE, axh_id);
80 WriteCoord(MSG_ONE, loc_x);
81 WriteCoord(MSG_ONE, loc_y);
82 WriteCoord(MSG_ONE, loc_z);
84 WriteByte(MSG_ONE, rint(clr_x * 255));
85 WriteByte(MSG_ONE, rint(clr_y * 255));
86 WriteByte(MSG_ONE, rint(clr_z * 255));
93 Notifies the client that he enterd a vehicle, and sends
96 only sends vehicle_id atm (wich is a HUD_* constant, ex. HUD_SPIDERBOT)
98 void CSQCVehicleSetup(entity own, float vehicle_id)
102 WriteByte(MSG_ONE, SVC_TEMPENTITY);
103 WriteByte(MSG_ONE, TE_CSQC_VEHICLESETUP);
105 WriteByte(MSG_ONE, vehicle_id);
107 WriteByte(MSG_ONE, 1 + own.vehicle.vehicle_weapon2mode + HUD_VEHICLE_LAST);
110 /** vehicles_locktarget
112 Generic target locking.
114 Figure out if what target is "locked" (if any), for missile tracking as such.
116 after calling, "if(self.lock_target != world && self.lock_strength == 1)" mean
117 you have a locked in target.
119 Exspects a crosshair_trace() or equivalent to be
124 .float lock_strength;
126 .float lock_soundtime;
127 float DAMAGE_TARGETDRONE = 10;
129 vector targetdrone_getnewspot()
134 for(i = 0; i < 100; ++i)
136 spot = self.origin + randomvec() * 1024;
137 tracebox(spot, self.mins, self.maxs, spot, MOVE_NORMAL, self);
138 if(trace_fraction == 1.0 && trace_startsolid == 0 && trace_allsolid == 0)
145 void targetdrone_think();
146 void targetdrone_damage(entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force);
147 void targetdrone_renwe()
149 self.think = targetdrone_think;
150 self.nextthink = time + 0.1;
151 setorigin(self, targetdrone_getnewspot());
153 self.takedamage = DAMAGE_TARGETDRONE;
154 self.event_damage = targetdrone_damage;
155 self.solid = SOLID_BBOX;
156 setmodel(self, "models/runematch/rune.mdl");
157 self.effects = EF_LOWPRECISION;
159 self.movetype = MOVETYPE_BOUNCEMISSILE;
160 setsize(self, '-100 -100 -100', '100 100 100');
163 void targetdrone_damage(entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
165 self.health -= damage;
168 pointparticles(particleeffectnum("explosion_medium"), self.origin, '0 0 0', 1);
174 self.think = targetdrone_renwe;
175 self.nextthink = time + 1 + random() * 2;
176 self.solid = SOLID_NOT;
181 entity targetdrone_getfear()
186 for(i = 64; i <= 1024; i += 64)
188 fear = findradius(self.origin, i);
200 void targetdrone_think()
202 self.nextthink = time + 0.1;
205 if(self.wp00.deadflag != DEAD_NO)
206 self.wp00 = targetdrone_getfear();
209 self.wp00 = targetdrone_getfear();
214 newdir = steerlib_push(self.wp00.origin) + randomvec() * 0.75;
216 newdir = randomvec() * 0.75;
218 newdir = newdir * 0.5 + normalize(self.velocity) * 0.5;
221 self.velocity = normalize(newdir) * (500 + (1024 / min(vlen(self.wp00.origin - self.origin), 1024)) * 700);
223 self.velocity = normalize(newdir) * 750;
225 tracebox(self.origin, self.mins, self.maxs, self.origin + self.velocity * 2, MOVE_NORMAL, self);
226 if(trace_fraction != 1.0)
227 self.velocity = self.velocity * -1;
229 //normalize((normalize(self.velocity) * 0.5 + newdir * 0.5)) * 750;
232 void targetdrone_spawn(vector _where, float _autorenew)
234 entity drone = spawn();
235 setorigin(drone, _where);
236 drone.think = targetdrone_renwe;
237 drone.nextthink = time + 0.1;
238 drone.cnt = _autorenew;
242 void vehicles_locktarget(float incr, float decr, float _lock_time)
244 if(self.lock_target && self.lock_target.deadflag != DEAD_NO)
246 self.lock_target = world;
247 self.lock_strength = 0;
251 if(self.lock_time > time)
254 if(self.lock_soundtime < time)
256 self.lock_soundtime = time + 0.5;
257 play2(self.owner, "vehicles/locked.wav");
263 if(trace_ent != world)
265 if(teamplay && trace_ent.team == self.team)
268 if(trace_ent.deadflag != DEAD_NO)
271 if not (trace_ent.vehicle_flags & VHF_ISVEHICLE ||
272 trace_ent.turrcaps_flags & TFL_TURRCAPS_ISTURRET ||
273 trace_ent.takedamage == DAMAGE_TARGETDRONE)
277 if(self.lock_target == world && trace_ent != world)
278 self.lock_target = trace_ent;
280 if(self.lock_target && trace_ent == self.lock_target)
282 if(self.lock_strength != 1 && self.lock_strength + incr >= 1)
284 play2(self.owner, "vehicles/lock.wav");
285 self.lock_soundtime = time + 0.8;
287 else if (self.lock_strength != 1 && self.lock_soundtime < time)
289 play2(self.owner, "vehicles/locking.wav");
290 self.lock_soundtime = time + 0.3;
295 // Have a locking target
296 // Trace hit current target
297 if(trace_ent == self.lock_target && trace_ent != world)
299 self.lock_strength = min(self.lock_strength + incr, 1);
300 if(self.lock_strength == 1)
301 self.lock_time = time + _lock_time;
306 self.lock_strength = max(self.lock_strength - decr * 2, 0);
308 self.lock_strength = max(self.lock_strength - decr, 0);
310 if(self.lock_strength == 0)
311 self.lock_target = world;
315 #define VEHICLE_UPDATE_PLAYER(fld,vhname) \
316 self.owner.vehicle_##fld = (self.vehicle_##fld / autocvar_g_vehicle_##vhname##_##fld) * 100
318 #define vehicles_sweap_collision(orig,vel,dt,acm,mult) \
319 traceline(orig, orig + vel * dt, MOVE_NORMAL, self); \
320 if(trace_fraction != 1) \
321 acm += normalize(self.origin - trace_endpos) * (vlen(vel) * mult)
323 // Hover movement support
324 float force_fromtag_power;
325 float force_fromtag_normpower;
326 vector force_fromtag_origin;
327 vector vehicles_force_fromtag_hover(string tag_name, float spring_length, float max_power)
329 force_fromtag_origin = gettaginfo(self, gettagindex(self, tag_name));
330 v_forward = normalize(v_forward) * -1;
331 traceline(force_fromtag_origin, force_fromtag_origin - (v_forward * spring_length), MOVE_NORMAL, self);
333 force_fromtag_power = (1 - trace_fraction) * max_power;
334 force_fromtag_normpower = force_fromtag_power / max_power;
336 return v_forward * force_fromtag_power;
339 // Experimental hovermode wich uses attraction/repulstion from surface insted of gravity/repulsion
340 // Can possibly be use to move abt any surface (inclusing walls/celings)
341 vector vehicles_force_fromtag_maglev(string tag_name, float spring_length, float max_power)
344 force_fromtag_origin = gettaginfo(self, gettagindex(self, tag_name));
345 v_forward = normalize(v_forward) * -1;
346 traceline(force_fromtag_origin, force_fromtag_origin - (v_forward * spring_length), MOVE_NORMAL, self);
348 // TODO - this may NOT be compatible with wall/celing movement, unhardcode 0.25 (engine count multiplier)
349 if(trace_fraction == 1.0)
351 force_fromtag_normpower = -0.25;
355 force_fromtag_power = ((1 - trace_fraction) - trace_fraction) * max_power;
356 force_fromtag_normpower = force_fromtag_power / max_power;
358 return v_forward * force_fromtag_power;
361 // Generic vehile projectile system
362 void vehicles_projectile_damage(entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
364 // Ignore damage from oterh projectiles from my owner (dont mess up volly's)
365 if(inflictor.owner == self.owner)
368 self.health -= damage;
369 self.velocity += force;
372 self.takedamage = DAMAGE_NO;
373 self.event_damage = SUB_Null;
374 self.think = self.use;
375 self.nextthink = time;
379 void vehicles_projectile_explode()
381 if(self.owner && other != world)
383 if(other == self.owner.vehicle)
386 if(other == self.owner.vehicle.tur_head)
392 self.event_damage = SUB_Null;
393 RadiusDamage (self, self.realowner, self.shot_dmg, 0, self.shot_radius, self, world, self.shot_force, self.totalfrags, other);
398 entity vehicles_projectile(string _mzlfx, string _mzlsound,
399 vector _org, vector _vel,
400 float _dmg, float _radi, float _force, float _size,
401 float _deahtype, float _projtype, float _health,
402 float _cull, float _clianim)
408 PROJECTILE_MAKETRIGGER(proj);
409 setorigin(proj, _org);
411 proj.shot_dmg = _dmg;
412 proj.shot_radius = _radi;
413 proj.shot_force = _force;
414 proj.totalfrags = _deahtype;
415 proj.solid = SOLID_BBOX;
416 proj.movetype = MOVETYPE_FLYMISSILE;
417 proj.flags = FL_PROJECTILE;
418 proj.bot_dodge = TRUE;
419 proj.bot_dodgerating = _dmg;
420 proj.velocity = _vel;
421 proj.touch = vehicles_projectile_explode;
422 proj.use = vehicles_projectile_explode;
424 proj.realowner = self.owner;
425 proj.think = SUB_Remove;
426 proj.nextthink = time + 30;
430 proj.takedamage = DAMAGE_AIM;
431 proj.event_damage = vehicles_projectile_damage;
432 proj.health = _health;
435 proj.flags = FL_PROJECTILE | FL_NOTARGET;
438 sound (self, CH_WEAPON_A, _mzlsound, VOL_BASE, ATTN_NORM);
441 pointparticles(particleeffectnum(_mzlfx), proj.origin, proj.velocity, 1);
444 setsize (proj, '-1 -1 -1' * _size, '1 1 1' * _size);
446 CSQCProjectile(proj, _clianim, _projtype, _cull);
450 // End generic vehile projectile system
453 Exetuted for all vehicles on (re)spawn.
454 Sets defaults for newly spawned units.
456 void vehicles_spawn()
458 dprint("Spawning vehicle: ", self.netname, "\n");
461 self.vehicle_hudmodel.viewmodelforclient = self;
464 self.touch = vehicles_touch;
465 self.event_damage = vehicles_damage;
466 self.iscreature = TRUE;
467 self.damagedbycontents = TRUE;
468 self.movetype = MOVETYPE_WALK;
469 self.solid = SOLID_SLIDEBOX;
470 self.takedamage = DAMAGE_AIM;
471 self.deadflag = DEAD_NO;
472 self.bot_attack = TRUE;
473 self.flags = FL_NOTARGET;
474 self.avelocity = '0 0 0';
475 self.velocity = '0 0 0';
478 self.lock_strength = 0;
479 self.lock_target = world;
480 self.misc_bulletcounter = 0;
483 self.angles = self.pos2;
484 setorigin(self, self.pos1 + '0 0 0');
486 pointparticles(particleeffectnum("teleport"), self.origin + '0 0 64', '0 0 0', 1);
488 vehicles_reset_colors();
489 self.vehicle_spawn();
492 // Better way of determening whats crushable needed! (fl_crushable?)
493 float vehicles_crushable(entity e)
495 if(e.classname == "player")
498 if(e.classname == "monster_zombie")
504 void vehilces_impact(float _minspeed, float _speedfac, float _maxpain)
506 if (trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT)
509 if(self.play_time < time)
511 float wc = vlen(self.velocity - self.oldvelocity);
512 //dprint("oldvel: ", vtos(self.oldvelocity), "\n");
513 //dprint("vel: ", vtos(self.velocity), "\n");
516 float take = min(_speedfac * wc, _maxpain);
517 Damage (self, world, world, take, DEATH_FALL, self.origin, '0 0 0');
518 self.play_time = time + 0.25;
520 //dprint("wc: ", ftos(wc), "\n");
521 //dprint("take: ", ftos(take), "\n");
526 .void() vehicle_impact;
527 void vehicles_touch()
529 // Vehicle currently in use
533 if(vehicles_crushable(other))
535 if(vlen(self.velocity) != 0)
536 Damage(other, self, self.owner, autocvar_g_vehicles_crush_dmg, DEATH_VHCRUSH, '0 0 0', normalize(other.origin - self.origin) * autocvar_g_vehicles_crush_force);
538 return; // Dont do selfdamage when hitting "soft targets".
541 if(self.play_time < time)
542 if(self.vehicle_impact)
543 self.vehicle_impact();
548 if(other.classname != "player")
551 if(other.deadflag != DEAD_NO)
554 if(other.vehicle != world)
557 // Remove this when bots know how to use vehicles.
558 if (clienttype(other) != CLIENTTYPE_REAL)
564 void vehicles_enter()
566 // Remove this when bots know how to use vehicles
567 if (clienttype(other) != CLIENTTYPE_REAL)
570 if(self.phase > time)
575 if(self.team != other.team)
578 RemoveGrapplingHook(other);
580 self.vehicle_ammo1 = 0;
581 self.vehicle_ammo2 = 0;
582 self.vehicle_reload1 = 0;
583 self.vehicle_reload2 = 0;
584 self.vehicle_energy = 0;
587 self.switchweapon = other.switchweapon;
589 // .viewmodelforclient works better.
590 //self.vehicle_hudmodel.drawonlytoclient = self.owner;
592 self.vehicle_hudmodel.viewmodelforclient = self.owner;
594 self.event_damage = vehicles_damage;
596 self.owner.angles = self.angles;
597 self.owner.takedamage = DAMAGE_NO;
598 self.owner.solid = SOLID_NOT;
599 self.owner.movetype = MOVETYPE_NOCLIP;
600 self.owner.alpha = -1;
601 self.owner.vehicle = self;
602 self.owner.event_damage = SUB_Null;
603 self.owner.view_ofs = '0 0 0';
604 self.colormap = self.owner.colormap;
606 self.tur_head.colormap = self.owner.colormap;
608 self.owner.hud = self.hud;
609 self.owner.PlayerPhysplug = self.PlayerPhysplug;
611 self.owner.vehicle_ammo1 = self.vehicle_ammo1;
612 self.owner.vehicle_ammo2 = self.vehicle_ammo2;
613 self.owner.vehicle_reload1 = self.vehicle_reload1;
614 self.owner.vehicle_reload2 = self.vehicle_reload2;
616 // Cant do this, hides attached objects too.
617 //self.exteriormodeltoclient = self.owner;
618 //self.tur_head.exteriormodeltoclient = self.owner;
620 other.flags &~= FL_ONGROUND;
621 self.flags &~= FL_ONGROUND;
623 self.team = self.owner.team;
624 self.flags -= FL_NOTARGET;
627 WriteByte (MSG_ONE, SVC_SETVIEWPORT);
628 WriteEntity(MSG_ONE, self.vehicle_viewport);
630 WriteByte (MSG_ONE, SVC_SETVIEWANGLES);
633 WriteAngle(MSG_ONE, self.tur_head.angles_x + self.angles_x); // tilt
634 WriteAngle(MSG_ONE, self.tur_head.angles_y + self.angles_y); // yaw
635 WriteAngle(MSG_ONE, 0); // roll
639 WriteAngle(MSG_ONE, self.angles_x * -1); // tilt
640 WriteAngle(MSG_ONE, self.angles_y); // yaw
641 WriteAngle(MSG_ONE, 0); // roll
644 vehicles_clearrturn();
646 CSQCVehicleSetup(self.owner, self.hud);
648 if(other.flagcarried)
650 if(!autocvar_g_vehicles_allow_flagcarry)
651 DropFlag(other.flagcarried, world, world);
654 other.flagcarried.scale = 1;
655 setattachment(other.flagcarried, self, "");
656 setorigin(other, '0 0 96');
660 self.vehicle_enter();
661 antilag_clear(other);
664 /** vehicles_findgoodexit
665 Locates a valid location for the player to exit the vehicle.
666 Will first try prefer_spot, then up 100 random spots arround the vehicle
667 wich are in direct line of sight and empty enougth to hold a players bbox
669 vector vehicles_findgoodexit(vector prefer_spot)
674 tracebox(self.origin + '0 0 32', PL_MIN, PL_MAX, prefer_spot, MOVE_NORMAL, self.owner);
675 if(trace_fraction == 1.0 && !trace_startsolid && !trace_allsolid)
678 mysize = vlen(self.maxs - self.mins);
681 v2 = 0.5 * (self.absmin + self.absmax);
682 for(i = 0; i < 100; ++i)
686 v = v2 + normalize(v) * mysize;
687 tracebox(v2, PL_MIN, PL_MAX, v, MOVE_NORMAL, self.owner);
688 if(trace_fraction == 1.0 && !trace_startsolid && !trace_allsolid)
693 exitspot = (self.origin + '0 0 48') + v_forward * mysize;
694 tracebox(self.origin + '0 0 32', PL_MIN, PL_MAX, exitspot, MOVE_NORMAL, self.owner);
695 if(trace_fraction == 1.0 && !trace_startsolid && !trace_allsolid)
698 exitspot = (self.origin + '0 0 48') - v_forward * mysize;
699 tracebox(self.origin + '0 0 32', PL_MIN, PL_MAX, exitspot, MOVE_NORMAL, self.owner);
700 if(trace_fraction == 1.0 && !trace_startsolid && !trace_allsolid)
703 exitspot = (self.origin + '0 0 48') + v_right * mysize;
704 tracebox(self.origin + '0 0 32', PL_MIN, PL_MAX, exitspot, MOVE_NORMAL, self.owner);
705 if(trace_fraction == 1.0 && !trace_startsolid && !trace_allsolid)
708 exitspot = (self.origin + '0 0 48') - v_right * mysize;
709 tracebox(self.origin + '0 0 32', PL_MIN, PL_MAX, exitspot, MOVE_NORMAL, self.owner);
710 if(trace_fraction == 1.0 && !trace_startsolid && !trace_allsolid)
718 Standarrd vehicle release fucntion.
719 custom code goes in self.vehicle_exit
721 void vehicles_exit(float eject)
724 if(self.flags & FL_CLIENT)
730 self.flags |= FL_NOTARGET;
734 msg_entity = self.owner;
735 WriteByte (MSG_ONE, SVC_SETVIEWPORT);
736 WriteEntity( MSG_ONE, self.owner);
738 WriteByte (MSG_ONE, SVC_SETVIEWANGLES);
739 WriteAngle(MSG_ONE, 0); // pich
740 WriteAngle(MSG_ONE, self.angles_y); // yaw
741 WriteAngle(MSG_ONE, 0); // roll
743 setsize(self.owner, PL_MIN,PL_MAX);
745 self.owner.takedamage = DAMAGE_AIM;
746 self.owner.solid = SOLID_SLIDEBOX;
747 self.owner.movetype = MOVETYPE_WALK;
748 self.owner.effects &~= EF_NODRAW;
749 self.owner.alpha = 1;
750 self.owner.PlayerPhysplug = SUB_Null;
751 self.owner.vehicle = world;
752 self.owner.view_ofs = PL_VIEW_OFS;
753 self.owner.event_damage = PlayerDamage;
754 self.owner.hud = HUD_NORMAL;
755 self.owner.switchweapon = self.switchweapon;
756 //self.owner.BUTTON_USE = 0;
758 CSQCVehicleSetup(self.owner, HUD_NORMAL);
761 if(self.deadflag == DEAD_NO)
762 self.avelocity = '0 0 0';
764 self.vehicle_hudmodel.viewmodelforclient = self;
765 self.tur_head.nodrawtoclient = world;
766 vehicles_setreturn();
768 self.phase = time + 1;
773 self.team = self.tur_head.team;
775 if(self.owner.flagcarried)
777 self.owner.flagcarried.scale = 0.6;
778 setattachment(self.owner.flagcarried, self.owner, "");
779 setorigin(self.owner.flagcarried, FLAG_CARRY_POS);
782 sound (self, CH_TRIGGER_SINGLE, "misc/null.wav", 1, ATTN_NORM);
783 self.vehicle_exit(eject);
785 vehicles_reset_colors();
792 void vehicles_regen(.float timer, .float regen_field, float field_max, float rpause, float regen, float delta_time, float _healthscale)
794 if(self.regen_field < field_max)
795 if(self.timer + rpause < time)
798 regen = regen * (self.vehicle_health / self.tur_health);
800 self.regen_field = min(self.regen_field + regen * delta_time, field_max);
803 self.owner.regen_field = (self.regen_field / field_max) * 100;
807 void shieldhit_think()
812 //setmodel(self, "");
817 self.nextthink = time + 0.1;
821 void vehicles_painframe()
823 if(self.owner.vehicle_health <= 50)
824 if(self.pain_frame < time)
827 _ftmp = self.owner.vehicle_health / 50;
828 self.pain_frame = time + 0.1 + (random() * 0.5 * _ftmp);
829 pointparticles(particleeffectnum("smoke_small"), (self.origin + (randomvec() * 80)), '0 0 0', 1);
831 if(self.vehicle_flags & VHF_DMGSHAKE)
832 self.velocity += randomvec() * 30;
834 if(self.vehicle_flags & VHF_DMGROLL)
835 if(self.vehicle_flags & VHF_DMGHEADROLL)
836 self.tur_head.angles += randomvec();
838 self.angles += randomvec();
843 void vehicles_damage(entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
845 self.dmg_time = time;
847 if(DEATH_ISWEAPON(deathtype, WEP_NEX))
848 damage *= autocvar_g_vehicles_nex_damagerate;
850 if(DEATH_ISWEAPON(deathtype, WEP_UZI))
851 damage *= autocvar_g_vehicles_uzi_damagerate;
853 if(DEATH_ISWEAPON(deathtype, WEP_RIFLE))
854 damage *= autocvar_g_vehicles_rifle_damagerate;
856 if(DEATH_ISWEAPON(deathtype, WEP_MINSTANEX))
857 damage *= autocvar_g_vehicles_minstanex_damagerate;
859 self.enemy = attacker;
861 if((self.vehicle_flags & VHF_HASSHIELD) && (self.vehicle_shield > 0))
863 if (wasfreed(self.vehicle_shieldent) || self.vehicle_shieldent == world)
865 self.vehicle_shieldent = spawn();
866 self.vehicle_shieldent.effects = EF_LOWPRECISION;
868 setmodel(self.vehicle_shieldent, "models/vhshield.md3");
869 setattachment(self.vehicle_shieldent, self, "");
870 setorigin(self.vehicle_shieldent, real_origin(self) - self.origin);
871 self.vehicle_shieldent.scale = 256 / vlen(self.maxs - self.mins);
872 self.vehicle_shieldent.think = shieldhit_think;
875 self.vehicle_shieldent.colormod = '1 1 1';
876 self.vehicle_shieldent.alpha = 0.45;
877 self.vehicle_shieldent.angles = vectoangles(normalize(hitloc - (self.origin + self.vehicle_shieldent.origin))) - self.angles;
878 self.vehicle_shieldent.nextthink = time;
880 self.vehicle_shield -= damage;
882 if(self.vehicle_shield < 0)
884 self.vehicle_health -= fabs(self.vehicle_shield);
885 self.vehicle_shieldent.colormod = '2 0 0';
886 self.vehicle_shield = 0;
887 self.vehicle_shieldent.alpha = 0.75;
889 if(sound_allowed(MSG_BROADCAST, attacker))
890 spamsound (self, CH_PAIN, "onslaught/ons_hit2.wav", VOL_BASE, ATTN_NORM); // FIXME: PLACEHOLDER
893 if(sound_allowed(MSG_BROADCAST, attacker))
894 spamsound (self, CH_PAIN, "onslaught/electricity_explode.wav", VOL_BASE, ATTN_NORM); // FIXME: PLACEHOLDER
899 self.vehicle_health -= damage;
901 if(sound_allowed(MSG_BROADCAST, attacker))
902 spamsound (self, CH_PAIN, "onslaught/ons_hit2.wav", VOL_BASE, ATTN_NORM); // FIXME: PLACEHOLDER
905 self.velocity += force; // * (vlen(force) / self.mass);
907 if(self.vehicle_health <= 0)
910 if(self.vehicle_flags & VHF_DEATHEJECT)
911 vehicles_exit(VHEF_EJECT);
913 vehicles_exit(VHEF_RELESE);
916 vehicles_setreturn();
920 void vehicles_clearrturn()
923 // Remove "return helper", if any.
924 ret = findchain(classname, "vehicle_return");
930 ret.think = SUB_Remove;
931 ret.nextthink = time + 0.1;
933 if(ret.waypointsprite_attached)
934 WaypointSprite_Kill(ret.waypointsprite_attached);
942 void vehicles_return()
944 pointparticles(particleeffectnum("teleport"), self.wp00.origin + '0 0 64', '0 0 0', 1);
946 self.wp00.think = vehicles_spawn;
947 self.wp00.nextthink = time;
949 if(self.waypointsprite_attached)
950 WaypointSprite_Kill(self.waypointsprite_attached);
955 void vehicles_showwp_goaway()
957 if(self.waypointsprite_attached)
958 WaypointSprite_Kill(self.waypointsprite_attached);
964 void vehicles_showwp()
971 self.think = vehicles_return;
972 self.nextthink = self.cnt;
976 self.think = vehicles_return;
977 self.nextthink = time +1;
981 setmodel(self, "null");
982 self.team = oldself.wp00.team;
983 self.wp00 = oldself.wp00;
984 setorigin(self, oldself.wp00.pos1);
986 self.nextthink = time + 5;
987 self.think = vehicles_showwp_goaway;
990 if(teamplay && self.team)
991 rgb = TeamColor(self.team);
994 WaypointSprite_Spawn("vehicle", 0, 0, self, '0 0 64', world, 0, self, waypointsprite_attached, TRUE, RADARICON_POWERUP, rgb);
995 if(self.waypointsprite_attached)
997 WaypointSprite_UpdateRule(self.waypointsprite_attached, self.wp00.team, SPRITERULE_DEFAULT);
999 WaypointSprite_UpdateBuildFinished(self.waypointsprite_attached, self.nextthink);
1000 WaypointSprite_Ping(self.waypointsprite_attached);
1003 if(oldself != world)
1007 void vehicles_setreturn()
1011 vehicles_clearrturn();
1014 ret.classname = "vehicle_return";
1016 ret.team = self.team;
1017 ret.think = vehicles_showwp;
1019 if(self.deadflag != DEAD_NO)
1021 ret.cnt = time + self.vehicle_respawntime;
1022 ret.nextthink = min(time + self.vehicle_respawntime, time + self.vehicle_respawntime - 5);
1026 ret.nextthink = min(time + self.vehicle_respawntime, time + self.vehicle_respawntime - 1);
1029 setmodel(ret, "null");
1030 setorigin(ret, self.pos1 + '0 0 96');
1034 void vehicles_configcheck(string configname, float check_cvar)
1037 localcmd(strcat("exec ", configname, "\n"));
1040 void vehicles_reset_colors()
1043 float _effects, _colormap;
1044 vector _glowmod, _colormod;
1046 if(autocvar_g_nodepthtestplayers)
1047 _effects = EF_NODEPTHTEST;
1049 if(autocvar_g_fullbrightplayers)
1050 _effects |= EF_FULLBRIGHT;
1053 _colormap = 1024 + (self.team - 1) * 17;
1058 _colormod = '0 0 0';
1060 // Find all ents attacked to main model and setup effects, colormod etc.
1061 e = findchainentity(tag_entity, self);
1064 if(e != self.vehicle_shieldent)
1066 e.effects = _effects; // | EF_LOWPRECISION;
1067 e.colormod = _colormod;
1068 e.colormap = _colormap;
1074 self.vehicle_hudmodel.effects = self.effects = _effects; // | EF_LOWPRECISION;
1075 self.vehicle_hudmodel.colormod = self.colormod = _colormod;
1076 self.vehicle_hudmodel.colormap = self.colormap = _colormap;
1077 self.vehicle_viewport.effects = (EF_ADDITIVE | EF_DOUBLESIDED | EF_FULLBRIGHT | EF_NODEPTHTEST | EF_NOGUNBOB | EF_NOSHADOW | EF_LOWPRECISION | EF_SELECTABLE | EF_TELEPORT_BIT);
1080 self.avelocity = '0 0 0';
1081 self.velocity = '0 0 0';
1082 self.effects = _effects;
1085 float vehicle_initialize(string net_name,
1100 void(float extflag) exitfunc,
1106 addstat(STAT_HUD, AS_INT, hud);
1107 addstat(STAT_VEHICLESTAT_HEALTH, AS_INT, vehicle_health);
1108 addstat(STAT_VEHICLESTAT_SHIELD, AS_INT, vehicle_shield);
1109 addstat(STAT_VEHICLESTAT_ENERGY, AS_INT, vehicle_energy);
1111 addstat(STAT_VEHICLESTAT_AMMO1, AS_INT, vehicle_ammo1);
1112 addstat(STAT_VEHICLESTAT_RELOAD1, AS_INT, vehicle_reload1);
1114 addstat(STAT_VEHICLESTAT_AMMO2, AS_INT, vehicle_ammo2);
1115 addstat(STAT_VEHICLESTAT_RELOAD2, AS_INT, vehicle_reload2);
1118 error("vehicles: missing bodymodel!");
1121 error("vehicles: missing hudmodel!");
1124 self.netname = self.classname;
1126 self.netname = net_name;
1128 if(self.team && !teamplay)
1131 self.vehicle_flags |= VHF_ISVEHICLE;
1133 setmodel(self, bodymodel);
1135 self.vehicle_viewport = spawn();
1136 self.vehicle_hudmodel = spawn();
1137 self.tur_head = spawn();
1138 self.tur_head.owner = self;
1139 self.takedamage = DAMAGE_AIM;
1140 self.bot_attack = TRUE;
1141 self.iscreature = TRUE;
1142 self.damagedbycontents = TRUE;
1144 self.tur_health = _max_health;
1145 self.vehicle_die = dieproc;
1146 self.vehicle_exit = exitfunc;
1147 self.vehicle_enter = enterproc;
1148 self.PlayerPhysplug = physproc;
1149 self.event_damage = vehicles_damage;
1150 self.touch = vehicles_touch;
1151 self.think = vehicles_spawn;
1152 self.nextthink = time;
1153 self.vehicle_respawntime = _respawntime;
1154 self.vehicle_spawn = spawnproc;
1156 if(autocvar_g_nodepthtestplayers)
1157 self.effects = self.effects | EF_NODEPTHTEST;
1159 if(autocvar_g_fullbrightplayers)
1160 self.effects = self.effects | EF_FULLBRIGHT;
1162 setmodel(self.vehicle_hudmodel, hudmodel);
1163 setmodel(self.vehicle_viewport, "null");
1168 setmodel(self.tur_head, topmodel);
1169 setattachment(self.tur_head, self, toptag);
1170 setattachment(self.vehicle_hudmodel, self.tur_head, hudtag);
1171 setattachment(self.vehicle_viewport, self.vehicle_hudmodel, viewtag);
1175 setattachment(self.tur_head, self, "");
1176 setattachment(self.vehicle_hudmodel, self, hudtag);
1177 setattachment(self.vehicle_viewport, self.vehicle_hudmodel, viewtag);
1180 setsize(self, min_s, max_s);
1183 setorigin(self, self.origin);
1184 tracebox(self.origin + '0 0 100', min_s, max_s, self.origin - '0 0 10000', MOVE_WORLDONLY, self);
1185 setorigin(self, trace_endpos);
1188 self.pos1 = self.origin;
1189 self.pos2 = self.angles;
1190 self.tur_head.team = self.team;
1195 void vehicle_aimturret(entity _vehic, vector _target, entity _turrret, string _tagname,
1196 float _pichlimit_min, float _pichlimit_max,
1197 float _rotlimit_min, float _rotlimit_max, float _aimspeed)
1202 vtmp = vectoangles(normalize(_target - gettaginfo(_turrret, gettagindex(_turrret, _tagname))));
1203 vtmp = AnglesTransform_ToAngles(AnglesTransform_LeftDivide(AnglesTransform_FromAngles(_vehic.angles), AnglesTransform_FromAngles(vtmp))) - _turrret.angles;
1204 vtmp = AnglesTransform_Normalize(vtmp, TRUE);
1206 ftmp = _aimspeed * sys_frametime;
1207 vtmp_y = bound(-ftmp, vtmp_y, ftmp);
1208 vtmp_x = bound(-ftmp, vtmp_x, ftmp);
1209 _turrret.angles_y = bound(_rotlimit_min, _turrret.angles_y + vtmp_y, _rotlimit_max);
1210 _turrret.angles_x = bound(_pichlimit_min, _turrret.angles_x + vtmp_x, _pichlimit_max);
1216 self.vehicle_exit = self.vehicle_exit;
1217 self.vehicle_enter = self.vehicle_exit;
1218 self.vehicle_die = self.vehicle_exit;
1219 self.vehicle_spawn = self.vehicle_exit;
1220 self.AuxiliaryXhair = self.AuxiliaryXhair;