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(trace_ent != world)
102 if(teams_matter && trace_ent.team == self.team)
105 if(trace_ent.deadflag != DEAD_NO)
108 if not (trace_ent.vehicle_flags & VHF_ISVEHICLE || trace_ent.turrcaps_flags & TFL_TURRCAPS_ISTURRET)
112 if(self.lock_time > time)
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;
128 self.lock_strength = max(self.lock_strength - decr, 0);
130 if(self.lock_strength == 0)
131 self.lock_target = world;
136 #define VEHICLE_UPDATE_PLAYER(fld,vhname) \
137 self.owner.vehicle_##fld = self.vehicle_##fld / autocvar_g_vehicle_##vhname##_##fld
139 #define vehicles_sweap_collision(orig,vel,dt,acm,mult) \
140 traceline(orig, orig + vel * dt, MOVE_NORMAL, self); \
141 if(trace_fraction != 1) \
142 acm += normalize(self.origin - trace_endpos) * (vlen(vel) * mult)
144 float force_fromtag_power;
145 float force_fromtag_normpower;
146 vector force_fromtag_origin;
147 vector vehicles_force_fromtag_hover(string tag_name, float spring_length, float max_power)
149 force_fromtag_origin = gettaginfo(self, gettagindex(self, tag_name));
150 v_forward = normalize(v_forward) * -1;
151 traceline(force_fromtag_origin, force_fromtag_origin - (v_forward * spring_length), MOVE_NORMAL, self);
153 force_fromtag_power = (1 - trace_fraction) * max_power;
154 force_fromtag_normpower = force_fromtag_power / max_power;
156 return v_forward * force_fromtag_power;
159 vector vehicles_force_fromtag_maglev(string tag_name, float spring_length, float max_power)
162 force_fromtag_origin = gettaginfo(self, gettagindex(self, tag_name));
163 v_forward = normalize(v_forward) * -1;
164 traceline(force_fromtag_origin, force_fromtag_origin - (v_forward * spring_length), MOVE_NORMAL, self);
166 if(trace_fraction == 1.0)
168 force_fromtag_normpower = -0.25;
172 force_fromtag_power = ((1 - trace_fraction) - trace_fraction) * max_power;
173 force_fromtag_normpower = force_fromtag_power / max_power;
175 return v_forward * force_fromtag_power;
180 void vehicles_spawn()
182 dprint("Spawning vehicle: ", self.netname, "\n");
185 self.vehicle_hudmodel.viewmodelforclient = self;
187 self.touch = vehicles_touch;
188 self.event_damage = vehicles_damage;
189 self.iscreature = TRUE;
190 self.movetype = MOVETYPE_WALK;
191 self.solid = SOLID_SLIDEBOX;
192 self.takedamage = DAMAGE_AIM;
193 self.deadflag = DEAD_NO;
194 self.bot_attack = TRUE;
195 self.flags = FL_NOTARGET;
196 self.avelocity = '0 0 0';
199 self.lock_strength = 0;
200 self.lock_target = world;
201 self.misc_bulletcounter = 0;
204 self.angles = self.pos2;
205 setorigin(self, self.pos1 + '0 0 128');
207 pointparticles(particleeffectnum("teleport"), self.origin + '0 0 64', '0 0 0', 1);
209 vehicles_reset_colors();
210 self.vehicle_spawn();
213 // Better way of determening whats crushable needed! (fl_crushable?)
214 float vehicles_crushable(entity e)
216 if(e.classname == "player")
219 if(e.classname == "monster_zombie")
225 void vehicles_touch()
227 // Vehicle currently in use
230 // Colided with world?
233 // Apply velocity based self damage here
237 if(other.vehicle_flags & VHF_ISVEHICLE)
239 //other.velocity += self.velocity * (self.mass / other.mass);
241 else if(vehicles_crushable(other))
243 if(vlen(self.velocity) != 0)
244 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);
251 if(other.classname != "player")
254 if(other.deadflag != DEAD_NO)
257 if(other.vehicle != world)
260 // Remove this when bots know how to use vehicles.
261 if (clienttype(other) != CLIENTTYPE_REAL)
267 void vehicles_enter()
269 // Remove this when bots know how to use vehicles
270 if (clienttype(other) != CLIENTTYPE_REAL)
273 if(self.phase > time)
278 if(self.team != other.team)
281 self.vehicle_ammo1 = 0;
282 self.vehicle_ammo2 = 0;
283 self.vehicle_reload1 = 0;
284 self.vehicle_reload2 = 0;
285 self.vehicle_energy = 0;
288 self.switchweapon = other.switchweapon;
290 self.vehicle_hudmodel.viewmodelforclient = self.owner;
291 self.event_damage = vehicles_damage;
293 self.owner.angles = self.angles;
294 self.owner.takedamage = DAMAGE_NO;
295 self.owner.solid = SOLID_NOT;
296 self.owner.movetype = MOVETYPE_NOCLIP;
297 self.owner.alpha = -1;
298 self.owner.vehicle = self;
299 self.owner.event_damage = SUB_Null;
300 self.owner.view_ofs = '0 0 0';
301 self.colormap = self.owner.colormap;
303 self.tur_head.colormap = self.owner.colormap;
305 self.owner.hud = self.hud;
306 self.owner.PlayerPhysplug = self.PlayerPhysplug;
308 self.owner.vehicle_ammo1 = self.vehicle_ammo1;
309 self.owner.vehicle_ammo2 = self.vehicle_ammo2;
310 self.owner.vehicle_reload1 = self.vehicle_reload1;
311 self.owner.vehicle_reload2 = self.vehicle_reload2;
313 other.flags &~= FL_ONGROUND;
314 self.flags &~= FL_ONGROUND;
316 self.team = self.owner.team;
317 self.flags -= FL_NOTARGET;
320 WriteByte (MSG_ONE, SVC_SETVIEWPORT);
321 WriteEntity(MSG_ONE, self.vehicle_viewport);
323 WriteByte (MSG_ONE, SVC_SETVIEWANGLES); // 10 = SVC_SETVIEWANGLES
326 WriteAngle(MSG_ONE, self.tur_head.angles_x + self.angles_x); // tilt
327 WriteAngle(MSG_ONE, self.tur_head.angles_y + self.angles_y); // yaw
328 WriteAngle(MSG_ONE, 0); // roll
332 WriteByte (MSG_ONE, SVC_SETVIEWANGLES); // 10 = SVC_SETVIEWANGLES
333 WriteAngle(MSG_ONE, self.angles_x * -1); // tilt
334 WriteAngle(MSG_ONE, self.angles_y); // yaw
335 WriteAngle(MSG_ONE, 0); // roll
338 vehicles_clearrturn();
340 CSQCVehicleSetup(self.owner, self.hud);
342 self.vehicle_enter();
345 void vehicles_exit(float eject)
347 self.flags |= FL_NOTARGET;
351 msg_entity = self.owner;
352 WriteByte (MSG_ONE, SVC_SETVIEWPORT);
353 WriteEntity( MSG_ONE, self.owner);
355 WriteByte (MSG_ONE, SVC_SETVIEWANGLES); // 10 = SVC_SETVIEWANGLES
356 WriteAngle(MSG_ONE, 0); // tilt
357 WriteAngle(MSG_ONE, self.angles_y); // yaw
358 WriteAngle(MSG_ONE, 0); // roll
360 setsize(self.owner, PL_MIN,PL_MAX);
362 self.owner.takedamage = DAMAGE_AIM;
363 self.owner.solid = SOLID_SLIDEBOX;
364 self.owner.movetype = MOVETYPE_WALK;
365 self.owner.effects &~= EF_NODRAW;
366 self.owner.alpha = 1;
367 self.owner.PlayerPhysplug = SUB_Null;
368 self.owner.vehicle = world;
369 self.owner.view_ofs = PL_VIEW_OFS;
370 self.owner.event_damage = PlayerDamage;
371 self.owner.hud = HUD_NORMAL;
372 self.owner.switchweapon = self.switchweapon;
375 if(self.deadflag == DEAD_NO)
376 self.avelocity = '0 0 0';
378 self.vehicle_hudmodel.viewmodelforclient = self;
379 self.tur_head.nodrawtoclient = self;
380 vehicles_setreturn();
382 self.phase = time + 1;
387 self.vehicle_exit(eject);
392 void vehicles_regen(.float timer, .float regen_field, float field_max, float rpause, float regen, float delta_time)
394 if(self.regen_field < field_max)
395 if(self.timer + rpause < time)
397 self.regen_field = min(self.regen_field + regen * delta_time, field_max);
400 self.owner.regen_field = self.regen_field / field_max;
404 void shieldhit_think()
414 self.nextthink = time + 0.1;
418 void vehicles_damage(entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
422 self.dmg_time = time;
424 if((self.vehicle_flags & VHF_HASSHIELD) && (self.vehicle_shield > 0))
426 if (wasfreed(self.tur_head.enemy) || self.tur_head.enemy == world)
428 self.tur_head.enemy = spawn();
429 self.tur_head.enemy.effects = EF_LOWPRECISION;
432 setmodel(self.tur_head.enemy, "models/vhshield.md3");
433 setattachment(self.tur_head.enemy, self, "");
435 self.tur_head.enemy.colormod = '1 1 1';
436 self.tur_head.enemy.alpha = 0.45;
437 self.tur_head.enemy.scale = 256 / vlen(self.maxs - self.mins);
438 self.tur_head.enemy.angles = vectoangles(normalize(hitloc - self.origin)) - self.angles;
439 self.tur_head.enemy.think = shieldhit_think;
440 self.tur_head.enemy.nextthink = time;
442 self.vehicle_shield -= damage;
443 if(self.vehicle_shield < 0)
445 self.tur_head.enemy.colormod = '2 0 0';
446 ddmg_take = fabs(self.vehicle_shield);
447 self.vehicle_shield = 0;
448 self.tur_head.enemy.alpha = 0.75;
449 self.vehicle_health -= ddmg_take;
453 self.vehicle_health -= damage;
455 self.velocity += force; // * (vlen(force) / self.mass);
457 if(self.vehicle_health <= 0)
460 if(self.vehicle_flags & VHF_DEATHEJECT)
461 vehicles_exit(VHEF_EJECT);
463 vehicles_exit(VHEF_RELESE);
466 vehicles_setreturn();
470 void vehicles_return()
472 pointparticles(particleeffectnum("teleport"), self.enemy.origin + '0 0 64', '0 0 0', 1);
474 self.enemy.think = vehicles_spawn;
475 self.enemy.nextthink = time;
480 void vehicles_clearrturn()
483 // Remove "return helper", if any.
484 ret = findchain(classname, "vehicle_return");
487 if(ret.enemy == self)
490 ret.think = SUB_Remove;
491 ret.nextthink = time + 0.1;
499 void vehicles_setreturn()
503 vehicles_clearrturn();
506 ret.classname = "vehicle_return";
508 ret.think = vehicles_return;
509 ret.nextthink = time + self.vehicle_respawntime;
512 float vehicles_customizeentityforclient()
514 if(self.deadflag == DEAD_DEAD)
520 void vehicles_configcheck(string configname, float check_cvar)
523 localcmd(strcat("exec ", configname, "\n"));
526 void vehicles_reset_colors()
529 float _effects, _colormap;
530 vector _glowmod, _colormod;
532 if(autocvar_g_nodepthtestplayers)
533 _effects = EF_NODEPTHTEST;
535 if(autocvar_g_fullbrightplayers)
536 _effects |= EF_FULLBRIGHT;
539 _colormap = 1024 + (self.team - 1) * 17;
546 // Find all ents attacked to main model and setup effects, colormod etc.
547 e = findchainentity(tag_entity, self);
550 e.effects = _effects;
551 e.colormod = _colormod;
552 e.colormap = _colormap;
558 self.effects = _effects;
559 self.colormod = _colormod;
560 self.colormap = _colormap;
563 self.avelocity = '0 0 0';
564 self.velocity = '0 0 0';
568 float vehicle_initialize(string net_name,
583 void(float extflag) exitfunc,
587 addstat(STAT_HUD, AS_INT, hud);
588 addstat(STAT_VEHICLESTAT_HEALTH, AS_FLOAT, vehicle_health);
589 addstat(STAT_VEHICLESTAT_SHIELD, AS_FLOAT, vehicle_shield);
590 addstat(STAT_VEHICLESTAT_ENERGY, AS_FLOAT, vehicle_energy);
592 addstat(STAT_VEHICLESTAT_AMMO1, AS_INT, vehicle_ammo1);
593 addstat(STAT_VEHICLESTAT_RELOAD1, AS_FLOAT, vehicle_reload1);
595 addstat(STAT_VEHICLESTAT_AMMO2, AS_INT, vehicle_ammo2);
596 addstat(STAT_VEHICLESTAT_RELOAD2, AS_FLOAT, vehicle_reload2);
600 error("vehicles: missing bodymodel!");
603 error("vehicles: missing hudmodel!");
606 self.netname = self.classname;
608 self.netname = net_name;
610 if(self.team && !teams_matter)
613 self.vehicle_flags |= VHF_ISVEHICLE;
615 setmodel(self, bodymodel);
617 self.vehicle_viewport = spawn();
618 self.vehicle_hudmodel = spawn();
619 self.tur_head = spawn();
620 self.tur_head.owner = self;
621 self.takedamage = DAMAGE_AIM;
622 self.bot_attack = TRUE;
623 self.iscreature = TRUE;
626 self.customizeentityforclient = vehicles_customizeentityforclient;
627 self.vehicle_die = dieproc;
628 self.vehicle_exit = exitfunc;
629 self.vehicle_enter = enterproc;
630 self.PlayerPhysplug = physproc;
631 self.event_damage = vehicles_damage;
632 self.touch = vehicles_touch;
633 self.think = vehicles_spawn;
634 self.nextthink = time;
635 self.vehicle_respawntime = _respawntime;
636 self.vehicle_spawn = spawnproc;
638 if(autocvar_g_nodepthtestplayers)
639 self.effects = self.effects | EF_NODEPTHTEST;
641 if(autocvar_g_fullbrightplayers)
642 self.effects = self.effects | EF_FULLBRIGHT;
644 setmodel(self.vehicle_hudmodel, hudmodel);
645 setmodel(self.vehicle_viewport, "null");
650 setmodel(self.tur_head, topmodel);
651 setattachment(self.tur_head, self, toptag);
652 setattachment(self.vehicle_hudmodel, self.tur_head, hudtag);
653 setattachment(self.vehicle_viewport, self.vehicle_hudmodel, viewtag);
657 setattachment(self.tur_head, self, "");
658 setattachment(self.vehicle_hudmodel, self, hudtag);
659 setattachment(self.vehicle_viewport, self.vehicle_hudmodel, viewtag);
662 setsize(self, min_s, max_s);
665 setorigin(self, self.origin);
666 tracebox(self.origin + '0 0 100', min_s, max_s, self.origin - '0 0 10000', MOVE_WORLDONLY, self);
667 setorigin(self, trace_endpos);
670 self.pos1 = self.origin;
671 self.pos2 = self.angles;
679 self.vehicle_exit = self.vehicle_exit;
680 self.vehicle_enter = self.vehicle_exit;
681 self.vehicle_die = self.vehicle_exit;
682 self.vehicle_spawn = self.vehicle_exit;
683 self.AuxiliaryXhair = self.AuxiliaryXhair;