Xonotic QuakeC
The free, fast arena FPS with crisp movement and a wide array of weapons
machinegun.qc File Reference
Include dependency graph for machinegun.qc:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

ERASEABLE float MachineGun_Heat (float spread_accum)
ERASEABLE void MachineGun_Update_Spread (entity actor,.entity weaponentity)
void W_MachineGun_Attack (Weapon thiswep, int deathtype, entity actor,.entity weaponentity)
void W_MachineGun_Attack_Auto (Weapon thiswep, entity actor,.entity weaponentity, int fire)
void W_MachineGun_Attack_Burst (Weapon thiswep, entity actor,.entity weaponentity, int fire)
void W_MachineGun_Attack_Frame (Weapon thiswep, entity actor,.entity weaponentity, int fire)

Variables

float machinegun_spread_accumulation
float spreadUpdateTime

Function Documentation

◆ MachineGun_Heat()

ERASEABLE float MachineGun_Heat ( float spread_accum)

Definition at line 34 of file machinegun.qc.

35{
36 // function for reducing mg's damage with no spread and adding damage with
37 // heated up barrel or vice versa depending on the values of exposed cvars
38 float heatMultiplierApplicationPercent = 0.5;
39 float coldMultiplierApplicationPercent = 0.5;
40
41 float spreadSpectrumDistance = fabs(WEP_CVAR(WEP_MACHINEGUN, spread_max) - WEP_CVAR(WEP_MACHINEGUN, spread_min));
42
43 if (spreadSpectrumDistance > 0) // avoid division by 0, can never be < 0 either due to how it is set when defined
44 {
45 heatMultiplierApplicationPercent = spread_accum / spreadSpectrumDistance;
46 coldMultiplierApplicationPercent = 1 - heatMultiplierApplicationPercent;
47 }
48
49 // example where low end has halved damage and high end has tripled damage:
50 // with 50% spread accumulation: heat = (0.5 * 0.5) + (0.5 * 3) = 0.25 + 1.5 = 1.75 damage multiplier
51 // with 90% spread accumulation: heat = (0.1 * 0.5) + (0.9 * 3) = 0.05 + 2.7 = 2.75 damage multiplier
52 // NOTE: multipliers do not apply when unset for compatibility
53 float cold_multiplier = WEP_CVAR(WEP_MACHINEGUN, spread_cold_damagemultiplier);
54 float heat_multiplier = WEP_CVAR(WEP_MACHINEGUN, spread_heat_damagemultiplier);
55 return (cold_multiplier ? coldMultiplierApplicationPercent * cold_multiplier : coldMultiplierApplicationPercent)
56 + (heat_multiplier ? heatMultiplierApplicationPercent * heat_multiplier : heatMultiplierApplicationPercent);
57}
float fabs(float f)
#define WEP_CVAR(wep, name)
Definition all.qh:321

References fabs(), and WEP_CVAR.

Referenced by W_MachineGun_Attack_Auto(), and W_MachineGun_Attack_Burst().

◆ MachineGun_Update_Spread()

ERASEABLE void MachineGun_Update_Spread ( entity actor,
.entity weaponentity )

Definition at line 9 of file machinegun.qc.

10{
11 float spread_accum = actor.(weaponentity).machinegun_spread_accumulation;
12
13 // time based spread decay
14 if (WEP_CVAR(WEP_MACHINEGUN, spread_decay))
15 {
16 float spreadSpectrumDistance = fabs(WEP_CVAR(WEP_MACHINEGUN, spread_max) - WEP_CVAR(WEP_MACHINEGUN, spread_min));
17 float timediff = time - actor.(weaponentity).spreadUpdateTime;
18 spread_accum = bound(0,
19 spread_accum - (timediff * WEP_CVAR(WEP_MACHINEGUN, spread_decay)),
20 spreadSpectrumDistance);
21 }
22 else // legacy behavior for Nexuiz weapon balance
23 {
24 spread_accum = bound(WEP_CVAR(WEP_MACHINEGUN, spread_min),
25 (WEP_CVAR(WEP_MACHINEGUN, spread_add) * actor.(weaponentity).misc_bulletcounter),
26 WEP_CVAR(WEP_MACHINEGUN, spread_max));
27 }
28
29 actor.(weaponentity).machinegun_spread_accumulation = spread_accum;
30 actor.(weaponentity).spreadUpdateTime = time;
31}
float time
float bound(float min, float value, float max)
float spreadUpdateTime
Definition machinegun.qc:6
float machinegun_spread_accumulation
Definition machinegun.qc:5

