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 .entity AuxiliaryXhair[MAX_AXH];
16 float SendAuxiliaryXhair(entity to, float sf)
19 WriteByte(MSG_ENTITY, ENT_CLIENT_AUXILIARYXHAIR);
21 WriteByte(MSG_ENTITY, self.cnt);
23 WriteCoord(MSG_ENTITY, self.origin_x);
24 WriteCoord(MSG_ENTITY, self.origin_y);
25 WriteCoord(MSG_ENTITY, self.origin_z);
27 WriteByte(MSG_ENTITY, rint(self.colormod_x * 255));
28 WriteByte(MSG_ENTITY, rint(self.colormod_y * 255));
29 WriteByte(MSG_ENTITY, rint(self.colormod_z * 255));
34 void UpdateAuxiliaryXhair(entity own, vector loc, vector clr, float axh_id)
38 axh_id = bound(0, axh_id, MAX_AXH);
39 axh = own.AuxiliaryXhair[axh_id];
41 if(axh == world || wasfreed(axh)) // MADNESS? THIS IS QQQQCCCCCCCCC (wasfreed, why do you exsist?)
45 axh.drawonlytoclient = own;
47 Net_LinkEntity(axh, FALSE, 0, SendAuxiliaryXhair);
53 own.AuxiliaryXhair[axh_id] = axh;
57 // SVC_TEMPENTITY based, horrible with even 50 ping. hm.
58 // WriteByte(MSG_ONE, SVC_TEMPENTITY) uses reliable messagess, never use for thinsg that need continous updates.
59 void SendAuxiliaryXhair2(entity own, vector loc, vector clr, float axh_id)
63 WriteByte(MSG_ONE, SVC_TEMPENTITY);
64 WriteByte(MSG_ONE, TE_CSQC_AUXILIARYXHAIR);
66 WriteByte(MSG_ONE, axh_id);
68 WriteCoord(MSG_ONE, loc_x);
69 WriteCoord(MSG_ONE, loc_y);
70 WriteCoord(MSG_ONE, loc_z);
72 WriteByte(MSG_ONE, rint(clr_x * 255));
73 WriteByte(MSG_ONE, rint(clr_y * 255));
74 WriteByte(MSG_ONE, rint(clr_z * 255));
79 void CSQCVehicleSetup(entity own, float vehicle_id)
83 WriteByte(MSG_ONE, SVC_TEMPENTITY);
84 WriteByte(MSG_ONE, TE_CSQC_VEHICLESETUP);
85 WriteByte(MSG_ONE, vehicle_id);
91 void vehicles_locktarget(float incr, float decr, float _lock_time)
93 if(self.lock_target && self.lock_target.deadflag != DEAD_NO)
95 self.lock_target = world;
96 self.lock_strength = 0;
100 if(self.lock_time > time)
103 if(trace_ent != world)
105 if(teams_matter && trace_ent.team == self.team)
108 if(trace_ent.deadflag != DEAD_NO)
111 if not (trace_ent.vehicle_flags & VHF_ISVEHICLE || trace_ent.turrcaps_flags & TFL_TURRCAPS_ISTURRET)
115 if(self.lock_target == world && trace_ent != world)
116 self.lock_target = trace_ent;
118 // Have a locking target
119 // Trace hit current target
120 if(trace_ent == self.lock_target && trace_ent != world)
122 self.lock_strength = min(self.lock_strength + incr, 1);
123 if(self.lock_strength == 1)
124 self.lock_time = time + _lock_time;
129 self.lock_strength = max(self.lock_strength - decr * 2, 0);
131 self.lock_strength = max(self.lock_strength - decr, 0);
133 if(self.lock_strength == 0)
134 self.lock_target = world;
138 #define VEHICLE_UPDATE_PLAYER(fld,vhname) \
139 self.owner.vehicle_##fld = self.vehicle_##fld / autocvar_g_vehicle_##vhname##_##fld
141 #define vehicles_sweap_collision(orig,vel,dt,acm,mult) \
142 traceline(orig, orig + vel * dt, MOVE_NORMAL, self); \
143 if(trace_fraction != 1) \
144 acm += normalize(self.origin - trace_endpos) * (vlen(vel) * mult)
146 float force_fromtag_power;
147 float force_fromtag_normpower;
148 vector force_fromtag_origin;
149 vector vehicles_force_fromtag_hover(string tag_name, float spring_length, float max_power)
151 force_fromtag_origin = gettaginfo(self, gettagindex(self, tag_name));
152 v_forward = normalize(v_forward) * -1;
153 traceline(force_fromtag_origin, force_fromtag_origin - (v_forward * spring_length), MOVE_NORMAL, self);
155 force_fromtag_power = (1 - trace_fraction) * max_power;
156 force_fromtag_normpower = force_fromtag_power / max_power;
158 return v_forward * force_fromtag_power;
161 vector vehicles_force_fromtag_maglev(string tag_name, float spring_length, float max_power)
164 force_fromtag_origin = gettaginfo(self, gettagindex(self, tag_name));
165 v_forward = normalize(v_forward) * -1;
166 traceline(force_fromtag_origin, force_fromtag_origin - (v_forward * spring_length), MOVE_NORMAL, self);
168 if(trace_fraction == 1.0)
170 force_fromtag_normpower = -0.25;
174 force_fromtag_power = ((1 - trace_fraction) - trace_fraction) * max_power;
175 force_fromtag_normpower = force_fromtag_power / max_power;
177 return v_forward * force_fromtag_power;
180 void vehicles_projectile_damage(entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
182 self.health -= damage;
183 self.velocity += force;
186 self.takedamage = DAMAGE_NO;
187 self.event_damage = SUB_Null;
188 self.think = self.use;
189 self.nextthink = time;
194 void vehicles_projectile_explode()
196 if(self.owner && other != world)
198 if(other == self.owner.vehicle)
201 if(other == self.owner.vehicle.tur_head)
207 self.event_damage = SUB_Null;
208 RadiusDamage (self, self.realowner, self.shot_dmg, 0, self.shot_radius, self, self.shot_force, self.totalfrags, other);
213 entity vehicles_projectile(string _mzlfx, string _mzlsound,
214 vector _org, vector _vel,
215 float _dmg, float _radi, float _force, float _size,
216 float _deahtype, float _projtype, float _health)
222 PROJECTILE_MAKETRIGGER(proj);
223 setorigin(proj, _org);
225 proj.shot_dmg = _dmg;
226 proj.shot_radius = _radi;
227 proj.shot_force = _force;
228 proj.totalfrags = _deahtype;
229 proj.solid = SOLID_BBOX;
230 proj.movetype = MOVETYPE_FLYMISSILE;
231 proj.flags = FL_PROJECTILE;
232 proj.bot_dodge = TRUE;
233 proj.bot_dodgerating = _dmg;
234 proj.velocity = _vel;
235 proj.touch = vehicles_projectile_explode;
236 proj.use = vehicles_projectile_explode;
238 proj.realowner = self.owner;
239 proj.think = SUB_Remove;
240 proj.nextthink = time + 30;
244 proj.takedamage = DAMAGE_AIM;
245 proj.event_damage = vehicles_projectile_damage;
246 proj.health = _health;
249 proj.flags = FL_PROJECTILE | FL_NOTARGET;
252 sound (self, CHAN_WEAPON, _mzlsound, VOL_BASE, ATTN_NORM);
255 pointparticles(particleeffectnum(_mzlfx), proj.origin, proj.velocity, 1);
258 setsize (proj, '-1 -1 -1' * _size, '1 1 1' * _size);
260 CSQCProjectile(proj, TRUE, _projtype, TRUE);
265 void vehicles_spawn()
267 dprint("Spawning vehicle: ", self.netname, "\n");
270 self.vehicle_hudmodel.viewmodelforclient = self;
273 self.touch = vehicles_touch;
274 self.event_damage = vehicles_damage;
275 self.iscreature = TRUE;
276 self.movetype = MOVETYPE_WALK;
277 self.solid = SOLID_SLIDEBOX;
278 self.takedamage = DAMAGE_AIM;
279 self.deadflag = DEAD_NO;
280 self.bot_attack = TRUE;
281 self.flags = FL_NOTARGET;
282 self.avelocity = '0 0 0';
285 self.lock_strength = 0;
286 self.lock_target = world;
287 self.misc_bulletcounter = 0;
290 self.angles = self.pos2;
291 setorigin(self, self.pos1 + '0 0 128');
293 pointparticles(particleeffectnum("teleport"), self.origin + '0 0 64', '0 0 0', 1);
295 vehicles_reset_colors();
296 self.vehicle_spawn();
299 // Better way of determening whats crushable needed! (fl_crushable?)
300 float vehicles_crushable(entity e)
302 if(e.classname == "player")
305 if(e.classname == "monster_zombie")
311 void vehicles_touch()
313 // Vehicle currently in use
316 // Colided with world?
319 // Apply velocity based self damage here
323 if(other.vehicle_flags & VHF_ISVEHICLE)
325 //other.velocity += self.velocity * (self.mass / other.mass);
327 else if(vehicles_crushable(other))
329 if(vlen(self.velocity) != 0)
330 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);
336 if(other.classname != "player")
339 if(other.deadflag != DEAD_NO)
342 if(other.vehicle != world)
345 // Remove this when bots know how to use vehicles.
346 if (clienttype(other) != CLIENTTYPE_REAL)
352 void vehicles_enter()
354 // Remove this when bots know how to use vehicles
355 if (clienttype(other) != CLIENTTYPE_REAL)
358 if(self.phase > time)
363 if(self.team != other.team)
366 self.vehicle_ammo1 = 0;
367 self.vehicle_ammo2 = 0;
368 self.vehicle_reload1 = 0;
369 self.vehicle_reload2 = 0;
370 self.vehicle_energy = 0;
373 self.switchweapon = other.switchweapon;
375 // .viewmodelforclient works better.
376 //self.vehicle_hudmodel.drawonlytoclient = self.owner;
378 self.vehicle_hudmodel.viewmodelforclient = self.owner;
380 self.event_damage = vehicles_damage;
382 self.owner.angles = self.angles;
383 self.owner.takedamage = DAMAGE_NO;
384 self.owner.solid = SOLID_NOT;
385 self.owner.movetype = MOVETYPE_NOCLIP;
386 self.owner.alpha = -1;
387 self.owner.vehicle = self;
388 self.owner.event_damage = SUB_Null;
389 self.owner.view_ofs = '0 0 0';
390 self.colormap = self.owner.colormap;
392 self.tur_head.colormap = self.owner.colormap;
394 self.owner.hud = self.hud;
395 self.owner.PlayerPhysplug = self.PlayerPhysplug;
397 self.owner.vehicle_ammo1 = self.vehicle_ammo1;
398 self.owner.vehicle_ammo2 = self.vehicle_ammo2;
399 self.owner.vehicle_reload1 = self.vehicle_reload1;
400 self.owner.vehicle_reload2 = self.vehicle_reload2;
402 // Cnnt do this, hides attached objects too.
403 //self.exteriormodeltoclient = self.owner;
404 //self.tur_head.exteriormodeltoclient = self.owner;
406 other.flags &~= FL_ONGROUND;
407 self.flags &~= FL_ONGROUND;
409 self.team = self.owner.team;
410 self.flags -= FL_NOTARGET;
413 WriteByte (MSG_ONE, SVC_SETVIEWPORT);
414 WriteEntity(MSG_ONE, self.vehicle_viewport);
416 WriteByte (MSG_ONE, SVC_SETVIEWANGLES);
419 WriteAngle(MSG_ONE, self.tur_head.angles_x + self.angles_x); // tilt
420 WriteAngle(MSG_ONE, self.tur_head.angles_y + self.angles_y); // yaw
421 WriteAngle(MSG_ONE, 0); // roll
425 WriteByte (MSG_ONE, SVC_SETVIEWANGLES);
426 WriteAngle(MSG_ONE, self.angles_x * -1); // tilt
427 WriteAngle(MSG_ONE, self.angles_y); // yaw
428 WriteAngle(MSG_ONE, 0); // roll
431 vehicles_clearrturn();
433 CSQCVehicleSetup(self.owner, self.hud);
435 self.vehicle_enter();
438 void vehicles_exit(float eject)
440 self.flags |= FL_NOTARGET;
444 msg_entity = self.owner;
445 WriteByte (MSG_ONE, SVC_SETVIEWPORT);
446 WriteEntity( MSG_ONE, self.owner);
448 WriteByte (MSG_ONE, SVC_SETVIEWANGLES); // 10 = SVC_SETVIEWANGLES
449 WriteAngle(MSG_ONE, 0); // tilt
450 WriteAngle(MSG_ONE, self.angles_y); // yaw
451 WriteAngle(MSG_ONE, 0); // roll
453 setsize(self.owner, PL_MIN,PL_MAX);
455 self.owner.takedamage = DAMAGE_AIM;
456 self.owner.solid = SOLID_SLIDEBOX;
457 self.owner.movetype = MOVETYPE_WALK;
458 self.owner.effects &~= EF_NODRAW;
459 self.owner.alpha = 1;
460 self.owner.PlayerPhysplug = SUB_Null;
461 self.owner.vehicle = world;
462 self.owner.view_ofs = PL_VIEW_OFS;
463 self.owner.event_damage = PlayerDamage;
464 self.owner.hud = HUD_NORMAL;
465 self.owner.switchweapon = self.switchweapon;
466 self.owner.BUTTON_USE = 0;
469 if(self.deadflag == DEAD_NO)
470 self.avelocity = '0 0 0';
472 self.vehicle_hudmodel.viewmodelforclient = self;
473 self.tur_head.nodrawtoclient = world;
474 vehicles_setreturn();
476 self.phase = time + 1;
481 self.vehicle_exit(eject);
486 void vehicles_regen(.float timer, .float regen_field, float field_max, float rpause, float regen, float delta_time)
488 if(self.regen_field < field_max)
489 if(self.timer + rpause < time)
491 self.regen_field = min(self.regen_field + regen * delta_time, field_max);
494 self.owner.regen_field = self.regen_field / field_max;
498 void shieldhit_think()
503 //setmodel(self, "");
508 self.nextthink = time + 0.1;
512 void vehicles_damage(entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
514 self.dmg_time = time;
516 if((self.vehicle_flags & VHF_HASSHIELD) && (self.vehicle_shield > 0))
518 if (wasfreed(self.vehicle_shieldent) || self.vehicle_shieldent == world)
520 self.vehicle_shieldent = spawn();
521 self.vehicle_shieldent.effects = EF_LOWPRECISION;
523 setmodel(self.vehicle_shieldent, "models/vhshield.md3");
524 setattachment(self.vehicle_shieldent, self, "");
525 setorigin(self.vehicle_shieldent, real_origin(self) - self.origin);
526 self.vehicle_shieldent.scale = 256 / vlen(self.maxs - self.mins);
527 self.vehicle_shieldent.think = shieldhit_think;
531 self.vehicle_shieldent.colormod = '1 1 1';
532 self.vehicle_shieldent.alpha = 0.45;
533 self.vehicle_shieldent.angles = vectoangles(normalize(hitloc - (self.origin + self.vehicle_shieldent.origin))) - self.angles;
534 self.vehicle_shieldent.nextthink = time;
536 self.vehicle_shield -= damage;
538 if(self.vehicle_shield < 0)
540 self.vehicle_shieldent.colormod = '2 0 0';
541 self.vehicle_shield = 0;
542 self.vehicle_shieldent.alpha = 0.75;
543 self.vehicle_health -= fabs(self.vehicle_shield);
547 self.vehicle_health -= damage;
549 self.velocity += force; // * (vlen(force) / self.mass);
551 if(self.vehicle_health <= 0)
554 if(self.vehicle_flags & VHF_DEATHEJECT)
555 vehicles_exit(VHEF_EJECT);
557 vehicles_exit(VHEF_RELESE);
560 vehicles_setreturn();
564 void vehicles_return()
566 pointparticles(particleeffectnum("teleport"), self.enemy.origin + '0 0 64', '0 0 0', 1);
568 self.enemy.think = vehicles_spawn;
569 self.enemy.nextthink = time;
574 void vehicles_clearrturn()
577 // Remove "return helper", if any.
578 ret = findchain(classname, "vehicle_return");
581 if(ret.enemy == self)
584 ret.think = SUB_Remove;
585 ret.nextthink = time + 0.1;
593 void vehicles_setreturn()
597 vehicles_clearrturn();
600 ret.classname = "vehicle_return";
602 ret.think = vehicles_return;
603 ret.nextthink = time + self.vehicle_respawntime;
606 float vehicles_customizeentityforclient()
608 if(self.deadflag == DEAD_DEAD)
614 void vehicles_configcheck(string configname, float check_cvar)
617 localcmd(strcat("exec ", configname, "\n"));
620 void vehicles_reset_colors()
623 float _effects, _colormap;
624 vector _glowmod, _colormod;
626 if(autocvar_g_nodepthtestplayers)
627 _effects = EF_NODEPTHTEST;
629 if(autocvar_g_fullbrightplayers)
630 _effects |= EF_FULLBRIGHT;
633 _colormap = 1024 + (self.team - 1) * 17;
640 // Find all ents attacked to main model and setup effects, colormod etc.
641 e = findchainentity(tag_entity, self);
644 if(e != self.vehicle_shieldent)
646 e.effects = _effects;
647 e.colormod = _colormod;
648 e.colormap = _colormap;
654 self.vehicle_hudmodel.effects = self.effects = _effects;
655 self.vehicle_hudmodel.colormod = self.colormod = _colormod;
656 self.vehicle_hudmodel.colormap = self.colormap = _colormap;
659 self.avelocity = '0 0 0';
660 self.velocity = '0 0 0';
664 //#define VEHICLES_CSQC
669 #define VSF_COLORMAP 16
672 float SendVehicle(entity to, float sf)
674 WriteByte(MSG_ENTITY, ENT_CLIENT_VEHICLE_RACER);
676 WriteByte(MSG_ENTITY, self.cnt);
678 WriteCoord(MSG_ENTITY, self.origin_x);
679 WriteCoord(MSG_ENTITY, self.origin_y);
680 WriteCoord(MSG_ENTITY, self.origin_z);
682 WriteCoord(MSG_ENTITY, self.velocity_x);
683 WriteCoord(MSG_ENTITY, self.velocity_y);
684 WriteCoord(MSG_ENTITY, self.velocity_z);
686 WriteAngle(MSG_ENTITY, self.angles_x);
687 WriteAngle(MSG_ENTITY, self.angles_y);
688 WriteAngle(MSG_ENTITY, self.angles_z);
693 void NetLinkVehicle()
695 self.SendFlags = 0xFFFFFF;
696 Net_LinkEntity(self, FALSE, 0, SendVehicle);
700 float vehicle_initialize(string net_name,
715 void(float extflag) exitfunc,
719 addstat(STAT_HUD, AS_INT, hud);
720 addstat(STAT_VEHICLESTAT_HEALTH, AS_FLOAT, vehicle_health);
721 addstat(STAT_VEHICLESTAT_SHIELD, AS_FLOAT, vehicle_shield);
722 addstat(STAT_VEHICLESTAT_ENERGY, AS_FLOAT, vehicle_energy);
724 addstat(STAT_VEHICLESTAT_AMMO1, AS_INT, vehicle_ammo1);
725 addstat(STAT_VEHICLESTAT_RELOAD1, AS_FLOAT, vehicle_reload1);
727 addstat(STAT_VEHICLESTAT_AMMO2, AS_INT, vehicle_ammo2);
728 addstat(STAT_VEHICLESTAT_RELOAD2, AS_FLOAT, vehicle_reload2);
731 error("vehicles: missing bodymodel!");
734 error("vehicles: missing hudmodel!");
737 self.netname = self.classname;
739 self.netname = net_name;
741 if(self.team && !teams_matter)
744 self.vehicle_flags |= VHF_ISVEHICLE;
746 setmodel(self, bodymodel);
748 self.vehicle_viewport = spawn();
749 self.vehicle_hudmodel = spawn();
750 self.tur_head = spawn();
751 self.tur_head.owner = self;
752 self.takedamage = DAMAGE_AIM;
753 self.bot_attack = TRUE;
754 self.iscreature = TRUE;
757 //self.customizeentityforclient = vehicles_customizeentityforclient;
758 self.vehicle_die = dieproc;
759 self.vehicle_exit = exitfunc;
760 self.vehicle_enter = enterproc;
761 self.PlayerPhysplug = physproc;
762 self.event_damage = vehicles_damage;
763 self.touch = vehicles_touch;
764 self.think = vehicles_spawn;
765 self.nextthink = time;
766 self.vehicle_respawntime = _respawntime;
767 self.vehicle_spawn = spawnproc;
769 if(autocvar_g_nodepthtestplayers)
770 self.effects = self.effects | EF_NODEPTHTEST;
772 if(autocvar_g_fullbrightplayers)
773 self.effects = self.effects | EF_FULLBRIGHT;
775 setmodel(self.vehicle_hudmodel, hudmodel);
776 setmodel(self.vehicle_viewport, "null");
781 setmodel(self.tur_head, topmodel);
782 setattachment(self.tur_head, self, toptag);
783 setattachment(self.vehicle_hudmodel, self.tur_head, hudtag);
784 setattachment(self.vehicle_viewport, self.vehicle_hudmodel, viewtag);
788 setattachment(self.tur_head, self, "");
789 setattachment(self.vehicle_hudmodel, self, hudtag);
790 setattachment(self.vehicle_viewport, self.vehicle_hudmodel, viewtag);
793 setsize(self, min_s, max_s);
796 setorigin(self, self.origin);
797 tracebox(self.origin + '0 0 100', min_s, max_s, self.origin - '0 0 10000', MOVE_WORLDONLY, self);
798 setorigin(self, trace_endpos);
801 //self.vehicle_hudmodel.effects = EF_NODEPTHTEST;
802 self.pos1 = self.origin;
803 self.pos2 = self.angles;
811 self.vehicle_exit = self.vehicle_exit;
812 self.vehicle_enter = self.vehicle_exit;
813 self.vehicle_die = self.vehicle_exit;
814 self.vehicle_spawn = self.vehicle_exit;
815 self.AuxiliaryXhair = self.AuxiliaryXhair;