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 if (fire & 1)
14 if (weapon_prepareattack(thiswep, player, weaponentity, false, autocvar_g_vehicle_racer_cannon_refire)) {
15 if (veh) {
16 veh.vehicle_energy -= autocvar_g_vehicle_racer_cannon_cost;
17 veh.wait = time;
18 }
19 if(!isPlayer)
20 {
21 string tagname = (veh.cnt)
22 ? (veh.cnt = 0, "tag_fire1")
23 : (veh.cnt = 1, "tag_fire2");
24 vector vshotorg = gettaginfo(veh, gettagindex(veh, tagname));
25 w_shotorg = vshotorg;
27
28 // Fix z-aim (for chase mode)
29 crosshair_trace(player);
30 w_shotdir.z = normalize(trace_endpos - vshotorg).z * 0.5;
31 }
32 if (isPlayer) W_SetupShot_Dir(player, weaponentity, v_forward, false, 0, SND_Null, CH_WEAPON_B, 0, DEATH_VH_WAKI_GUN.m_id);
35 entity bolt = vehicles_projectile(((veh) ? veh : player), EFFECT_RACER_MUZZLEFLASH, SND_RacerAttack_LASER_FIRE,
38 DEATH_VH_WAKI_GUN.m_id, PROJECTILE_WAKICANNON, 0, true, true, player);
40 weapon_thinkf(player, weaponentity, WFRAME_FIRE1, 0, w_ready);
41 }
42 if (fire & 2)
43 if (!isPlayer || weapon_prepareattack(thiswep, actor, weaponentity, false, 0.2)) {
44 if (isPlayer) W_SetupShot_Dir(actor, weaponentity, v_forward, false, 0, SND_Null, CH_WEAPON_B, 0, DEATH_VH_WAKI_ROCKET.m_id);
45 racer_fire_rocket(((veh) ? veh : player), player, w_shotorg, w_shotdir, NULL);
46 weapon_thinkf(actor, weaponentity, WFRAME_FIRE2, 0, w_ready);
47 }
48}
49
50METHOD(RacerAttack, wr_checkammo1, bool(RacerAttack thiswep, entity actor, .entity weaponentity))
51{
52 bool isPlayer = IS_PLAYER(actor);
53 entity player = isPlayer ? actor : actor.owner;
54 entity veh = player.vehicle;
55 return isPlayer || veh.vehicle_energy >= autocvar_g_vehicle_racer_cannon_cost;
56}
57
60
62{
63 entity rocket = vehicles_projectile(this, EFFECT_RACER_ROCKETLAUNCH, SND_RacerAttack_ROCKET_FIRE,
66 DEATH_VH_WAKI_ROCKET.m_id, PROJECTILE_WAKIROCKET, 20, false, false, player);
67
70 rocket.nextthink = time;
71 rocket.enemy = trg;
72 rocket.cnt = time + 15;
73
74 if(trg)
76 else
78}
79
81{
82 vector olddir, newdir;
83 float oldvel, newvel;
84
85 this.nextthink = time;
86
87 if (IS_DEAD(this.owner) || this.cnt < time)
88 {
89 this.use(this, NULL, NULL);
90 return;
91 }
92
93 if(!this.realowner.vehicle)
94 {
96 return;
97 }
98
99 olddir = normalize(this.velocity);
100 oldvel = vlen(this.velocity);
101 newvel = oldvel + this.lip;
102 makevectors(vectoangles(olddir));
103
104 float time_to_impact = min(vlen(this.enemy.origin - this.origin) / vlen(this.velocity), 1);
105 vector predicted_origin = this.enemy.origin + this.enemy.velocity * time_to_impact;
106
107 traceline(this.origin, this.origin + v_forward * 64 - '0 0 32', MOVE_NORMAL, this);
108 newdir = normalize(predicted_origin - this.origin);
109
110 //vector
111 float height_diff = predicted_origin_z - this.origin_z;
112
114 {
115 //bprint("Target lost!\n");
116 //dprint("OF:", ftos(vlen(newdir - v_forward)), "\n");
118 return;
119 }
120
121 if(trace_fraction != 1.0 && trace_ent != this.enemy)
122 newdir_z += 16 * sys_frametime;
123
124 this.velocity = normalize(olddir + newdir * autocvar_g_vehicle_racer_rocket_turnrate) * newvel;
125 this.velocity_z -= 800 * sys_frametime;
126 this.velocity_z += max(height_diff, autocvar_g_vehicle_racer_rocket_climbspeed) * sys_frametime ;
127
129 return;
130}
131
133{
134 vector olddir, newdir;
135 float oldvel, newvel;
136
137 this.nextthink = time;
138
139 if(IS_DEAD(this.owner) || this.cnt < time)
140 {
141 this.use(this, NULL, NULL);
142 return;
143 }
144
145 if(!this.realowner.vehicle)
146 {
148 return;
149 }
150
151 olddir = normalize(this.velocity);
152 oldvel = vlen(this.velocity);
153 newvel = oldvel + this.lip;
154
155 tracebox(this.origin, this.mins, this.maxs, this.origin + olddir * 64, MOVE_WORLDONLY,this);
156 if(trace_fraction <= 0.5)
157 {
158 // Hitting somethign soon, just speed ahead
159 this.velocity = olddir * newvel;
161 return;
162 }
163
164 traceline(trace_endpos, trace_endpos - '0 0 64', MOVE_NORMAL, this);
165 if(trace_fraction != 1.0)
166 {
168 this.velocity = normalize(olddir + newdir) * newvel;
169 }
170 else
171 {
172 this.velocity = olddir * newvel;
173 this.velocity_z -= 1600 * sys_frametime; // 2x grav looks better for this one
174 }
175
176 int cont = pointcontents(this.origin - '0 0 32');
177 if(cont == CONTENT_WATER || cont == CONTENT_LAVA || cont == CONTENT_SLIME)
178 this.velocity_z += 200;
179
181 return;
182}
183
184#endif
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:245
#define IS_PLAYER(s)
Definition player.qh:243
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:225
#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:549
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)