References bound(), entity(), fabs(), machinegun_spread_accumulation, spreadUpdateTime, time, and WEP_CVAR.

Referenced by W_MachineGun_Attack_Auto(), and W_MachineGun_Attack_Burst().

◆ W_MachineGun_Attack()

void W_MachineGun_Attack ( Weapon thiswep,
int deathtype,
entity actor,
.entity weaponentity )

Definition at line 59 of file machinegun.qc.

60{
61 W_SetupShot(actor, weaponentity, true, 0, SND_MACHINEGUN_FIRE, CH_WEAPON_A, ((actor.(weaponentity).misc_bulletcounter == 1) ? WEP_CVAR(WEP_MACHINEGUN, first_damage) : WEP_CVAR(WEP_MACHINEGUN, sustained_damage)), deathtype);
62
64 {
65 actor.punchangle_x = random() - 0.5;
66 actor.punchangle_y = random() - 0.5;
67 }
68
69 // this attack_finished just enforces a cooldown at the end of a burst
70 ATTACK_FINISHED(actor, weaponentity) = time + WEP_CVAR(WEP_MACHINEGUN, first_refire) * W_WeaponRateFactor(actor);
71
72 float spread_accuracy = (IS_DUCKED(actor) && IS_ONGROUND(actor))
73 ? WEP_CVAR(WEP_MACHINEGUN, spread_crouchmod)
74 : 1;
75
76 if(actor.(weaponentity).misc_bulletcounter == 1)
77 fireBullet_falloff(actor, weaponentity, w_shotorg, w_shotdir,
78 WEP_CVAR(WEP_MACHINEGUN, first_spread) * spread_accuracy,
79 WEP_CVAR(WEP_MACHINEGUN, solidpenetration),
80 WEP_CVAR(WEP_MACHINEGUN, first_damage),
81 WEP_CVAR(WEP_MACHINEGUN, damagefalloff_halflife),
82 WEP_CVAR(WEP_MACHINEGUN, damagefalloff_mindist),
83 WEP_CVAR(WEP_MACHINEGUN, damagefalloff_maxdist),
84 0,
85 WEP_CVAR(WEP_MACHINEGUN, first_force),
86 WEP_CVAR(WEP_MACHINEGUN, damagefalloff_forcehalflife),
87 deathtype, EFFECT_BULLET, true);
88 else
89 fireBullet_falloff(actor, weaponentity, w_shotorg, w_shotdir,
90 WEP_CVAR(WEP_MACHINEGUN, sustained_spread) * spread_accuracy,
91 WEP_CVAR(WEP_MACHINEGUN, solidpenetration),
92 WEP_CVAR(WEP_MACHINEGUN, sustained_damage),
93 WEP_CVAR(WEP_MACHINEGUN, damagefalloff_halflife),
94 WEP_CVAR(WEP_MACHINEGUN, damagefalloff_mindist),
95 WEP_CVAR(WEP_MACHINEGUN, damagefalloff_maxdist),
96 0,
97 WEP_CVAR(WEP_MACHINEGUN, sustained_force),
98 WEP_CVAR(WEP_MACHINEGUN, damagefalloff_forcehalflife),
99 deathtype, EFFECT_BULLET, true);
100
101 W_MuzzleFlash(thiswep, actor, weaponentity, w_shotorg, w_shotdir);
102
103 // casing code
104 if(autocvar_g_casings >= 2)
105 {
106 makevectors(actor.v_angle); // for some reason, this is lost
107 SpawnCasing(((random() * 50 + 50) * v_right) - (v_forward * (random() * 25 + 25)) - ((random() * 5 - 70) * v_up), vectoangles(v_forward), 3, actor, weaponentity);
108 }
109
110 if(actor.(weaponentity).misc_bulletcounter == 1)
111 W_DecreaseAmmo(thiswep, actor, WEP_CVAR(WEP_MACHINEGUN, first_ammo), weaponentity);
112 else
113 W_DecreaseAmmo(thiswep, actor, WEP_CVAR(WEP_MACHINEGUN, sustained_ammo), weaponentity);
114}
void SpawnCasing(vector vel, vector ang, int casingtype, entity casingowner,.entity weaponentity)
Definition casings.qc:17
int autocvar_g_casings
Definition casings.qh:17
#define IS_DUCKED(s)
Definition player.qh:210
float W_WeaponRateFactor(entity this)
vector v_up
vector v_right
vector v_forward
float random(void)
vector vectoangles(vector v)
#define IS_ONGROUND(s)
Definition movetypes.qh:16
#define makevectors
Definition post.qh:21
const int CH_WEAPON_A
Definition sound.qh:7
void fireBullet_falloff(entity this,.entity weaponentity, vector start, vector dir, float spread, float max_solid_penetration, float damage, float falloff_halflife, float falloff_mindist, float falloff_maxdist, float headshot_multiplier, float force, float falloff_forcehalflife, float dtype, entity tracer_effect, bool do_antilag)
Definition tracing.qc:364
bool autocvar_g_norecoil
Definition tracing.qh:16
vector w_shotdir
Definition tracing.qh:20
vector w_shotorg
Definition tracing.qh:19
#define W_SetupShot(ent, wepent, antilag, recoil, snd, chan, maxdamage, deathtype)
Definition tracing.qh:34
void W_MuzzleFlash(Weapon thiswep, entity actor,.entity weaponentity, vector shotorg, vector shotdir)
Definition all.qc:728
void W_DecreaseAmmo(Weapon wep, entity actor, float ammo_use,.entity weaponentity)
#define ATTACK_FINISHED(ent, w)

