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