Makefile: use `-I.`
[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 <common/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(entity player, string tagname, entity trg)
157 {
158         entity racer = player.vehicle;
159         vector v = gettaginfo(racer, gettagindex(racer, tagname));
160         racer_fire_rocket(player, 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(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(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                 .entity weaponentity = weaponentities[0];
325                 wep1.wr_think(wep1, self, weaponentity, 1);
326         }
327
328         if(autocvar_g_vehicle_racer_rocket_locktarget)
329         {
330                 vehicles_locktarget((1 / autocvar_g_vehicle_racer_rocket_locking_time) * frametime,
331                                                  (1 / autocvar_g_vehicle_racer_rocket_locking_releasetime) * frametime,
332                                                  autocvar_g_vehicle_racer_rocket_locked_time);
333
334                 if(self.lock_target)
335                 {
336                         if(racer.lock_strength == 1)
337                                 UpdateAuxiliaryXhair(player, real_origin(self.lock_target), '1 0 0', 0);
338                         else if(self.lock_strength > 0.5)
339                                 UpdateAuxiliaryXhair(player, real_origin(self.lock_target), '0 1 0', 0);
340                         else if(self.lock_strength < 0.5)
341                                 UpdateAuxiliaryXhair(player, real_origin(self.lock_target), '0 0 1', 0);
342                 }
343         }
344
345         if(!forbidWeaponUse(player))
346         if(time > racer.delay)
347         if(player.BUTTON_ATCK2)
348         {
349                 racer.misc_bulletcounter += 1;
350                 racer.delay = time + 0.3;
351
352                 if(racer.misc_bulletcounter == 1)
353                 {
354                         racer_fire_rocket_aim(player, "tag_rocket_r", (racer.lock_strength == 1 && racer.lock_target) ? racer.lock_target : world);
355                         player.vehicle_ammo2 = 50;
356                 }
357                 else if(racer.misc_bulletcounter == 2)
358                 {
359                         racer_fire_rocket_aim(player, "tag_rocket_l", (racer.lock_strength == 1 && racer.lock_target) ? racer.lock_target : world);
360                         racer.lock_strength  = 0;
361                         racer.lock_target       = world;
362                         racer.misc_bulletcounter = 0;
363                         racer.delay = time + autocvar_g_vehicle_racer_rocket_refire;
364                         racer.lip = time;
365                         player.vehicle_ammo2 = 0;
366                 }
367         }
368         else if(racer.misc_bulletcounter == 0)
369                 player.vehicle_ammo2 = 100;
370
371         player.vehicle_reload2 = bound(0, 100 * ((time - racer.lip) / (racer.delay - racer.lip)), 100);
372
373         if(racer.vehicle_flags  & VHF_SHIELDREGEN)
374                 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);
375
376         if(racer.vehicle_flags  & VHF_HEALTHREGEN)
377                 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);
378
379         if(racer.vehicle_flags  & VHF_ENERGYREGEN)
380                 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);
381
382
383         VEHICLE_UPDATE_PLAYER(player, health, racer);
384         VEHICLE_UPDATE_PLAYER(player, energy, racer);
385
386         if(racer.vehicle_flags & VHF_HASSHIELD)
387                 VEHICLE_UPDATE_PLAYER(player, shield, racer);
388
389         player.BUTTON_ATCK = player.BUTTON_ATCK2 = 0;
390 #endif
391
392         setorigin(player,racer.origin + '0 0 32');
393         player.velocity = racer.velocity;
394
395         setself(player);
396         return 1;
397 }
398
399 void racer_think()
400 {SELFPARAM();
401         self.nextthink = time;
402
403         float pushdeltatime = time - self.lastpushtime;
404         if (pushdeltatime > 0.15) pushdeltatime = 0;
405         self.lastpushtime = time;
406         if(!pushdeltatime) return;
407
408         tracebox(self.origin, self.mins, self.maxs, self.origin - ('0 0 1' * autocvar_g_vehicle_racer_springlength), MOVE_NOMONSTERS, self);
409
410         vector df = self.velocity * -autocvar_g_vehicle_racer_friction;
411         df_z += (1 - trace_fraction) * autocvar_g_vehicle_racer_hoverpower + sin(time * 2) * (autocvar_g_vehicle_racer_springlength * 2);
412
413         float forced = autocvar_g_vehicle_racer_upforcedamper;
414
415         int cont = pointcontents(self.origin - '0 0 64');
416         if(cont == CONTENT_WATER || cont == CONTENT_LAVA || cont == CONTENT_SLIME)
417         {
418                 forced = autocvar_g_vehicle_racer_water_upforcedamper;
419                 self.velocity_z += 200;
420         }
421
422         self.velocity += df * pushdeltatime;
423         if(self.velocity_z > 0)
424                 self.velocity_z *= 1 - forced * pushdeltatime;
425
426         self.angles_x *= 1 - (autocvar_g_vehicle_racer_anglestabilizer * pushdeltatime);
427         self.angles_z *= 1 - (autocvar_g_vehicle_racer_anglestabilizer * pushdeltatime);
428
429         CSQCMODEL_AUTOUPDATE(self);
430 }
431
432 void racer_exit(float eject)
433 {SELFPARAM();
434         vector spot;
435
436         self.think        = racer_think;
437         self.nextthink  = time;
438         self.movetype   = MOVETYPE_BOUNCE;
439         sound (self.tur_head, CH_TRIGGER_SINGLE, SND_Null, VOL_VEHICLEENGINE, ATTEN_NORM);
440
441         if(!self.owner)
442                 return;
443
444         makevectors(self.angles);
445         if(eject)
446         {
447                 spot = self.origin + v_forward * 100 + '0 0 64';
448                 spot = vehicles_findgoodexit(spot);
449                 setorigin(self.owner , spot);
450                 self.owner.velocity = (v_up + v_forward * 0.25) * 750;
451                 self.owner.oldvelocity = self.owner.velocity;
452         }
453         else
454         {
455                 if(vlen(self.velocity) > 2 * autocvar_sv_maxairspeed)
456                 {
457                         self.owner.velocity = normalize(self.velocity) * autocvar_sv_maxairspeed * 2;
458                         self.owner.velocity_z += 200;
459                         spot = self.origin + v_forward * 32 + '0 0 32';
460                         spot = vehicles_findgoodexit(spot);
461                 }
462                 else
463                 {
464                         self.owner.velocity = self.velocity * 0.5;
465                         self.owner.velocity_z += 10;
466                         spot = self.origin - v_forward * 200 + '0 0 32';
467                         spot = vehicles_findgoodexit(spot);
468                 }
469                 self.owner.oldvelocity = self.owner.velocity;
470                 setorigin(self.owner , spot);
471         }
472         antilag_clear(self.owner);
473         self.owner = world;
474 }
475
476 void racer_blowup()
477 {SELFPARAM();
478         self.deadflag   = DEAD_DEAD;
479         self.vehicle_exit(VHEF_NORMAL);
480
481         RadiusDamage (self, self.enemy, autocvar_g_vehicle_racer_blowup_coredamage,
482                                         autocvar_g_vehicle_racer_blowup_edgedamage,
483                                         autocvar_g_vehicle_racer_blowup_radius, world, world,
484                                         autocvar_g_vehicle_racer_blowup_forceintensity,
485                                         DEATH_VH_WAKI_DEATH.m_id, world);
486
487         self.nextthink  = time + autocvar_g_vehicle_racer_respawntime;
488         self.think        = vehicles_spawn;
489         self.movetype   = MOVETYPE_NONE;
490         self.effects    = EF_NODRAW;
491         self.solid = SOLID_NOT;
492
493         self.colormod  = '0 0 0';
494         self.avelocity = '0 0 0';
495         self.velocity  = '0 0 0';
496
497         setorigin(self, self.pos1);
498 }
499
500 void racer_blowup_think()
501 {SELFPARAM();
502         self.nextthink = time;
503
504         if(time >= self.delay)
505                 racer_blowup();
506
507         CSQCMODEL_AUTOUPDATE(self);
508 }
509
510 void racer_deadtouch()
511 {SELFPARAM();
512         self.avelocity_x *= 0.7;
513         self.cnt -= 1;
514         if(self.cnt <= 0)
515                 racer_blowup();
516 }
517
518 spawnfunc(vehicle_racer)
519 {
520         if(!autocvar_g_vehicle_racer) { remove(self); return; }
521         if(!vehicle_initialize(VEH_RACER, false)) { remove(self); return; }
522 }
523
524 #endif // SVQC
525
526 #ifdef CSQC
527 #if 0
528 void racer_draw()
529 {SELFPARAM();
530         float pushdeltatime = time - self.lastpushtime;
531         if (pushdeltatime > 0.15) pushdeltatime = 0;
532         self.lastpushtime = time;
533         if(!pushdeltatime) return;
534
535         tracebox(self.move_origin, self.mins, self.maxs, self.move_origin - ('0 0 1' * STAT(VEH_RACER_SPRINGLENGTH)), MOVE_NOMONSTERS, self);
536
537         vector df = self.move_velocity * -STAT(VEH_RACER_FRICTION);
538         df_z += (1 - trace_fraction) * STAT(VEH_RACER_HOVERPOWER) + sin(time * 2) * (STAT(VEH_RACER_SPRINGLENGTH) * 2);
539
540         float forced = STAT(VEH_RACER_UPFORCEDAMPER);
541
542         int cont = pointcontents(self.move_origin - '0 0 64');
543         if(cont == CONTENT_WATER || cont == CONTENT_LAVA || cont == CONTENT_SLIME)
544         {
545                 forced = STAT(VEH_RACER_WATER_UPFORCEDAMPER);
546                 self.move_velocity_z += 200;
547         }
548
549         self.move_velocity += df * pushdeltatime;
550         if(self.move_velocity_z > 0)
551                 self.move_velocity_z *= 1 - forced * pushdeltatime;
552
553         self.move_angles_x *= 1 - (STAT(VEH_RACER_ANGLESTABILIZER) * pushdeltatime);
554         self.move_angles_z *= 1 - (STAT(VEH_RACER_ANGLESTABILIZER) * pushdeltatime);
555
556         Movetype_Physics_MatchServer(false);
557 }
558 #endif
559 #endif
560
561                 METHOD(Racer, vr_impact, void(Racer thisveh))
562                 {
563                 #ifdef SVQC
564                         if(autocvar_g_vehicle_racer_bouncepain)
565                                 vehicles_impact(autocvar_g_vehicle_racer_bouncepain_x, autocvar_g_vehicle_racer_bouncepain_y, autocvar_g_vehicle_racer_bouncepain_z);
566                 #endif
567                 }
568
569                 METHOD(Racer, vr_enter, void(Racer thisveh))
570                 {
571                 #ifdef SVQC
572                         self.movetype = MOVETYPE_BOUNCE;
573                         self.owner.vehicle_health = (self.vehicle_health / autocvar_g_vehicle_racer_health)  * 100;
574                         self.owner.vehicle_shield = (self.vehicle_shield / autocvar_g_vehicle_racer_shield)  * 100;
575
576                         if(self.owner.flagcarried)
577                            setorigin(self.owner.flagcarried, '-190 0 96');
578                 #elif defined(CSQC)
579
580                         self.move_movetype = MOVETYPE_BOUNCE;
581                 #endif
582                 }
583
584                 METHOD(Racer, vr_spawn, void(Racer thisveh))
585                 {
586                 #ifdef SVQC
587                         if(self.scale != 0.5)
588                         {
589                                 if(autocvar_g_vehicle_racer_hovertype != 0)
590                                         racer_force_from_tag = vehicles_force_fromtag_maglev;
591                                 else
592                                         racer_force_from_tag = vehicles_force_fromtag_hover;
593
594                                 // FIXME: this be hakkz, fix the models insted (scale body, add tag_viewport to the hudmodel).
595                                 self.scale = 0.5;
596                                 setattachment(self.vehicle_hudmodel, self, "");
597                                 setattachment(self.vehicle_viewport, self, "tag_viewport");
598
599                                 self.mass                          = 900;
600                         }
601
602                         self.think                = racer_think;
603                         self.nextthink    = time;
604                         self.vehicle_health = autocvar_g_vehicle_racer_health;
605                         self.vehicle_shield = autocvar_g_vehicle_racer_shield;
606
607                         self.movetype     = MOVETYPE_TOSS;
608                         self.solid                = SOLID_SLIDEBOX;
609                         self.delay                = time;
610                         self.scale                = 0.5;
611
612                         self.PlayerPhysplug = racer_frame;
613
614                         self.bouncefactor = autocvar_g_vehicle_racer_bouncefactor;
615                         self.bouncestop = autocvar_g_vehicle_racer_bouncestop;
616                         self.damageforcescale = 0.5;
617                         self.vehicle_health = autocvar_g_vehicle_racer_health;
618                         self.vehicle_shield = autocvar_g_vehicle_racer_shield;
619                 #endif
620                 }
621
622                 METHOD(Racer, vr_death, void(Racer thisveh))
623                 {
624                 #ifdef SVQC
625                         self.SendEntity         = func_null; // stop networking this racer (for now)
626                         self.health                     = 0;
627                         self.event_damage       = func_null;
628                         self.solid                      = SOLID_CORPSE;
629                         self.takedamage         = DAMAGE_NO;
630                         self.deadflag           = DEAD_DYING;
631                         self.movetype           = MOVETYPE_BOUNCE;
632                         self.wait                       = time;
633                         self.delay                      = 2 + time + random() * 3;
634                         self.cnt                        = 1 + random() * 2;
635                         self.touch                      = racer_deadtouch;
636
637                         Send_Effect(EFFECT_EXPLOSION_MEDIUM, self.origin, '0 0 0', 1);
638
639                         if(random() < 0.5)
640                                 self.avelocity_z = 32;
641                         else
642                                 self.avelocity_z = -32;
643
644                         self.avelocity_x = -vlen(self.velocity) * 0.2;
645                         self.velocity += '0 0 700';
646                         self.colormod = '-0.5 -0.5 -0.5';
647
648                         self.think = racer_blowup_think;
649                         self.nextthink = time;
650                 #endif
651                 }
652
653 #ifdef CSQC
654                 METHOD(Racer, vr_hud, void(Racer thisveh))
655                 {
656                         Vehicles_drawHUD(VEH_RACER.m_icon, "vehicle_racer_weapon1", "vehicle_racer_weapon2",
657                                                          "vehicle_icon_ammo1", autocvar_hud_progressbar_vehicles_ammo1_color,
658                                                          "vehicle_icon_ammo2", autocvar_hud_progressbar_vehicles_ammo2_color);
659                 }
660                 METHOD(Racer, vr_crosshair, void(Racer thisveh))
661                 {
662                         Vehicles_drawCrosshair(vCROSS_GUIDE);
663                 }
664 #endif
665                 METHOD(Racer, vr_setup, void(Racer thisveh))
666                 {
667                 #ifdef SVQC
668                         self.vehicle_exit = racer_exit;
669                 #endif
670
671                 #ifdef SVQC
672                         // we have no need to network energy
673                         if(autocvar_g_vehicle_racer_energy)
674                         if(autocvar_g_vehicle_racer_energy_regen)
675                                 self.vehicle_flags |= VHF_ENERGYREGEN;
676
677                         if(autocvar_g_vehicle_racer_shield)
678                                 self.vehicle_flags |= VHF_HASSHIELD;
679
680                         if(autocvar_g_vehicle_racer_shield_regen)
681                                 self.vehicle_flags |= VHF_SHIELDREGEN;
682
683                         if(autocvar_g_vehicle_racer_health_regen)
684                                 self.vehicle_flags |= VHF_HEALTHREGEN;
685
686                         self.respawntime = autocvar_g_vehicle_racer_respawntime;
687                         self.vehicle_health = autocvar_g_vehicle_racer_health;
688                         self.vehicle_shield = autocvar_g_vehicle_racer_shield;
689                         self.max_health = self.vehicle_health;
690                 #endif
691
692                 #ifdef CSQC
693                         AuxiliaryXhair[0].axh_image = vCROSS_LOCK; // Rocket
694                 #endif
695                 }
696
697 #endif