References ATTACK_FINISHED, autocvar_g_casings, autocvar_g_norecoil, CH_WEAPON_A, entity(), fireBullet_falloff(), IS_DUCKED, IS_ONGROUND, makevectors, random(), SpawnCasing(), time, v_forward, v_right, v_up, vectoangles(), W_DecreaseAmmo(), W_MuzzleFlash(), W_SetupShot, w_shotdir, w_shotorg, W_WeaponRateFactor(), and WEP_CVAR.

Referenced by W_MachineGun_Attack_Frame().

◆ W_MachineGun_Attack_Auto()

void W_MachineGun_Attack_Auto ( Weapon thiswep,
entity actor,
.entity weaponentity,
int fire )

Definition at line 142 of file machinegun.qc.

143{
144 if(!(fire & 1) || !weapon_prepareattack_check(thiswep, actor, weaponentity, false, -1))
145 {
146 w_ready(thiswep, actor, weaponentity, fire);
147 return;
148 }
149
150 if(!thiswep.wr_checkammo1(thiswep, actor, weaponentity))
151 if(!(actor.items & IT_UNLIMITED_AMMO))
152 {
153 W_SwitchWeapon_Force(actor, w_getbestweapon(actor, weaponentity), weaponentity);
154 w_ready(thiswep, actor, weaponentity, fire);
155 return;
156 }
157
158 W_DecreaseAmmo(thiswep, actor, WEP_CVAR(WEP_MACHINEGUN, sustained_ammo), weaponentity);
159
160 W_SetupShot(actor, weaponentity, true, 0, SND_MACHINEGUN_FIRE, CH_WEAPON_A, WEP_CVAR(WEP_MACHINEGUN, sustained_damage), thiswep.m_id);
162 {
163 actor.punchangle_x = random() - 0.5;
164 actor.punchangle_y = random() - 0.5;
165 }
166
167 MachineGun_Update_Spread(actor, weaponentity);
168
169 float spread_accum = actor.(weaponentity).machinegun_spread_accumulation;
170
171 float heat = MachineGun_Heat(spread_accum);
172
173 float spread_accuracy;
174 if (WEP_CVAR(WEP_MACHINEGUN, spread_min) < WEP_CVAR(WEP_MACHINEGUN, spread_max))
175 spread_accuracy = WEP_CVAR(WEP_MACHINEGUN, spread_min) + spread_accum;
176 else // inverted
177 spread_accuracy = WEP_CVAR(WEP_MACHINEGUN, spread_min) - spread_accum;
178
179 if (IS_DUCKED(actor) && IS_ONGROUND(actor))
180 spread_accuracy *= WEP_CVAR(WEP_MACHINEGUN, spread_crouchmod);
181
182 fireBullet_falloff(actor, weaponentity, w_shotorg, w_shotdir,
183 spread_accuracy,
184 WEP_CVAR(WEP_MACHINEGUN, solidpenetration),
185 WEP_CVAR(WEP_MACHINEGUN, sustained_damage) * heat,
186 WEP_CVAR(WEP_MACHINEGUN, damagefalloff_halflife),
187 WEP_CVAR(WEP_MACHINEGUN, damagefalloff_mindist),
188 WEP_CVAR(WEP_MACHINEGUN, damagefalloff_maxdist),
189 0,
190 WEP_CVAR(WEP_MACHINEGUN, sustained_force),
191 WEP_CVAR(WEP_MACHINEGUN, damagefalloff_forcehalflife),
192 thiswep.m_id, EFFECT_BULLET, true);
193
194 ++actor.(weaponentity).misc_bulletcounter;
195
196 spread_accum += WEP_CVAR(WEP_MACHINEGUN, spread_add);
197
198 actor.(weaponentity).machinegun_spread_accumulation = spread_accum;
199
200 W_MuzzleFlash(thiswep, actor, weaponentity, w_shotorg, w_shotdir);
201
202 if(autocvar_g_casings >= 2) // casing code
203 {
204 makevectors(actor.v_angle); // for some reason, this is lost
205 SpawnCasing(((random() * 50 + 50) * v_right) - (v_forward * (random() * 25 + 25)) - ((random() * 5 - 70) * v_up), vectoangles(v_forward), 3, actor, weaponentity);
206 }
207
208 ATTACK_FINISHED(actor, weaponentity) = time + WEP_CVAR(WEP_MACHINEGUN, first_refire) * W_WeaponRateFactor(actor);
209 weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR(WEP_MACHINEGUN, sustained_refire), W_MachineGun_Attack_Auto);
210}
int m_id
Definition weapon.qh:45
virtual void wr_checkammo1()
(SERVER) checks ammo for weapon primary
Definition weapon.qh:92
const int IT_UNLIMITED_AMMO
Definition item.qh:23
void W_SwitchWeapon_Force(Player this, Weapon w,.entity weaponentity)
Definition selection.qc:246
#define w_getbestweapon(ent, wepent)
Definition selection.qh:23
float misc_bulletcounter
Definition common.qh:19
ERASEABLE float MachineGun_Heat(float spread_accum)
Definition machinegun.qc:34
void W_MachineGun_Attack_Auto(Weapon thiswep, entity actor,.entity weaponentity, int fire)
ERASEABLE void MachineGun_Update_Spread(entity actor,.entity weaponentity)
Definition machinegun.qc:9
void weapon_thinkf(entity actor,.entity weaponentity, WFRAME fr, float t, void(Weapon thiswep, entity actor,.entity weaponentity, int fire) func)
void w_ready(Weapon thiswep, entity actor,.entity weaponentity, int fire)
bool weapon_prepareattack_check(Weapon thiswep, entity actor,.entity weaponentity, bool secondary, float attacktime)

