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