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 float okmachinegun_spread;
8
9 if(!(fire & 1))
10 {
11 w_ready(thiswep, actor, weaponentity, fire);
12 return;
13 }
14
15 if(!thiswep.wr_checkammo1(thiswep, actor, weaponentity))
16 if(!(actor.items & IT_UNLIMITED_AMMO))
17 {
18 W_SwitchWeapon_Force(actor, w_getbestweapon(actor, weaponentity), weaponentity);
19 w_ready(thiswep, actor, weaponentity, fire);
20 return;
21 }
22
23 W_DecreaseAmmo(WEP_OVERKILL_MACHINEGUN, actor, WEP_CVAR_PRI(WEP_OVERKILL_MACHINEGUN, ammo), weaponentity);
24
25 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);
27 {
28 actor.punchangle_x = random() - 0.5;
29 actor.punchangle_y = random() - 0.5;
30 }
31
32 okmachinegun_spread = bound(WEP_CVAR_PRI(WEP_OVERKILL_MACHINEGUN, spread_min), WEP_CVAR_PRI(WEP_OVERKILL_MACHINEGUN, spread_min) + (WEP_CVAR_PRI(WEP_OVERKILL_MACHINEGUN, spread_add) * actor.(weaponentity).misc_bulletcounter), WEP_CVAR_PRI(WEP_OVERKILL_MACHINEGUN, spread_max));
33
34 fireBullet_falloff(actor, weaponentity, w_shotorg, w_shotdir, okmachinegun_spread,
35 WEP_CVAR_PRI(WEP_OVERKILL_MACHINEGUN, solidpenetration),
36 WEP_CVAR_PRI(WEP_OVERKILL_MACHINEGUN, damage),
37 WEP_CVAR(WEP_OVERKILL_MACHINEGUN, damagefalloff_halflife),
38 WEP_CVAR(WEP_OVERKILL_MACHINEGUN, damagefalloff_mindist),
39 WEP_CVAR(WEP_OVERKILL_MACHINEGUN, damagefalloff_maxdist),
40 0,
41 WEP_CVAR_PRI(WEP_OVERKILL_MACHINEGUN, force),
42 WEP_CVAR(WEP_OVERKILL_MACHINEGUN, damagefalloff_forcehalflife),
43 WEP_OVERKILL_MACHINEGUN.m_id, EFFECT_RIFLE, true);
44
45 actor.(weaponentity).misc_bulletcounter = actor.(weaponentity).misc_bulletcounter + 1;
46
47 W_MuzzleFlash(thiswep, actor, weaponentity, w_shotorg, w_shotdir);
48
49 if(autocvar_g_casings >= 2) // casing code
50 {
51 makevectors(actor.v_angle); // for some reason, this is lost
52 SpawnCasing(((random() * 50 + 50) * v_right) - (v_forward * (random() * 25 + 25)) - ((random() * 5 - 70) * v_up), vectoangles(v_forward), 3, actor, weaponentity);
53 }
54
55 ATTACK_FINISHED(actor, weaponentity) = time + WEP_CVAR_PRI(WEP_OVERKILL_MACHINEGUN, refire) * W_WeaponRateFactor(actor);
56 weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR_PRI(WEP_OVERKILL_MACHINEGUN, refire), W_OverkillMachineGun_Attack_Auto);
57}
58
59METHOD(OverkillMachineGun, wr_aim, void(entity thiswep, entity actor, .entity weaponentity))
60{
61 if(vdist(actor.origin - actor.enemy.origin, <, 3000 - bound(0, skill, 10) * 200))
62 PHYS_INPUT_BUTTON_ATCK(actor) = bot_aim(actor, weaponentity, 1000000, 0, 0.001, false, true);
63}
64
65METHOD(OverkillMachineGun, wr_think, void(entity thiswep, entity actor, .entity weaponentity, int fire))
66{
67 if ((WEP_CVAR_SEC(WEP_OVERKILL_MACHINEGUN, refire_type) == 1) && (fire & 2) && (time >= actor.jump_interval))
68 {
69 // Secondary uses it's own refire timer if refire_type is 1.
70 actor.jump_interval = time + WEP_CVAR_PRI(WEP_BLASTER, refire) * W_WeaponRateFactor(actor);
71 makevectors(actor.v_angle);
72 W_Blaster_Attack(actor, weaponentity);
73 if ((actor.(weaponentity).wframe == WFRAME_IDLE) ||
74 (actor.(weaponentity).wframe == WFRAME_FIRE2))
75 {
76 // Set secondary fire animation.
77 actor.(weaponentity).wframe = WFRAME_FIRE2;
79 if (it == actor || (IS_SPEC(it) && it.enemy == actor))
80 {
81 wframe_send(it, actor.(weaponentity), WFRAME_FIRE2, autocvar_g_weaponratefactor, true);
82 }
83 ));
85 }
86 }
87 if (WEP_CVAR(WEP_OVERKILL_MACHINEGUN, reload_ammo) && actor.(weaponentity).clip_load < WEP_CVAR_PRI(WEP_OVERKILL_MACHINEGUN, ammo))
88 {
89 // Forced reload
90 thiswep.wr_reload(thiswep, actor, weaponentity);
91 return;
92 }
93 if (fire & 1) // Primary attack
94 {
95 if (!weapon_prepareattack(thiswep, actor, weaponentity, false, 0))
96 {
97 return;
98 }
99 actor.(weaponentity).misc_bulletcounter = 0;
100 W_OverkillMachineGun_Attack_Auto(thiswep, actor, weaponentity, fire);
101 return;
102 }
103 if ((fire & 2) && (WEP_CVAR_SEC(WEP_OVERKILL_MACHINEGUN, refire_type) == 0)) // Secondary attack
104 {
105 if (!weapon_prepareattack(thiswep, actor, weaponentity, true, WEP_CVAR_PRI(WEP_BLASTER, refire)))
106 {
107 return;
108 }
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;
118 ammo_amount = GetResource(actor, thiswep.ammo_type) >= WEP_CVAR_PRI(WEP_OVERKILL_MACHINEGUN, ammo);
119 if (WEP_CVAR(WEP_OVERKILL_MACHINEGUN, reload_ammo))
120 {
121 ammo_amount += actor.(weaponentity).(weapon_load[WEP_OVERKILL_MACHINEGUN.m_id]) >= WEP_CVAR_PRI(WEP_OVERKILL_MACHINEGUN, ammo);
122 }
123 return ammo_amount;
124}
125
126METHOD(OverkillMachineGun, wr_checkammo2, bool(entity thiswep, entity actor, .entity weaponentity))
127{
128 return true; // Blaster secondary is unlimited.
129}
130
131METHOD(OverkillMachineGun, wr_reload, void(entity thiswep, entity actor, .entity weaponentity))
132{
133 W_Reload(actor, weaponentity, WEP_CVAR_PRI(WEP_OVERKILL_MACHINEGUN, ammo), SND_RELOAD);
134}
135
136METHOD(OverkillMachineGun, wr_suicidemessage, Notification(entity thiswep))
137{
138 return WEAPON_THINKING_WITH_PORTALS;
139}
140
141METHOD(OverkillMachineGun, wr_killmessage, Notification(entity thiswep))
142{
143 return WEAPON_OVERKILL_MACHINEGUN_MURDER;
144}
145
146#endif
147#ifdef CSQC
148
149METHOD(OverkillMachineGun, wr_impacteffect, void(entity thiswep, entity actor))
150{
151 vector org2 = w_org + w_backoff * 2;
152 pointparticles(EFFECT_MACHINEGUN_IMPACT, org2, w_backoff * 1000, 1);
153 if(!w_issilent)
155}
156
157#endif
158#ifdef MENUQC
161
162METHOD(OverkillMachineGun, describe, string(OverkillMachineGun this))
163{
164 TC(OverkillMachineGun, this);
166 PAR(_("The %s quickly fires bullets with a small degree of spread."), COLORED_NAME(this));
167 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));
168 PAR(_("The primary fire consumes %s ammo, although you spawn with an infinite amount of it in %s. "
169 "It has a limited magazine size, so needs reloading after several shots."), COLORED_NAME(ITEM_Bullets), COLORED_NAME(MUTATOR_ok));
170 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));
171 PAR(W_Guide_Keybinds(this));
172 PAR(W_Guide_DPS_onlyOne(this.netname, "primary"));
173 return PAGE_TEXT;
174}
175
176#endif
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:54
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:44
virtual void wr_checkammo1()
(SERVER) checks ammo for weapon primary
Definition weapon.qh:92
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:150
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:246
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:643
#define PAR(...)
Adds an individually translatable paragraph to PAGE_TEXT without having to deal with strcat and sprin...
Definition string.qh:649
#define PAGE_TEXT_INIT()
Definition string.qh:642
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: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
#define IS_SPEC(v)
Definition utils.qh:10
#define FOREACH_CLIENT(cond, body)
Definition utils.qh:50
#define vdist(v, cmp, f)
Vector distance comparison, avoids sqrt()
Definition vector.qh:8
string W_Guide_Keybinds(Weapon wep)
Definition all.qc:836
void W_MuzzleFlash(Weapon thiswep, entity actor,.entity weaponentity, vector shotorg, vector shotdir)
Definition all.qc:728
string W_Guide_DPS_onlyOne(string name, string fire)
Definition all.qc:926
#define WEP_CVAR_PRI(wep, name)
Definition all.qh:322
WFRAME wframe
Definition all.qh:414
#define WEP_CVAR(wep, name)
Definition all.qh:321
#define WEP_CVAR_SEC(wep, name)
Definition all.qh:323
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 weapon_load[REGISTRY_MAX(Weapons)]