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