Cleanse the touch functions of the other evil
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / vehicles / vehicle / racer.qc
1 #ifndef VEHICLE_RACER
2 #define VEHICLE_RACER
3
4 #include "racer_weapon.qh"
5
6 CLASS(Racer, Vehicle)
7 /* spawnflags */ ATTRIB(Racer, spawnflags, int, VHF_DMGSHAKE | VHF_DMGROLL);
8 /* mins       */ ATTRIB(Racer, mins, vector, '-120 -120 -40' * 0.5);
9 /* maxs       */ ATTRIB(Racer, maxs, vector, '120 120 40' * 0.5);
10 /* view offset*/ ATTRIB(Racer, view_ofs, vector, '0 0 50');
11 /* view dist  */ ATTRIB(Racer, height, float, 200);
12 /* model          */ ATTRIB(Racer, mdl, string, "models/vehicles/wakizashi.dpm");
13 /* model          */ ATTRIB(Racer, model, string, "models/vehicles/wakizashi.dpm");
14 /* head_model */ ATTRIB(Racer, head_model, string, "null");
15 /* hud_model  */ ATTRIB(Racer, hud_model, string, "models/vehicles/wakizashi_cockpit.dpm");
16 /* tags       */ ATTRIB(Racer, tag_head, string, "");
17 /* tags       */ ATTRIB(Racer, tag_hud, string, "");
18 /* tags       */ ATTRIB(Racer, tag_view, string, "tag_viewport");
19 /* netname    */ ATTRIB(Racer, netname, string, "racer");
20 /* fullname   */ ATTRIB(Racer, vehicle_name, string, _("Racer"));
21 /* icon       */ ATTRIB(Racer, m_icon, string, "vehicle_racer");
22 ENDCLASS(Racer)
23 REGISTER_VEHICLE(RACER, NEW(Racer));
24
25 #endif
26
27 #ifdef IMPLEMENTATION
28
29 #ifdef SVQC
30 #include <common/triggers/trigger/impulse.qh>
31
32 bool autocvar_g_vehicle_racer = true;
33
34 float autocvar_g_vehicle_racer_thinkrate = 0.05; // TODO: any higher causes it to sink in liquids
35
36 float autocvar_g_vehicle_racer_speed_afterburn = 3000;
37 // energy consumed per second
38 float autocvar_g_vehicle_racer_afterburn_cost = 100;
39
40 float autocvar_g_vehicle_racer_waterburn_cost = 5;
41 float autocvar_g_vehicle_racer_waterburn_speed = 750;
42
43 float autocvar_g_vehicle_racer_water_speed_forward = 600;
44 float autocvar_g_vehicle_racer_water_speed_strafe = 600;
45
46 float autocvar_g_vehicle_racer_pitchlimit = 30;
47
48 float autocvar_g_vehicle_racer_water_downforce = 0.03;
49 float autocvar_g_vehicle_racer_water_upforcedamper = 15;
50
51 float autocvar_g_vehicle_racer_anglestabilizer = 1.75;
52 float autocvar_g_vehicle_racer_downforce = 0.01;
53
54 float autocvar_g_vehicle_racer_speed_forward = 650;
55 float autocvar_g_vehicle_racer_speed_strafe = 650;
56 float autocvar_g_vehicle_racer_springlength = 70;
57 float autocvar_g_vehicle_racer_upforcedamper = 10;
58 float autocvar_g_vehicle_racer_friction = 0.45;
59
60 float autocvar_g_vehicle_racer_water_time = 5;
61
62 float autocvar_g_vehicle_racer_collision_multiplier = 0.05;
63
64 // 0 = hover, != 0 = maglev
65 int autocvar_g_vehicle_racer_hovertype = 0;
66 // NOTE!! x 4 (4 engines)
67 float autocvar_g_vehicle_racer_hoverpower = 8000;
68
69 float autocvar_g_vehicle_racer_turnroll = 30;
70 float autocvar_g_vehicle_racer_turnspeed = 220;
71 float autocvar_g_vehicle_racer_pitchspeed = 125;
72
73 float autocvar_g_vehicle_racer_energy = 100;
74 float autocvar_g_vehicle_racer_energy_regen = 50;
75 float autocvar_g_vehicle_racer_energy_regen_pause = 1;
76
77 float autocvar_g_vehicle_racer_health = 200;
78 float autocvar_g_vehicle_racer_health_regen = 0;
79 float autocvar_g_vehicle_racer_health_regen_pause = 0;
80
81 float autocvar_g_vehicle_racer_shield = 100;
82 float autocvar_g_vehicle_racer_shield_regen = 30;
83 float autocvar_g_vehicle_racer_shield_regen_pause = 1;
84
85 bool autocvar_g_vehicle_racer_rocket_locktarget = true;
86 float autocvar_g_vehicle_racer_rocket_locking_time = 0.9;
87 float autocvar_g_vehicle_racer_rocket_locking_releasetime = 0.5;
88 float autocvar_g_vehicle_racer_rocket_locked_time = 4;
89
90 float autocvar_g_vehicle_racer_respawntime = 35;
91
92 float autocvar_g_vehicle_racer_blowup_radius = 250;
93 float autocvar_g_vehicle_racer_blowup_coredamage = 250;
94 float autocvar_g_vehicle_racer_blowup_edgedamage = 15;
95 float autocvar_g_vehicle_racer_blowup_forceintensity = 250;
96
97 // Factor of old velocity to keep after collision
98 float autocvar_g_vehicle_racer_bouncefactor = 0.25;
99 // if != 0, New veloctiy after bounce = 0 if new velocity < this
100 float autocvar_g_vehicle_racer_bouncestop = 0;
101 // "minspeed_for_pain speedchange_to_pain_factor max_damage"
102 vector autocvar_g_vehicle_racer_bouncepain = '60 0.75 300';
103
104 .float racer_watertime;
105
106 var vector racer_force_from_tag(entity this, string tag_name, float spring_length, float max_power);
107
108 void racer_align4point(entity this, float _delta)
109 {
110         vector push_vector;
111         float fl_push, fr_push, bl_push, br_push;
112
113         push_vector  = racer_force_from_tag(this, "tag_engine_fr", autocvar_g_vehicle_racer_springlength, autocvar_g_vehicle_racer_hoverpower);
114         fr_push   = force_fromtag_normpower;
115         //vehicles_sweap_collision(force_fromtag_origin, this.velocity, _delta, v_add, autocvar_g_vehicle_racer_collision_multiplier);
116
117         push_vector += racer_force_from_tag(this, "tag_engine_fl", autocvar_g_vehicle_racer_springlength, autocvar_g_vehicle_racer_hoverpower);
118         fl_push   = force_fromtag_normpower;
119         //vehicles_sweap_collision(force_fromtag_origin, this.velocity, _delta, v_add, autocvar_g_vehicle_racer_collision_multiplier);
120
121         push_vector += racer_force_from_tag(this, "tag_engine_br", autocvar_g_vehicle_racer_springlength, autocvar_g_vehicle_racer_hoverpower);
122         br_push   = force_fromtag_normpower;
123         //vehicles_sweap_collision(force_fromtag_origin, this.velocity, _delta, v_add, autocvar_g_vehicle_racer_collision_multiplier);
124
125         push_vector += racer_force_from_tag(this, "tag_engine_bl", autocvar_g_vehicle_racer_springlength, autocvar_g_vehicle_racer_hoverpower);
126         bl_push   = force_fromtag_normpower;
127         //vehicles_sweap_collision(force_fromtag_origin, this.velocity, _delta, v_add, autocvar_g_vehicle_racer_collision_multiplier);
128
129         this.velocity += push_vector * _delta;
130
131         float uforce = autocvar_g_vehicle_racer_upforcedamper;
132
133         int cont = pointcontents(this.origin - '0 0 64');
134         if(cont == CONTENT_WATER || cont == CONTENT_LAVA || cont == CONTENT_SLIME)
135         {
136                 uforce = autocvar_g_vehicle_racer_water_upforcedamper;
137
138                 if(PHYS_INPUT_BUTTON_CROUCH(this.owner) && time < this.air_finished)
139                         this.velocity_z += 30;
140                 else
141                         this.velocity_z += 200;
142         }
143
144
145         // Anti ocilation
146         if(this.velocity_z > 0)
147                 this.velocity_z *= 1 - uforce * _delta;
148
149         push_vector_x =  (fl_push - bl_push);
150         push_vector_x += (fr_push - br_push);
151         push_vector_x *= 360;
152
153         push_vector_z = (fr_push - fl_push);
154         push_vector_z += (br_push - bl_push);
155         push_vector_z *= 360;
156
157         // Apply angle diffrance
158         this.angles_z += push_vector_z * _delta;
159         this.angles_x += push_vector_x * _delta;
160
161         // Apply stabilizer
162         this.angles_x *= 1 - (autocvar_g_vehicle_racer_anglestabilizer * _delta);
163         this.angles_z *= 1 - (autocvar_g_vehicle_racer_anglestabilizer * _delta);
164 }
165
166 void racer_fire_rocket_aim(entity player, string tagname, entity trg)
167 {
168         entity racer = player.vehicle;
169         vector v = gettaginfo(racer, gettagindex(racer, tagname));
170         racer_fire_rocket(player, v, v_forward, trg);
171 }
172
173 bool racer_frame(entity this)
174 {
175         entity vehic = this.vehicle;
176         return = true;
177
178         if(intermission_running)
179         {
180                 vehic.velocity = '0 0 0';
181                 vehic.avelocity = '0 0 0';
182                 return;
183         }
184
185         vehicles_frame(vehic, this);
186
187         traceline(vehic.origin, vehic.origin + '0 0 1', MOVE_NOMONSTERS, this);
188         int cont = trace_dpstartcontents;
189         if(cont & DPCONTENTS_WATER)
190                 vehic.air_finished = time + autocvar_g_vehicle_racer_water_time;
191
192         if(IS_DEAD(vehic))
193         {
194                 PHYS_INPUT_BUTTON_ATCK(this) = PHYS_INPUT_BUTTON_ATCK2(this) = false;
195                 return;
196         }
197
198         racer_align4point(vehic, PHYS_INPUT_TIMELENGTH);
199
200         PHYS_INPUT_BUTTON_ZOOM(this) = PHYS_INPUT_BUTTON_CROUCH(this) = false;
201
202         if(time >= vehic.vehicle_last_trace)
203         {
204                 crosshair_trace(this);
205                 vehic.vehicle_last_trace = time + autocvar_g_vehicle_racer_thinkrate;
206         }
207
208         vehic.angles_x *= -1;
209
210         // Yaw
211         float ftmp = autocvar_g_vehicle_racer_turnspeed * PHYS_INPUT_TIMELENGTH;
212         ftmp = bound(-ftmp, shortangle_f(this.v_angle_y - vehic.angles_y, vehic.angles_y), ftmp);
213         vehic.angles_y = anglemods(vehic.angles_y + ftmp);
214
215         // Roll
216         vehic.angles_z += -ftmp * autocvar_g_vehicle_racer_turnroll * PHYS_INPUT_TIMELENGTH;
217
218         // Pitch
219         ftmp = autocvar_g_vehicle_racer_pitchspeed  * PHYS_INPUT_TIMELENGTH;
220         ftmp = bound(-ftmp, shortangle_f(this.v_angle_x - vehic.angles_x, vehic.angles_x), ftmp);
221         vehic.angles_x = bound(-autocvar_g_vehicle_racer_pitchlimit, anglemods(vehic.angles_x + ftmp), autocvar_g_vehicle_racer_pitchlimit);
222
223         makevectors(vehic.angles);
224         vehic.angles_x *= -1;
225
226         //ftmp = vehic.velocity_z;
227         vector df = vehic.velocity * -autocvar_g_vehicle_racer_friction;
228         //vehic.velocity_z = ftmp;
229
230         if(this.movement)
231         {
232                 if(cont & DPCONTENTS_LIQUIDSMASK)
233                 {
234                         if(this.movement_x) { df += v_forward * ((this.movement_x > 0) ? autocvar_g_vehicle_racer_water_speed_forward : -autocvar_g_vehicle_racer_water_speed_forward); }
235                         if(this.movement_y) { df += v_right * ((this.movement_y > 0) ? autocvar_g_vehicle_racer_water_speed_strafe : -autocvar_g_vehicle_racer_water_speed_strafe); }
236                 }
237                 else
238                 {
239                         if(this.movement_x) { df += v_forward * ((this.movement_x > 0) ? autocvar_g_vehicle_racer_speed_forward : -autocvar_g_vehicle_racer_speed_forward); }
240                         if(this.movement_y) { df += v_right * ((this.movement_y > 0) ? autocvar_g_vehicle_racer_speed_strafe : -autocvar_g_vehicle_racer_speed_strafe); }
241                 }
242
243 #ifdef SVQC
244                 if(vehic.sound_nexttime < time || vehic.sounds != 1)
245                 {
246                         vehic.sounds = 1;
247                         vehic.sound_nexttime = time + 10.922667; //soundlength("vehicles/racer_move.wav");
248                         sound (vehic, CH_TRIGGER_SINGLE, SND_VEH_RACER_MOVE, VOL_VEHICLEENGINE, ATTEN_NORM);
249                 }
250 #endif
251         }
252 #ifdef SVQC
253         else
254         {
255                 if(vehic.sound_nexttime < time || vehic.sounds != 0)
256                 {
257                         vehic.sounds = 0;
258                         vehic.sound_nexttime = time + 11.888604; //soundlength("vehicles/racer_idle.wav");
259                         sound (vehic, CH_TRIGGER_SINGLE, SND_VEH_RACER_IDLE, VOL_VEHICLEENGINE, ATTEN_NORM);
260                 }
261         }
262 #endif
263
264         // Afterburn
265         if (PHYS_INPUT_BUTTON_JUMP(this) && vehic.vehicle_energy >= (autocvar_g_vehicle_racer_afterburn_cost * PHYS_INPUT_TIMELENGTH))
266         {
267 #ifdef SVQC
268                 if(time - vehic.wait > 0.2)
269                         pointparticles(EFFECT_RACER_BOOSTER, vehic.origin - v_forward * 32, v_forward  * vlen(vehic.velocity), 1);
270 #endif
271
272                 vehic.wait = time;
273
274                 if(cont & DPCONTENTS_LIQUIDSMASK)
275                 {
276                         vehic.vehicle_energy -= autocvar_g_vehicle_racer_waterburn_cost * PHYS_INPUT_TIMELENGTH;
277                         df += (v_forward * autocvar_g_vehicle_racer_waterburn_speed);
278                 }
279                 else
280                 {
281                         vehic.vehicle_energy -= autocvar_g_vehicle_racer_afterburn_cost * PHYS_INPUT_TIMELENGTH;
282                         df += (v_forward * autocvar_g_vehicle_racer_speed_afterburn);
283                 }
284
285 #ifdef SVQC
286                 if(vehic.invincible_finished < time)
287                 {
288                         traceline(vehic.origin, vehic.origin - '0 0 256', MOVE_NORMAL, vehic);
289                         if(trace_fraction != 1.0)
290                                 pointparticles(EFFECT_SMOKE_SMALL, trace_endpos, '0 0 0', 1);
291
292                         vehic.invincible_finished = time + 0.1 + (random() * 0.1);
293                 }
294
295                 if(vehic.strength_finished < time)
296                 {
297                         vehic.strength_finished = time + 10.922667; //soundlength("vehicles/racer_boost.wav");
298                         sound (vehic.tur_head, CH_TRIGGER_SINGLE, SND_VEH_RACER_BOOST, VOL_VEHICLEENGINE, ATTEN_NORM);
299                 }
300 #endif
301         }
302         else
303         {
304                 vehic.strength_finished = 0;
305                 sound (vehic.tur_head, CH_TRIGGER_SINGLE, SND_Null, VOL_VEHICLEENGINE, ATTEN_NORM);
306         }
307
308         if(cont & DPCONTENTS_LIQUIDSMASK)
309                 vehic.racer_watertime = time;
310
311         float dforce = autocvar_g_vehicle_racer_downforce;
312         if(time - vehic.racer_watertime <= 3)
313                 dforce = autocvar_g_vehicle_racer_water_downforce;
314
315         df -= v_up * (vlen(vehic.velocity) * dforce);
316         this.movement = vehic.velocity += df * PHYS_INPUT_TIMELENGTH;
317
318 #ifdef SVQC
319
320         Weapon wep1 = WEP_RACER;
321         if (!forbidWeaponUse(this))
322         if (PHYS_INPUT_BUTTON_ATCK(this))
323         if (wep1.wr_checkammo1(wep1, vehic))
324         {
325                 string tagname = (vehic.cnt)
326                     ? (vehic.cnt = 0, "tag_fire1")
327                     : (vehic.cnt = 1, "tag_fire2");
328                 vector org = gettaginfo(vehic, gettagindex(vehic, tagname));
329                 w_shotorg = org;
330                 w_shotdir = v_forward;
331                 // Fix z-aim (for chase mode)
332                 crosshair_trace(this);
333                 w_shotdir.z = normalize(trace_endpos - org).z * 0.5;
334                 .entity weaponentity = weaponentities[0];
335                 wep1.wr_think(wep1, vehic, weaponentity, 1);
336         }
337
338         if(autocvar_g_vehicle_racer_rocket_locktarget)
339         {
340                 if(vehic.vehicle_last_trace == time + autocvar_g_vehicle_racer_thinkrate)
341                 vehicles_locktarget(vehic, (1 / autocvar_g_vehicle_racer_rocket_locking_time) * frametime,
342                                                  (1 / autocvar_g_vehicle_racer_rocket_locking_releasetime) * frametime,
343                                                  autocvar_g_vehicle_racer_rocket_locked_time);
344
345                 if(vehic.lock_target)
346                 {
347                         if(vehic.lock_strength == 1)
348                                 UpdateAuxiliaryXhair(this, real_origin(vehic.lock_target), '1 0 0', 0);
349                         else if(vehic.lock_strength > 0.5)
350                                 UpdateAuxiliaryXhair(this, real_origin(vehic.lock_target), '0 1 0', 0);
351                         else if(vehic.lock_strength < 0.5)
352                                 UpdateAuxiliaryXhair(this, real_origin(vehic.lock_target), '0 0 1', 0);
353                 }
354         }
355
356         if(!forbidWeaponUse(this))
357         if(time > vehic.delay)
358         if(PHYS_INPUT_BUTTON_ATCK2(this))
359         {
360                 vehic.misc_bulletcounter += 1;
361                 vehic.delay = time + 0.3;
362
363                 if(vehic.misc_bulletcounter == 1)
364                 {
365                         racer_fire_rocket_aim(this, "tag_rocket_r", (vehic.lock_strength == 1 && vehic.lock_target) ? vehic.lock_target : NULL);
366                         this.vehicle_ammo2 = 50;
367                 }
368                 else if(vehic.misc_bulletcounter == 2)
369                 {
370                         racer_fire_rocket_aim(this, "tag_rocket_l", (vehic.lock_strength == 1 && vehic.lock_target) ? vehic.lock_target : NULL);
371                         vehic.lock_strength  = 0;
372                         vehic.lock_target       = NULL;
373                         vehic.misc_bulletcounter = 0;
374                         vehic.delay = time + autocvar_g_vehicle_racer_rocket_refire;
375                         vehic.lip = time;
376                         this.vehicle_ammo2 = 0;
377                 }
378         }
379         else if(vehic.misc_bulletcounter == 0)
380                 this.vehicle_ammo2 = 100;
381
382         this.vehicle_reload2 = bound(0, 100 * ((time - vehic.lip) / (vehic.delay - vehic.lip)), 100);
383
384         if(vehic.vehicle_flags  & VHF_SHIELDREGEN)
385                 vehicles_regen(vehic, vehic.dmg_time, vehicle_shield, autocvar_g_vehicle_racer_shield, autocvar_g_vehicle_racer_shield_regen_pause, autocvar_g_vehicle_racer_shield_regen, frametime, true);
386
387         if(vehic.vehicle_flags  & VHF_HEALTHREGEN)
388                 vehicles_regen(vehic, vehic.dmg_time, vehicle_health, autocvar_g_vehicle_racer_health, autocvar_g_vehicle_racer_health_regen_pause, autocvar_g_vehicle_racer_health_regen, frametime, false);
389
390         if(vehic.vehicle_flags  & VHF_ENERGYREGEN)
391                 vehicles_regen(vehic, vehic.wait, vehicle_energy, autocvar_g_vehicle_racer_energy, autocvar_g_vehicle_racer_energy_regen_pause, autocvar_g_vehicle_racer_energy_regen, frametime, false);
392
393         VEHICLE_UPDATE_PLAYER(this, vehic, health, racer);
394         VEHICLE_UPDATE_PLAYER(this, vehic, energy, racer);
395
396         if(vehic.vehicle_flags & VHF_HASSHIELD)
397                 VEHICLE_UPDATE_PLAYER(this, vehic, shield, racer);
398
399         PHYS_INPUT_BUTTON_ATCK(this) = PHYS_INPUT_BUTTON_ATCK2(this) = false;
400 #endif
401
402         setorigin(this, vehic.origin + '0 0 32');
403         this.velocity = vehic.velocity;
404 }
405
406 void racer_think(entity this)
407 {
408         this.nextthink = time + autocvar_g_vehicle_racer_thinkrate;
409
410         tracebox(this.origin, this.mins, this.maxs, this.origin - ('0 0 1' * autocvar_g_vehicle_racer_springlength), MOVE_NOMONSTERS, this);
411
412         vector df = this.velocity * -autocvar_g_vehicle_racer_friction;
413         df_z += (1 - trace_fraction) * autocvar_g_vehicle_racer_hoverpower + sin(time * 2) * (autocvar_g_vehicle_racer_springlength * 2);
414
415         float forced = autocvar_g_vehicle_racer_upforcedamper;
416
417         //int cont = pointcontents(this.origin - '0 0 64');
418         traceline(this.origin - '0 0 64', this.origin - '0 0 64', MOVE_NOMONSTERS, this);
419         //if(cont == CONTENT_WATER || cont == CONTENT_LAVA || cont == CONTENT_SLIME)
420         if(trace_dpstartcontents & DPCONTENTS_LIQUIDSMASK)
421         {
422                 forced = autocvar_g_vehicle_racer_water_upforcedamper;
423                 this.velocity_z += 200;
424         }
425
426         this.velocity += df * autocvar_g_vehicle_racer_thinkrate;
427         if(this.velocity_z > 0)
428                 this.velocity_z *= 1 - forced * autocvar_g_vehicle_racer_thinkrate;
429
430         this.angles_x *= 1 - (autocvar_g_vehicle_racer_anglestabilizer * autocvar_g_vehicle_racer_thinkrate);
431         this.angles_z *= 1 - (autocvar_g_vehicle_racer_anglestabilizer * autocvar_g_vehicle_racer_thinkrate);
432
433         CSQCMODEL_AUTOUPDATE(this);
434 }
435
436 void racer_exit(entity this, int eject)
437 {
438         vector spot;
439
440         setthink(this, racer_think);
441         this.nextthink  = time;
442         this.movetype   = MOVETYPE_BOUNCE;
443         sound (this.tur_head, CH_TRIGGER_SINGLE, SND_Null, VOL_VEHICLEENGINE, ATTEN_NORM);
444
445         if(!this.owner)
446                 return;
447
448         makevectors(this.angles);
449         if(eject)
450         {
451                 spot = this.origin + v_forward * 100 + '0 0 64';
452                 spot = vehicles_findgoodexit(this, spot);
453                 setorigin(this.owner, spot);
454                 this.owner.velocity = (v_up + v_forward * 0.25) * 750;
455                 this.owner.oldvelocity = this.owner.velocity;
456         }
457         else
458         {
459                 if(vdist(this.velocity, >, 2 * autocvar_sv_maxairspeed))
460                 {
461                         this.owner.velocity = normalize(this.velocity) * autocvar_sv_maxairspeed * 2;
462                         this.owner.velocity_z += 200;
463                         spot = this.origin + v_forward * 32 + '0 0 32';
464                         spot = vehicles_findgoodexit(this, spot);
465                 }
466                 else
467                 {
468                         this.owner.velocity = this.velocity * 0.5;
469                         this.owner.velocity_z += 10;
470                         spot = this.origin - v_forward * 200 + '0 0 32';
471                         spot = vehicles_findgoodexit(this, spot);
472                 }
473                 this.owner.oldvelocity = this.owner.velocity;
474                 setorigin(this.owner , spot);
475         }
476         antilag_clear(this.owner, CS(this.owner));
477         this.owner = NULL;
478 }
479
480 void racer_blowup(entity this)
481 {
482         this.deadflag = DEAD_DEAD;
483         this.vehicle_exit(this, VHEF_NORMAL);
484
485         RadiusDamage (this, this.enemy, autocvar_g_vehicle_racer_blowup_coredamage,
486                                         autocvar_g_vehicle_racer_blowup_edgedamage,
487                                         autocvar_g_vehicle_racer_blowup_radius, NULL, NULL,
488                                         autocvar_g_vehicle_racer_blowup_forceintensity,
489                                         DEATH_VH_WAKI_DEATH.m_id, NULL);
490
491         this.nextthink  = time + autocvar_g_vehicle_racer_respawntime;
492         setthink(this, vehicles_spawn);
493         this.movetype   = MOVETYPE_NONE;
494         this.effects    = EF_NODRAW;
495         this.solid = SOLID_NOT;
496
497         this.colormod  = '0 0 0';
498         this.avelocity = '0 0 0';
499         this.velocity  = '0 0 0';
500
501         setorigin(this, this.pos1);
502 }
503
504 void racer_blowup_think(entity this)
505 {
506         this.nextthink = time;
507
508         if(time >= this.delay)
509                 racer_blowup(this);
510
511         CSQCMODEL_AUTOUPDATE(this);
512 }
513
514 void racer_deadtouch(entity this, entity toucher)
515 {
516         this.avelocity_x *= 0.7;
517         this.cnt -= 1;
518         if(this.cnt <= 0)
519                 racer_blowup(this);
520 }
521
522 spawnfunc(vehicle_racer)
523 {
524         if(!autocvar_g_vehicle_racer) { remove(this); return; }
525         if(!vehicle_initialize(this, VEH_RACER, false)) { remove(this); return; }
526 }
527
528 #endif // SVQC
529
530 #ifdef CSQC
531 #if 0
532 void racer_draw(entity this)
533 {
534         float pushdeltatime = time - this.lastpushtime;
535         if (pushdeltatime > 0.15) pushdeltatime = 0;
536         this.lastpushtime = time;
537         if(!pushdeltatime) return;
538
539         tracebox(this.move_origin, this.mins, this.maxs, this.move_origin - ('0 0 1' * STAT(VEH_RACER_SPRINGLENGTH)), MOVE_NOMONSTERS, this);
540
541         vector df = this.move_velocity * -STAT(VEH_RACER_FRICTION);
542         df_z += (1 - trace_fraction) * STAT(VEH_RACER_HOVERPOWER) + sin(time * 2) * (STAT(VEH_RACER_SPRINGLENGTH) * 2);
543
544         float forced = STAT(VEH_RACER_UPFORCEDAMPER);
545
546         int cont = pointcontents(this.move_origin - '0 0 64');
547         if(cont == CONTENT_WATER || cont == CONTENT_LAVA || cont == CONTENT_SLIME)
548         {
549                 forced = STAT(VEH_RACER_WATER_UPFORCEDAMPER);
550                 this.move_velocity_z += 200;
551         }
552
553         this.move_velocity += df * pushdeltatime;
554         if(this.move_velocity_z > 0)
555                 this.move_velocity_z *= 1 - forced * pushdeltatime;
556
557         this.move_angles_x *= 1 - (STAT(VEH_RACER_ANGLESTABILIZER) * pushdeltatime);
558         this.move_angles_z *= 1 - (STAT(VEH_RACER_ANGLESTABILIZER) * pushdeltatime);
559
560         Movetype_Physics_MatchServer(this, false);
561 }
562 #endif
563 #endif
564
565 METHOD(Racer, vr_impact, void(Racer thisveh, entity instance))
566 {
567 #ifdef SVQC
568     if(autocvar_g_vehicle_racer_bouncepain)
569         vehicles_impact(instance, autocvar_g_vehicle_racer_bouncepain_x, autocvar_g_vehicle_racer_bouncepain_y, autocvar_g_vehicle_racer_bouncepain_z);
570 #endif
571 }
572
573 METHOD(Racer, vr_enter, void(Racer thisveh, entity instance))
574 {
575 #ifdef SVQC
576     instance.movetype = MOVETYPE_BOUNCE;
577     instance.owner.vehicle_health = (instance.vehicle_health / autocvar_g_vehicle_racer_health)  * 100;
578     instance.owner.vehicle_shield = (instance.vehicle_shield / autocvar_g_vehicle_racer_shield)  * 100;
579
580     if(instance.owner.flagcarried)
581        setorigin(instance.owner.flagcarried, '-190 0 96');
582 #elif defined(CSQC)
583     instance.move_movetype = MOVETYPE_BOUNCE;
584 #endif
585 }
586
587 METHOD(Racer, vr_spawn, void(Racer thisveh, entity instance))
588 {
589 #ifdef SVQC
590     if(instance.scale != 0.5)
591     {
592         if(autocvar_g_vehicle_racer_hovertype != 0)
593             racer_force_from_tag = vehicles_force_fromtag_maglev;
594         else
595             racer_force_from_tag = vehicles_force_fromtag_hover;
596
597         // FIXME: this be hakkz, fix the models insted (scale body, add tag_viewport to the hudmodel).
598         instance.scale = 0.5;
599         setattachment(instance.vehicle_hudmodel, instance, "");
600         setattachment(instance.vehicle_viewport, instance, "tag_viewport");
601
602         instance.mass                      = 900;
603     }
604
605     setthink(instance, racer_think);
606     instance.nextthink    = time;
607     instance.vehicle_health = autocvar_g_vehicle_racer_health;
608     instance.vehicle_shield = autocvar_g_vehicle_racer_shield;
609
610     instance.movetype     = MOVETYPE_TOSS;
611     instance.solid                = SOLID_SLIDEBOX;
612     instance.delay                = time;
613     instance.scale                = 0.5;
614
615     instance.PlayerPhysplug = racer_frame;
616
617     instance.bouncefactor = autocvar_g_vehicle_racer_bouncefactor;
618     instance.bouncestop = autocvar_g_vehicle_racer_bouncestop;
619     instance.damageforcescale = 0.5;
620     instance.vehicle_health = autocvar_g_vehicle_racer_health;
621     instance.vehicle_shield = autocvar_g_vehicle_racer_shield;
622 #endif
623 }
624
625 METHOD(Racer, vr_death, void(Racer thisveh, entity instance))
626 {
627 #ifdef SVQC
628     setSendEntity(instance, func_null); // stop networking this racer (for now)
629     instance.health                     = 0;
630     instance.event_damage       = func_null;
631     instance.solid                      = SOLID_CORPSE;
632     instance.takedamage         = DAMAGE_NO;
633     instance.deadflag           = DEAD_DYING;
634     instance.movetype           = MOVETYPE_BOUNCE;
635     instance.wait                       = time;
636     instance.delay                      = 2 + time + random() * 3;
637     instance.cnt                        = 1 + random() * 2;
638     settouch(instance, racer_deadtouch);
639
640     Send_Effect(EFFECT_EXPLOSION_MEDIUM, instance.origin, '0 0 0', 1);
641
642     if(random() < 0.5)
643         instance.avelocity_z = 32;
644     else
645         instance.avelocity_z = -32;
646
647     instance.avelocity_x = -vlen(instance.velocity) * 0.2;
648     instance.velocity += '0 0 700';
649     instance.colormod = '-0.5 -0.5 -0.5';
650
651     setthink(instance, racer_blowup_think);
652     instance.nextthink = time;
653 #endif
654 }
655
656 #ifdef CSQC
657 METHOD(Racer, vr_hud, void(Racer thisveh))
658 {
659     Vehicles_drawHUD(VEH_RACER.m_icon, "vehicle_racer_weapon1", "vehicle_racer_weapon2",
660                      "vehicle_icon_ammo1", autocvar_hud_progressbar_vehicles_ammo1_color,
661                      "vehicle_icon_ammo2", autocvar_hud_progressbar_vehicles_ammo2_color);
662 }
663 METHOD(Racer, vr_crosshair, void(Racer thisveh, entity player))
664 {
665     Vehicles_drawCrosshair(vCROSS_GUIDE);
666 }
667 #endif
668 METHOD(Racer, vr_setup, void(Racer thisveh, entity instance))
669 {
670 #ifdef SVQC
671     instance.vehicle_exit = racer_exit;
672
673     // we have no need to network energy
674     if(autocvar_g_vehicle_racer_energy)
675     if(autocvar_g_vehicle_racer_energy_regen)
676         instance.vehicle_flags |= VHF_ENERGYREGEN;
677
678     if(autocvar_g_vehicle_racer_shield)
679         instance.vehicle_flags |= VHF_HASSHIELD;
680
681     if(autocvar_g_vehicle_racer_shield_regen)
682         instance.vehicle_flags |= VHF_SHIELDREGEN;
683
684     if(autocvar_g_vehicle_racer_health_regen)
685         instance.vehicle_flags |= VHF_HEALTHREGEN;
686
687     instance.respawntime = autocvar_g_vehicle_racer_respawntime;
688     instance.vehicle_health = autocvar_g_vehicle_racer_health;
689     instance.vehicle_shield = autocvar_g_vehicle_racer_shield;
690     instance.max_health = instance.vehicle_health;
691 #endif
692
693 #ifdef CSQC
694     AuxiliaryXhair[0].axh_image = vCROSS_LOCK; // Rocket
695 #endif
696 }
697
698 #endif