41a31743f621d94fcd8c35db61f72d499feeeded
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / vehicles / vehicle / racer.qc
1 #include "racer.qh"
2
3 #ifdef IMPLEMENTATION
4
5 #ifdef SVQC
6 #include <common/triggers/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 = 100;
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 = 70;
33 float autocvar_g_vehicle_racer_upforcedamper = 10;
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 = 50;
51 float autocvar_g_vehicle_racer_energy_regen_pause = 1;
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.9;
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 = '60 0.75 300';
79
80 .float racer_watertime;
81
82 var vector racer_force_from_tag(entity this, string tag_name, float spring_length, float max_power);
83
84 void racer_align4point(entity this, float _delta)
85 {
86         vector push_vector;
87         float fl_push, fr_push, bl_push, br_push;
88
89         push_vector  = 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 += 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 += 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 += 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(this.owner) && 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 player, string tagname, entity trg)
143 {
144         entity racer = player.vehicle;
145         vector v = gettaginfo(racer, gettagindex(racer, tagname));
146         racer_fire_rocket(player, v, v_forward, trg);
147 }
148
149 bool racer_frame(entity this, float dt)
150 {
151         entity vehic = this.vehicle;
152         return = true;
153
154         if(intermission_running)
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, this);
163
164         traceline(vehic.origin, vehic.origin + '0 0 1', MOVE_NOMONSTERS, this);
165         int cont = trace_dpstartcontents;
166         if(!(cont & DPCONTENTS_WATER))
167                 vehic.air_finished = time + autocvar_g_vehicle_racer_water_time;
168
169         if(IS_DEAD(vehic))
170         {
171                 PHYS_INPUT_BUTTON_ATCK(this) = PHYS_INPUT_BUTTON_ATCK2(this) = false;
172                 return;
173         }
174
175         racer_align4point(vehic, dt);
176
177         PHYS_INPUT_BUTTON_ZOOM(this) = PHYS_INPUT_BUTTON_CROUCH(this) = false;
178
179         vehic.angles_x *= -1;
180
181         // Yaw
182         float ftmp = autocvar_g_vehicle_racer_turnspeed * dt;
183         ftmp = bound(-ftmp, shortangle_f(this.v_angle_y - vehic.angles_y, vehic.angles_y), ftmp);
184         vehic.angles_y = anglemods(vehic.angles_y + ftmp);
185
186         // Roll
187         vehic.angles_z += -ftmp * autocvar_g_vehicle_racer_turnroll * dt;
188
189         // Pitch
190         ftmp = autocvar_g_vehicle_racer_pitchspeed  * dt;
191         ftmp = bound(-ftmp, shortangle_f(this.v_angle_x - vehic.angles_x, vehic.angles_x), ftmp);
192         vehic.angles_x = bound(-autocvar_g_vehicle_racer_pitchlimit, anglemods(vehic.angles_x + ftmp), autocvar_g_vehicle_racer_pitchlimit);
193
194         makevectors(vehic.angles);
195         vehic.angles_x *= -1;
196
197         //ftmp = vehic.velocity_z;
198         vector df = vehic.velocity * -autocvar_g_vehicle_racer_friction;
199         //vehic.velocity_z = ftmp;
200
201         if(this.movement)
202         {
203                 if(cont & DPCONTENTS_LIQUIDSMASK)
204                 {
205                         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); }
206                         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); }
207                 }
208                 else
209                 {
210                         if(this.movement_x) { df += v_forward * ((this.movement_x > 0) ? autocvar_g_vehicle_racer_speed_forward : -autocvar_g_vehicle_racer_speed_forward); }
211                         if(this.movement_y) { df += v_right * ((this.movement_y > 0) ? autocvar_g_vehicle_racer_speed_strafe : -autocvar_g_vehicle_racer_speed_strafe); }
212                 }
213
214 #ifdef SVQC
215                 if(vehic.sound_nexttime < time || vehic.sounds != 1)
216                 {
217                         vehic.sounds = 1;
218                         vehic.sound_nexttime = time + 10.922667; //soundlength("vehicles/racer_move.wav");
219                         sound (vehic, CH_TRIGGER_SINGLE, SND_VEH_RACER_MOVE, VOL_VEHICLEENGINE, ATTEN_NORM);
220                 }
221 #endif
222         }
223 #ifdef SVQC
224         else
225         {
226                 if(vehic.sound_nexttime < time || vehic.sounds != 0)
227                 {
228                         vehic.sounds = 0;
229                         vehic.sound_nexttime = time + 11.888604; //soundlength("vehicles/racer_idle.wav");
230                         sound (vehic, CH_TRIGGER_SINGLE, SND_VEH_RACER_IDLE, VOL_VEHICLEENGINE, ATTEN_NORM);
231                 }
232         }
233 #endif
234
235         // Afterburn
236         if (PHYS_INPUT_BUTTON_JUMP(this) && vehic.vehicle_energy >= (autocvar_g_vehicle_racer_afterburn_cost * dt))
237         {
238 #ifdef SVQC
239                 if(time - vehic.wait > 0.2)
240                         pointparticles(EFFECT_RACER_BOOSTER, vehic.origin - v_forward * 32, v_forward  * vlen(vehic.velocity), 1);
241 #endif
242
243                 vehic.wait = time;
244
245                 if(cont & DPCONTENTS_LIQUIDSMASK)
246                 {
247                         vehic.vehicle_energy -= autocvar_g_vehicle_racer_waterburn_cost * dt;
248                         df += (v_forward * autocvar_g_vehicle_racer_waterburn_speed);
249                 }
250                 else
251                 {
252                         vehic.vehicle_energy -= autocvar_g_vehicle_racer_afterburn_cost * dt;
253                         df += (v_forward * autocvar_g_vehicle_racer_speed_afterburn);
254                 }
255
256 #ifdef SVQC
257                 if(vehic.invincible_finished < time)
258                 {
259                         traceline(vehic.origin, vehic.origin - '0 0 256', MOVE_NORMAL, vehic);
260                         if(trace_fraction != 1.0)
261                                 pointparticles(EFFECT_SMOKE_SMALL, trace_endpos, '0 0 0', 1);
262
263                         vehic.invincible_finished = time + 0.1 + (random() * 0.1);
264                 }
265
266                 if(vehic.strength_finished < time)
267                 {
268                         vehic.strength_finished = time + 10.922667; //soundlength("vehicles/racer_boost.wav");
269                         sound (vehic.tur_head, CH_TRIGGER_SINGLE, SND_VEH_RACER_BOOST, VOL_VEHICLEENGINE, ATTEN_NORM);
270                 }
271 #endif
272         }
273         else
274         {
275                 vehic.strength_finished = 0;
276                 sound (vehic.tur_head, CH_TRIGGER_SINGLE, SND_Null, VOL_VEHICLEENGINE, ATTEN_NORM);
277         }
278
279         if(cont & DPCONTENTS_LIQUIDSMASK)
280                 vehic.racer_watertime = time;
281
282         float dforce = autocvar_g_vehicle_racer_downforce;
283         if(time - vehic.racer_watertime <= 3)
284                 dforce = autocvar_g_vehicle_racer_water_downforce;
285
286         df -= v_up * (vlen(vehic.velocity) * dforce);
287         this.movement = vehic.velocity += df * dt;
288
289 #ifdef SVQC
290
291         Weapon wep1 = WEP_RACER;
292         if (!forbidWeaponUse(this))
293         if (PHYS_INPUT_BUTTON_ATCK(this))
294         if (wep1.wr_checkammo1(wep1, vehic))
295         {
296                 string tagname = (vehic.cnt)
297                     ? (vehic.cnt = 0, "tag_fire1")
298                     : (vehic.cnt = 1, "tag_fire2");
299                 vector org = gettaginfo(vehic, gettagindex(vehic, tagname));
300                 w_shotorg = org;
301                 w_shotdir = v_forward;
302                 // Fix z-aim (for chase mode)
303                 crosshair_trace(this);
304                 w_shotdir.z = normalize(trace_endpos - org).z * 0.5;
305                 .entity weaponentity = weaponentities[0];
306                 wep1.wr_think(wep1, vehic, weaponentity, 1);
307         }
308
309         if(autocvar_g_vehicle_racer_rocket_locktarget)
310         {
311                 if(time >= vehic.vehicle_last_trace)
312                 {
313                         crosshair_trace(this);
314
315                         vehicles_locktarget(vehic, (1 / autocvar_g_vehicle_racer_rocket_locking_time) * dt,
316                                                          (1 / autocvar_g_vehicle_racer_rocket_locking_releasetime) * dt,
317                                                          autocvar_g_vehicle_racer_rocket_locked_time);
318
319                         vehic.vehicle_last_trace = time + autocvar_g_vehicle_racer_thinkrate;
320                 }
321
322                 if(vehic.lock_target)
323                 {
324                         if(vehic.lock_strength == 1)
325                                 UpdateAuxiliaryXhair(this, real_origin(vehic.lock_target), '1 0 0', 0);
326                         else if(vehic.lock_strength > 0.5)
327                                 UpdateAuxiliaryXhair(this, real_origin(vehic.lock_target), '0 1 0', 0);
328                         else if(vehic.lock_strength < 0.5)
329                                 UpdateAuxiliaryXhair(this, real_origin(vehic.lock_target), '0 0 1', 0);
330                 }
331         }
332
333         if(!forbidWeaponUse(this))
334         if(time > vehic.delay)
335         if(PHYS_INPUT_BUTTON_ATCK2(this))
336         {
337                 vehic.misc_bulletcounter += 1;
338                 vehic.delay = time + 0.3;
339
340                 if(vehic.misc_bulletcounter == 1)
341                 {
342                         racer_fire_rocket_aim(this, "tag_rocket_r", (vehic.lock_strength == 1 && vehic.lock_target) ? vehic.lock_target : NULL);
343                         this.vehicle_ammo2 = 50;
344                 }
345                 else if(vehic.misc_bulletcounter == 2)
346                 {
347                         racer_fire_rocket_aim(this, "tag_rocket_l", (vehic.lock_strength == 1 && vehic.lock_target) ? vehic.lock_target : NULL);
348                         vehic.lock_strength  = 0;
349                         vehic.lock_target       = NULL;
350                         vehic.misc_bulletcounter = 0;
351                         vehic.delay = time + autocvar_g_vehicle_racer_rocket_refire;
352                         vehic.lip = time;
353                         this.vehicle_ammo2 = 0;
354                 }
355         }
356         else if(vehic.misc_bulletcounter == 0)
357                 this.vehicle_ammo2 = 100;
358
359         this.vehicle_reload2 = bound(0, 100 * ((time - vehic.lip) / (vehic.delay - vehic.lip)), 100);
360
361         if(vehic.vehicle_flags  & VHF_SHIELDREGEN)
362                 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);
363
364         if(vehic.vehicle_flags  & VHF_HEALTHREGEN)
365                 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, dt, false);
366
367         if(vehic.vehicle_flags  & VHF_ENERGYREGEN)
368                 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);
369
370         VEHICLE_UPDATE_PLAYER(this, vehic, health, racer);
371         VEHICLE_UPDATE_PLAYER(this, vehic, energy, racer);
372
373         if(vehic.vehicle_flags & VHF_HASSHIELD)
374                 VEHICLE_UPDATE_PLAYER(this, vehic, shield, racer);
375
376         PHYS_INPUT_BUTTON_ATCK(this) = PHYS_INPUT_BUTTON_ATCK2(this) = false;
377 #endif
378
379         setorigin(this, vehic.origin + '0 0 32');
380         this.velocity = vehic.velocity;
381 }
382
383 void racer_think(entity this)
384 {
385         this.nextthink = time + autocvar_g_vehicle_racer_thinkrate;
386
387         tracebox(this.origin, this.mins, this.maxs, this.origin - ('0 0 1' * autocvar_g_vehicle_racer_springlength), MOVE_NOMONSTERS, this);
388
389         vector df = this.velocity * -autocvar_g_vehicle_racer_friction;
390         df_z += (1 - trace_fraction) * autocvar_g_vehicle_racer_hoverpower + sin(time * 2) * (autocvar_g_vehicle_racer_springlength * 2);
391
392         float forced = autocvar_g_vehicle_racer_upforcedamper;
393
394         //int cont = pointcontents(this.origin - '0 0 64');
395         traceline(this.origin - '0 0 64', this.origin - '0 0 64', MOVE_NOMONSTERS, this);
396         //if(cont == CONTENT_WATER || cont == CONTENT_LAVA || cont == CONTENT_SLIME)
397         if(trace_dpstartcontents & DPCONTENTS_LIQUIDSMASK)
398         {
399                 forced = autocvar_g_vehicle_racer_water_upforcedamper;
400                 this.velocity_z += 200;
401         }
402
403         this.velocity += df * autocvar_g_vehicle_racer_thinkrate;
404         if(this.velocity_z > 0)
405                 this.velocity_z *= 1 - forced * autocvar_g_vehicle_racer_thinkrate;
406
407         this.angles_x *= 1 - (autocvar_g_vehicle_racer_anglestabilizer * autocvar_g_vehicle_racer_thinkrate);
408         this.angles_z *= 1 - (autocvar_g_vehicle_racer_anglestabilizer * autocvar_g_vehicle_racer_thinkrate);
409
410         CSQCMODEL_AUTOUPDATE(this);
411 }
412
413 void racer_exit(entity this, int eject)
414 {
415         vector spot;
416
417         setthink(this, racer_think);
418         this.nextthink  = time;
419         set_movetype(this, MOVETYPE_BOUNCE);
420         sound (this.tur_head, CH_TRIGGER_SINGLE, SND_Null, VOL_VEHICLEENGINE, ATTEN_NORM);
421
422         if(!this.owner)
423                 return;
424
425         makevectors(this.angles);
426         if(eject)
427         {
428                 spot = this.origin + v_forward * 100 + '0 0 64';
429                 spot = vehicles_findgoodexit(this, spot);
430                 setorigin(this.owner, spot);
431                 this.owner.velocity = (v_up + v_forward * 0.25) * 750;
432                 this.owner.oldvelocity = this.owner.velocity;
433         }
434         else
435         {
436                 if(vdist(this.velocity, >, 2 * autocvar_sv_maxairspeed))
437                 {
438                         this.owner.velocity = normalize(this.velocity) * autocvar_sv_maxairspeed * 2;
439                         this.owner.velocity_z += 200;
440                         spot = this.origin + v_forward * 32 + '0 0 32';
441                         spot = vehicles_findgoodexit(this, spot);
442                 }
443                 else
444                 {
445                         this.owner.velocity = this.velocity * 0.5;
446                         this.owner.velocity_z += 10;
447                         spot = this.origin - v_forward * 200 + '0 0 32';
448                         spot = vehicles_findgoodexit(this, spot);
449                 }
450                 this.owner.oldvelocity = this.owner.velocity;
451                 setorigin(this.owner , spot);
452         }
453         antilag_clear(this.owner, CS(this.owner));
454         this.owner = NULL;
455 }
456
457 void racer_blowup(entity this)
458 {
459         this.deadflag = DEAD_DEAD;
460         this.vehicle_exit(this, VHEF_NORMAL);
461
462         RadiusDamage (this, this.enemy, autocvar_g_vehicle_racer_blowup_coredamage,
463                                         autocvar_g_vehicle_racer_blowup_edgedamage,
464                                         autocvar_g_vehicle_racer_blowup_radius, NULL, NULL,
465                                         autocvar_g_vehicle_racer_blowup_forceintensity,
466                                         DEATH_VH_WAKI_DEATH.m_id, NULL);
467
468         this.nextthink  = time + autocvar_g_vehicle_racer_respawntime;
469         setthink(this, vehicles_spawn);
470         set_movetype(this, MOVETYPE_NONE);
471         this.effects    = EF_NODRAW;
472         this.solid = SOLID_NOT;
473
474         this.colormod  = '0 0 0';
475         this.avelocity = '0 0 0';
476         this.velocity  = '0 0 0';
477
478         setorigin(this, this.pos1);
479 }
480
481 void racer_blowup_think(entity this)
482 {
483         this.nextthink = time;
484
485         if(time >= this.delay)
486                 racer_blowup(this);
487
488         CSQCMODEL_AUTOUPDATE(this);
489 }
490
491 void racer_deadtouch(entity this, entity toucher)
492 {
493         this.avelocity_x *= 0.7;
494         this.cnt -= 1;
495         if(this.cnt <= 0)
496                 racer_blowup(this);
497 }
498
499 spawnfunc(vehicle_racer)
500 {
501         if(!autocvar_g_vehicle_racer) { delete(this); return; }
502         if(!vehicle_initialize(this, VEH_RACER, false)) { delete(this); return; }
503 }
504
505 #endif // SVQC
506
507 METHOD(Racer, vr_impact, void(Racer thisveh, entity instance))
508 {
509 #ifdef SVQC
510     if(autocvar_g_vehicle_racer_bouncepain)
511         vehicles_impact(instance, autocvar_g_vehicle_racer_bouncepain_x, autocvar_g_vehicle_racer_bouncepain_y, autocvar_g_vehicle_racer_bouncepain_z);
512 #endif
513 }
514
515 METHOD(Racer, vr_enter, void(Racer thisveh, entity instance))
516 {
517 #ifdef SVQC
518     set_movetype(instance, MOVETYPE_BOUNCE);
519     instance.owner.vehicle_health = (instance.vehicle_health / autocvar_g_vehicle_racer_health)  * 100;
520     instance.owner.vehicle_shield = (instance.vehicle_shield / autocvar_g_vehicle_racer_shield)  * 100;
521
522     if(instance.owner.flagcarried)
523        setorigin(instance.owner.flagcarried, '-190 0 96');
524 #elif defined(CSQC)
525     set_movetype(instance, MOVETYPE_BOUNCE);
526 #endif
527 }
528
529 METHOD(Racer, vr_spawn, void(Racer thisveh, entity instance))
530 {
531 #ifdef SVQC
532     if(instance.scale != 0.5)
533     {
534         if(autocvar_g_vehicle_racer_hovertype != 0)
535             racer_force_from_tag = vehicles_force_fromtag_maglev;
536         else
537             racer_force_from_tag = vehicles_force_fromtag_hover;
538
539         // FIXME: this be hakkz, fix the models insted (scale body, add tag_viewport to the hudmodel).
540         instance.scale = 0.5;
541         setattachment(instance.vehicle_hudmodel, instance, "");
542         setattachment(instance.vehicle_viewport, instance, "tag_viewport");
543
544         instance.mass                      = 900;
545     }
546
547     setthink(instance, racer_think);
548     instance.nextthink    = time;
549     instance.vehicle_health = autocvar_g_vehicle_racer_health;
550     instance.vehicle_shield = autocvar_g_vehicle_racer_shield;
551
552     set_movetype(instance, MOVETYPE_TOSS);
553     instance.solid                = SOLID_SLIDEBOX;
554     instance.delay                = time;
555     instance.scale                = 0.5;
556
557     instance.PlayerPhysplug = racer_frame;
558
559     instance.bouncefactor = autocvar_g_vehicle_racer_bouncefactor;
560     instance.bouncestop = autocvar_g_vehicle_racer_bouncestop;
561     instance.damageforcescale = 0.5;
562     instance.vehicle_health = autocvar_g_vehicle_racer_health;
563     instance.vehicle_shield = autocvar_g_vehicle_racer_shield;
564 #endif
565 }
566
567 METHOD(Racer, vr_death, void(Racer thisveh, entity instance))
568 {
569 #ifdef SVQC
570     setSendEntity(instance, func_null); // stop networking this racer (for now)
571     instance.health                     = 0;
572     instance.event_damage       = func_null;
573     instance.solid                      = SOLID_CORPSE;
574     instance.takedamage         = DAMAGE_NO;
575     instance.deadflag           = DEAD_DYING;
576     set_movetype(instance, MOVETYPE_BOUNCE);
577     instance.wait                       = time;
578     instance.delay                      = 2 + time + random() * 3;
579     instance.cnt                        = 1 + random() * 2;
580     settouch(instance, racer_deadtouch);
581
582     Send_Effect(EFFECT_EXPLOSION_MEDIUM, instance.origin, '0 0 0', 1);
583
584     if(random() < 0.5)
585         instance.avelocity_z = 32;
586     else
587         instance.avelocity_z = -32;
588
589     instance.avelocity_x = -vlen(instance.velocity) * 0.2;
590     instance.velocity += '0 0 700';
591     instance.colormod = '-0.5 -0.5 -0.5';
592
593     setthink(instance, racer_blowup_think);
594     instance.nextthink = time;
595 #endif
596 }
597
598 #ifdef CSQC
599 METHOD(Racer, vr_hud, void(Racer thisveh))
600 {
601     Vehicles_drawHUD(VEH_RACER.m_icon, "vehicle_racer_weapon1", "vehicle_racer_weapon2",
602                      "vehicle_icon_ammo1", autocvar_hud_progressbar_vehicles_ammo1_color,
603                      "vehicle_icon_ammo2", autocvar_hud_progressbar_vehicles_ammo2_color);
604 }
605 METHOD(Racer, vr_crosshair, void(Racer thisveh, entity player))
606 {
607     Vehicles_drawCrosshair(vCROSS_GUIDE);
608 }
609 #endif
610 METHOD(Racer, vr_setup, void(Racer thisveh, entity instance))
611 {
612 #ifdef SVQC
613     instance.vehicle_exit = racer_exit;
614
615     // we have no need to network energy
616     if(autocvar_g_vehicle_racer_energy)
617     if(autocvar_g_vehicle_racer_energy_regen)
618         instance.vehicle_flags |= VHF_ENERGYREGEN;
619
620     if(autocvar_g_vehicle_racer_shield)
621         instance.vehicle_flags |= VHF_HASSHIELD;
622
623     if(autocvar_g_vehicle_racer_shield_regen)
624         instance.vehicle_flags |= VHF_SHIELDREGEN;
625
626     if(autocvar_g_vehicle_racer_health_regen)
627         instance.vehicle_flags |= VHF_HEALTHREGEN;
628
629     instance.respawntime = autocvar_g_vehicle_racer_respawntime;
630     instance.vehicle_health = autocvar_g_vehicle_racer_health;
631     instance.vehicle_shield = autocvar_g_vehicle_racer_shield;
632     instance.max_health = instance.vehicle_health;
633 #endif
634
635 #ifdef CSQC
636     AuxiliaryXhair[0].axh_image = vCROSS_LOCK; // Rocket
637 #endif
638 }
639
640 #endif