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;
139 #define VEHICLE_UPDATE_PLAYER(fld,vhname) \
140 self.owner.vehicle_##fld = self.vehicle_##fld / autocvar_g_vehicle_##vhname##_##fld
142 #define vehicles_sweap_collision(orig,vel,dt,acm,mult) \
143 traceline(orig, orig + vel * dt, MOVE_NORMAL, self); \
144 if(trace_fraction != 1) \
145 acm += normalize(self.origin - trace_endpos) * (vlen(vel) * mult)
147 float force_fromtag_power;
148 float force_fromtag_normpower;
149 vector force_fromtag_origin;
150 vector vehicles_force_fromtag_hover(string tag_name, float spring_length, float max_power)
152 force_fromtag_origin = gettaginfo(self, gettagindex(self, tag_name));
153 v_forward = normalize(v_forward) * -1;
154 traceline(force_fromtag_origin, force_fromtag_origin - (v_forward * spring_length), MOVE_NORMAL, self);
156 force_fromtag_power = (1 - trace_fraction) * max_power;
157 force_fromtag_normpower = force_fromtag_power / max_power;
159 return v_forward * force_fromtag_power;
162 vector vehicles_force_fromtag_maglev(string tag_name, float spring_length, float max_power)
165 force_fromtag_origin = gettaginfo(self, gettagindex(self, tag_name));
166 v_forward = normalize(v_forward) * -1;
167 traceline(force_fromtag_origin, force_fromtag_origin - (v_forward * spring_length), MOVE_NORMAL, self);
169 if(trace_fraction == 1.0)
171 force_fromtag_normpower = -0.25;
175 force_fromtag_power = ((1 - trace_fraction) - trace_fraction) * max_power;
176 force_fromtag_normpower = force_fromtag_power / max_power;
178 return v_forward * force_fromtag_power;
181 void vehicles_projectile_damage(entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
183 self.health -= damage;
184 self.velocity += force;
187 self.takedamage = DAMAGE_NO;
188 self.event_damage = SUB_Null;
189 self.think = self.use;
190 self.nextthink = time;
195 void vehicles_projectile_explode()
197 if(self.owner && other != world)
199 if(other == self.owner.vehicle)
202 if(other == self.owner.vehicle.tur_head)
208 self.event_damage = SUB_Null;
209 sound (self, CHAN_PROJECTILE, self.target2, VOL_BASE, ATTN_NORM);
210 pointparticles(particleeffectnum(self.target3), findbetterlocation (self.origin, 16), '0 0 0', 1);
211 RadiusDamage (self, self.realowner, self.shot_dmg, 0, self.shot_radius, self, self.shot_force, self.totalfrags, other);
216 entity vehicles_projectile(string _impactfx, string _impactsnd, string _mzlfx, string _mzlsound,
217 vector _org, vector _vel,
218 float _dmg, float _radi, float _force, float _size,
219 float _deahtype, float _projtype, float _health)
225 PROJECTILE_MAKETRIGGER(proj);
226 setorigin(proj, _org);
228 proj.shot_dmg = _dmg;
229 proj.shot_radius = _radi;
230 proj.shot_force = _force;
231 proj.totalfrags = _deahtype;
232 proj.target2 = _impactsnd;
233 proj.target3 = _impactfx;
234 proj.solid = SOLID_BBOX;
235 proj.movetype = MOVETYPE_FLYMISSILE;
236 proj.flags = FL_PROJECTILE;
237 proj.bot_dodge = TRUE;
238 proj.bot_dodgerating = _dmg;
239 proj.velocity = _vel;
240 proj.touch = vehicles_projectile_explode;
241 proj.use = vehicles_projectile_explode;
243 proj.realowner = self.owner;
244 proj.think = SUB_Remove;
245 proj.nextthink = time + 30;
249 proj.takedamage = DAMAGE_AIM;
250 proj.event_damage = vehicles_projectile_damage;
251 proj.health = _health;
254 proj.flags = FL_PROJECTILE | FL_NOTARGET;
257 sound (self, CHAN_WEAPON, _mzlsound, VOL_BASE, ATTN_NORM);
260 pointparticles(particleeffectnum(_mzlfx), proj.origin, proj.velocity, 1);
263 setsize (proj, '-1 -1 -1' * _size, '1 1 1' * _size);
265 CSQCProjectile(proj, TRUE, _projtype, TRUE);
270 void vehicles_spawn()
272 dprint("Spawning vehicle: ", self.netname, "\n");
275 self.vehicle_hudmodel.viewmodelforclient = self;
277 self.touch = vehicles_touch;
278 self.event_damage = vehicles_damage;
279 self.iscreature = TRUE;
280 self.movetype = MOVETYPE_WALK;
281 self.solid = SOLID_SLIDEBOX;
282 self.takedamage = DAMAGE_AIM;
283 self.deadflag = DEAD_NO;
284 self.bot_attack = TRUE;
285 self.flags = FL_NOTARGET;
286 self.avelocity = '0 0 0';
289 self.lock_strength = 0;
290 self.lock_target = world;
291 self.misc_bulletcounter = 0;
294 self.angles = self.pos2;
295 setorigin(self, self.pos1 + '0 0 128');
297 pointparticles(particleeffectnum("teleport"), self.origin + '0 0 64', '0 0 0', 1);
299 vehicles_reset_colors();
300 self.vehicle_spawn();
303 // Better way of determening whats crushable needed! (fl_crushable?)
304 float vehicles_crushable(entity e)
306 if(e.classname == "player")
309 if(e.classname == "monster_zombie")
315 void vehicles_touch()
317 // Vehicle currently in use
320 // Colided with world?
323 // Apply velocity based self damage here
327 if(other.vehicle_flags & VHF_ISVEHICLE)
329 //other.velocity += self.velocity * (self.mass / other.mass);
331 else if(vehicles_crushable(other))
333 if(vlen(self.velocity) != 0)
334 Damage(other, self, self.owner, autocvar_g_vehicles_crush_dmg, DEATH_SBCRUSH, '0 0 0', normalize(other.origin - self.origin) * autocvar_g_vehicles_crush_force);
340 if(other.classname != "player")
343 if(other.deadflag != DEAD_NO)
346 if(other.vehicle != world)
349 // Remove this when bots know how to use vehicles.
350 if (clienttype(other) != CLIENTTYPE_REAL)
356 void vehicles_enter()
358 // Remove this when bots know how to use vehicles
359 if (clienttype(other) != CLIENTTYPE_REAL)
362 if(self.phase > time)
367 if(self.team != other.team)
370 self.vehicle_ammo1 = 0;
371 self.vehicle_ammo2 = 0;
372 self.vehicle_reload1 = 0;
373 self.vehicle_reload2 = 0;
374 self.vehicle_energy = 0;
377 self.switchweapon = other.switchweapon;
379 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 other.flags &~= FL_ONGROUND;
403 self.flags &~= FL_ONGROUND;
405 self.team = self.owner.team;
406 self.flags -= FL_NOTARGET;
409 WriteByte (MSG_ONE, SVC_SETVIEWPORT);
410 WriteEntity(MSG_ONE, self.vehicle_viewport);
412 WriteByte (MSG_ONE, SVC_SETVIEWANGLES); // 10 = SVC_SETVIEWANGLES
415 WriteAngle(MSG_ONE, self.tur_head.angles_x + self.angles_x); // tilt
416 WriteAngle(MSG_ONE, self.tur_head.angles_y + self.angles_y); // yaw
417 WriteAngle(MSG_ONE, 0); // roll
421 WriteByte (MSG_ONE, SVC_SETVIEWANGLES); // 10 = SVC_SETVIEWANGLES
422 WriteAngle(MSG_ONE, self.angles_x * -1); // tilt
423 WriteAngle(MSG_ONE, self.angles_y); // yaw
424 WriteAngle(MSG_ONE, 0); // roll
427 vehicles_clearrturn();
429 CSQCVehicleSetup(self.owner, self.hud);
431 self.vehicle_enter();
434 void vehicles_exit(float eject)
436 self.flags |= FL_NOTARGET;
440 msg_entity = self.owner;
441 WriteByte (MSG_ONE, SVC_SETVIEWPORT);
442 WriteEntity( MSG_ONE, self.owner);
444 WriteByte (MSG_ONE, SVC_SETVIEWANGLES); // 10 = SVC_SETVIEWANGLES
445 WriteAngle(MSG_ONE, 0); // tilt
446 WriteAngle(MSG_ONE, self.angles_y); // yaw
447 WriteAngle(MSG_ONE, 0); // roll
449 setsize(self.owner, PL_MIN,PL_MAX);
451 self.owner.takedamage = DAMAGE_AIM;
452 self.owner.solid = SOLID_SLIDEBOX;
453 self.owner.movetype = MOVETYPE_WALK;
454 self.owner.effects &~= EF_NODRAW;
455 self.owner.alpha = 1;
456 self.owner.PlayerPhysplug = SUB_Null;
457 self.owner.vehicle = world;
458 self.owner.view_ofs = PL_VIEW_OFS;
459 self.owner.event_damage = PlayerDamage;
460 self.owner.hud = HUD_NORMAL;
461 self.owner.switchweapon = self.switchweapon;
462 self.owner.BUTTON_USE = 0;
465 if(self.deadflag == DEAD_NO)
466 self.avelocity = '0 0 0';
468 self.vehicle_hudmodel.viewmodelforclient = self;
469 self.tur_head.nodrawtoclient = self;
470 vehicles_setreturn();
472 self.phase = time + 1;
477 self.vehicle_exit(eject);
482 void vehicles_regen(.float timer, .float regen_field, float field_max, float rpause, float regen, float delta_time)
484 if(self.regen_field < field_max)
485 if(self.timer + rpause < time)
487 self.regen_field = min(self.regen_field + regen * delta_time, field_max);
490 self.owner.regen_field = self.regen_field / field_max;
494 void shieldhit_think()
504 self.nextthink = time + 0.1;
508 void vehicles_damage(entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
512 self.dmg_time = time;
514 if((self.vehicle_flags & VHF_HASSHIELD) && (self.vehicle_shield > 0))
516 if (wasfreed(self.tur_head.enemy) || self.tur_head.enemy == world)
518 self.tur_head.enemy = spawn();
519 self.tur_head.enemy.effects = EF_LOWPRECISION;
522 setmodel(self.tur_head.enemy, "models/vhshield.md3");
523 setattachment(self.tur_head.enemy, self, "");
525 self.tur_head.enemy.colormod = '1 1 1';
526 self.tur_head.enemy.alpha = 0.45;
527 self.tur_head.enemy.scale = 256 / vlen(self.maxs - self.mins);
528 self.tur_head.enemy.angles = vectoangles(normalize(hitloc - self.origin)) - self.angles;
529 self.tur_head.enemy.think = shieldhit_think;
530 self.tur_head.enemy.nextthink = time;
532 self.vehicle_shield -= damage;
533 if(self.vehicle_shield < 0)
535 self.tur_head.enemy.colormod = '2 0 0';
536 ddmg_take = fabs(self.vehicle_shield);
537 self.vehicle_shield = 0;
538 self.tur_head.enemy.alpha = 0.75;
539 self.vehicle_health -= ddmg_take;
543 self.vehicle_health -= damage;
545 self.velocity += force; // * (vlen(force) / self.mass);
547 if(self.vehicle_health <= 0)
550 if(self.vehicle_flags & VHF_DEATHEJECT)
551 vehicles_exit(VHEF_EJECT);
553 vehicles_exit(VHEF_RELESE);
556 vehicles_setreturn();
560 void vehicles_return()
562 pointparticles(particleeffectnum("teleport"), self.enemy.origin + '0 0 64', '0 0 0', 1);
564 self.enemy.think = vehicles_spawn;
565 self.enemy.nextthink = time;
570 void vehicles_clearrturn()
573 // Remove "return helper", if any.
574 ret = findchain(classname, "vehicle_return");
577 if(ret.enemy == self)
580 ret.think = SUB_Remove;
581 ret.nextthink = time + 0.1;
589 void vehicles_setreturn()
593 vehicles_clearrturn();
596 ret.classname = "vehicle_return";
598 ret.think = vehicles_return;
599 ret.nextthink = time + self.vehicle_respawntime;
602 float vehicles_customizeentityforclient()
604 if(self.deadflag == DEAD_DEAD)
610 void vehicles_configcheck(string configname, float check_cvar)
613 localcmd(strcat("exec ", configname, "\n"));
616 void vehicles_reset_colors()
619 float _effects, _colormap;
620 vector _glowmod, _colormod;
622 if(autocvar_g_nodepthtestplayers)
623 _effects = EF_NODEPTHTEST;
625 if(autocvar_g_fullbrightplayers)
626 _effects |= EF_FULLBRIGHT;
629 _colormap = 1024 + (self.team - 1) * 17;
636 // Find all ents attacked to main model and setup effects, colormod etc.
637 e = findchainentity(tag_entity, self);
640 e.effects = _effects;
641 e.colormod = _colormod;
642 e.colormap = _colormap;
649 self.vehicle_hudmodel.effects = self.effects = _effects;
650 self.vehicle_hudmodel.colormod = self.colormod = _colormod;
651 self.vehicle_hudmodel.colormap = self.colormap = _colormap;
654 self.avelocity = '0 0 0';
655 self.velocity = '0 0 0';
659 float vehicle_initialize(string net_name,
674 void(float extflag) exitfunc,
678 addstat(STAT_HUD, AS_INT, hud);
679 addstat(STAT_VEHICLESTAT_HEALTH, AS_FLOAT, vehicle_health);
680 addstat(STAT_VEHICLESTAT_SHIELD, AS_FLOAT, vehicle_shield);
681 addstat(STAT_VEHICLESTAT_ENERGY, AS_FLOAT, vehicle_energy);
683 addstat(STAT_VEHICLESTAT_AMMO1, AS_INT, vehicle_ammo1);
684 addstat(STAT_VEHICLESTAT_RELOAD1, AS_FLOAT, vehicle_reload1);
686 addstat(STAT_VEHICLESTAT_AMMO2, AS_INT, vehicle_ammo2);
687 addstat(STAT_VEHICLESTAT_RELOAD2, AS_FLOAT, vehicle_reload2);
690 error("vehicles: missing bodymodel!");
693 error("vehicles: missing hudmodel!");
696 self.netname = self.classname;
698 self.netname = net_name;
700 if(self.team && !teams_matter)
703 self.vehicle_flags |= VHF_ISVEHICLE;
705 setmodel(self, bodymodel);
707 self.vehicle_viewport = spawn();
708 self.vehicle_hudmodel = spawn();
709 self.tur_head = spawn();
710 self.tur_head.owner = self;
711 self.takedamage = DAMAGE_AIM;
712 self.bot_attack = TRUE;
713 self.iscreature = TRUE;
716 self.customizeentityforclient = vehicles_customizeentityforclient;
717 self.vehicle_die = dieproc;
718 self.vehicle_exit = exitfunc;
719 self.vehicle_enter = enterproc;
720 self.PlayerPhysplug = physproc;
721 self.event_damage = vehicles_damage;
722 self.touch = vehicles_touch;
723 self.think = vehicles_spawn;
724 self.nextthink = time;
725 self.vehicle_respawntime = _respawntime;
726 self.vehicle_spawn = spawnproc;
728 if(autocvar_g_nodepthtestplayers)
729 self.effects = self.effects | EF_NODEPTHTEST;
731 if(autocvar_g_fullbrightplayers)
732 self.effects = self.effects | EF_FULLBRIGHT;
734 setmodel(self.vehicle_hudmodel, hudmodel);
735 setmodel(self.vehicle_viewport, "null");
740 setmodel(self.tur_head, topmodel);
741 setattachment(self.tur_head, self, toptag);
742 setattachment(self.vehicle_hudmodel, self.tur_head, hudtag);
743 setattachment(self.vehicle_viewport, self.vehicle_hudmodel, viewtag);
747 setattachment(self.tur_head, self, "");
748 setattachment(self.vehicle_hudmodel, self, hudtag);
749 setattachment(self.vehicle_viewport, self.vehicle_hudmodel, viewtag);
752 setsize(self, min_s, max_s);
755 setorigin(self, self.origin);
756 tracebox(self.origin + '0 0 100', min_s, max_s, self.origin - '0 0 10000', MOVE_WORLDONLY, self);
757 setorigin(self, trace_endpos);
760 self.pos1 = self.origin;
761 self.pos2 = self.angles;
769 self.vehicle_exit = self.vehicle_exit;
770 self.vehicle_enter = self.vehicle_exit;
771 self.vehicle_die = self.vehicle_exit;
772 self.vehicle_spawn = self.vehicle_exit;
773 self.AuxiliaryXhair = self.AuxiliaryXhair;