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)
9 return;
10 return = true;
11 M_ARGV(3, float) /* damage */ = (M_ARGV(0, entity)).max_health * 0.1;
12}
13
14void W_OverkillHeavyMachineGun_Attack_Auto(Weapon thiswep, entity actor, .entity weaponentity, int fire)
15{
16 if (!PHYS_INPUT_BUTTON_ATCK(actor))
17 {
18 w_ready(thiswep, actor, weaponentity, fire);
19 return;
20 }
21
22 if ((!thiswep.wr_checkammo1(thiswep, actor, weaponentity) && !(actor.items & IT_UNLIMITED_AMMO))
23 || (!StatusEffects_active(STATUSEFFECT_Superweapon, actor) && !(actor.items & IT_UNLIMITED_SUPERWEAPONS)))
24 {
25 W_SwitchWeapon_Force(actor, w_getbestweapon(actor, weaponentity), weaponentity);
26 w_ready(thiswep, actor, weaponentity, fire);
27 return;
28 }
29
30 W_DecreaseAmmo(WEP_OVERKILL_HMG, actor, WEP_CVAR_PRI(WEP_OVERKILL_HMG, ammo), weaponentity);
31
32 W_SetupShot(actor, weaponentity, true, 0, SND_HMG_FIRE, CH_WEAPON_A, WEP_CVAR_PRI(WEP_OVERKILL_HMG, damage), WEP_OVERKILL_HMG.m_id);
33
35 {
36 actor.punchangle_x = random () - 0.5;
37 actor.punchangle_y = random () - 0.5;
38 }
39
40 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));
41 fireBullet(actor, weaponentity, w_shotorg, w_shotdir,
42 okhmg_spread,
43 WEP_CVAR_PRI(WEP_OVERKILL_HMG, solidpenetration),
44 WEP_CVAR_PRI(WEP_OVERKILL_HMG, damage),
45 0,
46 WEP_CVAR_PRI(WEP_OVERKILL_HMG, force),
47 WEP_OVERKILL_HMG.m_id,
48 EFFECT_RIFLE
49 );
50
51 ++actor.(weaponentity).misc_bulletcounter;
52
53 W_MuzzleFlash(thiswep, actor, weaponentity, w_shotorg, w_shotdir);
54
55 if (autocvar_g_casings >= 2) // casing code
56 {
57 makevectors(actor.v_angle); // for some reason, this is lost
58 SpawnCasing(((random () * 50 + 50) * v_right) - (v_forward * (random () * 25 + 25)) - ((random () * 5 - 70) * v_up), vectoangles(v_forward), 3, actor, weaponentity);
59 }
60
61 ATTACK_FINISHED(actor, weaponentity) = time + WEP_CVAR_PRI(WEP_OVERKILL_HMG, refire) * W_WeaponRateFactor(actor);
62 weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR_PRI(WEP_OVERKILL_HMG, refire), W_OverkillHeavyMachineGun_Attack_Auto);
63}
64
65METHOD(OverkillHeavyMachineGun, wr_aim, void(entity thiswep, entity actor, .entity weaponentity))
66{
67 if (vdist(actor.origin - actor.enemy.origin, <, 3000 - bound(0, skill, 10) * 200))
68 PHYS_INPUT_BUTTON_ATCK(actor) = bot_aim(actor, weaponentity, 1000000, 0, 0.001, false, true);
69}
70
71METHOD(OverkillHeavyMachineGun, wr_think, void(entity thiswep, entity actor, .entity weaponentity, int fire))
72{
73 if (WEP_CVAR_SEC(WEP_OVERKILL_HMG, refire_type) == 1 && (fire & 2)
74 && time >= actor.jump_interval)
75 {
76 // Secondary uses it's own refire timer if refire_type is 1.
77 actor.jump_interval = time + WEP_CVAR_PRI(WEP_BLASTER, refire) * W_WeaponRateFactor(actor);
78 makevectors(actor.v_angle);
79 W_Blaster_Attack(actor, weaponentity);
80 if (actor.(weaponentity).wframe == WFRAME_IDLE
81 || actor.(weaponentity).wframe == WFRAME_FIRE2)
82 {
83 // Set secondary fire animation.
84 actor.(weaponentity).wframe = WFRAME_FIRE2;
86 if (it == actor || (IS_SPEC(it) && it.enemy == actor))
87 wframe_send(it, actor.(weaponentity), WFRAME_FIRE2, autocvar_g_weaponratefactor, true);
88 ));
90 }
91 }
92 if (WEP_CVAR(WEP_OVERKILL_HMG, reload_ammo) && actor.(weaponentity).clip_load < WEP_CVAR_PRI(WEP_OVERKILL_HMG, ammo))
93 { // forced reload
94 thiswep.wr_reload(thiswep, actor, weaponentity);
95 return;
96 }
97
98 if (fire & 1) // Primary attack
99 {
100 if (!weapon_prepareattack(thiswep, actor, weaponentity, false, 0))
101 return;
102 actor.(weaponentity).misc_bulletcounter = 0;
103 W_OverkillHeavyMachineGun_Attack_Auto(thiswep, actor, weaponentity, fire);
104 return;
105 }
106 if ((fire & 2) && WEP_CVAR_SEC(WEP_OVERKILL_HMG, refire_type) == 0) // Secondary attack
107 {
108 if (!weapon_prepareattack(thiswep, actor, weaponentity, false, WEP_CVAR_PRI(WEP_BLASTER, refire)))
109 return;
110 makevectors(actor.v_angle);
111 W_Blaster_Attack(actor, weaponentity);
112 weapon_thinkf(actor, weaponentity, WFRAME_FIRE2, WEP_CVAR_PRI(WEP_BLASTER, animtime), w_ready);
113 }
114}
115
116METHOD(OverkillHeavyMachineGun, wr_checkammo1, bool(entity thiswep, entity actor, .entity weaponentity))
117{
118 float ammo_amount = GetResource(actor, thiswep.ammo_type) >= WEP_CVAR_PRI(WEP_OVERKILL_HMG, ammo);
119 if (autocvar_g_balance_okhmg_reload_ammo)
120 ammo_amount += actor.(weaponentity).(weapon_load[WEP_OVERKILL_HMG.m_id]) >= WEP_CVAR_PRI(WEP_OVERKILL_HMG, ammo);
121 return ammo_amount;
122}
123
124METHOD(OverkillHeavyMachineGun, wr_checkammo2, bool(entity thiswep, entity actor, .entity weaponentity))
125{
126 float ammo_amount = GetResource(actor, thiswep.ammo_type) >= WEP_CVAR_PRI(WEP_BLASTER, ammo);
127 if (autocvar_g_balance_okhmg_reload_ammo)
128 ammo_amount += actor.(weaponentity).(weapon_load[WEP_OVERKILL_HMG.m_id]) >= WEP_CVAR_PRI(WEP_BLASTER, ammo);
129 return ammo_amount;
130}
131
132METHOD(OverkillHeavyMachineGun, wr_reload, void(entity thiswep, entity actor, .entity weaponentity))
133{
134 W_Reload(actor, weaponentity, WEP_CVAR_PRI(WEP_OVERKILL_HMG, ammo), SND_RELOAD);
135}
136
137METHOD(OverkillHeavyMachineGun, wr_suicidemessage, Notification(entity thiswep))
138{
139 return WEAPON_THINKING_WITH_PORTALS;
140}
141
142METHOD(OverkillHeavyMachineGun, wr_killmessage, Notification(entity thiswep))
143{
144 return WEAPON_OVERKILL_HMG_MURDER_SPRAY;
145}
146
147#endif // SVQC
148#ifdef CSQC
149
150METHOD(OverkillHeavyMachineGun, wr_impacteffect, void(entity thiswep, entity actor))
151{
152 vector org2 = w_org + w_backoff * 2;
153 pointparticles(EFFECT_MACHINEGUN_IMPACT, org2, w_backoff * 1000, 1);
154 if (!w_issilent)
156}
157
158#endif // CSQC
159#ifdef MENUQC
162#include "okmachinegun.qh"
163
165{
168 PAR(_("The %s is a superweapon that rapidly fires harmful bullets with a small degree of spread."), COLORED_NAME(this));
169 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));
170 PAR(_("It is a superweapon found on some maps, meaning that it breaks down after some time."));
171 PAR(_("The primary fire consumes %s ammo, although you spawn with an infinite amount of it in %s. "
172 "It has a limited magazine size, so needs reloading after several shots."), COLORED_NAME(ITEM_Bullets), COLORED_NAME(MUTATOR_ok));
173 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));
174 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));
175 PAR(W_Guide_Keybinds(this));
176 PAR(W_Guide_DPS_onlyOne(this.netname, "primary"));
177 return PAGE_TEXT;
178}
179
180#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)
#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: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 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: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
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:152
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: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_OverkillHeavyMachineGun_Attack_Auto(Weapon thiswep, entity actor,.entity weaponentity, int fire)
Definition okhmg.qc:14
#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: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(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:537
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)]