Xonotic QuakeC
The free, fast arena FPS with crisp movement and a wide array of weapons
okhmg.qc
Go to the documentation of this file.
1#include "okhmg.qh"
2
3#ifdef SVQC
4
5REGISTER_MUTATOR(okhmg_nadesupport, true);
6MUTATOR_HOOKFUNCTION(okhmg_nadesupport, Nade_Damage)
7{
8 if (M_ARGV(1, entity) != WEP_OVERKILL_HMG) return;
9 return = true;
10 M_ARGV(3, float) /* damage */ = (M_ARGV(0, entity)).max_health * 0.1;
11}
12
13void W_OverkillHeavyMachineGun_Attack_Auto(Weapon thiswep, entity actor, .entity weaponentity, int fire)
14{
15 if (!PHYS_INPUT_BUTTON_ATCK(actor))
16 {
17 w_ready(thiswep, actor, weaponentity, fire);
18 return;
19 }
20
21 if((!thiswep.wr_checkammo1(thiswep, actor, weaponentity) && !(actor.items & IT_UNLIMITED_AMMO)) || (!StatusEffects_active(STATUSEFFECT_Superweapon, actor) && !(actor.items & IT_UNLIMITED_SUPERWEAPONS)))
22 {
23 W_SwitchWeapon_Force(actor, w_getbestweapon(actor, weaponentity), weaponentity);
24 w_ready(thiswep, actor, weaponentity, fire);
25 return;
26 }
27
28 W_DecreaseAmmo(WEP_OVERKILL_HMG, actor, WEP_CVAR_PRI(WEP_OVERKILL_HMG, ammo), weaponentity);
29
30 W_SetupShot(actor, weaponentity, true, 0, SND_HMG_FIRE, CH_WEAPON_A, WEP_CVAR_PRI(WEP_OVERKILL_HMG, damage), WEP_OVERKILL_HMG.m_id);
31
33 {
34 actor.punchangle_x = random () - 0.5;
35 actor.punchangle_y = random () - 0.5;
36 }
37
38 float okhmg_spread = bound(WEP_CVAR_PRI(WEP_OVERKILL_HMG, spread_min), WEP_CVAR_PRI(WEP_OVERKILL_HMG, spread_min) + (WEP_CVAR_PRI(WEP_OVERKILL_HMG, spread_add) * actor.(weaponentity).misc_bulletcounter), WEP_CVAR_PRI(WEP_OVERKILL_HMG, spread_max));
39 fireBullet(actor, weaponentity, w_shotorg, w_shotdir, okhmg_spread, WEP_CVAR_PRI(WEP_OVERKILL_HMG, solidpenetration), WEP_CVAR_PRI(WEP_OVERKILL_HMG, damage), 0, WEP_CVAR_PRI(WEP_OVERKILL_HMG, force), WEP_OVERKILL_HMG.m_id, EFFECT_RIFLE);
40
41 actor.(weaponentity).misc_bulletcounter = actor.(weaponentity).misc_bulletcounter + 1;
42
43 W_MuzzleFlash(thiswep, actor, weaponentity, w_shotorg, w_shotdir);
44
45 if (autocvar_g_casings >= 2) // casing code
46 {
47 makevectors(actor.v_angle); // for some reason, this is lost
48 SpawnCasing(((random () * 50 + 50) * v_right) - (v_forward * (random () * 25 + 25)) - ((random () * 5 - 70) * v_up), vectoangles(v_forward), 3, actor, weaponentity);
49 }
50
51 ATTACK_FINISHED(actor, weaponentity) = time + WEP_CVAR_PRI(WEP_OVERKILL_HMG, refire) * W_WeaponRateFactor(actor);
52 weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR_PRI(WEP_OVERKILL_HMG, refire), W_OverkillHeavyMachineGun_Attack_Auto);
53}
54
55METHOD(OverkillHeavyMachineGun, wr_aim, void(entity thiswep, entity actor, .entity weaponentity))
56{
57 if(vdist(actor.origin - actor.enemy.origin, <, 3000 - bound(0, skill, 10) * 200))
58 PHYS_INPUT_BUTTON_ATCK(actor) = bot_aim(actor, weaponentity, 1000000, 0, 0.001, false, true);
59}
60
61METHOD(OverkillHeavyMachineGun, wr_think, void(entity thiswep, entity actor, .entity weaponentity, int fire))
62{
63 if ((WEP_CVAR_SEC(WEP_OVERKILL_HMG, refire_type) == 1) && (fire & 2) && (time >= actor.jump_interval))
64 {
65 // Secondary uses it's own refire timer if refire_type is 1.
66 actor.jump_interval = time + WEP_CVAR_PRI(WEP_BLASTER, refire) * W_WeaponRateFactor(actor);
67 makevectors(actor.v_angle);
68 W_Blaster_Attack(actor, weaponentity);
69 if ((actor.(weaponentity).wframe == WFRAME_IDLE) ||
70 (actor.(weaponentity).wframe == WFRAME_FIRE2))
71 {
72 // Set secondary fire animation.
73 actor.(weaponentity).wframe = WFRAME_FIRE2;
75 if (it == actor || (IS_SPEC(it) && it.enemy == actor))
76 {
77 wframe_send(it, actor.(weaponentity), WFRAME_FIRE2, autocvar_g_weaponratefactor, true);
78 }
79 ));
81 }
82 }
83 if (WEP_CVAR(WEP_OVERKILL_HMG, reload_ammo) && actor.(weaponentity).clip_load < WEP_CVAR_PRI(WEP_OVERKILL_HMG, ammo))
84 {
85 // Forced reload.
86 thiswep.wr_reload(thiswep, actor, weaponentity);
87 return;
88 }
89 if (fire & 1) // Primary attack
90 {
91 if (!weapon_prepareattack(thiswep, actor, weaponentity, false, 0))
92 {
93 return;
94 }
95 actor.(weaponentity).misc_bulletcounter = 0;
96 W_OverkillHeavyMachineGun_Attack_Auto(thiswep, actor, weaponentity, fire);
97 return;
98 }
99 if ((fire & 2) && (WEP_CVAR_SEC(WEP_OVERKILL_HMG, refire_type) == 0)) // Secondary attack
100 {
101 if (!weapon_prepareattack(thiswep, actor, weaponentity, false, WEP_CVAR_PRI(WEP_BLASTER, refire)))
102 {
103 return;
104 }
105 makevectors(actor.v_angle);
106 W_Blaster_Attack(actor, weaponentity);
107 weapon_thinkf(actor, weaponentity, WFRAME_FIRE2, WEP_CVAR_PRI(WEP_BLASTER, animtime), w_ready);
108 }
109}
110
111METHOD(OverkillHeavyMachineGun, wr_checkammo1, bool(entity thiswep, entity actor, .entity weaponentity))
112{
113 float ammo_amount = GetResource(actor, thiswep.ammo_type) >= WEP_CVAR_PRI(WEP_OVERKILL_HMG, ammo);
114 if (autocvar_g_balance_okhmg_reload_ammo)
115 {
116 ammo_amount += actor.(weaponentity).(weapon_load[WEP_OVERKILL_HMG.m_id]) >= WEP_CVAR_PRI(WEP_OVERKILL_HMG, ammo);
117 }
118 return ammo_amount;
119}
120
121METHOD(OverkillHeavyMachineGun, wr_checkammo2, bool(entity thiswep, entity actor, .entity weaponentity))
122{
123 float ammo_amount = GetResource(actor, thiswep.ammo_type) >= WEP_CVAR_PRI(WEP_BLASTER, ammo);
124 if (autocvar_g_balance_okhmg_reload_ammo)
125 {
126 ammo_amount += actor.(weaponentity).(weapon_load[WEP_OVERKILL_HMG.m_id]) >= WEP_CVAR_PRI(WEP_BLASTER, ammo);
127 }
128 return ammo_amount;
129}
130
131METHOD(OverkillHeavyMachineGun, wr_reload, void(entity thiswep, entity actor, .entity weaponentity))
132{
133 W_Reload(actor, weaponentity, WEP_CVAR_PRI(WEP_OVERKILL_HMG, ammo), SND_RELOAD);
134}
135
136METHOD(OverkillHeavyMachineGun, wr_suicidemessage, Notification(entity thiswep))
137{
138 return WEAPON_THINKING_WITH_PORTALS;
139}
140
141METHOD(OverkillHeavyMachineGun, wr_killmessage, Notification(entity thiswep))
142{
143 return WEAPON_OVERKILL_HMG_MURDER_SPRAY;
144}
145
146#endif
147#ifdef CSQC
148
149METHOD(OverkillHeavyMachineGun, 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#include "okmachinegun.qh"
162
164{
167 PAR(_("The %s is a superweapon that rapidly fires harmful bullets with a small degree of spread."), COLORED_NAME(this));
168 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));
169 PAR(_("It is a superweapon found on some maps, meaning that it breaks down after some time."));
170 PAR(_("The primary fire consumes %s ammo, although you spawn with an infinite amount of it in %s. "
171 "It has a limited magazine size, so needs reloading after several shots."), COLORED_NAME(ITEM_Bullets), COLORED_NAME(MUTATOR_ok));
172 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));
173 PAR(_("Since its bullets deal a lot more damage than the %s bullets, it is often heavily contested when it spawns in."), COLORED_NAME(WEP_OVERKILL_MACHINEGUN));
174 PAR(W_Guide_Keybinds(this));
175 PAR(W_Guide_DPS_onlyOne(this.netname, "primary"));
176 return PAGE_TEXT;
177}
178
179#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)
#define REGISTER_MUTATOR(...)
Definition base.qh:295
#define MUTATOR_HOOKFUNCTION(...)
Definition base.qh:335
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 max_health
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
const int IT_UNLIMITED_SUPERWEAPONS
Definition item.qh:24
#define M_ARGV(x, type)
Definition events.qh:17
#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
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_OverkillHeavyMachineGun_Attack_Auto(Weapon thiswep, entity actor,.entity weaponentity, int fire)
Definition okhmg.qc:13
#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
const float ATTEN_NORM
Definition sound.qh:30
#define sound(e, c, s, v, a)
Definition sound.qh:52
Sound SND_RIC_RANDOM()
Definition all.inc:33
bool StatusEffects_active(StatusEffect this, entity actor)
#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(entity this,.entity weaponentity, vector start, vector dir, float spread, float max_solid_penetration, float damage, float headshot_multiplier, float force, float dtype, entity tracer_effect)
Definition tracing.qc:544
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)]