Merge remote-tracking branch 'origin/divVerent/allow-override-item-model'
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / vehicles / racer.qc
1 #define RACER_MIN '-120 -120 -40'
2 #define RACER_MAX '120 120 40'
3
4 #ifdef SVQC
5 void racer_exit(float eject);
6 void racer_enter();
7
8 // Auto cvars
9 float autocvar_g_vehicle_racer_speed_afterburn;
10 float autocvar_g_vehicle_racer_afterburn_cost;
11
12 float autocvar_g_vehicle_racer_anglestabilizer;
13 float autocvar_g_vehicle_racer_downforce;
14
15 float autocvar_g_vehicle_racer_speed_forward;
16 float autocvar_g_vehicle_racer_speed_strafe;
17 float autocvar_g_vehicle_racer_springlength;
18 float autocvar_g_vehicle_racer_upforcedamper;
19 float autocvar_g_vehicle_racer_friction;
20
21 float autocvar_g_vehicle_racer_hovertype;
22 float autocvar_g_vehicle_racer_hoverpower;
23
24 float autocvar_g_vehicle_racer_turnroll;
25 float autocvar_g_vehicle_racer_turnspeed;
26 float autocvar_g_vehicle_racer_pitchspeed;
27
28 float autocvar_g_vehicle_racer_energy;
29 float autocvar_g_vehicle_racer_energy_regen;
30 float autocvar_g_vehicle_racer_energy_regen_pause;
31
32 float autocvar_g_vehicle_racer_health;
33 float autocvar_g_vehicle_racer_health_regen;
34 float autocvar_g_vehicle_racer_health_regen_pause;
35
36 float autocvar_g_vehicle_racer_shield;
37 float autocvar_g_vehicle_racer_shield_regen;
38 float autocvar_g_vehicle_racer_shield_regen_pause;
39
40 float autocvar_g_vehicle_racer_cannon_cost;
41 float autocvar_g_vehicle_racer_cannon_damage;
42 float autocvar_g_vehicle_racer_cannon_radius;
43 float autocvar_g_vehicle_racer_cannon_refire;
44 float autocvar_g_vehicle_racer_cannon_speed;
45 float autocvar_g_vehicle_racer_cannon_spread;
46 float autocvar_g_vehicle_racer_cannon_force;
47
48 float autocvar_g_vehicle_racer_rocket_accel;
49 float autocvar_g_vehicle_racer_rocket_damage;
50 float autocvar_g_vehicle_racer_rocket_radius;
51 float autocvar_g_vehicle_racer_rocket_force;
52 float autocvar_g_vehicle_racer_rocket_refire;
53 float autocvar_g_vehicle_racer_rocket_speed;
54 float autocvar_g_vehicle_racer_rocket_turnrate;
55
56 float autocvar_g_vehicle_racer_rocket_locktarget;
57 float autocvar_g_vehicle_racer_rocket_locking_time;
58 float autocvar_g_vehicle_racer_rocket_locking_releasetime;
59 float autocvar_g_vehicle_racer_rocket_locked_time;
60 float autocvar_g_vehicle_racer_rocket_locked_maxangle;
61
62 float autocvar_g_vehicle_racer_respawntime;
63
64 float autocvar_g_vehicle_racer_blowup_radius;
65 float autocvar_g_vehicle_racer_blowup_coredamage;
66 float autocvar_g_vehicle_racer_blowup_edgedamage;
67 float autocvar_g_vehicle_racer_blowup_forceintensity;
68
69 float autocvar_g_vehicle_racer_bouncefactor;
70 float autocvar_g_vehicle_racer_bouncestop;
71 vector autocvar_g_vehicle_racer_bouncepain;
72
73 var vector racer_force_from_tag(string tag_name, float spring_length, float max_power);
74
75 void racer_align4point()
76 {
77     vector push_vector, v_add;
78     float fl_push, fr_push, bl_push, br_push;
79
80
81     push_vector  = racer_force_from_tag("tag_engine_fr", autocvar_g_vehicle_racer_springlength, autocvar_g_vehicle_racer_hoverpower);
82     fr_push      = force_fromtag_normpower;
83     //vehicles_sweap_collision(force_fromtag_origin, self.velocity, frametime, v_add, autocvar_g_vehicle_racer_collision_multiplier);
84
85     push_vector += racer_force_from_tag("tag_engine_fl", autocvar_g_vehicle_racer_springlength, autocvar_g_vehicle_racer_hoverpower);
86     fl_push      = force_fromtag_normpower;
87     //vehicles_sweap_collision(force_fromtag_origin, self.velocity, frametime, v_add, autocvar_g_vehicle_racer_collision_multiplier);
88
89     push_vector += racer_force_from_tag("tag_engine_br", autocvar_g_vehicle_racer_springlength, autocvar_g_vehicle_racer_hoverpower);
90     br_push      = force_fromtag_normpower;
91     //vehicles_sweap_collision(force_fromtag_origin, self.velocity, frametime, v_add, autocvar_g_vehicle_racer_collision_multiplier);
92
93     push_vector += racer_force_from_tag("tag_engine_bl", autocvar_g_vehicle_racer_springlength, autocvar_g_vehicle_racer_hoverpower);
94     bl_push      = force_fromtag_normpower;
95     //vehicles_sweap_collision(force_fromtag_origin, self.velocity, frametime, v_add, autocvar_g_vehicle_racer_collision_multiplier);
96
97     self.velocity += (push_vector * frametime);
98
99     // Anti ocilation
100     if(self.velocity_z  > 0)
101         self.velocity_z *= 1 - (autocvar_g_vehicle_racer_upforcedamper * frametime);
102
103     self.velocity   += v_add;
104     //self.velocity_z -= autocvar_sv_gravity * frametime;
105
106     push_vector_x =  (fl_push - bl_push);
107     push_vector_x += (fr_push - br_push);
108     push_vector_x *= 360;
109
110     push_vector_z = (fr_push - fl_push);
111     push_vector_z += (br_push - bl_push);
112     push_vector_z *= 360;
113
114     // Apply angle diffrance
115     self.angles_z += push_vector_z * frametime;
116     self.angles_x += push_vector_x * frametime;
117
118     // Apply stabilizer
119     self.angles_x *= 1 - (autocvar_g_vehicle_racer_anglestabilizer * frametime);
120     self.angles_z *= 1 - (autocvar_g_vehicle_racer_anglestabilizer * frametime);
121 }
122
123 void racer_fire_cannon(string tagname)
124 {
125     vector v;
126     entity bolt;
127
128     v = gettaginfo(self, gettagindex(self, tagname));
129     bolt = vehicles_projectile("wakizashi_gun_muzzleflash", "weapons/lasergun_fire.wav",
130                            v, normalize(v_forward + randomvec() * autocvar_g_vehicle_racer_cannon_spread) * autocvar_g_vehicle_racer_cannon_speed,
131                            autocvar_g_vehicle_racer_cannon_damage, autocvar_g_vehicle_racer_cannon_radius, autocvar_g_vehicle_racer_cannon_force,  0,
132                            DEATH_WAKIGUN, PROJECTILE_WAKICANNON, 0, TRUE, TRUE);
133
134         // Fix z-aim (for chase mode)
135     v = normalize(trace_endpos - bolt.origin);
136     v_forward_z = v_z * 0.5;
137     bolt.velocity = v_forward * autocvar_g_vehicle_racer_cannon_speed;
138 }
139
140 void racer_rocket_groundhugger()
141 {
142     vector olddir, newdir;
143     float oldvel, newvel;
144
145     self.nextthink  = time;
146
147     if(self.owner.deadflag != DEAD_NO || self.cnt < time)
148     {
149         self.use();
150         return;
151     }
152
153     if not (self.realowner.vehicle)
154     {
155         UpdateCSQCProjectile(self);
156         return;
157     }
158
159     olddir = normalize(self.velocity);
160     oldvel = vlen(self.velocity);
161     newvel = oldvel + self.lip;
162
163     tracebox(self.origin, self.mins, self.maxs, self.origin + olddir * 64, MOVE_WORLDONLY,self);
164     if(trace_fraction <= 0.5)
165     {
166         // Hitting somethign soon, just speed ahead
167         self.velocity = olddir * newvel;
168         UpdateCSQCProjectile(self);
169         return;
170     }
171
172     traceline(trace_endpos, trace_endpos - '0 0 64', MOVE_NORMAL, self);
173     if(trace_fraction != 1.0)
174     {
175         newdir = normalize(trace_endpos + '0 0 64' - self.origin) * autocvar_g_vehicle_racer_rocket_turnrate;
176         self.velocity = normalize(olddir + newdir) * newvel;
177     }
178     else
179     {
180         self.velocity = olddir * newvel;
181         self.velocity_z -= 1600 * sys_frametime; // 2x grav looks better for this one
182     }
183
184     UpdateCSQCProjectile(self);
185     return;
186 }
187
188 void racer_rocket_tracker()
189 {
190     vector olddir, newdir;
191     float oldvel, newvel;
192
193     self.nextthink  = time;
194
195     if (self.owner.deadflag != DEAD_NO || self.cnt < time)
196     {
197         self.use();
198         return;
199     }
200
201     if not (self.realowner.vehicle)
202     {
203         UpdateCSQCProjectile(self);
204         return;
205     }
206
207     olddir = normalize(self.velocity);
208     oldvel = vlen(self.velocity);
209     newvel = oldvel + self.lip;
210     makevectors(vectoangles(olddir));
211
212     traceline(self.origin, self.origin + v_forward * 64 - '0 0 32', MOVE_NORMAL, self);
213     newdir = normalize(self.enemy.origin - self.origin);
214
215     if(vlen(newdir - v_forward) > autocvar_g_vehicle_racer_rocket_locked_maxangle)
216     {
217         //bprint("Target lost!\n");
218         //dprint("OF:", ftos(vlen(newdir - v_forward)), "\n");
219         self.think = racer_rocket_groundhugger;
220         return;
221     }
222
223     if(trace_fraction != 1.0)
224         newdir_z += 16 * sys_frametime;
225
226     self.velocity = normalize(olddir + newdir * autocvar_g_vehicle_racer_rocket_turnrate) * newvel;
227     self.velocity_z -= 800 * sys_frametime;
228
229     UpdateCSQCProjectile(self);
230     return;
231 }
232
233 void racer_fire_rocket(string tagname, entity trg)
234 {
235     vector v;
236     entity rocket;
237
238     v = gettaginfo(self, gettagindex(self, tagname));
239     rocket = vehicles_projectile("wakizashi_rocket_launch", "weapons/rocket_fire.wav",
240                            v, v_forward * autocvar_g_vehicle_racer_rocket_speed,
241                            autocvar_g_vehicle_racer_rocket_damage, autocvar_g_vehicle_racer_rocket_radius, autocvar_g_vehicle_racer_rocket_force, 3,
242                            DEATH_WAKIROCKET, PROJECTILE_WAKIROCKET, 20, FALSE, FALSE);
243
244     rocket.lip              = autocvar_g_vehicle_racer_rocket_accel * sys_frametime;
245     rocket.wait             = autocvar_g_vehicle_racer_rocket_turnrate;
246     rocket.nextthink        = time;
247     rocket.enemy            = trg;
248     rocket.cnt              = time + 15;
249
250     if(trg)
251         rocket.think            = racer_rocket_tracker;
252     else
253         rocket.think            = racer_rocket_groundhugger;
254 }
255
256 float racer_frame()
257 {
258     entity player, racer;
259     vector df;
260     float ftmp;
261
262         if(intermission_running)
263                 return 1;
264
265     player  = self;
266     racer   = self.vehicle;
267     self    = racer;
268     
269     player.BUTTON_ZOOM = player.BUTTON_CROUCH = 0;
270     
271     vehicles_painframe();
272     
273     if(racer.deadflag != DEAD_NO)
274     {
275         self = player;
276         player.BUTTON_ATCK = player.BUTTON_ATCK2 = 0;
277         return 1;
278     }
279
280     racer_align4point();
281
282     crosshair_trace(player);
283
284     racer.angles_x *= -1;
285
286     // Yaw
287     ftmp = autocvar_g_vehicle_racer_turnspeed * frametime;
288     ftmp = bound(-ftmp, shortangle_f(player.v_angle_y - racer.angles_y, racer.angles_y), ftmp);
289     racer.angles_y = anglemods(racer.angles_y + ftmp);
290
291     // Roll
292     racer.angles_z += -ftmp * autocvar_g_vehicle_racer_turnroll * frametime;
293
294     // Pitch
295     ftmp = autocvar_g_vehicle_racer_pitchspeed  * frametime;
296     ftmp = bound(-ftmp, shortangle_f(player.v_angle_x - racer.angles_x, racer.angles_x), ftmp);
297     racer.angles_x = bound(-30, anglemods(racer.angles_x + ftmp), 30);
298
299     makevectors(racer.angles);
300     racer.angles_x *= -1;
301
302
303     ftmp = racer.velocity_z;
304     df = racer.velocity * -autocvar_g_vehicle_racer_friction;
305     racer.velocity_z = ftmp;
306
307     if(player.movement_x != 0)
308     {
309         if(player.movement_x > 0)
310             df += v_forward  * autocvar_g_vehicle_racer_speed_forward;
311         else if(player.movement_x < 0)
312             df -= v_forward  * autocvar_g_vehicle_racer_speed_forward;
313     }
314
315     if(player.movement_y != 0)
316     {
317         if(player.movement_y < 0)
318             df -= v_right * autocvar_g_vehicle_racer_speed_strafe;
319         else if(player.movement_y > 0)
320             df += v_right * autocvar_g_vehicle_racer_speed_strafe;
321     }
322     
323     if(vlen(player.movement) != 0)
324     {
325         if(self.sound_nexttime < time || self.sounds != 1)
326         {        
327             self.sounds = 1;
328             self.sound_nexttime = time + 10.922667; //soundlength("vehicles/racer_move.wav");
329             sound (self, CH_TRIGGER_SINGLE, "vehicles/racer_move.wav", VOL_VEHICLEENGINE, ATTN_NORM);
330         }
331     }
332     else
333     {        
334         if(self.sound_nexttime < time || self.sounds != 0)
335         {        
336             self.sounds = 0;
337             self.sound_nexttime = time + 11.888604; //soundlength("vehicles/racer_idle.wav");
338             sound (self, CH_TRIGGER_SINGLE, "vehicles/racer_idle.wav", VOL_VEHICLEENGINE, ATTN_NORM);
339         }        
340     }
341     
342     // Afterburn
343     if (player.BUTTON_JUMP && racer.vehicle_energy >= (autocvar_g_vehicle_racer_afterburn_cost * frametime))
344     {
345         if(time - racer.wait > 0.2)
346             pointparticles(particleeffectnum("wakizashi_booster_smoke"), self.origin, '0 0 0', 1);            
347         
348         racer.wait = time;
349         racer.vehicle_energy -= autocvar_g_vehicle_racer_afterburn_cost * frametime;
350         df += (v_forward * autocvar_g_vehicle_racer_speed_afterburn);
351         
352         if(self.invincible_finished < time)
353         {            
354             traceline(self.origin, self.origin - '0 0 256', MOVE_NORMAL, self);
355             if(trace_fraction != 1.0)
356                 pointparticles(particleeffectnum("smoke_small"), trace_endpos, '0 0 0', 1);
357             
358             self.invincible_finished = time + 0.1 + (random() * 0.1);
359         }
360
361         if(self.strength_finished < time)
362         {        
363             //self.sounds = 2;
364             self.strength_finished = time + 10.922667; //soundlength("vehicles/racer_boost.wav");
365             sound (self.tur_head, CH_TRIGGER_SINGLE, "vehicles/racer_boost.wav", VOL_VEHICLEENGINE, ATTN_NORM);            
366         }        
367     }
368     else
369     {
370         self.strength_finished = 0;
371         sound (self.tur_head, CH_TRIGGER_SINGLE, "misc/null.wav", VOL_VEHICLEENGINE, ATTN_NORM);
372     }
373         
374
375     racer.velocity  += df * frametime;
376
377     df = (vlen(racer.velocity) * autocvar_g_vehicle_racer_downforce * v_up) * frametime;
378     racer.velocity  = racer.velocity - df;
379     player.movement = racer.velocity;
380
381     if(player.BUTTON_ATCK)
382     if(time > racer.attack_finished_single)
383     if(racer.vehicle_energy >= autocvar_g_vehicle_racer_cannon_cost)
384     {
385         racer.vehicle_energy -= autocvar_g_vehicle_racer_cannon_cost;
386         racer.wait = time;
387
388         crosshair_trace(player);
389         if(racer.cnt)
390         {
391             racer_fire_cannon("tag_fire1");
392             racer.cnt = 0;
393         }
394         else
395         {
396             racer_fire_cannon("tag_fire2");
397             racer.cnt = 1;
398         }
399         racer.attack_finished_single = time + autocvar_g_vehicle_racer_cannon_refire;
400         //self.owner.vehicle_energy = racer.vehicle_energy / autocvar_g_vehicle_racer_energy;
401     }
402
403     if(autocvar_g_vehicle_racer_rocket_locktarget)
404     {
405         vehicles_locktarget((1 / autocvar_g_vehicle_racer_rocket_locking_time) * frametime,
406                          (1 / autocvar_g_vehicle_racer_rocket_locking_releasetime) * frametime,
407                          autocvar_g_vehicle_racer_rocket_locked_time);
408
409         if(self.lock_target)
410         {
411             if(racer.lock_strength == 1)
412                 UpdateAuxiliaryXhair(player, real_origin(self.lock_target), '1 0 0', 0);
413             else if(self.lock_strength > 0.5)
414                 UpdateAuxiliaryXhair(player, real_origin(self.lock_target), '0 1 0', 0);
415             else if(self.lock_strength < 0.5)
416                 UpdateAuxiliaryXhair(player, real_origin(self.lock_target), '0 0 1', 0);
417         }
418     }
419
420     if(time > racer.delay)
421     if(player.BUTTON_ATCK2)
422     {
423         self.misc_bulletcounter += 1;
424         racer.delay = time + 0.3;
425         if(self.misc_bulletcounter == 1)
426             racer_fire_rocket("tag_rocket_r", (self.lock_strength == 1 && self.lock_target) ? self.lock_target : world);
427         else if(self.misc_bulletcounter == 2)
428         {
429             racer_fire_rocket("tag_rocket_l", (self.lock_strength == 1 && self.lock_target) ? self.lock_target : world);
430             self.lock_strength  = 0;
431             self.lock_target    = world;
432             self.misc_bulletcounter = 0;
433
434             racer.delay = time + autocvar_g_vehicle_racer_rocket_refire;
435             racer.lip = time;
436         }
437     }
438     player.vehicle_reload1 = bound(0, 100 * ((time - racer.lip) / (racer.delay - racer.lip)), 100);
439
440     if(self.vehicle_flags  & VHF_SHIELDREGEN)
441         vehicles_regen(dmg_time, vehicle_shield, autocvar_g_vehicle_racer_shield, autocvar_g_vehicle_racer_shield_regen_pause, autocvar_g_vehicle_racer_shield_regen, frametime);
442
443     if(self.vehicle_flags  & VHF_HEALTHREGEN)
444         vehicles_regen(dmg_time, vehicle_health, autocvar_g_vehicle_racer_health, autocvar_g_vehicle_racer_health_regen_pause, autocvar_g_vehicle_racer_health_regen, frametime);
445
446     if(self.vehicle_flags  & VHF_ENERGYREGEN)
447         vehicles_regen(wait, vehicle_energy, autocvar_g_vehicle_racer_energy, autocvar_g_vehicle_racer_energy_regen_pause, autocvar_g_vehicle_racer_energy_regen, frametime);
448
449
450     VEHICLE_UPDATE_PLAYER(health, racer);
451     VEHICLE_UPDATE_PLAYER(energy, racer);
452
453     if(self.vehicle_flags & VHF_HASSHIELD)
454         VEHICLE_UPDATE_PLAYER(shield, racer);
455
456
457     player.BUTTON_ATCK = player.BUTTON_ATCK2 = 0;
458     setorigin(player,racer.origin + '0 0 32');
459     player.velocity = racer.velocity;
460
461     self = player;
462     return 1;
463 }
464
465 void racer_think()
466 {
467     /*
468     float a, b, c;a = autocvar_g_vehicle_racer_anglestabilizer;
469     b = autocvar_g_vehicle_racer_springlength;
470     c = autocvar_g_vehicle_racer_hoverpower;
471
472     autocvar_g_vehicle_racer_anglestabilizer = 36;
473     autocvar_g_vehicle_racer_springlength = 96;
474     autocvar_g_vehicle_racer_hoverpower = 300;
475     */
476
477     racer_align4point(); //time - self.nextthink);
478
479     /*
480     //if(self.velocity_z > 0)
481     //    self.velocity_z *= 0.95;
482
483     autocvar_g_vehicle_racer_anglestabilizer = a;
484     autocvar_g_vehicle_racer_springlength = b;
485     autocvar_g_vehicle_racer_hoverpower = c;
486     */
487
488     self.velocity_x *= 0.9;
489     self.velocity_y *= 0.9;
490     self.velocity_z *= 0.8;
491     self.velocity_z += sin(time * 2) * 16;
492     self.nextthink = time; // + 0.05;
493 }
494
495 void racer_enter()
496 {
497     self.movetype = MOVETYPE_BOUNCE;
498     self.owner.vehicle_health = (self.vehicle_health / autocvar_g_vehicle_racer_health)  * 100;
499     self.owner.vehicle_shield = (self.vehicle_shield / autocvar_g_vehicle_racer_shield)  * 100;
500     
501     if(self.owner.flagcarried)
502        setorigin(self.owner.flagcarried, '-190 0 96');
503 }
504
505 void racer_exit(float eject)
506 {
507     vector spot;
508     
509     self.think      = racer_think;
510     self.nextthink  = time;
511     self.movetype   = MOVETYPE_TOSS;
512     sound (self.tur_head, CH_TRIGGER_SINGLE, "misc/null.wav", VOL_VEHICLEENGINE, ATTN_NORM);
513     
514     if not (self.owner)
515         return;
516
517         makevectors(self.angles);
518         if(eject)
519         {
520             spot = self.origin + v_forward * 100 + '0 0 64';
521             spot = vehicles_findgoodexit(spot);
522             setorigin(self.owner , spot);
523             self.owner.velocity = (v_up + v_forward * 0.25) * 750;
524         }
525         else
526         {
527             spot = self.origin - v_forward * 200 + '0 0 64';
528             spot = vehicles_findgoodexit(spot);
529             setorigin(self.owner , spot);
530         }
531         
532     self.owner = world;
533 }
534 void racer_impact()
535 {
536     if(autocvar_g_vehicle_racer_bouncepain_x)
537         vehilces_impact(autocvar_g_vehicle_racer_bouncepain_x, autocvar_g_vehicle_racer_bouncepain_y, autocvar_g_vehicle_racer_bouncepain_z);
538 }
539
540 void racer_spawn()
541 {
542     self.think          = racer_think;
543     self.nextthink      = time;
544     self.vehicle_health = autocvar_g_vehicle_racer_health;
545     self.vehicle_shield = autocvar_g_vehicle_racer_shield;
546
547     self.movetype       = MOVETYPE_TOSS;
548     self.solid          = SOLID_SLIDEBOX;
549     self.delay          = time;
550     self.scale          = 0.5;
551
552     setsize(self, RACER_MIN * 0.5, RACER_MAX * 0.5);
553     self.bouncefactor = autocvar_g_vehicle_racer_bouncefactor;
554     self.bouncestop = autocvar_g_vehicle_racer_bouncestop;    
555     self.vehicle_impact = racer_impact;
556     //self.destvec = autocvar_g_vehicle_racer_bouncepain;
557 }
558
559
560 void racer_blowup()
561 {
562     self.deadflag    = DEAD_DEAD;
563     self.vehicle_exit(VHEF_NORMAL);
564
565     RadiusDamage (self, self, autocvar_g_vehicle_racer_blowup_coredamage,
566                                         autocvar_g_vehicle_racer_blowup_edgedamage,
567                                         autocvar_g_vehicle_racer_blowup_radius, world,
568                                         autocvar_g_vehicle_racer_blowup_forceintensity,
569                                         DEATH_WAKIBLOWUP, world);
570
571     self.nextthink  = time + autocvar_g_vehicle_racer_respawntime;
572     self.think      = racer_spawn;
573     self.movetype   = MOVETYPE_NONE;
574     self.effects    = EF_NODRAW;
575
576     self.colormod  = '0 0 0';
577     self.avelocity = '0 0 0';
578     self.velocity  = '0 0 0';
579
580     setorigin(self, self.pos1);
581         self.think     = racer_spawn;
582         self.nextthink = time + autocvar_g_vehicle_racer_respawntime;
583 }
584
585 void racer_deadtouch()
586 {
587     self.avelocity_x *= 0.7;
588     self.cnt -= 1;
589     if(self.cnt <= 0)
590         racer_blowup();
591 }
592
593 void racer_die()
594 {
595     self.health       = 0;
596     self.event_damage = SUB_Null;
597     self.solid        = SOLID_CORPSE;
598     self.takedamage   = DAMAGE_NO;
599     self.deadflag     = DEAD_DYING;
600     self.movetype     = MOVETYPE_BOUNCE;
601     self.wait         = time;
602     self.cnt          = 1 + random() * 2;
603     self.touch        = racer_deadtouch;
604     
605     pointparticles(particleeffectnum("explosion_medium"), self.origin, '0 0 0', 1);    
606
607     if(random() < 0.5)
608         self.avelocity_z  = 32;
609     else
610         self.avelocity_z  = -32;
611
612     self.avelocity_x = -vlen(self.velocity) * 0.2;
613     self.velocity   += '0 0 700';
614     self.colormod    = '-0.5 -0.5 -0.5';
615
616         self.think     = racer_blowup;
617         self.nextthink = 2 + time + random() * 3;
618 }
619
620 void racer_dinit()
621 {
622     if not (vehicle_initialize(
623              "Wakizashi",
624              "models/vehicles/wakizashi.dpm",
625              "null", // we need this so tur_head is networked and usable for sounds
626              "models/vehicles/wakizashi_cockpit.dpm",
627              "", "", "tag_viewport",
628              HUD_WAKIZASHI,
629              0.5 * RACER_MIN, 0.5 * RACER_MAX,
630              FALSE,
631              racer_spawn, autocvar_g_vehicle_racer_respawntime,
632              racer_frame,
633              racer_enter, racer_exit,
634              racer_die,   racer_think,
635              TRUE))
636     {
637         remove(self);
638         return;
639     }
640
641     if(autocvar_g_vehicle_racer_hovertype != 0)
642         racer_force_from_tag = vehicles_force_fromtag_maglev;
643     else
644         racer_force_from_tag = vehicles_force_fromtag_hover;
645
646     // FIXME: this be hakkz, fix the models insted (scale body, add tag_viewport to the hudmodel).
647     self.scale = 0.5;
648     setattachment(self.vehicle_hudmodel, self, "");
649     setattachment(self.vehicle_viewport, self, "tag_viewport");
650
651     self.mass               = 900;
652 }
653
654 void spawnfunc_vehicle_racer()
655 {
656     self.vehicle_flags |= VHF_DMGSHAKE;
657     self.vehicle_flags |= VHF_DMGROLL;
658
659     precache_sound ("weapons/lasergun_fire.wav");
660     precache_sound ("weapons/rocket_fire.wav");
661     
662     precache_sound ("vehicles/racer_idle.wav");
663     precache_sound ("vehicles/racer_move.wav");
664     precache_sound ("vehicles/racer_boost.wav");
665
666     precache_model ("models/vhshield.md3");
667     precache_model ("models/vehicles/wakizashi.dpm");
668     precache_model ("models/vehicles/wakizashi_cockpit.dpm");
669
670     vehicles_configcheck("vehicle_racer.cfg", autocvar_g_vehicle_racer_health);
671     if(autocvar_g_vehicle_racer_energy)
672         if(autocvar_g_vehicle_racer_energy_regen)
673             self.vehicle_flags |= VHF_ENERGYREGEN;
674
675     if(autocvar_g_vehicle_racer_shield)
676         self.vehicle_flags |= VHF_HASSHIELD;
677
678     if(autocvar_g_vehicle_racer_shield_regen)
679         self.vehicle_flags |= VHF_SHIELDREGEN;
680
681     if(autocvar_g_vehicle_racer_health_regen)
682         self.vehicle_flags |= VHF_HEALTHREGEN;
683
684     self.think = racer_dinit;
685     
686     if(g_assault)
687         self.nextthink = time + 0.5;
688     else
689         self.nextthink = time + (autocvar_g_vehicles_delayspawn ? autocvar_g_vehicle_racer_respawntime + (random() * autocvar_g_vehicles_delayspawn_jitter) : 0.5);
690 }
691 #endif // SVQC