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