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
5{
7 || IS_DEAD(toucher) || STAT(FROZEN, toucher))
8 return;
9
10 int eff_cnt = 0;
11 float new_load;
12 for (int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
13 {
14 .entity weaponentity = weaponentities[slot];
15 if (toucher.(weaponentity).clip_size)
16 {
17 if (SAME_TEAM(toucher, this.realowner))
18 {
19 new_load = toucher.(weaponentity).clip_size;
20 eff_cnt = ceil(5 * (new_load - toucher.(weaponentity).clip_load) / new_load);
21 }
22 else
23 new_load = max(0, toucher.(weaponentity).clip_load - toucher.(weaponentity).clip_size * (autocvar_g_nades_ammo_clip_empty_rate * frametime * 0.5));
24
25 toucher.(weaponentity).clip_load = toucher.(weaponentity).(weapon_load[toucher.(weaponentity).m_switchweapon.m_id]) = new_load;
26 }
27 }
28
29 float ammo_factor = autocvar_g_nades_ammo_rate * frametime * 0.5;
30 if (toucher != this.realowner)
31 ammo_factor *= (SAME_TEAM(toucher, this))
34
35 if (ammo_factor > 0)
36 {
37 #define GIVE_AMMO_RESOURCE(res_resource, max_resource) \
38 if (GetResource(toucher, res_resource) < max_resource) \
39 { \
40 GiveResourceWithLimit(toucher, res_resource, ammo_factor, max_resource); \
41 if (!eff_cnt && !(toucher.items & IT_UNLIMITED_AMMO)) \
42 eff_cnt = 1; \
43 }
44
49 #undef GIVE_AMMO_RESOURCE
50 }
51 else if (ammo_factor < 0) // Foe drops ammo points
52 {
53 float amresource;
54 #define DROP_AMMO_RESOURCE(res_resource) \
55 amresource = GetResource(toucher, res_resource); \
56 if (amresource > 0) \
57 SetResource(toucher, res_resource, max(0, amresource + ammo_factor));
58
59 DROP_AMMO_RESOURCE(RES_SHELLS);
60 DROP_AMMO_RESOURCE(RES_BULLETS);
61 DROP_AMMO_RESOURCE(RES_ROCKETS);
62 DROP_AMMO_RESOURCE(RES_CELLS);
63 #undef DROP_AMMO_RESOURCE
64 }
65
66 if (eff_cnt)
67 nade_Effect(toucher, EFFECT_AMMO_REGEN, eff_cnt);
68}
69
75#endif // SVQC
76#ifdef MENUQC
78
79METHOD(AmmoNade, describe, string(AmmoNade this))
80{
81 TC(AmmoNade, this);
83 PAR(_("The %s detonates after a short delay, temporarily creating an orb around the point where it detonated for several seconds. "
84 "If your team members enter the orb they will recover ammo, and if enemies enter the sphere they will lose ammo."), COLORED_NAME(this));
85 PAR(_("Similar to the %s buff, your weapon magazines remain full while you are inside the orb, so you don't need to reload."), COLORED_NAME(BUFF_AMMO));
86 return PAGE_TEXT;
87}
88#endif // MENUQC
var entity(vector mins, vector maxs,.entity tofield) findbox_tofield_OrFallback
#define COLORED_NAME(this)
Definition color.qh:189
int autocvar_g_pickup_rockets_max
Definition ammo.qh:116
int autocvar_g_pickup_shells_max
Definition ammo.qh:44
int autocvar_g_pickup_cells_max
Definition ammo.qh:152
int autocvar_g_pickup_nails_max
Definition ammo.qh:80
#define DROP_AMMO_RESOURCE(res_resource)
void nade_ammo_touch(entity this, entity toucher)
Definition ammo.qc:4
void nade_ammo_boom(entity this)
Definition ammo.qc:70
#define GIVE_AMMO_RESOURCE(res_resource, max_resource)
float autocvar_g_nades_ammo_rate
Definition ammo.qh:8
float autocvar_g_nades_ammo_radius
Definition ammo.qh:12
float autocvar_g_nades_ammo_time
Definition ammo.qh:7
float autocvar_g_nades_ammo_clip_empty_rate
Definition ammo.qh:11
float autocvar_g_nades_ammo_foe
Definition ammo.qh:10
float autocvar_g_nades_ammo_friend
Definition ammo.qh:9
#define IS_DEAD(s)
Definition player.qh:244
#define IS_PLAYER(s)
Definition player.qh:242
float frametime
#define TC(T, sym)
Definition _all.inc:82
#define STAT(...)
Definition stats.qh:94
float ceil(float f)
float max(float f,...)
void nade_Effect(entity player, entity eff, int eff_cnt)
Network nade effect data to player.
Definition net.qc:147
#define METHOD(cname, name, prototype)
Definition oo.qh:274
entity entity toucher
Definition self.qh:76
#define settouch(e, f)
Definition self.qh:77
#define PAGE_TEXT
Definition string.qh:651
#define PAR(...)
Adds an individually translatable paragraph to PAGE_TEXT without having to deal with strcat and sprin...
Definition string.qh:657
#define PAGE_TEXT_INIT()
Definition string.qh:650
entity nades_spawn_orb(entity this, float orb_lifetime, float orb_rad)
Spawns an orb for some nade types.
Definition sv_nades.qc:60
#define SAME_TEAM(a, b)
Definition teams.qh:241
entity realowner
#define IS_MONSTER(v)
Definition utils.qh:23
const int MAX_WEAPONSLOTS
Definition weapon.qh:16
entity weaponentities[MAX_WEAPONSLOTS]
Definition weapon.qh:17
int clip_load
Definition wepent.qh:14
int clip_size
Definition wepent.qh:15