1 void vehicles_damage(entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force);
2 void vehicles_return();
3 void vehicles_clearrturn();
6 .entity AuxiliaryXhair[MAX_AXH];
8 float SendAuxiliaryXhair(entity to, float sf)
11 WriteByte(MSG_ENTITY, ENT_CLIENT_AUXILIARYXHAIR);
13 WriteByte(MSG_ENTITY, self.cnt);
15 WriteCoord(MSG_ENTITY, self.origin_x);
16 WriteCoord(MSG_ENTITY, self.origin_y);
17 WriteCoord(MSG_ENTITY, self.origin_z);
19 WriteByte(MSG_ENTITY, rint(self.colormod_x * 255));
20 WriteByte(MSG_ENTITY, rint(self.colormod_y * 255));
21 WriteByte(MSG_ENTITY, rint(self.colormod_z * 255));
26 void UpdateAuxiliaryXhair(entity own, vector loc, vector clr, float axh_id)
30 axh_id = bound(0, axh_id, MAX_AXH);
31 axh = own.AuxiliaryXhair[axh_id];
33 if(axh == world || wasfreed(axh)) // MADNESS? THIS IS QQQQCCCCCCCCC (wasfreed, why do you exsist?)
37 axh.drawonlytoclient = own;
39 Net_LinkEntity(axh, FALSE, 0, SendAuxiliaryXhair);
45 own.AuxiliaryXhair[axh_id] = axh;
49 // SVC_TEMPENTITY based, horrible with even 50 ping. hm.
50 void SendAuxiliaryXhair2(entity own, vector loc, vector clr, float axh_id)
54 WriteByte(MSG_ONE, SVC_TEMPENTITY);
55 WriteByte(MSG_ONE, TE_CSQC_AUXILIARYXHAIR);
57 WriteByte(MSG_ONE, axh_id);
59 WriteCoord(MSG_ONE, loc_x);
60 WriteCoord(MSG_ONE, loc_y);
61 WriteCoord(MSG_ONE, loc_z);
63 WriteByte(MSG_ONE, rint(clr_x * 255));
64 WriteByte(MSG_ONE, rint(clr_y * 255));
65 WriteByte(MSG_ONE, rint(clr_z * 255));
70 void CSQCVehicleSetup(entity own, float vehicle_id)
74 WriteByte(MSG_ONE, SVC_TEMPENTITY);
75 WriteByte(MSG_ONE, TE_CSQC_VEHICLESETUP);
76 WriteByte(MSG_ONE, vehicle_id);
82 void vehicles_locktarget(float deltatime)
84 // no target hit by trace
85 if(trace_ent == world)
87 self.lock_strength = max(self.lock_strength - deltatime, 0);
88 if(self.lock_strength == 0)
89 self.lock_target = world;
94 // Current have no target
95 if(self.lock_target == world)
98 if(trace_ent != world)
100 self.lock_target = trace_ent;
101 self.lock_strength = deltatime;
106 // Have a locking target
107 // Trace hit current target
108 if(trace_ent == self.lock_target)
110 self.lock_strength = min(self.lock_strength + deltatime, 1);
114 self.lock_strength = max(self.lock_strength - deltatime, 0);
115 if(self.lock_strength == 0)
116 self.lock_target = world;
121 void vehicles_locktarget2(float incr, float decr, float _lock_time)
123 if(self.lock_time > time)
128 if not (trace_ent.vehicle_flags & VHF_ISVEHICLE || trace_ent.turrcaps_flags & TFL_TURRCAPS_ISTURRET)
129 self.lock_strength = min(self.lock_strength - decr, 1);
130 else if(trace_ent.deadflag != DEAD_NO)
131 self.lock_strength = min(self.lock_strength - decr, 1);
133 if(self.lock_target == world && trace_ent != world)
134 self.lock_target = trace_ent;
136 // Have a locking target
137 // Trace hit current target
138 if(trace_ent == self.lock_target && trace_ent != world)
140 self.lock_strength = min(self.lock_strength + incr, 1);
141 if(self.lock_strength == 1)
142 self.lock_time = time + _lock_time;
146 self.lock_strength = max(self.lock_strength - decr, 0);
148 if(self.lock_strength == 0)
149 self.lock_target = world;
154 #define VEHICLE_UPDATE_PLAYER(fld,vhname) \
155 self.owner.vehicle_##fld = self.vehicle_##fld / autocvar_g_vehicle_##vhname##_##fld
157 #define vehicles_sweap_collision(orig,vel,dt,acm,mult) \
158 traceline(orig, orig + vel * dt, MOVE_NORMAL, self); \
159 if(trace_fraction != 1) \
160 acm += normalize(self.origin - trace_endpos) * (vlen(vel) * mult)
162 float force_fromtag_power;
163 float force_fromtag_normpower;
164 vector force_fromtag_origin;
165 vector vehicles_force_fromtag_hover(string tag_name, float spring_length, float max_power)
167 force_fromtag_origin = gettaginfo(self, gettagindex(self, tag_name));
168 v_forward = normalize(v_forward) * -1;
169 traceline(force_fromtag_origin, force_fromtag_origin - (v_forward * spring_length), MOVE_NORMAL, self);
171 force_fromtag_power = (1 - trace_fraction) * max_power;
172 force_fromtag_normpower = force_fromtag_power / max_power;
174 return v_forward * force_fromtag_power;
177 vector vehicles_force_fromtag_maglev(string tag_name, float spring_length, float max_power)
180 force_fromtag_origin = gettaginfo(self, gettagindex(self, tag_name));
181 v_forward = normalize(v_forward) * -1;
182 traceline(force_fromtag_origin, force_fromtag_origin - (v_forward * spring_length), MOVE_NORMAL, self);
184 if(trace_fraction == 1.0)
186 force_fromtag_normpower = -0.25;
190 force_fromtag_power = ((1 - trace_fraction) - trace_fraction) * max_power;
191 force_fromtag_normpower = force_fromtag_power / max_power;
193 return v_forward * force_fromtag_power;
197 void vehicles_touch()
199 if(other.classname != "player")
202 if(other.deadflag != DEAD_NO)
205 if(other.vehicle != world)
208 // Remove this when bots know how to use vehicles.
209 if (clienttype(other) != CLIENTTYPE_REAL)
212 self.vehicle_enter();
215 void vehicles_enter()
217 // Remove this when bots know how to use vehicles
218 if (clienttype(other) != CLIENTTYPE_REAL)
221 self.colormod = self.tur_head.colormod = '0 0 0';
225 if(self.team != other.team)
229 self.switchweapon = other.switchweapon;
231 self.vehicle_hudmodel.viewmodelforclient = self.owner;
232 self.event_damage = vehicles_damage;
234 self.owner.angles = self.angles;
235 self.owner.takedamage = DAMAGE_NO;
236 self.owner.solid = SOLID_NOT;
237 self.owner.movetype = MOVETYPE_NOCLIP;
238 self.owner.alpha = -1;
239 self.owner.vehicle = self;
240 self.owner.event_damage = SUB_Null;
241 self.owner.view_ofs = '0 0 0';
242 self.colormap = self.owner.colormap;
244 self.tur_head.colormap = self.owner.colormap;
246 self.owner.hud = self.hud;
247 self.owner.PlayerPhysplug = self.PlayerPhysplug;
249 self.owner.vehicle_ammo1 = self.vehicle_ammo1;
250 self.owner.vehicle_ammo2 = self.vehicle_ammo2;
251 self.owner.vehicle_reload1 = self.vehicle_reload1;
252 self.owner.vehicle_reload2 = self.vehicle_reload2;
254 other.flags &~= FL_ONGROUND;
255 self.flags &~= FL_ONGROUND;
257 self.team = self.owner.team;
258 self.flags -= FL_NOTARGET;
261 WriteByte (MSG_ONE, SVC_SETVIEWPORT);
262 WriteEntity(MSG_ONE, self.vehicle_viewport);
264 WriteByte (MSG_ONE, SVC_SETVIEWANGLES); // 10 = SVC_SETVIEWANGLES
267 WriteAngle(MSG_ONE, self.tur_head.angles_x + self.angles_x); // tilt
268 WriteAngle(MSG_ONE, self.tur_head.angles_y + self.angles_y); // yaw
269 WriteAngle(MSG_ONE, 0); // roll
273 WriteByte (MSG_ONE, SVC_SETVIEWANGLES); // 10 = SVC_SETVIEWANGLES
274 WriteAngle(MSG_ONE, self.angles_x * -1); // tilt
275 WriteAngle(MSG_ONE, self.angles_y); // yaw
276 WriteAngle(MSG_ONE, 0); // roll
279 vehicles_clearrturn();
281 CSQCVehicleSetup(self.owner, self.hud);
283 if(self.vehicle_enter)
284 self.vehicle_enter();
287 void vehicles_exit(float eject)
289 self.colormap = 1024;
290 self.tur_head.colormap = 1024;
294 if (self.team == COLOR_TEAM1)
295 self.colormod = '1.4 0.8 0.8';
297 if (self.team == COLOR_TEAM2)
298 self.colormod = '0.8 0.8 1.4';
300 self.tur_head.colormod = self.colormod;
304 self.flags |= FL_NOTARGET;
308 msg_entity = self.owner;
309 WriteByte (MSG_ONE, SVC_SETVIEWPORT);
310 WriteEntity( MSG_ONE, self.owner);
312 WriteByte (MSG_ONE, SVC_SETVIEWANGLES); // 10 = SVC_SETVIEWANGLES
313 WriteAngle(MSG_ONE, 0); // tilt
314 WriteAngle(MSG_ONE, self.angles_y); // yaw
315 WriteAngle(MSG_ONE, 0); // roll
317 setsize(self.owner,PL_MIN,PL_MAX);
319 self.owner.takedamage = DAMAGE_AIM;
320 self.owner.solid = SOLID_SLIDEBOX;
321 self.owner.movetype = MOVETYPE_WALK;
322 self.owner.effects &~= EF_NODRAW;
323 self.owner.alpha = 1;
324 self.owner.PlayerPhysplug = SUB_Null;
325 self.owner.vehicle = world;
326 self.owner.view_ofs = PL_VIEW_OFS;
327 self.owner.event_damage = PlayerDamage;
328 self.owner.hud = HUD_NORMAL;
329 self.owner.switchweapon = self.switchweapon;
332 self.vehicle_hudmodel.viewmodelforclient = self;
333 self.tur_head.nodrawtoclient = self;
335 if(self.vehicle_exit)
336 self.vehicle_exit(eject);
342 void vehicles_regen(.float timer, .float regen_field, float field_max, float rpause, float regen, float delta_time)
344 if(self.regen_field < field_max)
345 if(self.timer + rpause < time)
347 self.regen_field = min(self.regen_field + regen * delta_time, field_max);
350 self.owner.regen_field = self.regen_field / field_max;
354 void shieldhit_think()
364 self.nextthink = time + 0.1;
368 void vehicles_damage(entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
372 self.dmg_time = time;
374 if((self.vehicle_flags & VHF_HASSHIELD) && (self.vehicle_shield > 0))
376 if (wasfreed(self.tur_head.enemy) || self.tur_head.enemy == world)
378 self.tur_head.enemy = spawn();
379 self.tur_head.enemy.effects = EF_LOWPRECISION;
382 setmodel(self.tur_head.enemy, "models/vhshield.md3");
383 setattachment(self.tur_head.enemy, self, "");
385 self.tur_head.enemy.colormod = '1 1 1';
386 self.tur_head.enemy.alpha = 0.45;
387 self.tur_head.enemy.scale = (256 / vlen(self.maxs - self.mins));
388 self.tur_head.enemy.angles = vectoangles(normalize(hitloc - self.origin)) - self.angles;
389 self.tur_head.enemy.think = shieldhit_think;
390 self.tur_head.enemy.nextthink = time;
392 self.vehicle_shield -= damage;
393 if(self.vehicle_shield < 0)
395 self.tur_head.enemy.colormod = '10 0 -1';
396 ddmg_take = fabs(self.vehicle_shield);
397 self.vehicle_shield = 0;
398 self.tur_head.enemy.alpha = 0.75;
399 self.vehicle_health -= ddmg_take;
403 self.vehicle_health -= damage;
405 if(self.vehicle_health <= 0)
408 if(self.vehicle_flags & VHF_DEATHEJECT)
409 vehicles_exit(VHEF_EJECT);
411 vehicles_exit(VHEF_RELESE);
417 void vehicles_return()
419 pointparticles(particleeffectnum("teleport"), self.enemy.origin + '0 0 64', '0 0 0', 1);
420 self.enemy.think = self.use;
421 self.enemy.nextthink = time;
425 void vehicles_clearrturn()
428 // Remove "return helper", if any.
429 ret = findchain(classname, "vehicle_return");
432 if(ret.enemy == self)
434 ret.think = SUB_Remove;
435 ret.nextthink = time + 0.1;
442 void vehicles_setreturn(float retime, void() respawn_proc)
444 vehicles_clearrturn();
446 if (self.deadflag == DEAD_NO)
451 ret.classname = "vehicle_return";
453 ret.think = vehicles_return;
454 ret.nextthink = time + retime;
455 ret.use = respawn_proc;
459 float vehicles_customizeentityforclient()
461 if(self.deadflag == DEAD_DEAD)
467 void vehicles_configcheck(string configname, float check_cvar)
470 localcmd(strcat("exec ", configname, "\n"));
473 void vehicles_common_spawn()
476 float _effects, _colormap;
477 vector _glowmod, _colormod;
479 if(autocvar_g_nodepthtestplayers)
480 _effects = EF_NODEPTHTEST;
482 if(autocvar_g_fullbrightplayers)
483 _effects |= EF_FULLBRIGHT;
486 _colormap = 1024 + (self.team - 1) * 17;
493 // Find all ents attacked to main model and setup effects, colormod etc.
494 e = findchainentity(tag_entity, self);
497 e.effects = _effects;
498 e.colormod = _colormod;
499 e.colormap = _colormap;
505 self.effects = _effects;
506 self.colormod = _colormod;
507 self.colormap = _colormap;
510 self.avelocity = '0 0 0';
511 self.velocity = '0 0 0';
515 float vehicle_initialize(string net_name,
529 void(float extflag) exitfunc,
533 addstat(STAT_HUD, AS_INT, hud);
534 addstat(STAT_VEHICLESTAT_HEALTH, AS_FLOAT, vehicle_health);
535 addstat(STAT_VEHICLESTAT_SHIELD, AS_FLOAT, vehicle_shield);
536 addstat(STAT_VEHICLESTAT_ENERGY, AS_FLOAT, vehicle_energy);
538 addstat(STAT_VEHICLESTAT_AMMO1, AS_INT, vehicle_ammo1);
539 addstat(STAT_VEHICLESTAT_RELOAD1, AS_FLOAT, vehicle_reload1);
541 addstat(STAT_VEHICLESTAT_AMMO2, AS_INT, vehicle_ammo2);
542 addstat(STAT_VEHICLESTAT_RELOAD2, AS_FLOAT, vehicle_reload2);
546 error("vehicles: missing bodymodel!");
549 error("vehicles: missing hudmodel!");
552 self.netname = self.classname;
554 self.netname = net_name;
556 if(self.team && !teams_matter)
559 self.vehicle_flags |= VHF_ISVEHICLE;
561 setmodel(self, bodymodel);
563 self.vehicle_viewport = spawn();
564 self.vehicle_hudmodel = spawn();
565 self.tur_head = spawn();
566 self.tur_head.owner = self;
567 self.takedamage = DAMAGE_AIM;
568 self.bot_attack = TRUE;
569 self.iscreature = TRUE;
572 self.customizeentityforclient = vehicles_customizeentityforclient;
573 self.vehicle_die = dieproc;
574 self.vehicle_exit = exitfunc;
575 self.vehicle_enter = enterproc;
576 self.PlayerPhysplug = physproc;
577 self.event_damage = vehicles_damage;
578 self.touch = vehicles_touch;
579 self.think = spawnproc;
580 self.nextthink = time;
582 if(autocvar_g_nodepthtestplayers)
583 self.effects = self.effects | EF_NODEPTHTEST;
585 if(autocvar_g_fullbrightplayers)
586 self.effects = self.effects | EF_FULLBRIGHT;
588 setmodel(self.vehicle_hudmodel, hudmodel);
589 setmodel(self.vehicle_viewport, "null");
593 setmodel(self.tur_head, topmodel);
594 setattachment(self.tur_head, self, toptag);
595 setattachment(self.vehicle_hudmodel, self.tur_head, hudtag);
596 setattachment(self.vehicle_viewport, self.vehicle_hudmodel, viewtag);
600 setattachment(self.tur_head, self, "");
601 setattachment(self.vehicle_hudmodel, self, hudtag);
602 setattachment(self.vehicle_viewport, self.vehicle_hudmodel, viewtag);
605 setsize(self, min_s, max_s);
608 setorigin(self, self.origin);
609 tracebox(self.origin + '0 0 100', min_s, max_s, self.origin - '0 0 10000', MOVE_WORLDONLY, self);
610 setorigin(self, trace_endpos);
613 self.pos1 = self.origin;
614 self.pos2 = self.angles;
621 self.vehicle_exit = self.vehicle_exit;
622 self.vehicle_enter = self.vehicle_exit;
623 self.vehicle_die = self.vehicle_exit;
624 self.vehicle_spawn = self.vehicle_exit;
625 //self.vehicle_message = self.vehicle_exit;