References ATTACK_FINISHED, autocvar_g_casings, autocvar_g_norecoil, CH_WEAPON_A, entity(), fireBullet_falloff(), IS_DUCKED, IS_ONGROUND, IT_UNLIMITED_AMMO, Weapon::m_id, MachineGun_Heat(), machinegun_spread_accumulation, MachineGun_Update_Spread(), makevectors, misc_bulletcounter, random(), SpawnCasing(), time, v_forward, v_right, v_up, vectoangles(), W_DecreaseAmmo(), w_getbestweapon, W_MachineGun_Attack_Auto(), W_MuzzleFlash(), w_ready(), W_SetupShot, w_shotdir, w_shotorg, W_SwitchWeapon_Force(), W_WeaponRateFactor(), weapon_prepareattack_check(), weapon_thinkf(), WEP_CVAR, and Weapon::wr_checkammo1().

Referenced by W_MachineGun_Attack_Auto().

◆ W_MachineGun_Attack_Burst()

void W_MachineGun_Attack_Burst ( Weapon thiswep,
entity actor,
.entity weaponentity,
int fire )

Definition at line 212 of file machinegun.qc.

213{
214 W_SetupShot(actor, weaponentity, true, 0, SND_MACHINEGUN_FIRE, CH_WEAPON_A, WEP_CVAR(WEP_MACHINEGUN, sustained_damage), thiswep.m_id);
216 {
217 actor.punchangle_x = random() - 0.5;
218 actor.punchangle_y = random() - 0.5;
219 }
220
221 MachineGun_Update_Spread(actor, weaponentity);
222
223 float spread_accum = actor.(weaponentity).machinegun_spread_accumulation;
224
225 float heat = MachineGun_Heat(spread_accum);
226
227 float spread_accuracy = WEP_CVAR(WEP_MACHINEGUN, burst_spread);
228 if (IS_DUCKED(actor) && IS_ONGROUND(actor))
229 spread_accuracy *= WEP_CVAR(WEP_MACHINEGUN, spread_crouchmod);
230
231 fireBullet_falloff(actor, weaponentity, w_shotorg, w_shotdir,
232 spread_accuracy,
233 WEP_CVAR(WEP_MACHINEGUN, solidpenetration),
234 WEP_CVAR(WEP_MACHINEGUN, sustained_damage) * heat,
235 WEP_CVAR(WEP_MACHINEGUN, damagefalloff_halflife),
236 WEP_CVAR(WEP_MACHINEGUN, damagefalloff_mindist),
237 WEP_CVAR(WEP_MACHINEGUN, damagefalloff_maxdist),
238 0,
239 WEP_CVAR(WEP_MACHINEGUN, sustained_force),
240 WEP_CVAR(WEP_MACHINEGUN, damagefalloff_forcehalflife),
241 thiswep.m_id, EFFECT_BULLET, true);
242
243 W_MuzzleFlash(thiswep, actor, weaponentity, w_shotorg, w_shotdir);
244
245 if(autocvar_g_casings >= 2) // casing code
246 {
247 makevectors(actor.v_angle); // for some reason, this is lost
248 SpawnCasing(((random() * 50 + 50) * v_right) - (v_forward * (random() * 25 + 25)) - ((random() * 5 - 70) * v_up), vectoangles(v_forward), 3, actor, weaponentity);
249 }
250
251 spread_accum += WEP_CVAR(WEP_MACHINEGUN, spread_add);
252
253 actor.(weaponentity).machinegun_spread_accumulation = spread_accum;
254
255 ++actor.(weaponentity).misc_bulletcounter;
256 if(actor.(weaponentity).misc_bulletcounter == 0)
257 {
258 ATTACK_FINISHED(actor, weaponentity) = time + WEP_CVAR(WEP_MACHINEGUN, burst_refire2) * W_WeaponRateFactor(actor);
259 weapon_thinkf(actor, weaponentity, WFRAME_FIRE2, WEP_CVAR(WEP_MACHINEGUN, burst_animtime), w_ready);
260 }
261 else
262 {
263 weapon_thinkf(actor, weaponentity, WFRAME_FIRE2, WEP_CVAR(WEP_MACHINEGUN, burst_refire), W_MachineGun_Attack_Burst);
264 }
265
266}
void W_MachineGun_Attack_Burst(Weapon thiswep, entity actor,.entity weaponentity, int fire)

