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)
48 if (clienttype(own) != CLIENTTYPE_REAL)
53 axh_id = bound(0, axh_id, MAX_AXH);
54 axh = own.(AuxiliaryXhair[axh_id]);
56 if(axh == world || wasfreed(axh)) // MADNESS? THIS IS QQQQCCCCCCCCC (wasfreed, why do you exsist?)
60 axh.drawonlytoclient = own;
62 Net_LinkEntity(axh, FALSE, 0, SendAuxiliaryXhair);
68 own.(AuxiliaryXhair[axh_id]) = axh;
72 // SVC_TEMPENTITY based, horrible with even 50 ping. hm.
73 // WriteByte(MSG_ONE, SVC_TEMPENTITY) uses reliable messagess, never use for thinsg that need continous updates.
74 void SendAuxiliaryXhair2(entity own, vector loc, vector clr, float axh_id)
78 WriteByte(MSG_ONE, SVC_TEMPENTITY);
79 WriteByte(MSG_ONE, TE_CSQC_AUXILIARYXHAIR);
81 WriteByte(MSG_ONE, axh_id);
83 WriteCoord(MSG_ONE, loc_x);
84 WriteCoord(MSG_ONE, loc_y);
85 WriteCoord(MSG_ONE, loc_z);
87 WriteByte(MSG_ONE, rint(clr_x * 255));
88 WriteByte(MSG_ONE, rint(clr_y * 255));
89 WriteByte(MSG_ONE, rint(clr_z * 255));
96 Notifies the client that he enterd a vehicle, and sends
99 only sends vehicle_id atm (wich is a HUD_* constant, ex. HUD_SPIDERBOT)
101 void CSQCVehicleSetup(entity own, float vehicle_id)
103 if (clienttype(own) != CLIENTTYPE_REAL)
108 WriteByte(MSG_ONE, SVC_TEMPENTITY);
109 WriteByte(MSG_ONE, TE_CSQC_VEHICLESETUP);
111 WriteByte(MSG_ONE, vehicle_id);
113 WriteByte(MSG_ONE, 1 + own.vehicle.vehicle_weapon2mode + HUD_VEHICLE_LAST);
116 /** vehicles_locktarget
118 Generic target locking.
120 Figure out if what target is "locked" (if any), for missile tracking as such.
122 after calling, "if(self.lock_target != world && self.lock_strength == 1)" mean
123 you have a locked in target.
125 Exspects a crosshair_trace() or equivalent to be
130 .float lock_strength;
132 .float lock_soundtime;
133 float DAMAGE_TARGETDRONE = 10;
135 vector targetdrone_getnewspot()
140 for(i = 0; i < 100; ++i)
142 spot = self.origin + randomvec() * 1024;
143 tracebox(spot, self.mins, self.maxs, spot, MOVE_NORMAL, self);
144 if(trace_fraction == 1.0 && trace_startsolid == 0 && trace_allsolid == 0)
151 void targetdrone_think();
152 void targetdrone_damage(entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force);
153 void targetdrone_renwe()
155 self.think = targetdrone_think;
156 self.nextthink = time + 0.1;
157 setorigin(self, targetdrone_getnewspot());
159 self.takedamage = DAMAGE_TARGETDRONE;
160 self.event_damage = targetdrone_damage;
161 self.solid = SOLID_BBOX;
162 setmodel(self, "models/runematch/rune.mdl");
163 self.effects = EF_LOWPRECISION;
165 self.movetype = MOVETYPE_BOUNCEMISSILE;
166 setsize(self, '-100 -100 -100', '100 100 100');
169 void targetdrone_damage(entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
171 self.health -= damage;
174 pointparticles(particleeffectnum("explosion_medium"), self.origin, '0 0 0', 1);
180 self.think = targetdrone_renwe;
181 self.nextthink = time + 1 + random() * 2;
182 self.solid = SOLID_NOT;
187 entity targetdrone_getfear()
192 for(i = 64; i <= 1024; i += 64)
194 fear = findradius(self.origin, i);
206 void targetdrone_think()
208 self.nextthink = time + 0.1;
211 if(self.wp00.deadflag != DEAD_NO)
212 self.wp00 = targetdrone_getfear();
215 self.wp00 = targetdrone_getfear();
220 newdir = steerlib_push(self.wp00.origin) + randomvec() * 0.75;
222 newdir = randomvec() * 0.75;
224 newdir = newdir * 0.5 + normalize(self.velocity) * 0.5;
227 self.velocity = normalize(newdir) * (500 + (1024 / min(vlen(self.wp00.origin - self.origin), 1024)) * 700);
229 self.velocity = normalize(newdir) * 750;
231 tracebox(self.origin, self.mins, self.maxs, self.origin + self.velocity * 2, MOVE_NORMAL, self);
232 if(trace_fraction != 1.0)
233 self.velocity = self.velocity * -1;
235 //normalize((normalize(self.velocity) * 0.5 + newdir * 0.5)) * 750;
238 void targetdrone_spawn(vector _where, float _autorenew)
240 entity drone = spawn();
241 setorigin(drone, _where);
242 drone.think = targetdrone_renwe;
243 drone.nextthink = time + 0.1;
244 drone.cnt = _autorenew;
248 void vehicles_locktarget(float incr, float decr, float _lock_time)
250 if(self.lock_target && self.lock_target.deadflag != DEAD_NO)
252 self.lock_target = world;
253 self.lock_strength = 0;
257 if(self.lock_time > time)
260 if(self.lock_soundtime < time)
262 self.lock_soundtime = time + 0.5;
263 play2(self.owner, "vehicles/locked.wav");
269 if(trace_ent != world)
271 if(teamplay && trace_ent.team == self.team)
274 if(trace_ent.deadflag != DEAD_NO)
277 if not (trace_ent.vehicle_flags & VHF_ISVEHICLE ||
278 trace_ent.turrcaps_flags & TFL_TURRCAPS_ISTURRET ||
279 trace_ent.takedamage == DAMAGE_TARGETDRONE)
283 if(self.lock_target == world && trace_ent != world)
284 self.lock_target = trace_ent;
286 if(self.lock_target && trace_ent == self.lock_target)
288 if(self.lock_strength != 1 && self.lock_strength + incr >= 1)
290 play2(self.owner, "vehicles/lock.wav");
291 self.lock_soundtime = time + 0.8;
293 else if (self.lock_strength != 1 && self.lock_soundtime < time)
295 play2(self.owner, "vehicles/locking.wav");
296 self.lock_soundtime = time + 0.3;
301 // Have a locking target
302 // Trace hit current target
303 if(trace_ent == self.lock_target && trace_ent != world)
305 self.lock_strength = min(self.lock_strength + incr, 1);
306 if(self.lock_strength == 1)
307 self.lock_time = time + _lock_time;
312 self.lock_strength = max(self.lock_strength - decr * 2, 0);
314 self.lock_strength = max(self.lock_strength - decr, 0);
316 if(self.lock_strength == 0)
317 self.lock_target = world;
321 #define VEHICLE_UPDATE_PLAYER(fld,vhname) \
322 self.owner.vehicle_##fld = (self.vehicle_##fld / autocvar_g_vehicle_##vhname##_##fld) * 100
324 #define vehicles_sweap_collision(orig,vel,dt,acm,mult) \
325 traceline(orig, orig + vel * dt, MOVE_NORMAL, self); \
326 if(trace_fraction != 1) \
327 acm += normalize(self.origin - trace_endpos) * (vlen(vel) * mult)
329 // Hover movement support
330 float force_fromtag_power;
331 float force_fromtag_normpower;
332 vector force_fromtag_origin;
333 vector vehicles_force_fromtag_hover(string tag_name, float spring_length, float max_power)
335 force_fromtag_origin = gettaginfo(self, gettagindex(self, tag_name));
336 v_forward = normalize(v_forward) * -1;
337 traceline(force_fromtag_origin, force_fromtag_origin - (v_forward * spring_length), MOVE_NORMAL, self);
339 force_fromtag_power = (1 - trace_fraction) * max_power;
340 force_fromtag_normpower = force_fromtag_power / max_power;
342 return v_forward * force_fromtag_power;
345 // Experimental hovermode wich uses attraction/repulstion from surface insted of gravity/repulsion
346 // Can possibly be use to move abt any surface (inclusing walls/celings)
347 vector vehicles_force_fromtag_maglev(string tag_name, float spring_length, float max_power)
350 force_fromtag_origin = gettaginfo(self, gettagindex(self, tag_name));
351 v_forward = normalize(v_forward) * -1;
352 traceline(force_fromtag_origin, force_fromtag_origin - (v_forward * spring_length), MOVE_NORMAL, self);
354 // TODO - this may NOT be compatible with wall/celing movement, unhardcode 0.25 (engine count multiplier)
355 if(trace_fraction == 1.0)
357 force_fromtag_normpower = -0.25;
361 force_fromtag_power = ((1 - trace_fraction) - trace_fraction) * max_power;
362 force_fromtag_normpower = force_fromtag_power / max_power;
364 return v_forward * force_fromtag_power;
367 // Generic vehile projectile system
368 void vehicles_projectile_damage(entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
370 // Ignore damage from oterh projectiles from my owner (dont mess up volly's)
371 if(inflictor.owner == self.owner)
374 self.health -= damage;
375 self.velocity += force;
378 self.takedamage = DAMAGE_NO;
379 self.event_damage = SUB_Null;
380 self.think = self.use;
381 self.nextthink = time;
385 void vehicles_projectile_explode()
387 if(self.owner && other != world)
389 if(other == self.owner.vehicle)
392 if(other == self.owner.vehicle.tur_head)
398 self.event_damage = SUB_Null;
399 RadiusDamage (self, self.realowner, self.shot_dmg, 0, self.shot_radius, self, self.shot_force, self.totalfrags, other);
404 entity vehicles_projectile(string _mzlfx, string _mzlsound,
405 vector _org, vector _vel,
406 float _dmg, float _radi, float _force, float _size,
407 float _deahtype, float _projtype, float _health,
408 float _cull, float _clianim)
414 PROJECTILE_MAKETRIGGER(proj);
415 setorigin(proj, _org);
417 proj.shot_dmg = _dmg;
418 proj.shot_radius = _radi;
419 proj.shot_force = _force;
420 proj.totalfrags = _deahtype;
421 proj.solid = SOLID_BBOX;
422 proj.movetype = MOVETYPE_FLYMISSILE;
423 proj.flags = FL_PROJECTILE;
424 proj.bot_dodge = TRUE;
425 proj.bot_dodgerating = _dmg;
426 proj.velocity = _vel;
427 proj.touch = vehicles_projectile_explode;
428 proj.use = vehicles_projectile_explode;
430 proj.realowner = self.owner;
431 proj.think = SUB_Remove;
432 proj.nextthink = time + 30;
436 proj.takedamage = DAMAGE_AIM;
437 proj.event_damage = vehicles_projectile_damage;
438 proj.health = _health;
441 proj.flags = FL_PROJECTILE | FL_NOTARGET;
444 sound (self, CH_WEAPON_A, _mzlsound, VOL_BASE, ATTN_NORM);
447 pointparticles(particleeffectnum(_mzlfx), proj.origin, proj.velocity, 1);
450 setsize (proj, '-1 -1 -1' * _size, '1 1 1' * _size);
452 CSQCProjectile(proj, _clianim, _projtype, _cull);
456 // End generic vehile projectile system
459 Exetuted for all vehicles on (re)spawn.
460 Sets defaults for newly spawned units.
462 void vehicles_spawn()
464 dprint("Spawning vehicle: ", self.netname, "\n");
467 self.vehicle_hudmodel.viewmodelforclient = self;
470 self.touch = vehicles_touch;
471 self.event_damage = vehicles_damage;
472 self.iscreature = TRUE;
473 self.damagedbycontents = TRUE;
474 self.movetype = MOVETYPE_WALK;
475 self.solid = SOLID_SLIDEBOX;
476 self.takedamage = DAMAGE_AIM;
477 self.deadflag = DEAD_NO;
478 self.bot_attack = TRUE;
479 self.flags = FL_NOTARGET;
480 self.avelocity = '0 0 0';
481 self.velocity = '0 0 0';
484 self.lock_strength = 0;
485 self.lock_target = world;
486 self.misc_bulletcounter = 0;
489 self.angles = self.pos2;
490 setorigin(self, self.pos1 + '0 0 0');
492 pointparticles(particleeffectnum("teleport"), self.origin + '0 0 64', '0 0 0', 1);
494 vehicles_reset_colors();
495 self.vehicle_spawn();
498 // Better way of determening whats crushable needed! (fl_crushable?)
499 float vehicles_crushable(entity e)
501 if(e.classname == "player")
504 if(e.classname == "monster_zombie")
510 void vehilces_impact(float _minspeed, float _speedfac, float _maxpain)
512 if (trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT)
515 if(self.play_time < time)
517 float wc = vlen(self.velocity - self.oldvelocity);
518 //dprint("oldvel: ", vtos(self.oldvelocity), "\n");
519 //dprint("vel: ", vtos(self.velocity), "\n");
522 float take = min(_speedfac * wc, _maxpain);
523 Damage (self, world, world, take, DEATH_FALL, self.origin, '0 0 0');
524 self.play_time = time + 0.25;
526 //dprint("wc: ", ftos(wc), "\n");
527 //dprint("take: ", ftos(take), "\n");
532 .void() vehicle_impact;
533 void vehicles_touch()
535 // Vehicle currently in use
539 if(vehicles_crushable(other))
541 if(vlen(self.velocity) != 0)
542 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);
544 return; // Dont do selfdamage when hitting "soft targets".
547 if(self.play_time < time)
548 if(self.vehicle_impact)
549 self.vehicle_impact();
554 if(other.classname != "player")
557 if(other.deadflag != DEAD_NO)
560 if(other.vehicle != world)
565 var float autocvar_g_vehicles_allow_bots = 0;
566 void vehicles_enter()
568 // Remove this when bots know how to use vehicles
570 if (clienttype(other) == CLIENTTYPE_BOT)
571 if (autocvar_g_vehicles_allow_bots)
572 dprint("Bot enters vehicle\n"); // This is where we need to disconnect (some, all?) normal bot AI and hand over to vehicle's _aiframe()
576 if(self.phase > time)
581 if(self.team != other.team)
584 RemoveGrapplingHook(other);
586 self.vehicle_ammo1 = 0;
587 self.vehicle_ammo2 = 0;
588 self.vehicle_reload1 = 0;
589 self.vehicle_reload2 = 0;
590 self.vehicle_energy = 0;
593 self.switchweapon = other.switchweapon;
595 // .viewmodelforclient works better.
596 //self.vehicle_hudmodel.drawonlytoclient = self.owner;
598 self.vehicle_hudmodel.viewmodelforclient = self.owner;
600 self.event_damage = vehicles_damage;
602 self.owner.angles = self.angles;
603 self.owner.takedamage = DAMAGE_NO;
604 self.owner.solid = SOLID_NOT;
605 self.owner.movetype = MOVETYPE_NOCLIP;
606 self.owner.alpha = -1;
607 self.owner.vehicle = self;
608 self.owner.event_damage = SUB_Null;
609 self.owner.view_ofs = '0 0 0';
610 self.colormap = self.owner.colormap;
612 self.tur_head.colormap = self.owner.colormap;
614 self.owner.hud = self.hud;
615 self.owner.PlayerPhysplug = self.PlayerPhysplug;
617 self.owner.vehicle_ammo1 = self.vehicle_ammo1;
618 self.owner.vehicle_ammo2 = self.vehicle_ammo2;
619 self.owner.vehicle_reload1 = self.vehicle_reload1;
620 self.owner.vehicle_reload2 = self.vehicle_reload2;
622 // Cant do this, hides attached objects too.
623 //self.exteriormodeltoclient = self.owner;
624 //self.tur_head.exteriormodeltoclient = self.owner;
626 other.flags &~= FL_ONGROUND;
627 self.flags &~= FL_ONGROUND;
629 self.team = self.owner.team;
630 self.flags -= FL_NOTARGET;
632 if (clienttype(other) == CLIENTTYPE_REAL)
635 WriteByte (MSG_ONE, SVC_SETVIEWPORT);
636 WriteEntity(MSG_ONE, self.vehicle_viewport);
638 WriteByte (MSG_ONE, SVC_SETVIEWANGLES);
641 WriteAngle(MSG_ONE, self.tur_head.angles_x + self.angles_x); // tilt
642 WriteAngle(MSG_ONE, self.tur_head.angles_y + self.angles_y); // yaw
643 WriteAngle(MSG_ONE, 0); // roll
647 WriteAngle(MSG_ONE, self.angles_x * -1); // tilt
648 WriteAngle(MSG_ONE, self.angles_y); // yaw
649 WriteAngle(MSG_ONE, 0); // roll
653 vehicles_clearrturn();
655 CSQCVehicleSetup(self.owner, self.hud);
657 if(other.flagcarried)
659 if(!autocvar_g_vehicles_allow_flagcarry)
660 DropFlag(other.flagcarried, world, world);
663 other.flagcarried.scale = 1;
664 setattachment(other.flagcarried, self, "");
665 setorigin(other, '0 0 96');
669 self.vehicle_enter();
670 antilag_clear(other);
673 /** vehicles_findgoodexit
674 Locates a valid location for the player to exit the vehicle.
675 Will first try prefer_spot, then up 100 random spots arround the vehicle
676 wich are in direct line of sight and empty enougth to hold a players bbox
678 vector vehicles_findgoodexit(vector prefer_spot)
683 tracebox(self.origin + '0 0 32', PL_MIN, PL_MAX, prefer_spot, MOVE_NORMAL, self.owner);
684 if(trace_fraction == 1.0 && !trace_startsolid && !trace_allsolid)
687 mysize = vlen(self.maxs - self.mins);
690 v2 = 0.5 * (self.absmin + self.absmax);
691 for(i = 0; i < 100; ++i)
695 v = v2 + normalize(v) * mysize;
696 tracebox(v2, PL_MIN, PL_MAX, v, MOVE_NORMAL, self.owner);
697 if(trace_fraction == 1.0 && !trace_startsolid && !trace_allsolid)
702 exitspot = (self.origin + '0 0 48') + v_forward * mysize;
703 tracebox(self.origin + '0 0 32', PL_MIN, PL_MAX, exitspot, MOVE_NORMAL, self.owner);
704 if(trace_fraction == 1.0 && !trace_startsolid && !trace_allsolid)
707 exitspot = (self.origin + '0 0 48') - v_forward * mysize;
708 tracebox(self.origin + '0 0 32', PL_MIN, PL_MAX, exitspot, MOVE_NORMAL, self.owner);
709 if(trace_fraction == 1.0 && !trace_startsolid && !trace_allsolid)
712 exitspot = (self.origin + '0 0 48') + v_right * mysize;
713 tracebox(self.origin + '0 0 32', PL_MIN, PL_MAX, exitspot, MOVE_NORMAL, self.owner);
714 if(trace_fraction == 1.0 && !trace_startsolid && !trace_allsolid)
717 exitspot = (self.origin + '0 0 48') - v_right * mysize;
718 tracebox(self.origin + '0 0 32', PL_MIN, PL_MAX, exitspot, MOVE_NORMAL, self.owner);
719 if(trace_fraction == 1.0 && !trace_startsolid && !trace_allsolid)
727 Standarrd vehicle release fucntion.
728 custom code goes in self.vehicle_exit
730 void vehicles_exit(float eject)
733 if(self.flags & FL_CLIENT)
739 self.flags |= FL_NOTARGET;
743 if (clienttype(self.owner) == CLIENTTYPE_REAL)
745 msg_entity = self.owner;
746 WriteByte (MSG_ONE, SVC_SETVIEWPORT);
747 WriteEntity( MSG_ONE, self.owner);
749 WriteByte (MSG_ONE, SVC_SETVIEWANGLES);
750 WriteAngle(MSG_ONE, 0); // pich
751 WriteAngle(MSG_ONE, self.angles_y); // yaw
752 WriteAngle(MSG_ONE, 0); // roll
755 setsize(self.owner, PL_MIN,PL_MAX);
757 self.owner.takedamage = DAMAGE_AIM;
758 self.owner.solid = SOLID_SLIDEBOX;
759 self.owner.movetype = MOVETYPE_WALK;
760 self.owner.effects &~= EF_NODRAW;
761 self.owner.alpha = 1;
762 self.owner.PlayerPhysplug = SUB_Null;
763 self.owner.vehicle = world;
764 self.owner.view_ofs = PL_VIEW_OFS;
765 self.owner.event_damage = PlayerDamage;
766 self.owner.hud = HUD_NORMAL;
767 self.owner.switchweapon = self.switchweapon;
768 //self.owner.BUTTON_USE = 0;
770 if(self.owner.flagcarried)
772 self.owner.flagcarried.scale = 0.6;
773 setattachment(self.owner.flagcarried, self.owner, "");
774 setorigin(self.owner.flagcarried, FLAG_CARRY_POS);
777 CSQCVehicleSetup(self.owner, HUD_NORMAL);
780 if(self.deadflag == DEAD_NO)
781 self.avelocity = '0 0 0';
783 self.vehicle_hudmodel.viewmodelforclient = self;
784 self.tur_head.nodrawtoclient = world;
785 vehicles_setreturn();
787 self.phase = time + 1;
792 self.team = self.tur_head.team;
795 sound (self, CH_TRIGGER_SINGLE, "misc/null.wav", 1, ATTN_NORM);
796 self.vehicle_exit(eject);
798 vehicles_reset_colors();
805 void vehicles_regen(.float timer, .float regen_field, float field_max, float rpause, float regen, float delta_time, float _healthscale)
807 if(self.regen_field < field_max)
808 if(self.timer + rpause < time)
811 regen = regen * (self.vehicle_health / self.tur_health);
813 self.regen_field = min(self.regen_field + regen * delta_time, field_max);
816 self.owner.regen_field = (self.regen_field / field_max) * 100;
820 void shieldhit_think()
825 //setmodel(self, "");
830 self.nextthink = time + 0.1;
834 void vehicles_painframe()
836 if(self.owner.vehicle_health <= 50)
837 if(self.pain_frame < time)
840 _ftmp = self.owner.vehicle_health / 50;
841 self.pain_frame = time + 0.1 + (random() * 0.5 * _ftmp);
842 pointparticles(particleeffectnum("smoke_small"), (self.origin + (randomvec() * 80)), '0 0 0', 1);
844 if(self.vehicle_flags & VHF_DMGSHAKE)
845 self.velocity += randomvec() * 30;
847 if(self.vehicle_flags & VHF_DMGROLL)
848 if(self.vehicle_flags & VHF_DMGHEADROLL)
849 self.tur_head.angles += randomvec();
851 self.angles += randomvec();
856 void vehicles_damage(entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
858 self.dmg_time = time;
860 if(DEATH_ISWEAPON(deathtype, WEP_NEX))
861 damage *= autocvar_g_vehicles_nex_damagerate;
863 if(DEATH_ISWEAPON(deathtype, WEP_UZI))
864 damage *= autocvar_g_vehicles_uzi_damagerate;
866 if(DEATH_ISWEAPON(deathtype, WEP_RIFLE))
867 damage *= autocvar_g_vehicles_rifle_damagerate;
869 if(DEATH_ISWEAPON(deathtype, WEP_MINSTANEX))
870 damage *= autocvar_g_vehicles_minstanex_damagerate;
872 self.enemy = attacker;
874 if((self.vehicle_flags & VHF_HASSHIELD) && (self.vehicle_shield > 0))
876 if (wasfreed(self.vehicle_shieldent) || self.vehicle_shieldent == world)
878 self.vehicle_shieldent = spawn();
879 self.vehicle_shieldent.effects = EF_LOWPRECISION;
881 setmodel(self.vehicle_shieldent, "models/vhshield.md3");
882 setattachment(self.vehicle_shieldent, self, "");
883 setorigin(self.vehicle_shieldent, real_origin(self) - self.origin);
884 self.vehicle_shieldent.scale = 256 / vlen(self.maxs - self.mins);
885 self.vehicle_shieldent.think = shieldhit_think;
888 self.vehicle_shieldent.colormod = '1 1 1';
889 self.vehicle_shieldent.alpha = 0.45;
890 self.vehicle_shieldent.angles = vectoangles(normalize(hitloc - (self.origin + self.vehicle_shieldent.origin))) - self.angles;
891 self.vehicle_shieldent.nextthink = time;
893 self.vehicle_shield -= damage;
895 if(self.vehicle_shield < 0)
897 self.vehicle_health -= fabs(self.vehicle_shield);
898 self.vehicle_shieldent.colormod = '2 0 0';
899 self.vehicle_shield = 0;
900 self.vehicle_shieldent.alpha = 0.75;
902 if(sound_allowed(MSG_BROADCAST, attacker))
903 spamsound (self, CH_PAIN, "onslaught/ons_hit2.wav", VOL_BASE, ATTN_NORM); // FIXME: PLACEHOLDER
906 if(sound_allowed(MSG_BROADCAST, attacker))
907 spamsound (self, CH_PAIN, "onslaught/electricity_explode.wav", VOL_BASE, ATTN_NORM); // FIXME: PLACEHOLDER
912 self.vehicle_health -= damage;
914 if(sound_allowed(MSG_BROADCAST, attacker))
915 spamsound (self, CH_PAIN, "onslaught/ons_hit2.wav", VOL_BASE, ATTN_NORM); // FIXME: PLACEHOLDER
918 self.velocity += force; // * (vlen(force) / self.mass);
920 if(self.vehicle_health <= 0)
923 if(self.vehicle_flags & VHF_DEATHEJECT)
924 vehicles_exit(VHEF_EJECT);
926 vehicles_exit(VHEF_RELESE);
929 vehicles_setreturn();
933 void vehicles_clearrturn()
936 // Remove "return helper", if any.
937 ret = findchain(classname, "vehicle_return");
943 ret.think = SUB_Remove;
944 ret.nextthink = time + 0.1;
946 if(ret.waypointsprite_attached)
947 WaypointSprite_Kill(ret.waypointsprite_attached);
955 void vehicles_return()
957 pointparticles(particleeffectnum("teleport"), self.wp00.origin + '0 0 64', '0 0 0', 1);
959 self.wp00.think = vehicles_spawn;
960 self.wp00.nextthink = time;
962 if(self.waypointsprite_attached)
963 WaypointSprite_Kill(self.waypointsprite_attached);
968 void vehicles_showwp_goaway()
970 if(self.waypointsprite_attached)
971 WaypointSprite_Kill(self.waypointsprite_attached);
977 void vehicles_showwp()
984 self.think = vehicles_return;
985 self.nextthink = self.cnt;
989 self.think = vehicles_return;
990 self.nextthink = time +1;
994 setmodel(self, "null");
995 self.team = oldself.wp00.team;
996 self.wp00 = oldself.wp00;
997 setorigin(self, oldself.wp00.pos1);
999 self.nextthink = time + 5;
1000 self.think = vehicles_showwp_goaway;
1003 if(teamplay && self.team)
1004 rgb = TeamColor(self.team);
1007 WaypointSprite_Spawn("vehicle", 0, 0, self, '0 0 64', world, 0, self, waypointsprite_attached, TRUE, RADARICON_POWERUP, rgb);
1008 if(self.waypointsprite_attached)
1010 WaypointSprite_UpdateRule(self.waypointsprite_attached, self.wp00.team, SPRITERULE_DEFAULT);
1011 if(oldself == world)
1012 WaypointSprite_UpdateBuildFinished(self.waypointsprite_attached, self.nextthink);
1013 WaypointSprite_Ping(self.waypointsprite_attached);
1016 if(oldself != world)
1020 void vehicles_setreturn()
1024 vehicles_clearrturn();
1027 ret.classname = "vehicle_return";
1029 ret.team = self.team;
1030 ret.think = vehicles_showwp;
1032 if(self.deadflag != DEAD_NO)
1034 ret.cnt = time + self.vehicle_respawntime;
1035 ret.nextthink = min(time + self.vehicle_respawntime, time + self.vehicle_respawntime - 5);
1039 ret.nextthink = min(time + self.vehicle_respawntime, time + self.vehicle_respawntime - 1);
1042 setmodel(ret, "null");
1043 setorigin(ret, self.pos1 + '0 0 96');
1047 void vehicles_configcheck(string configname, float check_cvar)
1050 localcmd(strcat("exec ", configname, "\n"));
1053 void vehicles_reset_colors()
1056 float _effects, _colormap;
1057 vector _glowmod, _colormod;
1059 if(autocvar_g_nodepthtestplayers)
1060 _effects = EF_NODEPTHTEST;
1062 if(autocvar_g_fullbrightplayers)
1063 _effects |= EF_FULLBRIGHT;
1066 _colormap = 1024 + (self.team - 1) * 17;
1071 _colormod = '0 0 0';
1073 // Find all ents attacked to main model and setup effects, colormod etc.
1074 e = findchainentity(tag_entity, self);
1077 if(e != self.vehicle_shieldent)
1079 e.effects = _effects; // | EF_LOWPRECISION;
1080 e.colormod = _colormod;
1081 e.colormap = _colormap;
1087 self.vehicle_hudmodel.effects = self.effects = _effects; // | EF_LOWPRECISION;
1088 self.vehicle_hudmodel.colormod = self.colormod = _colormod;
1089 self.vehicle_hudmodel.colormap = self.colormap = _colormap;
1090 self.vehicle_viewport.effects = (EF_ADDITIVE | EF_DOUBLESIDED | EF_FULLBRIGHT | EF_NODEPTHTEST | EF_NOGUNBOB | EF_NOSHADOW | EF_LOWPRECISION | EF_SELECTABLE | EF_TELEPORT_BIT);
1093 self.avelocity = '0 0 0';
1094 self.velocity = '0 0 0';
1095 self.effects = _effects;
1098 float vehicle_initialize(string net_name,
1113 void(float extflag) exitfunc,
1119 addstat(STAT_HUD, AS_INT, hud);
1120 addstat(STAT_VEHICLESTAT_HEALTH, AS_INT, vehicle_health);
1121 addstat(STAT_VEHICLESTAT_SHIELD, AS_INT, vehicle_shield);
1122 addstat(STAT_VEHICLESTAT_ENERGY, AS_INT, vehicle_energy);
1124 addstat(STAT_VEHICLESTAT_AMMO1, AS_INT, vehicle_ammo1);
1125 addstat(STAT_VEHICLESTAT_RELOAD1, AS_INT, vehicle_reload1);
1127 addstat(STAT_VEHICLESTAT_AMMO2, AS_INT, vehicle_ammo2);
1128 addstat(STAT_VEHICLESTAT_RELOAD2, AS_INT, vehicle_reload2);
1131 error("vehicles: missing bodymodel!");
1134 error("vehicles: missing hudmodel!");
1137 self.netname = self.classname;
1139 self.netname = net_name;
1141 if(self.team && !teamplay)
1144 self.vehicle_flags |= VHF_ISVEHICLE;
1146 setmodel(self, bodymodel);
1148 self.vehicle_viewport = spawn();
1149 self.vehicle_hudmodel = spawn();
1150 self.tur_head = spawn();
1151 self.tur_head.owner = self;
1152 self.takedamage = DAMAGE_AIM;
1153 self.bot_attack = TRUE;
1154 self.iscreature = TRUE;
1155 self.damagedbycontents = TRUE;
1157 self.tur_health = _max_health;
1158 self.vehicle_die = dieproc;
1159 self.vehicle_exit = exitfunc;
1160 self.vehicle_enter = enterproc;
1161 self.PlayerPhysplug = physproc;
1162 self.event_damage = vehicles_damage;
1163 self.touch = vehicles_touch;
1164 self.think = vehicles_spawn;
1165 self.nextthink = time;
1166 self.vehicle_respawntime = _respawntime;
1167 self.vehicle_spawn = spawnproc;
1169 if(autocvar_g_nodepthtestplayers)
1170 self.effects = self.effects | EF_NODEPTHTEST;
1172 if(autocvar_g_fullbrightplayers)
1173 self.effects = self.effects | EF_FULLBRIGHT;
1175 setmodel(self.vehicle_hudmodel, hudmodel);
1176 setmodel(self.vehicle_viewport, "null");
1181 setmodel(self.tur_head, topmodel);
1182 setattachment(self.tur_head, self, toptag);
1183 setattachment(self.vehicle_hudmodel, self.tur_head, hudtag);
1184 setattachment(self.vehicle_viewport, self.vehicle_hudmodel, viewtag);
1188 setattachment(self.tur_head, self, "");
1189 setattachment(self.vehicle_hudmodel, self, hudtag);
1190 setattachment(self.vehicle_viewport, self.vehicle_hudmodel, viewtag);
1193 setsize(self, min_s, max_s);
1196 setorigin(self, self.origin);
1197 tracebox(self.origin + '0 0 100', min_s, max_s, self.origin - '0 0 10000', MOVE_WORLDONLY, self);
1198 setorigin(self, trace_endpos);
1201 self.pos1 = self.origin;
1202 self.pos2 = self.angles;
1203 self.tur_head.team = self.team;
1208 void vehicle_aimturret(entity _vehic, vector _target, entity _turrret, string _tagname,
1209 float _pichlimit_min, float _pichlimit_max,
1210 float _rotlimit_min, float _rotlimit_max, float _aimspeed)
1215 vtmp = vectoangles(normalize(_target - gettaginfo(_turrret, gettagindex(_turrret, _tagname))));
1216 vtmp = AnglesTransform_ToAngles(AnglesTransform_LeftDivide(AnglesTransform_FromAngles(_vehic.angles), AnglesTransform_FromAngles(vtmp))) - _turrret.angles;
1217 vtmp = AnglesTransform_Normalize(vtmp, TRUE);
1219 ftmp = _aimspeed * sys_frametime;
1220 vtmp_y = bound(-ftmp, vtmp_y, ftmp);
1221 vtmp_x = bound(-ftmp, vtmp_x, ftmp);
1222 _turrret.angles_y = bound(_rotlimit_min, _turrret.angles_y + vtmp_y, _rotlimit_max);
1223 _turrret.angles_x = bound(_pichlimit_min, _turrret.angles_x + vtmp_x, _pichlimit_max);
1229 self.vehicle_exit = self.vehicle_exit;
1230 self.vehicle_enter = self.vehicle_exit;
1231 self.vehicle_die = self.vehicle_exit;
1232 self.vehicle_spawn = self.vehicle_exit;
1233 self.AuxiliaryXhair = self.AuxiliaryXhair;