1 float autocvar_g_vehicles_crush_dmg;
2 float autocvar_g_vehicles_crush_force;
4 void vehicles_damage(entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force);
5 void vehicles_return();
8 void vehicles_reset_colors();
9 void vehicles_clearrturn();
10 void vehicles_setreturn();
14 Send addictional points of interest to be drawn, to vehicle owner
17 .entity AuxiliaryXhair[MAX_AXH];
19 float SendAuxiliaryXhair(entity to, float sf)
22 WriteByte(MSG_ENTITY, ENT_CLIENT_AUXILIARYXHAIR);
24 WriteByte(MSG_ENTITY, self.cnt);
26 WriteCoord(MSG_ENTITY, self.origin_x);
27 WriteCoord(MSG_ENTITY, self.origin_y);
28 WriteCoord(MSG_ENTITY, self.origin_z);
30 WriteByte(MSG_ENTITY, rint(self.colormod_x * 255));
31 WriteByte(MSG_ENTITY, rint(self.colormod_y * 255));
32 WriteByte(MSG_ENTITY, rint(self.colormod_z * 255));
37 void UpdateAuxiliaryXhair(entity own, vector loc, vector clr, float axh_id)
41 axh_id = bound(0, axh_id, MAX_AXH);
42 axh = own.AuxiliaryXhair[axh_id];
44 if(axh == world || wasfreed(axh)) // MADNESS? THIS IS QQQQCCCCCCCCC (wasfreed, why do you exsist?)
48 axh.drawonlytoclient = own;
50 Net_LinkEntity(axh, FALSE, 0, SendAuxiliaryXhair);
56 own.AuxiliaryXhair[axh_id] = axh;
60 // SVC_TEMPENTITY based, horrible with even 50 ping. hm.
61 // WriteByte(MSG_ONE, SVC_TEMPENTITY) uses reliable messagess, never use for thinsg that need continous updates.
62 void SendAuxiliaryXhair2(entity own, vector loc, vector clr, float axh_id)
66 WriteByte(MSG_ONE, SVC_TEMPENTITY);
67 WriteByte(MSG_ONE, TE_CSQC_AUXILIARYXHAIR);
69 WriteByte(MSG_ONE, axh_id);
71 WriteCoord(MSG_ONE, loc_x);
72 WriteCoord(MSG_ONE, loc_y);
73 WriteCoord(MSG_ONE, loc_z);
75 WriteByte(MSG_ONE, rint(clr_x * 255));
76 WriteByte(MSG_ONE, rint(clr_y * 255));
77 WriteByte(MSG_ONE, rint(clr_z * 255));
83 void CSQCVehicleSetup(entity own, float vehicle_id)
87 WriteByte(MSG_ONE, SVC_TEMPENTITY);
88 WriteByte(MSG_ONE, TE_CSQC_VEHICLESETUP);
89 WriteByte(MSG_ONE, vehicle_id);
92 /** vehicles_locktarget
94 Generic target locking.
96 Figure out if what target is "locked" (if any), for missile tracking as such.
98 after calling, "if(self.lock_target != world && self.lock_strength == 1)" mean
99 you have a locked in target.
101 Exspects a crosshair_trace() or equivalent to be
106 .float lock_strength;
108 .float lock_soundtime;
109 void vehicles_locktarget(float incr, float decr, float _lock_time)
111 if(self.lock_target && self.lock_target.deadflag != DEAD_NO)
113 self.lock_target = world;
114 self.lock_strength = 0;
118 if(self.lock_time > time)
121 if(self.lock_soundtime < time)
123 self.lock_soundtime = time + 0.5;
124 play2(self.owner, "vehicles/locked.wav");
131 if(trace_ent != world)
133 if(teams_matter && trace_ent.team == self.team)
136 if(trace_ent.deadflag != DEAD_NO)
139 if not (trace_ent.vehicle_flags & VHF_ISVEHICLE || trace_ent.turrcaps_flags & TFL_TURRCAPS_ISTURRET)
143 if(self.lock_target == world && trace_ent != world)
144 self.lock_target = trace_ent;
146 if(self.lock_target && trace_ent == self.lock_target)
148 if(self.lock_strength != 1 && self.lock_strength + incr >= 1)
150 play2(self.owner, "vehicles/lock.wav");
151 self.lock_soundtime = time + 0.8;
153 else if (self.lock_strength != 1 && self.lock_soundtime < time)
155 play2(self.owner, "vehicles/locking.wav");
156 self.lock_soundtime = time + 0.3;
161 // Have a locking target
162 // Trace hit current target
163 if(trace_ent == self.lock_target && trace_ent != world)
165 self.lock_strength = min(self.lock_strength + incr, 1);
166 if(self.lock_strength == 1)
167 self.lock_time = time + _lock_time;
172 self.lock_strength = max(self.lock_strength - decr * 2, 0);
174 self.lock_strength = max(self.lock_strength - decr, 0);
176 if(self.lock_strength == 0)
177 self.lock_target = world;
181 #define VEHICLE_UPDATE_PLAYER(fld,vhname) \
182 self.owner.vehicle_##fld = (self.vehicle_##fld / autocvar_g_vehicle_##vhname##_##fld) * 100
184 #define vehicles_sweap_collision(orig,vel,dt,acm,mult) \
185 traceline(orig, orig + vel * dt, MOVE_NORMAL, self); \
186 if(trace_fraction != 1) \
187 acm += normalize(self.origin - trace_endpos) * (vlen(vel) * mult)
189 // Hover movement support
190 float force_fromtag_power;
191 float force_fromtag_normpower;
192 vector force_fromtag_origin;
193 vector vehicles_force_fromtag_hover(string tag_name, float spring_length, float max_power)
195 force_fromtag_origin = gettaginfo(self, gettagindex(self, tag_name));
196 v_forward = normalize(v_forward) * -1;
197 traceline(force_fromtag_origin, force_fromtag_origin - (v_forward * spring_length), MOVE_NORMAL, self);
199 force_fromtag_power = (1 - trace_fraction) * max_power;
200 force_fromtag_normpower = force_fromtag_power / max_power;
202 return v_forward * force_fromtag_power;
205 // Experimental hovermode wich uses attraction/repulstion from surface insted of gravity/repulsion
206 // Can possibly be use to move abt any surface (inclusing walls/celings)
207 vector vehicles_force_fromtag_maglev(string tag_name, float spring_length, float max_power)
210 force_fromtag_origin = gettaginfo(self, gettagindex(self, tag_name));
211 v_forward = normalize(v_forward) * -1;
212 traceline(force_fromtag_origin, force_fromtag_origin - (v_forward * spring_length), MOVE_NORMAL, self);
214 // TODO - this may NOT be compatible with wall/celing movement, unhardcode 0.25 (engine count multiplier)
215 if(trace_fraction == 1.0)
217 force_fromtag_normpower = -0.25;
221 force_fromtag_power = ((1 - trace_fraction) - trace_fraction) * max_power;
222 force_fromtag_normpower = force_fromtag_power / max_power;
224 return v_forward * force_fromtag_power;
227 // Generic vehile projectile system
228 void vehicles_projectile_damage(entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
230 self.health -= damage;
231 self.velocity += force;
234 self.takedamage = DAMAGE_NO;
235 self.event_damage = SUB_Null;
236 self.think = self.use;
237 self.nextthink = time;
242 void vehicles_projectile_explode()
244 if(self.owner && other != world)
246 if(other == self.owner.vehicle)
249 if(other == self.owner.vehicle.tur_head)
255 self.event_damage = SUB_Null;
256 RadiusDamage (self, self.realowner, self.shot_dmg, 0, self.shot_radius, self, self.shot_force, self.totalfrags, other);
261 entity vehicles_projectile(string _mzlfx, string _mzlsound,
262 vector _org, vector _vel,
263 float _dmg, float _radi, float _force, float _size,
264 float _deahtype, float _projtype, float _health,
265 float _cull, float _clianim)
271 PROJECTILE_MAKETRIGGER(proj);
272 setorigin(proj, _org);
274 proj.shot_dmg = _dmg;
275 proj.shot_radius = _radi;
276 proj.shot_force = _force;
277 proj.totalfrags = _deahtype;
278 proj.solid = SOLID_BBOX;
279 proj.movetype = MOVETYPE_FLYMISSILE;
280 proj.flags = FL_PROJECTILE;
281 proj.bot_dodge = TRUE;
282 proj.bot_dodgerating = _dmg;
283 proj.velocity = _vel;
284 proj.touch = vehicles_projectile_explode;
285 proj.use = vehicles_projectile_explode;
287 proj.realowner = self.owner;
288 proj.think = SUB_Remove;
289 proj.nextthink = time + 30;
293 proj.takedamage = DAMAGE_AIM;
294 proj.event_damage = vehicles_projectile_damage;
295 proj.health = _health;
298 proj.flags = FL_PROJECTILE | FL_NOTARGET;
301 sound (self, CHAN_WEAPON, _mzlsound, VOL_BASE, ATTN_NORM);
304 pointparticles(particleeffectnum(_mzlfx), proj.origin, proj.velocity, 1);
307 setsize (proj, '-1 -1 -1' * _size, '1 1 1' * _size);
309 CSQCProjectile(proj, _clianim, _projtype, _cull);
313 // End generic vehile projectile system
316 Exetuted for all vehiles on (re)spawn.
317 Sets defaults for newly spawned units.
319 void vehicles_spawn()
321 dprint("Spawning vehicle: ", self.netname, "\n");
324 self.vehicle_hudmodel.viewmodelforclient = self;
327 self.touch = vehicles_touch;
328 self.event_damage = vehicles_damage;
329 self.iscreature = TRUE;
330 self.movetype = MOVETYPE_WALK;
331 self.solid = SOLID_SLIDEBOX;
332 self.takedamage = DAMAGE_AIM;
333 self.deadflag = DEAD_NO;
334 self.bot_attack = TRUE;
335 self.flags = FL_NOTARGET;
336 self.avelocity = '0 0 0';
337 self.velocity = '0 0 0';
340 self.lock_strength = 0;
341 self.lock_target = world;
342 self.misc_bulletcounter = 0;
345 self.angles = self.pos2;
346 setorigin(self, self.pos1 + '0 0 128');
348 pointparticles(particleeffectnum("teleport"), self.origin + '0 0 64', '0 0 0', 1);
350 vehicles_reset_colors();
351 self.vehicle_spawn();
354 // Better way of determening whats crushable needed! (fl_crushable?)
355 float vehicles_crushable(entity e)
357 if(e.classname == "player")
360 if(e.classname == "monster_zombie")
366 void vehicles_touch()
368 // Vehicle currently in use
371 // Colided with world?
374 // Apply velocity based self damage here
378 if(other.vehicle_flags & VHF_ISVEHICLE)
380 //other.velocity += self.velocity * (self.mass / other.mass);
382 else if(vehicles_crushable(other))
384 if(vlen(self.velocity) != 0)
385 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);
391 if(other.classname != "player")
394 if(other.deadflag != DEAD_NO)
397 if(other.vehicle != world)
400 // Remove this when bots know how to use vehicles.
401 if (clienttype(other) != CLIENTTYPE_REAL)
407 void vehicles_enter()
409 // Remove this when bots know how to use vehicles
410 if (clienttype(other) != CLIENTTYPE_REAL)
413 if(self.phase > time)
418 if(self.team != other.team)
421 self.vehicle_ammo1 = 0;
422 self.vehicle_ammo2 = 0;
423 self.vehicle_reload1 = 0;
424 self.vehicle_reload2 = 0;
425 self.vehicle_energy = 0;
428 self.switchweapon = other.switchweapon;
430 // .viewmodelforclient works better.
431 //self.vehicle_hudmodel.drawonlytoclient = self.owner;
433 #ifndef VEHICLES_CSQC
434 self.vehicle_hudmodel.viewmodelforclient = self.owner;
437 self.event_damage = vehicles_damage;
439 self.owner.angles = self.angles;
440 self.owner.takedamage = DAMAGE_NO;
441 self.owner.solid = SOLID_NOT;
442 self.owner.movetype = MOVETYPE_NOCLIP;
443 self.owner.alpha = -1;
444 self.owner.vehicle = self;
445 self.owner.event_damage = SUB_Null;
446 self.owner.view_ofs = '0 0 0';
447 self.colormap = self.owner.colormap;
449 self.tur_head.colormap = self.owner.colormap;
451 self.owner.hud = self.hud;
452 self.owner.PlayerPhysplug = self.PlayerPhysplug;
454 self.owner.vehicle_ammo1 = self.vehicle_ammo1;
455 self.owner.vehicle_ammo2 = self.vehicle_ammo2;
456 self.owner.vehicle_reload1 = self.vehicle_reload1;
457 self.owner.vehicle_reload2 = self.vehicle_reload2;
459 // Cant do this, hides attached objects too.
460 //self.exteriormodeltoclient = self.owner;
461 //self.tur_head.exteriormodeltoclient = self.owner;
463 other.flags &~= FL_ONGROUND;
464 self.flags &~= FL_ONGROUND;
466 self.team = self.owner.team;
467 self.flags -= FL_NOTARGET;
469 #ifndef VEHICLES_CSQC
471 WriteByte (MSG_ONE, SVC_SETVIEWPORT);
472 WriteEntity(MSG_ONE, self.vehicle_viewport);
474 WriteByte (MSG_ONE, SVC_SETVIEWANGLES);
477 WriteAngle(MSG_ONE, self.tur_head.angles_x + self.angles_x); // tilt
478 WriteAngle(MSG_ONE, self.tur_head.angles_y + self.angles_y); // yaw
479 WriteAngle(MSG_ONE, 0); // roll
483 WriteByte (MSG_ONE, SVC_SETVIEWANGLES);
484 WriteAngle(MSG_ONE, self.angles_x * -1); // tilt
485 WriteAngle(MSG_ONE, self.angles_y); // yaw
486 WriteAngle(MSG_ONE, 0); // roll
491 vehicles_clearrturn();
493 CSQCVehicleSetup(self.owner, self.hud);
495 self.vehicle_enter();
498 void vehicles_exit(float eject)
500 self.flags |= FL_NOTARGET;
504 msg_entity = self.owner;
505 WriteByte (MSG_ONE, SVC_SETVIEWPORT);
506 WriteEntity( MSG_ONE, self.owner);
508 WriteByte (MSG_ONE, SVC_SETVIEWANGLES);
509 WriteAngle(MSG_ONE, 0); // pich
510 WriteAngle(MSG_ONE, self.angles_y); // yaw
511 WriteAngle(MSG_ONE, 0); // roll
513 setsize(self.owner, PL_MIN,PL_MAX);
515 self.owner.takedamage = DAMAGE_AIM;
516 self.owner.solid = SOLID_SLIDEBOX;
517 self.owner.movetype = MOVETYPE_WALK;
518 self.owner.effects &~= EF_NODRAW;
519 self.owner.alpha = 1;
520 self.owner.PlayerPhysplug = SUB_Null;
521 self.owner.vehicle = world;
522 self.owner.view_ofs = PL_VIEW_OFS;
523 self.owner.event_damage = PlayerDamage;
524 self.owner.hud = HUD_NORMAL;
525 self.owner.switchweapon = self.switchweapon;
526 self.owner.BUTTON_USE = 0;
529 if(self.deadflag == DEAD_NO)
530 self.avelocity = '0 0 0';
532 self.vehicle_hudmodel.viewmodelforclient = self;
533 self.tur_head.nodrawtoclient = world;
534 vehicles_setreturn();
536 self.phase = time + 1;
541 self.vehicle_exit(eject);
546 void vehicles_regen(.float timer, .float regen_field, float field_max, float rpause, float regen, float delta_time)
548 if(self.regen_field < field_max)
549 if(self.timer + rpause < time)
551 self.regen_field = min(self.regen_field + regen * delta_time, field_max);
554 self.owner.regen_field = (self.regen_field / field_max) * 100;
558 void shieldhit_think()
563 //setmodel(self, "");
568 self.nextthink = time + 0.1;
572 void vehicles_damage(entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
574 self.dmg_time = time;
576 if((self.vehicle_flags & VHF_HASSHIELD) && (self.vehicle_shield > 0))
578 if (wasfreed(self.vehicle_shieldent) || self.vehicle_shieldent == world)
580 self.vehicle_shieldent = spawn();
581 self.vehicle_shieldent.effects = EF_LOWPRECISION;
583 setmodel(self.vehicle_shieldent, "models/vhshield.md3");
584 setattachment(self.vehicle_shieldent, self, "");
585 setorigin(self.vehicle_shieldent, real_origin(self) - self.origin);
586 self.vehicle_shieldent.scale = 256 / vlen(self.maxs - self.mins);
587 self.vehicle_shieldent.think = shieldhit_think;
591 self.vehicle_shieldent.colormod = '1 1 1';
592 self.vehicle_shieldent.alpha = 0.45;
593 self.vehicle_shieldent.angles = vectoangles(normalize(hitloc - (self.origin + self.vehicle_shieldent.origin))) - self.angles;
594 self.vehicle_shieldent.nextthink = time;
596 self.vehicle_shield -= damage;
598 if(self.vehicle_shield < 0)
600 self.vehicle_shieldent.colormod = '2 0 0';
601 self.vehicle_shield = 0;
602 self.vehicle_shieldent.alpha = 0.75;
603 self.vehicle_health -= fabs(self.vehicle_shield);
607 self.vehicle_health -= damage;
609 self.velocity += force; // * (vlen(force) / self.mass);
611 if(self.vehicle_health <= 0)
614 if(self.vehicle_flags & VHF_DEATHEJECT)
615 vehicles_exit(VHEF_EJECT);
617 vehicles_exit(VHEF_RELESE);
620 vehicles_setreturn();
624 void vehicles_return()
626 pointparticles(particleeffectnum("teleport"), self.enemy.origin + '0 0 64', '0 0 0', 1);
628 self.enemy.think = vehicles_spawn;
629 self.enemy.nextthink = time;
634 void vehicles_clearrturn()
637 // Remove "return helper", if any.
638 ret = findchain(classname, "vehicle_return");
641 if(ret.enemy == self)
644 ret.think = SUB_Remove;
645 ret.nextthink = time + 0.1;
653 void vehicles_setreturn()
657 vehicles_clearrturn();
660 ret.classname = "vehicle_return";
662 ret.think = vehicles_return;
663 ret.nextthink = time + self.vehicle_respawntime;
666 float vehicles_customizeentityforclient()
668 if(self.deadflag == DEAD_DEAD)
674 void vehicles_configcheck(string configname, float check_cvar)
677 localcmd(strcat("exec ", configname, "\n"));
680 void vehicles_reset_colors()
683 float _effects, _colormap;
684 vector _glowmod, _colormod;
686 if(autocvar_g_nodepthtestplayers)
687 _effects = EF_NODEPTHTEST;
689 if(autocvar_g_fullbrightplayers)
690 _effects |= EF_FULLBRIGHT;
693 _colormap = 1024 + (self.team - 1) * 17;
700 // Find all ents attacked to main model and setup effects, colormod etc.
701 e = findchainentity(tag_entity, self);
704 if(e != self.vehicle_shieldent)
706 e.effects = _effects | EF_LOWPRECISION;
707 e.colormod = _colormod;
708 e.colormap = _colormap;
714 self.vehicle_hudmodel.effects = self.effects = _effects | EF_LOWPRECISION;
715 self.vehicle_hudmodel.colormod = self.colormod = _colormod;
716 self.vehicle_hudmodel.colormap = self.colormap = _colormap;
717 self.vehicle_viewport.effects = (EF_ADDITIVE | EF_DOUBLESIDED | EF_FULLBRIGHT | EF_NODEPTHTEST | EF_NOGUNBOB | EF_NOSHADOW | EF_LOWPRECISION | EF_SELECTABLE | EF_TELEPORT_BIT);
720 self.avelocity = '0 0 0';
721 self.velocity = '0 0 0';
722 self.effects = _effects;
725 float vehicle_initialize(string net_name,
740 void(float extflag) exitfunc,
745 addstat(STAT_HUD, AS_INT, hud);
746 addstat(STAT_VEHICLESTAT_HEALTH, AS_INT, vehicle_health);
747 addstat(STAT_VEHICLESTAT_SHIELD, AS_INT, vehicle_shield);
748 addstat(STAT_VEHICLESTAT_ENERGY, AS_INT, vehicle_energy);
750 addstat(STAT_VEHICLESTAT_AMMO1, AS_INT, vehicle_ammo1);
751 addstat(STAT_VEHICLESTAT_RELOAD1, AS_INT, vehicle_reload1);
753 addstat(STAT_VEHICLESTAT_AMMO2, AS_INT, vehicle_ammo2);
754 addstat(STAT_VEHICLESTAT_RELOAD2, AS_INT, vehicle_reload2);
757 error("vehicles: missing bodymodel!");
760 error("vehicles: missing hudmodel!");
763 self.netname = self.classname;
765 self.netname = net_name;
767 if(self.team && !teams_matter)
770 self.vehicle_flags |= VHF_ISVEHICLE;
772 setmodel(self, bodymodel);
774 self.vehicle_viewport = spawn();
775 self.vehicle_hudmodel = spawn();
776 self.tur_head = spawn();
777 self.tur_head.owner = self;
778 self.takedamage = DAMAGE_AIM;
779 self.bot_attack = TRUE;
780 self.iscreature = TRUE;
783 //self.customizeentityforclient = vehicles_customizeentityforclient;
784 self.vehicle_die = dieproc;
785 self.vehicle_exit = exitfunc;
786 self.vehicle_enter = enterproc;
787 self.PlayerPhysplug = physproc;
788 self.event_damage = vehicles_damage;
789 self.touch = vehicles_touch;
790 self.think = vehicles_spawn;
791 self.nextthink = time;
792 self.vehicle_respawntime = _respawntime;
793 self.vehicle_spawn = spawnproc;
795 if(autocvar_g_nodepthtestplayers)
796 self.effects = self.effects | EF_NODEPTHTEST;
798 if(autocvar_g_fullbrightplayers)
799 self.effects = self.effects | EF_FULLBRIGHT;
801 setmodel(self.vehicle_hudmodel, hudmodel);
802 setmodel(self.vehicle_viewport, "null");
807 setmodel(self.tur_head, topmodel);
808 setattachment(self.tur_head, self, toptag);
809 setattachment(self.vehicle_hudmodel, self.tur_head, hudtag);
810 setattachment(self.vehicle_viewport, self.vehicle_hudmodel, viewtag);
814 setattachment(self.tur_head, self, "");
815 setattachment(self.vehicle_hudmodel, self, hudtag);
816 setattachment(self.vehicle_viewport, self.vehicle_hudmodel, viewtag);
819 setsize(self, min_s, max_s);
822 setorigin(self, self.origin);
823 tracebox(self.origin + '0 0 100', min_s, max_s, self.origin - '0 0 10000', MOVE_WORLDONLY, self);
824 setorigin(self, trace_endpos);
827 self.pos1 = self.origin;
828 self.pos2 = self.angles;
839 self.vehicle_exit = self.vehicle_exit;
840 self.vehicle_enter = self.vehicle_exit;
841 self.vehicle_die = self.vehicle_exit;
842 self.vehicle_spawn = self.vehicle_exit;
843 self.AuxiliaryXhair = self.AuxiliaryXhair;