References ATTACK_FINISHED, autocvar_g_casings, autocvar_g_norecoil, CH_WEAPON_A, entity(), fireBullet_falloff(), IS_DUCKED, IS_ONGROUND, Weapon::m_id, MachineGun_Heat(), machinegun_spread_accumulation, MachineGun_Update_Spread(), makevectors, misc_bulletcounter, random(), SpawnCasing(), time, v_forward, v_right, v_up, vectoangles(), W_MachineGun_Attack_Burst(), W_MuzzleFlash(), w_ready(), W_SetupShot, w_shotdir, w_shotorg, W_WeaponRateFactor(), weapon_thinkf(), and WEP_CVAR.

Referenced by W_MachineGun_Attack_Burst().

◆ W_MachineGun_Attack_Frame()

void W_MachineGun_Attack_Frame ( Weapon thiswep,
entity actor,
.entity weaponentity,
int fire )

Definition at line 117 of file machinegun.qc.

118{
119 if(actor.(weaponentity).m_weapon != actor.(weaponentity).m_switchweapon || !weapon_prepareattack_check(thiswep, actor, weaponentity, (fire & 2), -1)) // abort immediately if switching
120 {
121 w_ready(thiswep, actor, weaponentity, fire);
122 return;
123 }
124 if(PHYS_INPUT_BUTTON_ATCK(actor))
125 {
126 if(!thiswep.wr_checkammo2(thiswep, actor, weaponentity))
127 if(!(actor.items & IT_UNLIMITED_AMMO))
128 {
129 W_SwitchWeapon_Force(actor, w_getbestweapon(actor, weaponentity), weaponentity);
130 w_ready(thiswep, actor, weaponentity, fire);
131 return;
132 }
133 ++actor.(weaponentity).misc_bulletcounter;
134 W_MachineGun_Attack(thiswep, thiswep.m_id, actor, weaponentity);
135 weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR(WEP_MACHINEGUN, sustained_refire), W_MachineGun_Attack_Frame);
136 }
137 else
138 weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR(WEP_MACHINEGUN, sustained_refire), w_ready);
139}
virtual void wr_checkammo2()
(SERVER) checks ammo for weapon second
Definition weapon.qh:94
#define PHYS_INPUT_BUTTON_ATCK(s)
Definition player.qh:150
void W_MachineGun_Attack(Weapon thiswep, int deathtype, entity actor,.entity weaponentity)
Definition machinegun.qc:59
void W_MachineGun_Attack_Frame(Weapon thiswep, entity actor,.entity weaponentity, int fire)

References entity(), IT_UNLIMITED_AMMO, Weapon::m_id, misc_bulletcounter, PHYS_INPUT_BUTTON_ATCK, w_getbestweapon, W_MachineGun_Attack(), W_MachineGun_Attack_Frame(), w_ready(), W_SwitchWeapon_Force(), weapon_prepareattack_check(), weapon_thinkf(), WEP_CVAR, and Weapon::wr_checkammo2().

Referenced by W_MachineGun_Attack_Frame().

Variable Documentation

◆ machinegun_spread_accumulation

float machinegun_spread_accumulation

◆ spreadUpdateTime

float spreadUpdateTime

Definition at line 6 of file machinegun.qc.

Referenced by MachineGun_Update_Spread().