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