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