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);
104 WriteByte(MSG_ONE, vehicle_id);
107 /** vehicles_locktarget
109 Generic target locking.
111 Figure out if what target is "locked" (if any), for missile tracking as such.
113 after calling, "if(self.lock_target != world && self.lock_strength == 1)" mean
114 you have a locked in target.
116 Exspects a crosshair_trace() or equivalent to be
121 .float lock_strength;
123 .float lock_soundtime;
124 float DAMAGE_TARGETDRONE = 10;
126 vector targetdrone_getnewspot()
131 for(i = 0; i < 100; ++i)
133 spot = self.origin + randomvec() * 1024;
134 tracebox(spot, self.mins, self.maxs, spot, MOVE_NORMAL, self);
135 if(trace_fraction == 1.0 && trace_startsolid == 0 && trace_allsolid == 0)
142 void targetdrone_think();
143 void targetdrone_damage(entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force);
144 void targetdrone_renwe()
146 self.think = targetdrone_think;
147 self.nextthink = time + 0.1;
148 setorigin(self, targetdrone_getnewspot());
150 self.takedamage = DAMAGE_TARGETDRONE;
151 self.event_damage = targetdrone_damage;
152 self.solid = SOLID_BBOX;
153 setmodel(self, "models/runematch/rune.mdl");
154 self.effects = EF_LOWPRECISION;
156 self.movetype = MOVETYPE_BOUNCEMISSILE;
157 setsize(self, '-100 -100 -100', '100 100 100');
160 void targetdrone_damage(entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
162 self.health -= damage;
165 pointparticles(particleeffectnum("explosion_medium"), self.origin, '0 0 0', 1);
171 self.think = targetdrone_renwe;
172 self.nextthink = time + 1 + random() * 2;
173 self.solid = SOLID_NOT;
178 entity targetdrone_getfear()
183 for(i = 64; i <= 1024; i += 64)
185 fear = findradius(self.origin, i);
197 void targetdrone_think()
199 self.nextthink = time + 0.1;
202 if(self.wp00.deadflag != DEAD_NO)
203 self.wp00 = targetdrone_getfear();
206 self.wp00 = targetdrone_getfear();
211 newdir = steerlib_push(self.wp00.origin) + randomvec() * 0.75;
213 newdir = randomvec() * 0.75;
215 newdir = newdir * 0.5 + normalize(self.velocity) * 0.5;
218 self.velocity = normalize(newdir) * (500 + (1024 / min(vlen(self.wp00.origin - self.origin), 1024)) * 700);
220 self.velocity = normalize(newdir) * 750;
222 tracebox(self.origin, self.mins, self.maxs, self.origin + self.velocity * 2, MOVE_NORMAL, self);
223 if(trace_fraction != 1.0)
224 self.velocity = self.velocity * -1;
226 //normalize((normalize(self.velocity) * 0.5 + newdir * 0.5)) * 750;
229 void targetdrone_spawn(vector _where, float _autorenew)
231 entity drone = spawn();
232 setorigin(drone, _where);
233 drone.think = targetdrone_renwe;
234 drone.nextthink = time + 0.1;
235 drone.cnt = _autorenew;
239 void vehicles_locktarget(float incr, float decr, float _lock_time)
241 if(self.lock_target && self.lock_target.deadflag != DEAD_NO)
243 self.lock_target = world;
244 self.lock_strength = 0;
248 if(self.lock_time > time)
251 if(self.lock_soundtime < time)
253 self.lock_soundtime = time + 0.5;
254 play2(self.owner, "vehicles/locked.wav");
260 if(trace_ent != world)
262 if(teamplay && trace_ent.team == self.team)
265 if(trace_ent.deadflag != DEAD_NO)
268 if not (trace_ent.vehicle_flags & VHF_ISVEHICLE ||
269 trace_ent.turrcaps_flags & TFL_TURRCAPS_ISTURRET ||
270 trace_ent.takedamage == DAMAGE_TARGETDRONE)
274 if(self.lock_target == world && trace_ent != world)
275 self.lock_target = trace_ent;
277 if(self.lock_target && trace_ent == self.lock_target)
279 if(self.lock_strength != 1 && self.lock_strength + incr >= 1)
281 play2(self.owner, "vehicles/lock.wav");
282 self.lock_soundtime = time + 0.8;
284 else if (self.lock_strength != 1 && self.lock_soundtime < time)
286 play2(self.owner, "vehicles/locking.wav");
287 self.lock_soundtime = time + 0.3;
292 // Have a locking target
293 // Trace hit current target
294 if(trace_ent == self.lock_target && trace_ent != world)
296 self.lock_strength = min(self.lock_strength + incr, 1);
297 if(self.lock_strength == 1)
298 self.lock_time = time + _lock_time;
303 self.lock_strength = max(self.lock_strength - decr * 2, 0);
305 self.lock_strength = max(self.lock_strength - decr, 0);
307 if(self.lock_strength == 0)
308 self.lock_target = world;
312 #define VEHICLE_UPDATE_PLAYER(fld,vhname) \
313 self.owner.vehicle_##fld = (self.vehicle_##fld / autocvar_g_vehicle_##vhname##_##fld) * 100
315 #define vehicles_sweap_collision(orig,vel,dt,acm,mult) \
316 traceline(orig, orig + vel * dt, MOVE_NORMAL, self); \
317 if(trace_fraction != 1) \
318 acm += normalize(self.origin - trace_endpos) * (vlen(vel) * mult)
320 // Hover movement support
321 float force_fromtag_power;
322 float force_fromtag_normpower;
323 vector force_fromtag_origin;
324 vector vehicles_force_fromtag_hover(string tag_name, float spring_length, float max_power)
326 force_fromtag_origin = gettaginfo(self, gettagindex(self, tag_name));
327 v_forward = normalize(v_forward) * -1;
328 traceline(force_fromtag_origin, force_fromtag_origin - (v_forward * spring_length), MOVE_NORMAL, self);
330 force_fromtag_power = (1 - trace_fraction) * max_power;
331 force_fromtag_normpower = force_fromtag_power / max_power;
333 return v_forward * force_fromtag_power;
336 // Experimental hovermode wich uses attraction/repulstion from surface insted of gravity/repulsion
337 // Can possibly be use to move abt any surface (inclusing walls/celings)
338 vector vehicles_force_fromtag_maglev(string tag_name, float spring_length, float max_power)
341 force_fromtag_origin = gettaginfo(self, gettagindex(self, tag_name));
342 v_forward = normalize(v_forward) * -1;
343 traceline(force_fromtag_origin, force_fromtag_origin - (v_forward * spring_length), MOVE_NORMAL, self);
345 // TODO - this may NOT be compatible with wall/celing movement, unhardcode 0.25 (engine count multiplier)
346 if(trace_fraction == 1.0)
348 force_fromtag_normpower = -0.25;
352 force_fromtag_power = ((1 - trace_fraction) - trace_fraction) * max_power;
353 force_fromtag_normpower = force_fromtag_power / max_power;
355 return v_forward * force_fromtag_power;
358 // Generic vehile projectile system
359 void vehicles_projectile_damage(entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
361 // Ignore damage from oterh projectiles from my owner (dont mess up volly's)
362 if(inflictor.owner == self.owner)
365 self.health -= damage;
366 self.velocity += force;
369 self.takedamage = DAMAGE_NO;
370 self.event_damage = SUB_Null;
371 self.think = self.use;
372 self.nextthink = time;
376 void vehicles_projectile_explode()
378 if(self.owner && other != world)
380 if(other == self.owner.vehicle)
383 if(other == self.owner.vehicle.tur_head)
389 self.event_damage = SUB_Null;
390 RadiusDamage (self, self.realowner, self.shot_dmg, 0, self.shot_radius, self, self.shot_force, self.totalfrags, other);
395 entity vehicles_projectile(string _mzlfx, string _mzlsound,
396 vector _org, vector _vel,
397 float _dmg, float _radi, float _force, float _size,
398 float _deahtype, float _projtype, float _health,
399 float _cull, float _clianim)
405 PROJECTILE_MAKETRIGGER(proj);
406 setorigin(proj, _org);
408 proj.shot_dmg = _dmg;
409 proj.shot_radius = _radi;
410 proj.shot_force = _force;
411 proj.totalfrags = _deahtype;
412 proj.solid = SOLID_BBOX;
413 proj.movetype = MOVETYPE_FLYMISSILE;
414 proj.flags = FL_PROJECTILE;
415 proj.bot_dodge = TRUE;
416 proj.bot_dodgerating = _dmg;
417 proj.velocity = _vel;
418 proj.touch = vehicles_projectile_explode;
419 proj.use = vehicles_projectile_explode;
421 proj.realowner = self.owner;
422 proj.think = SUB_Remove;
423 proj.nextthink = time + 30;
427 proj.takedamage = DAMAGE_AIM;
428 proj.event_damage = vehicles_projectile_damage;
429 proj.health = _health;
432 proj.flags = FL_PROJECTILE | FL_NOTARGET;
435 sound (self, CH_WEAPON_A, _mzlsound, VOL_BASE, ATTN_NORM);
438 pointparticles(particleeffectnum(_mzlfx), proj.origin, proj.velocity, 1);
441 setsize (proj, '-1 -1 -1' * _size, '1 1 1' * _size);
443 CSQCProjectile(proj, _clianim, _projtype, _cull);
447 // End generic vehile projectile system
450 Exetuted for all vehicles on (re)spawn.
451 Sets defaults for newly spawned units.
453 void vehicles_spawn()
455 dprint("Spawning vehicle: ", self.netname, "\n");
458 self.vehicle_hudmodel.viewmodelforclient = self;
461 self.touch = vehicles_touch;
462 self.event_damage = vehicles_damage;
463 self.iscreature = TRUE;
464 self.damagedbycontents = TRUE;
465 self.movetype = MOVETYPE_WALK;
466 self.solid = SOLID_SLIDEBOX;
467 self.takedamage = DAMAGE_AIM;
468 self.deadflag = DEAD_NO;
469 self.bot_attack = TRUE;
470 self.flags = FL_NOTARGET;
471 self.avelocity = '0 0 0';
472 self.velocity = '0 0 0';
475 self.lock_strength = 0;
476 self.lock_target = world;
477 self.misc_bulletcounter = 0;
480 self.angles = self.pos2;
481 setorigin(self, self.pos1 + '0 0 0');
483 pointparticles(particleeffectnum("teleport"), self.origin + '0 0 64', '0 0 0', 1);
485 vehicles_reset_colors();
486 self.vehicle_spawn();
489 // Better way of determening whats crushable needed! (fl_crushable?)
490 float vehicles_crushable(entity e)
492 if(e.classname == "player")
495 if(e.classname == "monster_zombie")
501 void vehilces_impact(float _minspeed, float _speedfac, float _maxpain)
503 if (trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT)
506 if(self.play_time < time)
508 float wc = vlen(self.velocity - self.oldvelocity);
509 //dprint("oldvel: ", vtos(self.oldvelocity), "\n");
510 //dprint("vel: ", vtos(self.velocity), "\n");
513 float take = min(_speedfac * wc, _maxpain);
514 Damage (self, world, world, take, DEATH_FALL, self.origin, '0 0 0');
515 self.play_time = time + 0.25;
517 //dprint("wc: ", ftos(wc), "\n");
518 //dprint("take: ", ftos(take), "\n");
523 .void() vehicle_impact;
524 void vehicles_touch()
526 // Vehicle currently in use
530 if(vehicles_crushable(other))
532 if(vlen(self.velocity) != 0)
533 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);
535 return; // Dont do selfdamage when hitting "soft targets".
538 if(self.play_time < time)
539 if(self.vehicle_impact)
540 self.vehicle_impact();
545 if(other.classname != "player")
548 if(other.deadflag != DEAD_NO)
551 if(other.vehicle != world)
554 // Remove this when bots know how to use vehicles.
555 if (clienttype(other) != CLIENTTYPE_REAL)
561 void vehicles_enter()
563 // Remove this when bots know how to use vehicles
564 if (clienttype(other) != CLIENTTYPE_REAL)
567 if(self.phase > time)
572 if(self.team != other.team)
575 RemoveGrapplingHook(other);
577 self.vehicle_ammo1 = 0;
578 self.vehicle_ammo2 = 0;
579 self.vehicle_reload1 = 0;
580 self.vehicle_reload2 = 0;
581 self.vehicle_energy = 0;
584 self.switchweapon = other.switchweapon;
586 // .viewmodelforclient works better.
587 //self.vehicle_hudmodel.drawonlytoclient = self.owner;
589 self.vehicle_hudmodel.viewmodelforclient = self.owner;
591 self.event_damage = vehicles_damage;
593 self.owner.angles = self.angles;
594 self.owner.takedamage = DAMAGE_NO;
595 self.owner.solid = SOLID_NOT;
596 self.owner.movetype = MOVETYPE_NOCLIP;
597 self.owner.alpha = -1;
598 self.owner.vehicle = self;
599 self.owner.event_damage = SUB_Null;
600 self.owner.view_ofs = '0 0 0';
601 self.colormap = self.owner.colormap;
603 self.tur_head.colormap = self.owner.colormap;
605 self.owner.hud = self.hud;
606 self.owner.PlayerPhysplug = self.PlayerPhysplug;
608 self.owner.vehicle_ammo1 = self.vehicle_ammo1;
609 self.owner.vehicle_ammo2 = self.vehicle_ammo2;
610 self.owner.vehicle_reload1 = self.vehicle_reload1;
611 self.owner.vehicle_reload2 = self.vehicle_reload2;
613 // Cant do this, hides attached objects too.
614 //self.exteriormodeltoclient = self.owner;
615 //self.tur_head.exteriormodeltoclient = self.owner;
617 other.flags &~= FL_ONGROUND;
618 self.flags &~= FL_ONGROUND;
620 self.team = self.owner.team;
621 self.flags -= FL_NOTARGET;
624 WriteByte (MSG_ONE, SVC_SETVIEWPORT);
625 WriteEntity(MSG_ONE, self.vehicle_viewport);
627 WriteByte (MSG_ONE, SVC_SETVIEWANGLES);
630 WriteAngle(MSG_ONE, self.tur_head.angles_x + self.angles_x); // tilt
631 WriteAngle(MSG_ONE, self.tur_head.angles_y + self.angles_y); // yaw
632 WriteAngle(MSG_ONE, 0); // roll
636 WriteAngle(MSG_ONE, self.angles_x * -1); // tilt
637 WriteAngle(MSG_ONE, self.angles_y); // yaw
638 WriteAngle(MSG_ONE, 0); // roll
641 vehicles_clearrturn();
643 CSQCVehicleSetup(self.owner, self.hud);
645 if(other.flagcarried)
647 if(!autocvar_g_vehicles_allow_flagcarry)
648 DropFlag(other.flagcarried, world, world);
651 other.flagcarried.scale = 1;
652 setattachment(other.flagcarried, self, "");
653 setorigin(other, '0 0 96');
657 self.vehicle_enter();
658 antilag_clear(other);
661 /** vehicles_findgoodexit
662 Locates a valid location for the player to exit the vehicle.
663 Will first try prefer_spot, then up 100 random spots arround the vehicle
664 wich are in direct line of sight and empty enougth to hold a players bbox
666 vector vehicles_findgoodexit(vector prefer_spot)
671 tracebox(self.origin + '0 0 32', PL_MIN, PL_MAX, prefer_spot, MOVE_NORMAL, self.owner);
672 if(trace_fraction == 1.0 && !trace_startsolid && !trace_allsolid)
675 mysize = vlen(self.maxs - self.mins);
678 v2 = 0.5 * (self.absmin + self.absmax);
679 for(i = 0; i < 100; ++i)
683 v = v2 + normalize(v) * mysize;
684 tracebox(v2, PL_MIN, PL_MAX, v, MOVE_NORMAL, self.owner);
685 if(trace_fraction == 1.0 && !trace_startsolid && !trace_allsolid)
690 exitspot = (self.origin + '0 0 48') + v_forward * mysize;
691 tracebox(self.origin + '0 0 32', PL_MIN, PL_MAX, exitspot, MOVE_NORMAL, self.owner);
692 if(trace_fraction == 1.0 && !trace_startsolid && !trace_allsolid)
695 exitspot = (self.origin + '0 0 48') - v_forward * mysize;
696 tracebox(self.origin + '0 0 32', PL_MIN, PL_MAX, exitspot, MOVE_NORMAL, self.owner);
697 if(trace_fraction == 1.0 && !trace_startsolid && !trace_allsolid)
700 exitspot = (self.origin + '0 0 48') + v_right * mysize;
701 tracebox(self.origin + '0 0 32', PL_MIN, PL_MAX, exitspot, MOVE_NORMAL, self.owner);
702 if(trace_fraction == 1.0 && !trace_startsolid && !trace_allsolid)
705 exitspot = (self.origin + '0 0 48') - v_right * mysize;
706 tracebox(self.origin + '0 0 32', PL_MIN, PL_MAX, exitspot, MOVE_NORMAL, self.owner);
707 if(trace_fraction == 1.0 && !trace_startsolid && !trace_allsolid)
715 Standarrd vehicle release fucntion.
716 custom code goes in self.vehicle_exit
718 void vehicles_exit(float eject)
721 if(self.flags & FL_CLIENT)
727 self.flags |= FL_NOTARGET;
731 msg_entity = self.owner;
732 WriteByte (MSG_ONE, SVC_SETVIEWPORT);
733 WriteEntity( MSG_ONE, self.owner);
735 WriteByte (MSG_ONE, SVC_SETVIEWANGLES);
736 WriteAngle(MSG_ONE, 0); // pich
737 WriteAngle(MSG_ONE, self.angles_y); // yaw
738 WriteAngle(MSG_ONE, 0); // roll
740 setsize(self.owner, PL_MIN,PL_MAX);
742 self.owner.takedamage = DAMAGE_AIM;
743 self.owner.solid = SOLID_SLIDEBOX;
744 self.owner.movetype = MOVETYPE_WALK;
745 self.owner.effects &~= EF_NODRAW;
746 self.owner.alpha = 1;
747 self.owner.PlayerPhysplug = SUB_Null;
748 self.owner.vehicle = world;
749 self.owner.view_ofs = PL_VIEW_OFS;
750 self.owner.event_damage = PlayerDamage;
751 self.owner.hud = HUD_NORMAL;
752 self.owner.switchweapon = self.switchweapon;
753 //self.owner.BUTTON_USE = 0;
755 CSQCVehicleSetup(self.owner, HUD_NORMAL);
758 if(self.deadflag == DEAD_NO)
759 self.avelocity = '0 0 0';
761 self.vehicle_hudmodel.viewmodelforclient = self;
762 self.tur_head.nodrawtoclient = world;
763 vehicles_setreturn();
765 self.phase = time + 1;
770 self.team = self.tur_head.team;
772 if(self.owner.flagcarried)
774 self.owner.flagcarried.scale = 0.6;
775 setattachment(self.owner.flagcarried, self.owner, "");
776 setorigin(self.owner.flagcarried, FLAG_CARRY_POS);
779 sound (self, CH_TRIGGER_SINGLE, "misc/null.wav", 1, ATTN_NORM);
780 self.vehicle_exit(eject);
782 vehicles_reset_colors();
789 void vehicles_regen(.float timer, .float regen_field, float field_max, float rpause, float regen, float delta_time)
791 if(self.regen_field < field_max)
792 if(self.timer + rpause < time)
794 self.regen_field = min(self.regen_field + regen * delta_time, field_max);
797 self.owner.regen_field = (self.regen_field / field_max) * 100;
801 void shieldhit_think()
806 //setmodel(self, "");
811 self.nextthink = time + 0.1;
815 void vehicles_painframe()
817 if(self.owner.vehicle_health <= 50)
818 if(self.pain_frame < time)
821 _ftmp = self.owner.vehicle_health / 50;
822 self.pain_frame = time + 0.1 + (random() * 0.5 * _ftmp);
823 pointparticles(particleeffectnum("smoke_small"), (self.origin + (randomvec() * 80)), '0 0 0', 1);
825 if(self.vehicle_flags & VHF_DMGSHAKE)
826 self.velocity += randomvec() * 30;
828 if(self.vehicle_flags & VHF_DMGROLL)
829 if(self.vehicle_flags & VHF_DMGHEADROLL)
830 self.tur_head.angles += randomvec();
832 self.angles += randomvec();
837 void vehicles_damage(entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
839 self.dmg_time = time;
841 if(DEATH_ISWEAPON(deathtype, WEP_NEX))
842 damage *= autocvar_g_vehicles_nex_damagerate;
844 if(DEATH_ISWEAPON(deathtype, WEP_UZI))
845 damage *= autocvar_g_vehicles_uzi_damagerate;
847 if(DEATH_ISWEAPON(deathtype, WEP_RIFLE))
848 damage *= autocvar_g_vehicles_rifle_damagerate;
850 if(DEATH_ISWEAPON(deathtype, WEP_MINSTANEX))
851 damage *= autocvar_g_vehicles_minstanex_damagerate;
853 self.enemy = attacker;
855 if((self.vehicle_flags & VHF_HASSHIELD) && (self.vehicle_shield > 0))
857 if (wasfreed(self.vehicle_shieldent) || self.vehicle_shieldent == world)
859 self.vehicle_shieldent = spawn();
860 self.vehicle_shieldent.effects = EF_LOWPRECISION;
862 setmodel(self.vehicle_shieldent, "models/vhshield.md3");
863 setattachment(self.vehicle_shieldent, self, "");
864 setorigin(self.vehicle_shieldent, real_origin(self) - self.origin);
865 self.vehicle_shieldent.scale = 256 / vlen(self.maxs - self.mins);
866 self.vehicle_shieldent.think = shieldhit_think;
869 self.vehicle_shieldent.colormod = '1 1 1';
870 self.vehicle_shieldent.alpha = 0.45;
871 self.vehicle_shieldent.angles = vectoangles(normalize(hitloc - (self.origin + self.vehicle_shieldent.origin))) - self.angles;
872 self.vehicle_shieldent.nextthink = time;
874 self.vehicle_shield -= damage;
876 if(self.vehicle_shield < 0)
878 self.vehicle_health -= fabs(self.vehicle_shield);
879 self.vehicle_shieldent.colormod = '2 0 0';
880 self.vehicle_shield = 0;
881 self.vehicle_shieldent.alpha = 0.75;
883 if(sound_allowed(MSG_BROADCAST, attacker))
884 spamsound (self, CH_PAIN, "onslaught/ons_hit2.wav", VOL_BASE, ATTN_NORM); // FIXME: PLACEHOLDER
887 if(sound_allowed(MSG_BROADCAST, attacker))
888 spamsound (self, CH_PAIN, "onslaught/electricity_explode.wav", VOL_BASE, ATTN_NORM); // FIXME: PLACEHOLDER
893 self.vehicle_health -= damage;
895 if(sound_allowed(MSG_BROADCAST, attacker))
896 spamsound (self, CH_PAIN, "onslaught/ons_hit2.wav", VOL_BASE, ATTN_NORM); // FIXME: PLACEHOLDER
899 self.velocity += force; // * (vlen(force) / self.mass);
901 if(self.vehicle_health <= 0)
904 if(self.vehicle_flags & VHF_DEATHEJECT)
905 vehicles_exit(VHEF_EJECT);
907 vehicles_exit(VHEF_RELESE);
910 vehicles_setreturn();
914 void vehicles_clearrturn()
917 // Remove "return helper", if any.
918 ret = findchain(classname, "vehicle_return");
924 ret.think = SUB_Remove;
925 ret.nextthink = time + 0.1;
927 if(ret.waypointsprite_attached)
928 WaypointSprite_Kill(ret.waypointsprite_attached);
936 void vehicles_return()
938 pointparticles(particleeffectnum("teleport"), self.wp00.origin + '0 0 64', '0 0 0', 1);
940 self.wp00.think = vehicles_spawn;
941 self.wp00.nextthink = time;
943 if(self.waypointsprite_attached)
944 WaypointSprite_Kill(self.waypointsprite_attached);
949 void vehicles_showwp_goaway()
951 if(self.waypointsprite_attached)
952 WaypointSprite_Kill(self.waypointsprite_attached);
958 void vehicles_showwp()
965 self.think = vehicles_return;
966 self.nextthink = self.cnt;
970 self.think = vehicles_return;
971 self.nextthink = time +1;
975 setmodel(self, "null");
976 self.team = oldself.wp00.team;
977 self.wp00 = oldself.wp00;
978 setorigin(self, oldself.wp00.pos1);
980 self.nextthink = time + 5;
981 self.think = vehicles_showwp_goaway;
984 if(teamplay && self.team)
985 rgb = TeamColor(self.team);
988 WaypointSprite_Spawn("vehicle", 0, 0, self, '0 0 64', world, 0, self, waypointsprite_attached, TRUE, RADARICON_POWERUP, rgb);
989 if(self.waypointsprite_attached)
991 WaypointSprite_UpdateRule(self.waypointsprite_attached, self.wp00.team, SPRITERULE_DEFAULT);
993 WaypointSprite_UpdateBuildFinished(self.waypointsprite_attached, self.nextthink);
994 WaypointSprite_Ping(self.waypointsprite_attached);
1001 void vehicles_setreturn()
1005 vehicles_clearrturn();
1008 ret.classname = "vehicle_return";
1010 ret.team = self.team;
1011 ret.think = vehicles_showwp;
1013 if(self.deadflag != DEAD_NO)
1015 ret.cnt = time + self.vehicle_respawntime;
1016 ret.nextthink = min(time + self.vehicle_respawntime, time + self.vehicle_respawntime - 5);
1020 ret.nextthink = min(time + self.vehicle_respawntime, time + self.vehicle_respawntime - 1);
1023 setmodel(ret, "null");
1024 setorigin(ret, self.pos1 + '0 0 96');
1028 void vehicles_configcheck(string configname, float check_cvar)
1031 localcmd(strcat("exec ", configname, "\n"));
1034 void vehicles_reset_colors()
1037 float _effects, _colormap;
1038 vector _glowmod, _colormod;
1040 if(autocvar_g_nodepthtestplayers)
1041 _effects = EF_NODEPTHTEST;
1043 if(autocvar_g_fullbrightplayers)
1044 _effects |= EF_FULLBRIGHT;
1047 _colormap = 1024 + (self.team - 1) * 17;
1052 _colormod = '0 0 0';
1054 // Find all ents attacked to main model and setup effects, colormod etc.
1055 e = findchainentity(tag_entity, self);
1058 if(e != self.vehicle_shieldent)
1060 e.effects = _effects; // | EF_LOWPRECISION;
1061 e.colormod = _colormod;
1062 e.colormap = _colormap;
1068 self.vehicle_hudmodel.effects = self.effects = _effects; // | EF_LOWPRECISION;
1069 self.vehicle_hudmodel.colormod = self.colormod = _colormod;
1070 self.vehicle_hudmodel.colormap = self.colormap = _colormap;
1071 self.vehicle_viewport.effects = (EF_ADDITIVE | EF_DOUBLESIDED | EF_FULLBRIGHT | EF_NODEPTHTEST | EF_NOGUNBOB | EF_NOSHADOW | EF_LOWPRECISION | EF_SELECTABLE | EF_TELEPORT_BIT);
1074 self.avelocity = '0 0 0';
1075 self.velocity = '0 0 0';
1076 self.effects = _effects;
1079 float vehicle_initialize(string net_name,
1094 void(float extflag) exitfunc,
1099 addstat(STAT_HUD, AS_INT, hud);
1100 addstat(STAT_VEHICLESTAT_HEALTH, AS_INT, vehicle_health);
1101 addstat(STAT_VEHICLESTAT_SHIELD, AS_INT, vehicle_shield);
1102 addstat(STAT_VEHICLESTAT_ENERGY, AS_INT, vehicle_energy);
1104 addstat(STAT_VEHICLESTAT_AMMO1, AS_INT, vehicle_ammo1);
1105 addstat(STAT_VEHICLESTAT_RELOAD1, AS_INT, vehicle_reload1);
1107 addstat(STAT_VEHICLESTAT_AMMO2, AS_INT, vehicle_ammo2);
1108 addstat(STAT_VEHICLESTAT_RELOAD2, AS_INT, vehicle_reload2);
1111 error("vehicles: missing bodymodel!");
1114 error("vehicles: missing hudmodel!");
1117 self.netname = self.classname;
1119 self.netname = net_name;
1121 if(self.team && !teamplay)
1124 self.vehicle_flags |= VHF_ISVEHICLE;
1126 setmodel(self, bodymodel);
1128 self.vehicle_viewport = spawn();
1129 self.vehicle_hudmodel = spawn();
1130 self.tur_head = spawn();
1131 self.tur_head.owner = self;
1132 self.takedamage = DAMAGE_AIM;
1133 self.bot_attack = TRUE;
1134 self.iscreature = TRUE;
1135 self.damagedbycontents = TRUE;
1138 self.vehicle_die = dieproc;
1139 self.vehicle_exit = exitfunc;
1140 self.vehicle_enter = enterproc;
1141 self.PlayerPhysplug = physproc;
1142 self.event_damage = vehicles_damage;
1143 self.touch = vehicles_touch;
1144 self.think = vehicles_spawn;
1145 self.nextthink = time;
1146 self.vehicle_respawntime = _respawntime;
1147 self.vehicle_spawn = spawnproc;
1149 if(autocvar_g_nodepthtestplayers)
1150 self.effects = self.effects | EF_NODEPTHTEST;
1152 if(autocvar_g_fullbrightplayers)
1153 self.effects = self.effects | EF_FULLBRIGHT;
1155 setmodel(self.vehicle_hudmodel, hudmodel);
1156 setmodel(self.vehicle_viewport, "null");
1161 setmodel(self.tur_head, topmodel);
1162 setattachment(self.tur_head, self, toptag);
1163 setattachment(self.vehicle_hudmodel, self.tur_head, hudtag);
1164 setattachment(self.vehicle_viewport, self.vehicle_hudmodel, viewtag);
1168 setattachment(self.tur_head, self, "");
1169 setattachment(self.vehicle_hudmodel, self, hudtag);
1170 setattachment(self.vehicle_viewport, self.vehicle_hudmodel, viewtag);
1173 setsize(self, min_s, max_s);
1176 setorigin(self, self.origin);
1177 tracebox(self.origin + '0 0 100', min_s, max_s, self.origin - '0 0 10000', MOVE_WORLDONLY, self);
1178 setorigin(self, trace_endpos);
1181 self.pos1 = self.origin;
1182 self.pos2 = self.angles;
1183 self.tur_head.team = self.team;
1190 self.vehicle_exit = self.vehicle_exit;
1191 self.vehicle_enter = self.vehicle_exit;
1192 self.vehicle_die = self.vehicle_exit;
1193 self.vehicle_spawn = self.vehicle_exit;
1194 self.AuxiliaryXhair = self.AuxiliaryXhair;