]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/vehicles/vehicles.qc
All vehicle stats as 0--100 (%) int. Spider minigun simplified
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / vehicles / vehicles.qc
1 float autocvar_g_vehicles_crush_dmg;
2 float autocvar_g_vehicles_crush_force;
3
4 void vehicles_damage(entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force);
5 void vehicles_return();
6 void vehicles_enter();
7 void vehicles_touch();
8 void vehicles_reset_colors();
9 void vehicles_clearrturn();
10 void vehicles_setreturn();
11
12
13 /** AuxiliaryXhair* 
14     Send addictional points of interest to be drawn, to vehicle owner
15 **/
16 float MAX_AXH = 4;
17 .entity AuxiliaryXhair[MAX_AXH];
18
19 float SendAuxiliaryXhair(entity to, float sf)
20 {
21
22         WriteByte(MSG_ENTITY, ENT_CLIENT_AUXILIARYXHAIR);
23
24         WriteByte(MSG_ENTITY, self.cnt);
25
26         WriteCoord(MSG_ENTITY, self.origin_x);
27         WriteCoord(MSG_ENTITY, self.origin_y);
28         WriteCoord(MSG_ENTITY, self.origin_z);
29
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));
33
34     return TRUE;
35 }
36
37 void UpdateAuxiliaryXhair(entity own, vector loc, vector clr, float axh_id)
38 {
39     entity axh;
40
41     axh_id = bound(0, axh_id, MAX_AXH);
42     axh = own.AuxiliaryXhair[axh_id];
43
44     if(axh == world || wasfreed(axh))  // MADNESS? THIS IS QQQQCCCCCCCCC (wasfreed, why do you exsist?)
45     {
46         axh                     = spawn();
47         axh.cnt                 = axh_id;
48         axh.drawonlytoclient    = own;
49         axh.owner               = own;
50         Net_LinkEntity(axh, FALSE, 0, SendAuxiliaryXhair);
51     }
52
53     setorigin(axh, loc);
54     axh.colormod            = clr;
55     axh.SendFlags           = 0x01;
56     own.AuxiliaryXhair[axh_id] = axh;
57 }
58
59 /*
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)
63 {
64         msg_entity = own;
65
66         WriteByte(MSG_ONE, SVC_TEMPENTITY);
67         WriteByte(MSG_ONE, TE_CSQC_AUXILIARYXHAIR);
68
69         WriteByte(MSG_ONE, axh_id);
70
71         WriteCoord(MSG_ONE, loc_x);
72         WriteCoord(MSG_ONE, loc_y);
73         WriteCoord(MSG_ONE, loc_z);
74
75     WriteByte(MSG_ONE, rint(clr_x * 255));
76     WriteByte(MSG_ONE, rint(clr_y * 255));
77     WriteByte(MSG_ONE, rint(clr_z * 255));
78
79 }
80 */
81 // End AuxiliaryXhair
82
83 void CSQCVehicleSetup(entity own, float vehicle_id)
84 {
85         msg_entity = own;
86
87         WriteByte(MSG_ONE, SVC_TEMPENTITY);
88         WriteByte(MSG_ONE, TE_CSQC_VEHICLESETUP);
89         WriteByte(MSG_ONE, vehicle_id);
90 }
91
92 /** vehicles_locktarget
93     
94     Generic target locking.
95     
96     Figure out if what target is "locked" (if any), for missile tracking as such.
97     
98     after calling, "if(self.lock_target != world && self.lock_strength == 1)" mean
99     you have a locked in target.
100     
101     Exspects a crosshair_trace() or equivalent to be
102     dont before calling.
103     
104 **/
105 .entity lock_target;
106 .float  lock_strength;
107 .float  lock_time;
108 void vehicles_locktarget(float incr, float decr, float _lock_time)
109 {
110     if(self.lock_target && self.lock_target.deadflag != DEAD_NO)
111     {
112         self.lock_target    = world;
113         self.lock_strength  = 0;
114         self.lock_time      = 0;
115     }
116
117     if(self.lock_time > time)
118         return;
119
120     if(trace_ent != world)
121     {
122         if(teams_matter && trace_ent.team == self.team)
123             trace_ent = world;
124
125         if(trace_ent.deadflag != DEAD_NO)
126             trace_ent = world;
127
128         if not (trace_ent.vehicle_flags & VHF_ISVEHICLE || trace_ent.turrcaps_flags & TFL_TURRCAPS_ISTURRET)
129             trace_ent = world;
130     }
131
132     if(self.lock_target == world && trace_ent != world)
133         self.lock_target = trace_ent;
134
135     // Have a locking target
136     // Trace hit current target
137     if(trace_ent == self.lock_target && trace_ent != world)
138     {
139         self.lock_strength = min(self.lock_strength + incr, 1);
140         if(self.lock_strength == 1)
141             self.lock_time = time + _lock_time;
142     }
143     else
144     {
145         if(trace_ent)
146             self.lock_strength = max(self.lock_strength - decr * 2, 0);
147         else
148             self.lock_strength = max(self.lock_strength - decr, 0);
149
150         if(self.lock_strength == 0)
151             self.lock_target = world;
152     }
153 }
154
155 #define VEHICLE_UPDATE_PLAYER(fld,vhname) \
156 self.owner.vehicle_##fld = (self.vehicle_##fld / autocvar_g_vehicle_##vhname##_##fld) * 100
157
158 #define vehicles_sweap_collision(orig,vel,dt,acm,mult) \
159 traceline(orig, orig + vel * dt, MOVE_NORMAL, self); \
160 if(trace_fraction != 1) \
161     acm += normalize(self.origin - trace_endpos) * (vlen(vel) * mult)
162
163 // Hover movement support
164 float  force_fromtag_power;
165 float  force_fromtag_normpower;
166 vector force_fromtag_origin;
167 vector vehicles_force_fromtag_hover(string tag_name, float spring_length, float max_power)
168 {
169     force_fromtag_origin = gettaginfo(self, gettagindex(self, tag_name));
170     v_forward  = normalize(v_forward) * -1;
171     traceline(force_fromtag_origin, force_fromtag_origin - (v_forward  * spring_length), MOVE_NORMAL, self);
172
173     force_fromtag_power = (1 - trace_fraction) * max_power;
174     force_fromtag_normpower = force_fromtag_power / max_power;
175
176     return v_forward  * force_fromtag_power;
177 }
178
179 // Experimental hovermode wich uses attraction/repulstion from surface unsted of gravity/repulsion
180 // Can possibly be use to move abt any surface (inclusing walls/celings)
181 vector vehicles_force_fromtag_maglev(string tag_name, float spring_length, float max_power)
182 {
183
184     force_fromtag_origin = gettaginfo(self, gettagindex(self, tag_name));
185     v_forward  = normalize(v_forward) * -1;
186     traceline(force_fromtag_origin, force_fromtag_origin - (v_forward  * spring_length), MOVE_NORMAL, self);
187
188     // TODO - this may NOT be compatible with wall/celing movement, unhardcode 0.25 (engine count multiplier)
189     if(trace_fraction == 1.0)
190     {
191         force_fromtag_normpower = -0.25;
192         return '0 0 -200';
193     }
194
195     force_fromtag_power = ((1 - trace_fraction) - trace_fraction) * max_power;
196     force_fromtag_normpower = force_fromtag_power / max_power;
197
198     return v_forward  * force_fromtag_power;
199 }
200
201 // Generic vehile projectile system
202 void vehicles_projectile_damage(entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
203 {
204     self.health -= damage;
205     self.velocity += force;
206     if(self.health < 1)
207     {
208         self.takedamage = DAMAGE_NO;
209         self.event_damage = SUB_Null;
210         self.think = self.use;
211         self.nextthink = time;
212     }
213
214 }
215
216 void vehicles_projectile_explode()
217 {
218     if(self.owner && other != world)
219     {
220         if(other == self.owner.vehicle)
221             return;
222
223         if(other == self.owner.vehicle.tur_head)
224             return;
225     }
226
227         PROJECTILE_TOUCH;
228
229         self.event_damage = SUB_Null;
230     RadiusDamage (self, self.realowner, self.shot_dmg, 0, self.shot_radius, self, self.shot_force, self.totalfrags, other);
231
232     remove (self);
233 }
234
235 entity vehicles_projectile(string _mzlfx, string _mzlsound,
236                            vector _org, vector _vel,
237                            float _dmg, float _radi, float _force,  float _size,
238                            float _deahtype, float _projtype, float _health, 
239                            float _cull, float _clianim)
240 {
241     entity proj;
242
243     proj = spawn();
244
245     PROJECTILE_MAKETRIGGER(proj);
246     setorigin(proj, _org);
247
248     proj.shot_dmg         = _dmg;
249     proj.shot_radius      = _radi;
250     proj.shot_force       = _force;
251     proj.totalfrags       = _deahtype;
252     proj.solid            = SOLID_BBOX;
253     proj.movetype         = MOVETYPE_FLYMISSILE;
254     proj.flags            = FL_PROJECTILE;
255     proj.bot_dodge        = TRUE;
256     proj.bot_dodgerating  = _dmg;
257     proj.velocity         = _vel;
258     proj.touch            = vehicles_projectile_explode;
259     proj.use              = vehicles_projectile_explode;
260     proj.owner            = self;
261     proj.realowner        = self.owner;
262     proj.think            = SUB_Remove;
263     proj.nextthink        = time + 30;
264
265     if(_health)
266     {
267         proj.takedamage       = DAMAGE_AIM;
268         proj.event_damage     = vehicles_projectile_damage;
269         proj.health           = _health;
270     }
271     else
272         proj.flags           = FL_PROJECTILE | FL_NOTARGET;
273
274     if(_mzlsound)
275         sound (self, CHAN_WEAPON, _mzlsound, VOL_BASE, ATTN_NORM);
276
277     if(_mzlfx)
278         pointparticles(particleeffectnum(_mzlfx), proj.origin, proj.velocity, 1);
279
280
281     setsize (proj, '-1 -1 -1' * _size, '1 1 1' * _size);
282
283     CSQCProjectile(proj, _clianim, _projtype, _cull);
284
285     return proj;
286 }
287 // End generic vehile projectile system
288
289 /** vehicles_spawn
290     Exetuted for all vehiles on (re)spawn.
291     Sets defaults for newly spawned units.
292 **/
293 void vehicles_spawn()
294 {
295     dprint("Spawning vehicle: ", self.netname, "\n");
296
297     // De-own & reset
298     self.vehicle_hudmodel.viewmodelforclient = self;
299     
300     self.owner              = world;
301     self.touch              = vehicles_touch;
302     self.event_damage       = vehicles_damage;
303     self.iscreature         = TRUE;
304     self.movetype           = MOVETYPE_WALK;
305     self.solid              = SOLID_SLIDEBOX;
306     self.takedamage         = DAMAGE_AIM;
307         self.deadflag           = DEAD_NO;
308     self.bot_attack         = TRUE;
309     self.flags              = FL_NOTARGET;
310     self.avelocity          = '0 0 0';
311
312     // Reset locking
313     self.lock_strength      = 0;
314     self.lock_target        = world;
315     self.misc_bulletcounter = 0;
316
317     // Return to spawn
318     self.angles             = self.pos2;
319     setorigin(self, self.pos1 + '0 0 128');
320     // Show it
321     pointparticles(particleeffectnum("teleport"), self.origin + '0 0 64', '0 0 0', 1);
322
323     vehicles_reset_colors();
324     self.vehicle_spawn();
325 }
326
327 // Better way of determening whats crushable needed! (fl_crushable?)
328 float vehicles_crushable(entity e)
329 {
330     if(e.classname == "player")
331         return TRUE;
332
333     if(e.classname == "monster_zombie")
334         return TRUE;
335
336     return FALSE;
337 }
338
339 void vehicles_touch()
340 {
341     // Vehicle currently in use
342     if(self.owner)
343     {
344         // Colided with world?
345         if(other == world)
346         {
347             // Apply velocity based self damage here
348         }
349         else
350         {
351             if(other.vehicle_flags & VHF_ISVEHICLE)
352             {
353                 //other.velocity += self.velocity * (self.mass / other.mass);
354             }
355             else if(vehicles_crushable(other))
356             {
357                 if(vlen(self.velocity) != 0)
358                     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);
359             }
360         }
361         return;
362     }
363
364     if(other.classname != "player")
365         return;
366
367     if(other.deadflag != DEAD_NO)
368         return;
369
370     if(other.vehicle != world)
371         return;
372
373     // Remove this when bots know how to use vehicles.
374     if (clienttype(other) != CLIENTTYPE_REAL)
375         return;
376
377     vehicles_enter();
378 }
379
380 void vehicles_enter()
381 {
382    // Remove this when bots know how to use vehicles
383     if (clienttype(other) != CLIENTTYPE_REAL)
384         return;
385
386     if(self.phase > time)
387         return;
388
389     if(teams_matter)
390     if(self.team)
391     if(self.team != other.team)
392         return;
393
394     self.vehicle_ammo1   = 0;
395     self.vehicle_ammo2   = 0;
396     self.vehicle_reload1 = 0;
397     self.vehicle_reload2 = 0;
398     self.vehicle_energy  = 0;
399
400     self.owner          = other;
401     self.switchweapon   = other.switchweapon;
402     
403     // .viewmodelforclient works better.
404     //self.vehicle_hudmodel.drawonlytoclient = self.owner;
405
406     self.vehicle_hudmodel.viewmodelforclient = self.owner;        
407     
408     self.event_damage         = vehicles_damage;
409     self.nextthink            = 0;
410     self.owner.angles         = self.angles;
411     self.owner.takedamage     = DAMAGE_NO;
412     self.owner.solid          = SOLID_NOT;
413     self.owner.movetype       = MOVETYPE_NOCLIP;
414     self.owner.alpha          = -1;
415     self.owner.vehicle        = self;
416     self.owner.event_damage   = SUB_Null;
417     self.owner.view_ofs       = '0 0 0';
418     self.colormap             = self.owner.colormap;
419     if(self.tur_head)
420         self.tur_head.colormap    = self.owner.colormap;
421
422     self.owner.hud            = self.hud;
423     self.owner.PlayerPhysplug = self.PlayerPhysplug;
424
425     self.owner.vehicle_ammo1    = self.vehicle_ammo1;
426     self.owner.vehicle_ammo2    = self.vehicle_ammo2;
427     self.owner.vehicle_reload1  = self.vehicle_reload1;
428     self.owner.vehicle_reload2  = self.vehicle_reload2;
429
430     // Cnnt do this, hides attached objects too.
431     //self.exteriormodeltoclient = self.owner;
432     //self.tur_head.exteriormodeltoclient = self.owner;
433
434     other.flags &~= FL_ONGROUND;
435     self.flags  &~= FL_ONGROUND;
436
437     self.team                 = self.owner.team;
438     self.flags               -= FL_NOTARGET;
439
440     msg_entity = other;
441     WriteByte (MSG_ONE, SVC_SETVIEWPORT);
442     WriteEntity(MSG_ONE, self.vehicle_viewport);
443
444     WriteByte (MSG_ONE, SVC_SETVIEWANGLES);
445     if(self.tur_head)
446     {
447         WriteAngle(MSG_ONE, self.tur_head.angles_x + self.angles_x); // tilt
448         WriteAngle(MSG_ONE, self.tur_head.angles_y + self.angles_y); // yaw
449         WriteAngle(MSG_ONE, 0);                                      // roll
450     }
451     else
452     {
453         WriteByte (MSG_ONE, SVC_SETVIEWANGLES);
454         WriteAngle(MSG_ONE,  self.angles_x * -1); // tilt
455         WriteAngle(MSG_ONE,  self.angles_y);      // yaw
456         WriteAngle(MSG_ONE,  0);                  // roll
457     }
458
459     vehicles_clearrturn();
460
461     CSQCVehicleSetup(self.owner, self.hud);
462
463     self.vehicle_enter();
464 }
465
466 void vehicles_exit(float eject)
467 {
468         self.flags |= FL_NOTARGET;
469
470     if (self.owner)
471     {
472         msg_entity = self.owner;
473         WriteByte (MSG_ONE, SVC_SETVIEWPORT);
474         WriteEntity( MSG_ONE, self.owner);
475
476         WriteByte (MSG_ONE, SVC_SETVIEWANGLES); // 10 = SVC_SETVIEWANGLES
477         WriteAngle(MSG_ONE, 0);                 // tilt
478         WriteAngle(MSG_ONE, self.angles_y);     // yaw
479         WriteAngle(MSG_ONE, 0);                 // roll
480
481         setsize(self.owner, PL_MIN,PL_MAX);
482
483         self.owner.takedamage     = DAMAGE_AIM;
484         self.owner.solid          = SOLID_SLIDEBOX;
485         self.owner.movetype       = MOVETYPE_WALK;
486         self.owner.effects        &~= EF_NODRAW;
487         self.owner.alpha          = 1;
488         self.owner.PlayerPhysplug = SUB_Null;
489         self.owner.vehicle        = world;
490         self.owner.view_ofs       = PL_VIEW_OFS;
491         self.owner.event_damage   = PlayerDamage;
492         self.owner.hud            = HUD_NORMAL;
493         self.owner.switchweapon   = self.switchweapon;
494         self.owner.BUTTON_USE     = 0;
495     }
496
497     if(self.deadflag == DEAD_NO)
498         self.avelocity          = '0 0 0';
499
500     self.vehicle_hudmodel.viewmodelforclient = self;
501         self.tur_head.nodrawtoclient             = world;
502     vehicles_setreturn();
503
504     self.phase = time + 1;
505
506     if(!teams_matter)
507         self.team = 0;
508
509     self.vehicle_exit(eject);
510     self.owner = world;
511 }
512
513
514 void vehicles_regen(.float timer, .float regen_field, float field_max, float rpause, float regen, float delta_time)
515 {
516     if(self.regen_field < field_max)
517     if(self.timer + rpause < time)
518     {
519         self.regen_field = min(self.regen_field + regen * delta_time, field_max);
520
521         if(self.owner)
522             self.owner.regen_field = (self.regen_field / field_max) * 100;
523     }
524 }
525
526 void shieldhit_think()
527 {
528     self.alpha -= 0.1;
529     if (self.alpha <= 0)
530     {
531         //setmodel(self, "");
532         self.alpha = -1;
533     }
534     else
535     {
536         self.nextthink = time + 0.1;
537     }
538 }
539
540 void vehicles_damage(entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
541 {
542     self.dmg_time = time;
543
544     if((self.vehicle_flags & VHF_HASSHIELD) && (self.vehicle_shield > 0))
545     {
546         if (wasfreed(self.vehicle_shieldent) || self.vehicle_shieldent == world)
547         {
548             self.vehicle_shieldent = spawn();
549             self.vehicle_shieldent.effects = EF_LOWPRECISION;
550
551             setmodel(self.vehicle_shieldent, "models/vhshield.md3");
552             setattachment(self.vehicle_shieldent, self, "");
553             setorigin(self.vehicle_shieldent, real_origin(self) - self.origin);
554             self.vehicle_shieldent.scale       = 256 / vlen(self.maxs - self.mins);
555             self.vehicle_shieldent.think       = shieldhit_think;
556         }
557
558
559         self.vehicle_shieldent.colormod    = '1 1 1';
560         self.vehicle_shieldent.alpha       = 0.45;
561         self.vehicle_shieldent.angles      = vectoangles(normalize(hitloc - (self.origin + self.vehicle_shieldent.origin))) - self.angles;
562         self.vehicle_shieldent.nextthink   = time;
563
564         self.vehicle_shield -= damage;
565
566         if(self.vehicle_shield < 0)
567         {
568             self.vehicle_shieldent.colormod = '2 0 0';
569             self.vehicle_shield             = 0;
570             self.vehicle_shieldent.alpha    = 0.75;
571             self.vehicle_health            -= fabs(self.vehicle_shield);
572         }
573     }
574     else
575         self.vehicle_health -= damage;
576
577     self.velocity += force; // * (vlen(force) / self.mass);
578
579     if(self.vehicle_health <= 0)
580     {
581         if(self.owner)
582             if(self.vehicle_flags & VHF_DEATHEJECT)
583                 vehicles_exit(VHEF_EJECT);
584             else
585                 vehicles_exit(VHEF_RELESE);
586
587         self.vehicle_die();
588         vehicles_setreturn();
589     }
590 }
591
592 void vehicles_return()
593 {
594     pointparticles(particleeffectnum("teleport"), self.enemy.origin + '0 0 64', '0 0 0', 1);
595
596     self.enemy.think     = vehicles_spawn;
597     self.enemy.nextthink = time;
598
599     remove(self);
600 }
601
602 void vehicles_clearrturn()
603 {
604     entity ret;
605     // Remove "return helper", if any.
606     ret = findchain(classname, "vehicle_return");
607     while(ret)
608     {
609         if(ret.enemy == self)
610         {
611             ret.classname   = "";
612             ret.think       = SUB_Remove;
613             ret.nextthink   = time + 0.1;
614             return;
615         }
616
617         ret = ret.chain;
618     }
619 }
620
621 void vehicles_setreturn()
622 {
623     entity ret;
624
625     vehicles_clearrturn();
626
627     ret = spawn();
628     ret.classname   = "vehicle_return";
629     ret.enemy       = self;
630     ret.think       = vehicles_return;
631     ret.nextthink   = time + self.vehicle_respawntime;
632 }
633
634 float vehicles_customizeentityforclient()
635 {
636     if(self.deadflag  == DEAD_DEAD)
637         return FALSE;
638     else
639         return TRUE;
640 }
641
642 void vehicles_configcheck(string  configname, float check_cvar)
643 {
644     if(check_cvar == 0)
645         localcmd(strcat("exec ", configname, "\n"));
646 }
647
648 void vehicles_reset_colors()
649 {
650     entity e;
651     float _effects, _colormap;
652     vector _glowmod, _colormod;
653
654     if(autocvar_g_nodepthtestplayers)
655         _effects = EF_NODEPTHTEST;
656
657     if(autocvar_g_fullbrightplayers)
658         _effects |= EF_FULLBRIGHT;
659         
660     if(self.team)
661         _colormap = 1024 + (self.team - 1) * 17;
662     else
663         _colormap = 1024;
664
665     _glowmod    = '0 0 0';
666     _colormod   = '0 0 0';
667
668     // Find all ents attacked to main model and setup effects, colormod etc.
669     e = findchainentity(tag_entity, self);
670     while(e)
671     {
672         if(e != self.vehicle_shieldent)
673         {
674             e.effects   = _effects  | EF_LOWPRECISION;
675             e.colormod  = _colormod;
676             e.colormap  = _colormap;
677             e.alpha     = 1;
678         }
679         e = e.chain;
680     }
681     
682     self.vehicle_hudmodel.effects  = self.effects  = _effects | EF_LOWPRECISION;
683     self.vehicle_hudmodel.colormod = self.colormod = _colormod;
684     self.vehicle_hudmodel.colormap = self.colormap = _colormap;
685     self.vehicle_viewport.effects = (EF_ADDITIVE | EF_DOUBLESIDED | EF_FULLBRIGHT | EF_NODEPTHTEST | EF_NOGUNBOB | EF_NOSHADOW | EF_LOWPRECISION | EF_SELECTABLE | EF_TELEPORT_BIT);
686
687     self.alpha          = 1;
688     self.avelocity      = '0 0 0';
689     self.velocity       = '0 0 0';
690     self.effects        = _effects;
691 }
692
693 float vehicle_initialize(string  net_name,
694                          string  bodymodel,
695                          string  topmodel,
696                          string  hudmodel,
697                          string  toptag,
698                          string  hudtag,
699                          string  viewtag,
700                          float   vhud,
701                          vector min_s,
702                          vector max_s,
703                          float  nodrop,
704                          void()  spawnproc,
705                          float   _respawntime,
706                          float() physproc,
707                          void()  enterproc,
708                          void(float extflag) exitfunc,
709                          void() dieproc,
710                          void() thinkproc )
711 {
712     addstat(STAT_HUD, AS_INT,  hud);
713         addstat(STAT_VEHICLESTAT_HEALTH,  AS_INT, vehicle_health);
714         addstat(STAT_VEHICLESTAT_SHIELD,  AS_INT, vehicle_shield);
715         addstat(STAT_VEHICLESTAT_ENERGY,  AS_INT, vehicle_energy);
716
717         addstat(STAT_VEHICLESTAT_AMMO1,   AS_INT,   vehicle_ammo1);
718         addstat(STAT_VEHICLESTAT_RELOAD1, AS_INT, vehicle_reload1);
719
720         addstat(STAT_VEHICLESTAT_AMMO2,   AS_INT,   vehicle_ammo2);
721         addstat(STAT_VEHICLESTAT_RELOAD2, AS_INT, vehicle_reload2);
722
723     if(bodymodel == "")
724         error("vehicles: missing bodymodel!");
725
726     if(hudmodel == "")
727         error("vehicles: missing hudmodel!");
728
729     if(net_name == "")
730         self.netname = self.classname;
731     else
732         self.netname = net_name;
733
734     if(self.team && !teams_matter)
735         self.team = 0;
736
737     self.vehicle_flags |= VHF_ISVEHICLE;
738
739     setmodel(self, bodymodel);
740
741     self.vehicle_viewport   = spawn();
742     self.vehicle_hudmodel   = spawn();
743     self.tur_head           = spawn();
744     self.tur_head.owner     = self;
745     self.takedamage         = DAMAGE_AIM;
746     self.bot_attack         = TRUE;
747     self.iscreature         = TRUE;
748     self.hud                = vhud;
749
750     //self.customizeentityforclient = vehicles_customizeentityforclient;
751     self.vehicle_die         = dieproc;
752     self.vehicle_exit        = exitfunc;
753     self.vehicle_enter       = enterproc;
754     self.PlayerPhysplug      = physproc;
755     self.event_damage        = vehicles_damage;
756     self.touch               = vehicles_touch;
757     self.think               = vehicles_spawn;
758     self.nextthink           = time;
759     self.vehicle_respawntime = _respawntime;
760     self.vehicle_spawn       = spawnproc;
761
762     if(autocvar_g_nodepthtestplayers)
763         self.effects = self.effects | EF_NODEPTHTEST;
764
765     if(autocvar_g_fullbrightplayers)
766         self.effects = self.effects | EF_FULLBRIGHT;
767
768     setmodel(self.vehicle_hudmodel, hudmodel);
769     setmodel(self.vehicle_viewport, "null");
770
771
772     if(topmodel != "")
773     {
774         setmodel(self.tur_head, topmodel);
775         setattachment(self.tur_head, self, toptag);
776         setattachment(self.vehicle_hudmodel, self.tur_head, hudtag);
777         setattachment(self.vehicle_viewport, self.vehicle_hudmodel, viewtag);
778     }
779     else
780     {
781         setattachment(self.tur_head, self, "");
782         setattachment(self.vehicle_hudmodel, self, hudtag);
783         setattachment(self.vehicle_viewport, self.vehicle_hudmodel, viewtag);
784     }
785
786     setsize(self, min_s, max_s);
787     if not (nodrop)
788     {
789         setorigin(self, self.origin);
790         tracebox(self.origin + '0 0 100', min_s, max_s, self.origin - '0 0 10000', MOVE_WORLDONLY, self);
791         setorigin(self, trace_endpos);
792     }
793     
794     //self.vehicle_hudmodel.effects = EF_NODEPTHTEST;
795     self.pos1 = self.origin;
796     self.pos2 = self.angles;
797
798     return TRUE;
799 }
800
801
802 void bugmenot()
803 {
804     self.vehicle_exit       = self.vehicle_exit;
805     self.vehicle_enter      = self.vehicle_exit;
806     self.vehicle_die        = self.vehicle_exit;
807     self.vehicle_spawn      = self.vehicle_exit;
808     self.AuxiliaryXhair     = self.AuxiliaryXhair;
809 }
810
811 #ifdef VEHICLES_CSQC
812 // SendFlags
813 float VSF_SETUP       = 2;          /// Send vehicle type etc
814 float VSF_ORIGIN      = 4;          /// Send location
815 float VSF_MOVEMENT    = 8;          /// Send movement update (and angle/avelocity)
816 float VSF_STATS       = 16;         /// Send ammo, health etc
817 float VSF_EXTRA       = 32;         /// Send additional data (turret rotations and such). Handeld per vehicle type.
818 float VSF_ANIMINFO    = 64;         /// Animation info
819 float VSF_FULL_UPDATE = 16777215    /// Send everything
820
821 #ifdef SVQC
822 float send_vehile(entity to, float sf)
823 {
824         float dist;
825         
826         // Always send a compleate update to owner, minus VSF_SETUP
827         if(to == self.owner && self.owner != world && sf != VSF_FULL_UPDATE)
828         sf |= (VSF_FULL_UPDATE &~= VSF_SETUP);
829     
830     dist = vlen(self.origin - to.origin);
831     // TODO: Distance based message filtering
832     
833         WriteByte(MSG_ENTITY, ENT_CLIENT_VEHICLE);
834         
835         // We need to know client-side what was sent
836         WriteByte(MSG_ENTITY, sf);
837         
838         if(sf & VSF_SETUP)
839         {
840         WriteByte(MSG_ENTITY,   self.hud);        //vehicle type = hud
841         WriteByte(MSG_ENTITY,   self.team);
842         WriteShort(MSG_ENTITY,  self.colormap);
843         }
844     
845     if(sf & VSF_ORIGIN)
846     {
847         WriteCoord(MSG_ENTITY, self.origin_x);
848         WriteCoord(MSG_ENTITY, self.origin_y);
849         WriteCoord(MSG_ENTITY, self.origin_z);        
850     }
851     
852     if(sf & VSF_MOVEMENT)
853     {    
854         WriteCoord(MSG_ENTITY, self.velocity_x);
855         WriteCoord(MSG_ENTITY, self.velocity_y);
856         WriteCoord(MSG_ENTITY, self.velocity_z);
857
858         WriteAngle(MSG_ENTITY, self.angles_x);
859         WriteAngle(MSG_ENTITY, self.angles_y);
860         WriteAngle(MSG_ENTITY, self.angles_z);
861
862         WriteCoord(MSG_ENTITY, self.avelocity_x);
863         WriteCoord(MSG_ENTITY, self.avelocity_y);
864         WriteCoord(MSG_ENTITY, self.avelocity_z);
865     }
866     
867     if(sf & VSF_STATS)
868     {
869         WriteByte(MSG_ENTITY, self.vehicle_health);
870         WriteByte(MSG_ENTITY, self.vehicle_shield);
871         WriteByte(MSG_ENTITY, self.vehicle_energy);
872         
873         WriteByte(MSG_ENTITY, self.vehicle_ammo1);
874         WriteByte(MSG_ENTITY, self.vehicle_reload1);
875         
876         WriteByte(MSG_ENTITY, self.vehicle_ammo2);
877         WriteByte(MSG_ENTITY, self.vehicle_reload2);
878     }
879     
880     if(sf & VSF_EXTRA)
881     {
882         self.vehile_send_exta(to);
883     }
884     
885     return TRUE;
886 }
887
888 void net_link_vehile()
889 {    
890     self.SendFlags = 0xFFFFFF;
891     Net_LinkEntity(self, FALSE, 0, send_vehile);    
892 }
893 #endif // SVQC
894
895 #ifdef CSQC
896 void Net_ReadVehicle(float bIsNew)
897 {
898     float sf;
899     
900     if(bIsNew)
901     {
902         setmodel(self, "models/vehicles/wakizashi.dpm");
903         self.move_movetype = MOVETYPE_BOUNCE;        
904         self.entremove = VehicleRacerRemove;
905         setsize(self,  '-60 -60 -20', '60 60 20');        
906         self.draw = VehicleRacerDraw;
907         self.scale = 0.5;
908     }
909
910     sf = ReadByte();    
911         if(sf & VSF_SETUP)
912         {
913         self.hud        = ReadByte();
914         self.team       = ReadByte();
915         self.colormap   = ReadShort();
916         }        
917     
918     if(sf & if(sf & VSF_ORIGIN))
919     {        
920         self.origin_x       = ReadCoord();
921         self.origin_y       = ReadCoord();
922         self.origin_z       = ReadCoord();
923         self.move_origin    = self.origin;
924     }
925     
926     if(sf & VSF_MOVEMENT)
927     {    
928         self.velocity_x     = ReadCoord();
929         self.velocity_y     = ReadCoord();
930         self.velocity_z     = ReadCoord();
931
932         self.angles_x       = ReadAngle();
933         self.angles_y       = ReadAngle();
934         self.angles_z       = ReadAngle();
935         
936         self.move_velocity  = self.velocity;
937         self.move_angles    = self.angles;
938
939     }
940     
941 }
942 #endif // CSQC
943
944 #endif // VEHICLES_CSQC