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 32 of file machinegun.qc.

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

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;
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 actor.(weaponentity).machinegun_spread_accumulation - (timediff * WEP_CVAR(WEP_MACHINEGUN, spread_decay)),
20 spreadSpectrumDistance);
21 }
22 else // legacy behavior for Nexuiz weapon balance
23 spread_accum = bound(WEP_CVAR(WEP_MACHINEGUN, spread_min),
24 (WEP_CVAR(WEP_MACHINEGUN, spread_add) * actor.(weaponentity).misc_bulletcounter),
25 WEP_CVAR(WEP_MACHINEGUN, spread_max));
26
27 actor.(weaponentity).machinegun_spread_accumulation = spread_accum;
28 actor.(weaponentity).spreadUpdateTime = time;
29}
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 57 of file machinegun.qc.

58{
59 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);
60
62 {
63 actor.punchangle.x = random() - 0.5;
64 actor.punchangle.y = random() - 0.5;
65 }
66
67 // this attack_finished just enforces a cooldown at the end of a burst
68 ATTACK_FINISHED(actor, weaponentity) = time + WEP_CVAR(WEP_MACHINEGUN, first_refire) * W_WeaponRateFactor(actor);
69
70 float spread_accuracy = (IS_DUCKED(actor) && IS_ONGROUND(actor))
71 ? WEP_CVAR(WEP_MACHINEGUN, spread_crouchmod)
72 : 1;
73
74 if (actor.(weaponentity).misc_bulletcounter == 1)
75 fireBullet_falloff(actor, weaponentity, w_shotorg, w_shotdir,
76 WEP_CVAR(WEP_MACHINEGUN, first_spread) * spread_accuracy,
77 WEP_CVAR(WEP_MACHINEGUN, solidpenetration),
78 WEP_CVAR(WEP_MACHINEGUN, first_damage),
79 WEP_CVAR(WEP_MACHINEGUN, damagefalloff_halflife),
80 WEP_CVAR(WEP_MACHINEGUN, damagefalloff_mindist),
81 WEP_CVAR(WEP_MACHINEGUN, damagefalloff_maxdist),
82 0,
83 WEP_CVAR(WEP_MACHINEGUN, first_force),
84 WEP_CVAR(WEP_MACHINEGUN, damagefalloff_forcehalflife),
85 deathtype,
86 EFFECT_BULLET,
87 true
88 );
89 else
90 fireBullet_falloff(actor, weaponentity, w_shotorg, w_shotdir,
91 WEP_CVAR(WEP_MACHINEGUN, sustained_spread) * spread_accuracy,
92 WEP_CVAR(WEP_MACHINEGUN, solidpenetration),
93 WEP_CVAR(WEP_MACHINEGUN, sustained_damage),
94 WEP_CVAR(WEP_MACHINEGUN, damagefalloff_halflife),
95 WEP_CVAR(WEP_MACHINEGUN, damagefalloff_mindist),
96 WEP_CVAR(WEP_MACHINEGUN, damagefalloff_maxdist),
97 0,
98 WEP_CVAR(WEP_MACHINEGUN, sustained_force),
99 WEP_CVAR(WEP_MACHINEGUN, damagefalloff_forcehalflife),
100 deathtype,
101 EFFECT_BULLET,
102 true
103 );
104
105 W_MuzzleFlash(thiswep, actor, weaponentity, w_shotorg, w_shotdir);
106
107 // casing code
108 if (autocvar_g_casings >= 2)
109 {
110 makevectors(actor.v_angle); // for some reason, this is lost
111 SpawnCasing(((random() * 50 + 50) * v_right) - (v_forward * (random() * 25 + 25)) - ((random() * 5 - 70) * v_up), vectoangles(v_forward), 3, actor, weaponentity);
112 }
113
114 if (actor.(weaponentity).misc_bulletcounter == 1)
115 W_DecreaseAmmo(thiswep, actor, WEP_CVAR(WEP_MACHINEGUN, first_ammo), weaponentity);
116 else
117 W_DecreaseAmmo(thiswep, actor, WEP_CVAR(WEP_MACHINEGUN, sustained_ammo), weaponentity);
118}
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:212
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:356
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:715
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 146 of file machinegun.qc.

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

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

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