Xonotic QuakeC
The free, fast arena FPS with crisp movement and a wide array of weapons
racer_weapon.qc
Go to the documentation of this file.
1#include "racer_weapon.qh"
2
3#ifdef SVQC
4
5void racer_fire_rocket(entity this, entity player, vector org, vector dir, entity trg);
6SOUND(RacerAttack_LASER_FIRE, W_Sound("lasergun_fire"));
7SOUND(RacerAttack_ROCKET_FIRE, W_Sound("rocket_fire"));
8METHOD(RacerAttack, wr_think, void(entity thiswep, entity actor, .entity weaponentity, int fire))
9{
10 bool isPlayer = IS_PLAYER(actor);
11 entity player = isPlayer ? actor : actor.owner;
12 entity veh = player.vehicle;
13
14 if (fire & 1)
15 if (weapon_prepareattack(thiswep, player, weaponentity, false, autocvar_g_vehicle_racer_cannon_refire))
16 {
17 if (veh)
18 {
19 veh.vehicle_energy -= autocvar_g_vehicle_racer_cannon_cost;
20 veh.wait = time;
21 }
22 if (!isPlayer)
23 {
24 vector vshotorg = gettaginfo(veh, gettagindex(veh, (veh.cnt ? "tag_fire1" : "tag_fire2")));
25 veh.cnt = !veh.cnt;
26 w_shotorg = vshotorg;
28
29 // Fix z-aim (for chase mode)
30 crosshair_trace(player);
31 w_shotdir.z = normalize(trace_endpos - vshotorg).z * 0.5;
32 }
33 if (isPlayer)
34 W_SetupShot_Dir(player, weaponentity, v_forward, false, 0, SND_Null, CH_WEAPON_B, 0, DEATH_VH_WAKI_GUN.m_id);
37 entity bolt = vehicles_projectile((veh ? veh : player), EFFECT_RACER_MUZZLEFLASH, SND_RacerAttack_LASER_FIRE,
40 DEATH_VH_WAKI_GUN.m_id, PROJECTILE_WAKICANNON, 0, true, true, player);
42 weapon_thinkf(player, weaponentity, WFRAME_FIRE1, 0, w_ready);
43 }
44 if (fire & 2)
45 if (!isPlayer || weapon_prepareattack(thiswep, actor, weaponentity, false, 0.2))
46 {
47 if (isPlayer)
48 W_SetupShot_Dir(actor, weaponentity, v_forward, false, 0, SND_Null, CH_WEAPON_B, 0, DEATH_VH_WAKI_ROCKET.m_id);
49 racer_fire_rocket((veh ? veh : player), player, w_shotorg, w_shotdir, NULL);
50 weapon_thinkf(actor, weaponentity, WFRAME_FIRE2, 0, w_ready);
51 }
52}
53
54METHOD(RacerAttack, wr_checkammo1, bool(RacerAttack thiswep, entity actor, .entity weaponentity))
55{
56 bool isPlayer = IS_PLAYER(actor);
57 entity player = isPlayer ? actor : actor.owner;
58 entity veh = player.vehicle;
59 return isPlayer || veh.vehicle_energy >= autocvar_g_vehicle_racer_cannon_cost;
60}
61
64
66{
67 entity rocket = vehicles_projectile(this, EFFECT_RACER_ROCKETLAUNCH, SND_RacerAttack_ROCKET_FIRE,
70 DEATH_VH_WAKI_ROCKET.m_id, PROJECTILE_WAKIROCKET, 20, false, false, player);
71
74 rocket.nextthink = time;
75 rocket.enemy = targ;
76 rocket.cnt = time + 15;
77
78 if (targ)
80 else
82}
83
85{
86 this.nextthink = time;
87
88 if (IS_DEAD(this.owner) || this.cnt < time)
89 {
90 this.use(this, NULL, NULL);
91 return;
92 }
93
94 if (!this.realowner.vehicle)
95 {
97 return;
98 }
99
100 vector olddir = normalize(this.velocity);
101 float oldvel = vlen(this.velocity);
102 float newvel = oldvel + this.lip;
103 makevectors(vectoangles(olddir));
104
105 float time_to_impact = min(vlen(this.enemy.origin - this.origin) / vlen(this.velocity), 1);
106 vector predicted_origin = this.enemy.origin + this.enemy.velocity * time_to_impact;
107
108 traceline(this.origin, this.origin + v_forward * 64 - '0 0 32', MOVE_NORMAL, this);
109 vector newdir = normalize(predicted_origin - this.origin);
110
111 //vector
112 float height_diff = predicted_origin.z - this.origin.z;
113
115 {
116 //bprint("Target lost!\n");
117 //dprint("OF:", ftos(vlen(newdir - v_forward)), "\n");
119 return;
120 }
121
122 if (trace_fraction != 1.0 && trace_ent != this.enemy)
123 newdir.z += 16 * sys_frametime;
124
125 this.velocity = normalize(olddir + newdir * autocvar_g_vehicle_racer_rocket_turnrate) * newvel;
126 this.velocity.z -= 800 * sys_frametime;
128
130 return;
131}
132
134{
135 this.nextthink = time;
136
137 if (IS_DEAD(this.owner) || this.cnt < time)
138 {
139 this.use(this, NULL, NULL);
140 return;
141 }
142
143 if (!this.realowner.vehicle)
144 {
146 return;
147 }
148
149 vector olddir = normalize(this.velocity);
150 float oldvel = vlen(this.velocity);
151 float newvel = oldvel + this.lip;
152
153 tracebox(this.origin, this.mins, this.maxs, this.origin + olddir * 64, MOVE_WORLDONLY, this);
154 if (trace_fraction <= 0.5)
155 {
156 // Hitting somethign soon, just speed ahead
157 this.velocity = olddir * newvel;
159 return;
160 }
161
162 traceline(trace_endpos, trace_endpos - '0 0 64', MOVE_NORMAL, this);
163 if (trace_fraction != 1.0)
164 {
166 this.velocity = normalize(olddir + newdir) * newvel;
167 }
168 else
169 {
170 this.velocity = olddir * newvel;
171 this.velocity.z -= 1600 * sys_frametime; // 2x grav looks better for this one
172 }
173
174 int cont = pointcontents(this.origin - '0 0 32');
175 if (cont == CONTENT_WATER
176 || cont == CONTENT_LAVA
177 || cont == CONTENT_SLIME)
178 this.velocity.z += 200;
179
181 return;
182}
183
184#endif // SVQC
var entity(vector mins, vector maxs,.entity tofield) findbox_tofield_OrFallback
float cnt
Definition powerups.qc:24
entity owner
Definition main.qh:87
#define IS_DEAD(s)
Definition player.qh:244
#define IS_PLAYER(s)
Definition player.qh:242
entity trace_ent
const float MOVE_NORMAL
vector mins
vector velocity
const float CONTENT_WATER
float time
vector trace_endpos
vector maxs
float nextthink
float MOVE_WORLDONLY
vector v_forward
vector origin
float trace_fraction
const float CONTENT_LAVA
const float CONTENT_SLIME
#define use
void UpdateCSQCProjectile(entity e)
#define gettagindex
float vlen(vector v)
vector vectoangles(vector v)
vector randomvec(void)
float min(float f,...)
vector normalize(vector v)
float max(float f,...)
#define METHOD(cname, name, prototype)
Definition oo.qh:269
#define NULL
Definition post.qh:14
#define makevectors
Definition post.qh:21
#define gettaginfo
Definition post.qh:32
const int PROJECTILE_WAKIROCKET
const int PROJECTILE_WAKICANNON
void racer_rocket_groundhugger(entity this)
void racer_rocket_tracker(entity this)
void racer_fire_rocket(entity this, entity player, vector org, vector dir, entity trg)
float autocvar_g_vehicle_racer_rocket_speed
float autocvar_g_vehicle_racer_cannon_refire
float autocvar_g_vehicle_racer_rocket_locked_maxangle
float autocvar_g_vehicle_racer_cannon_radius
float autocvar_g_vehicle_racer_cannon_spread
float autocvar_g_vehicle_racer_rocket_force
float autocvar_g_vehicle_racer_rocket_climbspeed
float autocvar_g_vehicle_racer_cannon_speed
float autocvar_g_vehicle_racer_cannon_force
float autocvar_g_vehicle_racer_rocket_turnrate
float autocvar_g_vehicle_racer_cannon_cost
float autocvar_g_vehicle_racer_cannon_damage
float autocvar_g_vehicle_racer_rocket_accel
float autocvar_g_vehicle_racer_rocket_radius
float autocvar_g_vehicle_racer_rocket_damage
#define setthink(e, f)
vector
Definition self.qh:92
vector org
Definition self.qh:92
float sys_frametime
Definition common.qh:57
int dir
Definition impulse.qc:89
const int CH_WEAPON_B
Definition sound.qh:8
string W_Sound(string w_snd)
Definition all.qc:226
#define SOUND(name, path)
Definition all.qh:30
float lip
Definition subs.qh:40
entity enemy
Definition sv_ctf.qh:153
entity vehicles_projectile(entity this, entity _mzlfx, Sound _mzlsound, vector _org, vector _vel, float _dmg, float _radi, float _force, float _size, int _deahtype, float _projtype, float _health, bool _cull, bool _clianim, entity _owner)
entity realowner
void crosshair_trace(entity pl)
Definition tracing.qc:542
vector w_shotdir
Definition tracing.qh:20
vector w_shotorg
Definition tracing.qh:19
#define W_SetupShot_Dir(ent, wepent, s_forward, antilag, recoil, snd, chan, maxdamage, deathtype)
Definition tracing.qh:32
#define vdist(v, cmp, f)
Vector distance comparison, avoids sqrt()
Definition vector.qh:8
void weapon_thinkf(entity actor,.entity weaponentity, WFRAME fr, float t, void(Weapon thiswep, entity actor,.entity weaponentity, int fire) func)
bool weapon_prepareattack(Weapon thiswep, entity actor,.entity weaponentity, bool secondary, float attacktime)
void w_ready(Weapon thiswep, entity actor,.entity weaponentity, int fire)