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