Xonotic QuakeC
The free, fast arena FPS with crisp movement and a wide array of weapons
ammo.qc
Go to the documentation of this file.
1#include "ammo.qh"
2
3#ifdef SVQC
4METHOD(AmmoBuff, m_apply, void(StatusEffect this, entity actor, float eff_time, float eff_flags))
5{
6 bool was_active = actor.statuseffects && (actor.statuseffects.statuseffect_flags[this.m_id] & STATUSEFFECT_FLAG_ACTIVE);
7 if (!was_active)
8 {
9 actor.buff_ammo_prev_infitems = (actor.items & IT_UNLIMITED_AMMO);
10 actor.items |= IT_UNLIMITED_AMMO;
11 for (int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
12 {
13 .entity weaponentity = weaponentities[slot];
14 if (!actor.(weaponentity))
15 continue;
16 if (actor.(weaponentity).clip_load)
17 actor.(weaponentity).buff_ammo_prev_clipload = actor.(weaponentity).clip_load;
18 if (actor.(weaponentity).clip_size)
19 actor.(weaponentity).clip_load = actor.(weaponentity).(weapon_load[actor.(weaponentity).m_switchweapon.m_id]) = actor.(weaponentity).clip_size;
20 }
21 }
22 SUPER(AmmoBuff).m_apply(this, actor, eff_time, eff_flags);
23}
24METHOD(AmmoBuff, m_remove, void(StatusEffect this, entity actor, int removal_type))
25{
26 bool was_active = actor.statuseffects && (actor.statuseffects.statuseffect_flags[this.m_id] & STATUSEFFECT_FLAG_ACTIVE);
27 if (was_active)
28 {
29 actor.items = BITSET(actor.items, IT_UNLIMITED_AMMO, actor.buff_ammo_prev_infitems);
30 for (int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
31 {
32 .entity weaponentity = weaponentities[slot];
33 if (!actor.(weaponentity))
34 continue;
35 if (actor.(weaponentity).buff_ammo_prev_clipload)
36 {
37 actor.(weaponentity).clip_load = actor.(weaponentity).buff_ammo_prev_clipload;
38 actor.(weaponentity).buff_ammo_prev_clipload = 0;
39 }
40 }
41 }
42 actor.buff_ammo_prev_infitems = 0;
43 SUPER(AmmoBuff).m_remove(this, actor, removal_type);
44}
45METHOD(AmmoBuff, m_tick, void(StatusEffect this, entity actor))
46{
47 if (IS_PLAYER(actor))
48 for (int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
49 {
50 .entity weaponentity = weaponentities[slot];
51 if (actor.(weaponentity).clip_size)
52 actor.(weaponentity).clip_load = actor.(weaponentity).(weapon_load[actor.(weaponentity).m_switchweapon.m_id]) = actor.(weaponentity).clip_size;
53 }
54
55 SUPER(AmmoBuff).m_tick(this, actor);
56}
57#endif // SVQC
58#ifdef MENUQC
61
62METHOD(AmmoBuff, describe, string(AmmoBuff this))
63{
64 TC(AmmoBuff, this);
66 PAR(_("The %s buff gives you infinite ammo until the buff expires, so you don't need to worry about running out of ammo."), COLORED_NAME(this));
67 PAR(_("It also removes the need to reload any weapons that require reloading, like the %s and %s."), COLORED_NAME(WEP_RIFLE), COLORED_NAME(WEP_OVERKILL_MACHINEGUN));
68 return PAGE_TEXT;
69}
70#endif // MENUQC
#define BITSET(var, mask, flag)
Definition bits.qh:11
var entity(vector mins, vector maxs,.entity tofield) findbox_tofield_OrFallback
#define COLORED_NAME(this)
Definition color.qh:195
const int IT_UNLIMITED_AMMO
Definition item.qh:23
int buff_ammo_prev_clipload
Definition ammo.qh:7
#define IS_PLAYER(s)
Definition player.qh:243
int m_id
Definition effect.qh:19
#define TC(T, sym)
Definition _all.inc:82
@ STATUSEFFECT_FLAG_ACTIVE
Definition all.qh:22
#define SUPER(cname)
Definition oo.qh:231
#define METHOD(cname, name, prototype)
Definition oo.qh:269
#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
const int MAX_WEAPONSLOTS
Definition weapon.qh:16
entity weaponentities[MAX_WEAPONSLOTS]
Definition weapon.qh:17
int clip_load
Definition wepent.qh:14