Xonotic QuakeC
The free, fast arena FPS with crisp movement and a wide array of weapons
okmachinegun.qc
Go to the documentation of this file.
1#include "okmachinegun.qh"
2
3#ifdef SVQC
4
5void W_OverkillMachineGun_Attack_Auto(Weapon thiswep, entity actor, .entity weaponentity, int fire)
6{
7 if (!(fire & 1))
8 {
9 w_ready(thiswep, actor, weaponentity, fire);
10 return;
11 }
12
13 if (!thiswep.wr_checkammo1(thiswep, actor, weaponentity)
14 && !(actor.items & IT_UNLIMITED_AMMO))
15 {
16 W_SwitchWeapon_Force(actor, w_getbestweapon(actor, weaponentity), weaponentity);
17 w_ready(thiswep, actor, weaponentity, fire);
18 return;
19 }
20
21 W_DecreaseAmmo(WEP_OVERKILL_MACHINEGUN, actor, WEP_CVAR_PRI(WEP_OVERKILL_MACHINEGUN, ammo), weaponentity);
22
23 W_SetupShot(actor, weaponentity, true, 0, SND_OK_MG_FIRE, CH_WEAPON_A, WEP_CVAR_PRI(WEP_OVERKILL_MACHINEGUN, damage), WEP_OVERKILL_MACHINEGUN.m_id);
25 {
26 actor.punchangle_x = random() - 0.5;
27 actor.punchangle_y = random() - 0.5;
28 }
29
30 float okmachinegun_spread = bound(
31 WEP_CVAR_PRI(WEP_OVERKILL_MACHINEGUN, spread_min),
32 WEP_CVAR_PRI(WEP_OVERKILL_MACHINEGUN, spread_min) + (WEP_CVAR_PRI(WEP_OVERKILL_MACHINEGUN, spread_add) * actor.(weaponentity).misc_bulletcounter),
33 WEP_CVAR_PRI(WEP_OVERKILL_MACHINEGUN, spread_max)
34 );
35
36 fireBullet_falloff(actor, weaponentity, w_shotorg, w_shotdir, okmachinegun_spread,
37 WEP_CVAR_PRI(WEP_OVERKILL_MACHINEGUN, solidpenetration),
38 WEP_CVAR_PRI(WEP_OVERKILL_MACHINEGUN, damage),
39 WEP_CVAR(WEP_OVERKILL_MACHINEGUN, damagefalloff_halflife),
40 WEP_CVAR(WEP_OVERKILL_MACHINEGUN, damagefalloff_mindist),
41 WEP_CVAR(WEP_OVERKILL_MACHINEGUN, damagefalloff_maxdist),
42 0,
43 WEP_CVAR_PRI(WEP_OVERKILL_MACHINEGUN, force),
44 WEP_CVAR(WEP_OVERKILL_MACHINEGUN, damagefalloff_forcehalflife),
45 WEP_OVERKILL_MACHINEGUN.m_id,
46 EFFECT_RIFLE,
47 true
48 );
49
50 ++actor.(weaponentity).misc_bulletcounter;
51
52 W_MuzzleFlash(thiswep, actor, weaponentity, w_shotorg, w_shotdir);
53
54 if (autocvar_g_casings >= 2) // casing code
55 {
56 makevectors(actor.v_angle); // for some reason, this is lost
57 SpawnCasing(((random() * 50 + 50) * v_right) - (v_forward * (random() * 25 + 25)) - ((random() * 5 - 70) * v_up), vectoangles(v_forward), 3, actor, weaponentity);
58 }
59
60 ATTACK_FINISHED(actor, weaponentity) = time + WEP_CVAR_PRI(WEP_OVERKILL_MACHINEGUN, refire) * W_WeaponRateFactor(actor);
61 weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR_PRI(WEP_OVERKILL_MACHINEGUN, refire), W_OverkillMachineGun_Attack_Auto);
62}
63
64METHOD(OverkillMachineGun, wr_aim, void(entity thiswep, entity actor, .entity weaponentity))
65{
66 if (vdist(actor.origin - actor.enemy.origin, <, 3000 - bound(0, skill, 10) * 200))
67 PHYS_INPUT_BUTTON_ATCK(actor) = bot_aim(actor, weaponentity, 1000000, 0, 0.001, false, true);
68}
69
70METHOD(OverkillMachineGun, wr_think, void(entity thiswep, entity actor, .entity weaponentity, int fire))
71{
72 if (WEP_CVAR_SEC(WEP_OVERKILL_MACHINEGUN, refire_type) == 1 && (fire & 2)
73 && time >= actor.jump_interval)
74 {
75 // Secondary uses it's own refire timer if refire_type is 1.
76 actor.jump_interval = time + WEP_CVAR_PRI(WEP_BLASTER, refire) * W_WeaponRateFactor(actor);
77 makevectors(actor.v_angle);
78 W_Blaster_Attack(actor, weaponentity);
79 if (actor.(weaponentity).wframe == WFRAME_IDLE
80 || actor.(weaponentity).wframe == WFRAME_FIRE2)
81 {
82 // Set secondary fire animation.
83 actor.(weaponentity).wframe = WFRAME_FIRE2;
85 if (it == actor || (IS_SPEC(it) && it.enemy == actor))
86 wframe_send(it, actor.(weaponentity), WFRAME_FIRE2, autocvar_g_weaponratefactor, true);
87 ));
89 }
90 }
91 if (WEP_CVAR(WEP_OVERKILL_MACHINEGUN, reload_ammo) && actor.(weaponentity).clip_load < WEP_CVAR_PRI(WEP_OVERKILL_MACHINEGUN, ammo))
92 { // forced reload
93 thiswep.wr_reload(thiswep, actor, weaponentity);
94 return;
95 }
96
97 if (fire & 1) // Primary attack
98 {
99 if (!weapon_prepareattack(thiswep, actor, weaponentity, false, 0))
100 return;
101 actor.(weaponentity).misc_bulletcounter = 0;
102 W_OverkillMachineGun_Attack_Auto(thiswep, actor, weaponentity, fire);
103 return;
104 }
105 if ((fire & 2) && WEP_CVAR_SEC(WEP_OVERKILL_MACHINEGUN, refire_type) == 0) // Secondary attack
106 {
107 if (!weapon_prepareattack(thiswep, actor, weaponentity, true, WEP_CVAR_PRI(WEP_BLASTER, refire)))
108 return;
109 makevectors(actor.v_angle);
110 W_Blaster_Attack(actor, weaponentity);
111 weapon_thinkf(actor, weaponentity, WFRAME_FIRE2, WEP_CVAR_PRI(WEP_BLASTER, animtime), w_ready);
112 }
113}
114
115METHOD(OverkillMachineGun, wr_checkammo1, bool(entity thiswep, entity actor, .entity weaponentity))
116{
117 float ammo_amount = GetResource(actor, thiswep.ammo_type) >= WEP_CVAR_PRI(WEP_OVERKILL_MACHINEGUN, ammo);
118 if (WEP_CVAR(WEP_OVERKILL_MACHINEGUN, reload_ammo))
119 ammo_amount += actor.(weaponentity).(weapon_load[WEP_OVERKILL_MACHINEGUN.m_id]) >= WEP_CVAR_PRI(WEP_OVERKILL_MACHINEGUN, ammo);
120 return ammo_amount;
121}
122
123METHOD(OverkillMachineGun, wr_checkammo2, bool(entity thiswep, entity actor, .entity weaponentity))
124{
125 return true; // Blaster secondary is unlimited.
126}
127
128METHOD(OverkillMachineGun, wr_reload, void(entity thiswep, entity actor, .entity weaponentity))
129{
130 W_Reload(actor, weaponentity, WEP_CVAR_PRI(WEP_OVERKILL_MACHINEGUN, ammo), SND_RELOAD);
131}
132
133METHOD(OverkillMachineGun, wr_suicidemessage, Notification(entity thiswep))
134{
135 return WEAPON_THINKING_WITH_PORTALS;
136}
137
138METHOD(OverkillMachineGun, wr_killmessage, Notification(entity thiswep))
139{
140 return WEAPON_OVERKILL_MACHINEGUN_MURDER;
141}
142
143#endif // SVQC
144#ifdef CSQC
145
146METHOD(OverkillMachineGun, wr_impacteffect, void(entity thiswep, entity actor))
147{
148 vector org2 = w_org + w_backoff * 2;
149 pointparticles(EFFECT_MACHINEGUN_IMPACT, org2, w_backoff * 1000, 1);
150 if (!w_issilent)
152}
153
154#endif // CSQC
155#ifdef MENUQC
158
159METHOD(OverkillMachineGun, describe, string(OverkillMachineGun this))
160{
161 TC(OverkillMachineGun, this);
163 PAR(_("The %s quickly fires bullets with a small degree of spread."), COLORED_NAME(this));
164 PAR(_("Like with all %s weapons, the secondary fire shoots a laser which doesn't damage or push enemies, but can be used to push yourself around."), COLORED_NAME(MUTATOR_ok));
165 PAR(_("The primary fire consumes %s ammo, although you spawn with an infinite amount of it in %s. "
166 "It has a limited magazine size, so needs reloading after several shots."), COLORED_NAME(ITEM_Bullets), COLORED_NAME(MUTATOR_ok));
167 PAR(_("The %s can be used in a lot of situations, and it works particularly well at long ranges since the bullets pierce the sky instantaneously."), COLORED_NAME(this));
168 PAR(W_Guide_Keybinds(this));
169 PAR(W_Guide_DPS_onlyOne(this.netname, "primary"));
170 return PAGE_TEXT;
171}
172
173#endif // MENUQC
void animdecide_setaction(entity e, float action, float restart)
const int ANIMACTION_SHOOT
float skill
Definition api.qh:35
bool bot_aim(entity this,.entity weaponentity, float shotspeed, float shotspeedupward, float maxshottime, float applygravity, bool shot_accurate)
void W_Blaster_Attack(entity actor,.entity weaponentity)
Definition blaster.qc:52
void SpawnCasing(vector vel, vector ang, int casingtype, entity casingowner,.entity weaponentity)
Definition casings.qc:17
int autocvar_g_casings
Definition casings.qh:17
var entity(vector mins, vector maxs,.entity tofield) findbox_tofield_OrFallback
float GetResource(entity e, Resource res_type)
Returns the current amount of resource the given entity has.
fields which are explicitly/manually set are marked with "M", fields set automatically are marked wit...
Definition weapon.qh:42
virtual void wr_checkammo1()
(SERVER) checks ammo for weapon primary
Definition weapon.qh:100
string netname
Definition powerups.qc:20
#define COLORED_NAME(this)
Definition color.qh:195
const int IT_UNLIMITED_AMMO
Definition item.qh:23
#define PHYS_INPUT_BUTTON_ATCK(s)
Definition player.qh:152
float W_WeaponRateFactor(entity this)
vector v_up
float time
vector v_right
vector v_forward
const float ATTN_NORM
void W_SwitchWeapon_Force(Player this, Weapon w,.entity weaponentity)
Definition selection.qc:237
vector w_org
vector w_backoff
float w_issilent
#define pointparticles(effect, org, vel, howmany)
Definition effect.qh:7
#define TC(T, sym)
Definition _all.inc:82
float bound(float min, float value, float max)
float random(void)
vector vectoangles(vector v)
#define LAMBDA(...)
Definition misc.qh:34
entity Notification
always last
Definition all.qh:81
void W_OverkillMachineGun_Attack_Auto(Weapon thiswep, entity actor,.entity weaponentity, int fire)
#define METHOD(cname, name, prototype)
Definition oo.qh:269
#define makevectors
Definition post.qh:21
#define w_getbestweapon(ent, wepent)
Definition selection.qh:23
vector
Definition self.qh:92
float misc_bulletcounter
Definition common.qh:19
const float VOL_BASE
Definition sound.qh:36
const int CH_SHOTS
Definition sound.qh:14
const int CH_WEAPON_A
Definition sound.qh:7
#define sound(e, c, s, v, a)
Definition sound.qh:52
Sound SND_RIC_RANDOM()
Definition all.inc:33
#define PAGE_TEXT
Definition string.qh:642
#define PAR(...)
Adds an individually translatable paragraph to PAGE_TEXT without having to deal with strcat and sprin...
Definition string.qh:648
#define PAGE_TEXT_INIT()
Definition string.qh:641
float ammo
Definition sv_turrets.qh:43
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
#define IS_SPEC(v)
Definition utils.qh:10
#define FOREACH_CLIENT(cond, body)
Definition utils.qh:52
#define vdist(v, cmp, f)
Vector distance comparison, avoids sqrt()
Definition vector.qh:8
void wframe_send(entity actor, entity weaponentity, int wepframe, float attackrate, bool restartanim)
Definition all.qc:577
string W_Guide_Keybinds(Weapon wep)
Definition all.qc:824
void W_MuzzleFlash(Weapon thiswep, entity actor,.entity weaponentity, vector shotorg, vector shotdir)
Definition all.qc:715
string W_Guide_DPS_onlyOne(string name, string fire)
Definition all.qc:914
#define WEP_CVAR_PRI(wep, name)
Definition all.qh:338
WFRAME wframe
Definition all.qh:439
#define WEP_CVAR(wep, name)
Definition all.qh:337
#define WEP_CVAR_SEC(wep, name)
Definition all.qh:339
void W_DecreaseAmmo(Weapon wep, entity actor, float ammo_use,.entity weaponentity)
void W_Reload(entity actor,.entity weaponentity, float sent_ammo_min, Sound sent_sound)
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)
#define ATTACK_FINISHED(ent, w)
float autocvar_g_weaponratefactor
float weapon_load[REGISTRY_MAX(Weapons)]