Xonotic QuakeC
The free, fast arena FPS with crisp movement and a wide array of weapons
throwing.qh File Reference
Include dependency graph for throwing.qh:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

void SpawnThrownWeapon (entity this, vector org, Weapon wep,.entity weaponentity)
bool W_IsWeaponThrowable (entity this, int w)
float W_ThrowNewWeapon (entity own, float wpn, float doreduce, vector org, vector velo,.entity weaponentity)
 Returns amount of ammo used, or -1 for failure, or 0 for no ammo count.
void W_ThrowWeapon (entity this,.entity weaponentity, vector velo, vector delta, float doreduce)
 Toss current weapon.

Variables

bool autocvar_g_weapon_throwable

Function Documentation

◆ SpawnThrownWeapon()

void SpawnThrownWeapon ( entity this,
vector org,
Weapon wep,
.entity weaponentity )

Definition at line 154 of file throwing.qc.

155{
156 //entity wep = this.(weaponentity).m_weapon;
157
158 if ((STAT(WEAPONS, this) & WepSet_FromWeapon(wep))
159 && W_IsWeaponThrowable(this, wep.m_id))
160 W_ThrowNewWeapon(this, wep.m_id, false, org, randomvec() * 125 + '0 0 200', weaponentity);
161}
int m_id
Definition weapon.qh:43
#define STAT(...)
Definition stats.qh:82
vector randomvec(void)
vector org
Definition self.qh:92
bool W_IsWeaponThrowable(entity this, int w)
Definition throwing.qc:116
float W_ThrowNewWeapon(entity own, float wpn, float doreduce, vector org, vector velo,.entity weaponentity)
Returns amount of ammo used, or -1 for failure, or 0 for no ammo count.
Definition throwing.qc:22
#define WepSet_FromWeapon(it)
Definition all.qh:48

References entity(), Weapon::m_id, org, randomvec(), STAT, vector, W_IsWeaponThrowable(), W_ThrowNewWeapon(), and WepSet_FromWeapon.

Referenced by PlayerDamage().

◆ W_IsWeaponThrowable()

bool W_IsWeaponThrowable ( entity this,
int w )

Definition at line 116 of file throwing.qc.

117{
118 if (MUTATOR_CALLHOOK(ForbidDropCurrentWeapon, this, w))
119 return false;
121 return false;
122 if (w == WEP_Null.m_id)
123 return false;
124
125 return (REGISTRY_GET(Weapons, w)).weaponthrowable;
126}
#define MUTATOR_CALLHOOK(id,...)
Definition base.qh:143
Weapons
Definition guide.qh:113
#define REGISTRY_GET(id, i)
Definition registry.qh:43
int autocvar_g_pickup_items
Definition items.qh:11
float g_weaponarena
Definition world.qh:75

References autocvar_g_pickup_items, entity(), g_weaponarena, MUTATOR_CALLHOOK, REGISTRY_GET, and Weapons.

Referenced by MUTATOR_HOOKFUNCTION(), SpawnThrownWeapon(), and W_ThrowWeapon().

◆ W_ThrowNewWeapon()

float W_ThrowNewWeapon ( entity own,
float wpn,
float doreduce,
vector org,
vector velo,
.entity weaponentity )

Returns amount of ammo used, or -1 for failure, or 0 for no ammo count.

Definition at line 22 of file throwing.qc.

23{
24 Weapon info = REGISTRY_GET(Weapons, wpn);
25 Resource ammotype = info.ammo_type;
26
27 entity wep = spawn();
28 ITEM_SET_LOOT(wep, true);
29 setorigin(wep, org);
30 wep.velocity = velo;
31 wep.owner = wep.enemy = own;
32 wep.flags |= FL_TOSSED;
33 wep.colormap = own.colormap;
34 // wep.glowmod will be set in weapon_defaultspawnfunc
36
37 W_DropEvent(wr_drop,own,wpn,wep,weaponentity);
38
40 {
41 ITEM_SET_EXPIRING(wep, true);
42 if (own.items & IT_UNLIMITED_SUPERWEAPONS)
43 wep.superweapons_finished = time + autocvar_g_balance_superweapons_time;
44 else
45 {
46 int superweapons = 1;
47 FOREACH(Weapons, it != WEP_Null,
48 {
49 WepSet set = it.m_wepset;
50 if ((WEPSET_SUPERWEAPONS & STAT(WEAPONS, own)) & set)
51 ++superweapons;
52 });
53 if (superweapons == 1)
54 {
55 wep.superweapons_finished = StatusEffects_gettime(STATUSEFFECT_Superweapon, own);
56 StatusEffects_remove(STATUSEFFECT_Superweapon, own, STATUSEFFECT_REMOVE_CLEAR);
57 }
58 else
59 {
60 float timeleft = StatusEffects_gettime(STATUSEFFECT_Superweapon, own) - time;
61 float weptimeleft = timeleft / superweapons;
62 wep.superweapons_finished = time + weptimeleft;
63 if (own.statuseffects)
64 {
65 // TODO: this doesn't explicitly enable the effect, use apply here?
66 own.statuseffects.statuseffect_time[STATUSEFFECT_Superweapon.m_id] -= weptimeleft;
68 }
69 }
70 }
71 }
72
73 weapon_defaultspawnfunc(wep, info);
75 return -1;
76
77 wep.pickup_anyway = true; // these are ALWAYS pickable
78
79 //wa = W_AmmoItemCode(wpn);
80 if (ammotype == RES_NONE)
81 return 0;
82 else
83 {
84 if (doreduce && g_weapon_stay == 2)
85 {
86 // if our weapon is loaded, give its load back to the player
87 int i = own.(weaponentity).m_weapon.m_id;
88 if (own.(weaponentity).(weapon_load[i]) > 0)
89 {
90 GiveResource(own, ammotype, own.(weaponentity).(weapon_load[i]));
91 own.(weaponentity).(weapon_load[i]) = -1; // schedule the weapon for reloading
92 }
93 SetResource(wep, ammotype, 0);
94 }
95 else if (doreduce)
96 {
97 // if our weapon is loaded, give its load back to the player
98 int i = own.(weaponentity).m_weapon.m_id;
99 if (own.(weaponentity).(weapon_load[i]) > 0)
100 {
101 GiveResource(own, ammotype, own.(weaponentity).(weapon_load[i]));
102 own.(weaponentity).(weapon_load[i]) = -1; // schedule the weapon for reloading
103 }
104
105 float ownderammo = GetResource(own, ammotype);
106 float thisammo = min(ownderammo, GetResource(wep, ammotype));
107 SetResource(wep, ammotype, thisammo);
108 SetResource(own, ammotype, ownderammo - thisammo);
109
110 return thisammo;
111 }
112 return 0;
113 }
114}
void navigation_dynamicgoal_init(entity this, bool initially_static)
Definition navigation.qc:77
var entity(vector mins, vector maxs,.entity tofield) findbox_tofield_OrFallback
void SetResource(entity e, Resource res_type, float amount)
Sets the current amount of resource the given entity will have.
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
Resource ammo_type
M: ammotype : main ammo type.
Definition weapon.qh:56
const int IT_UNLIMITED_SUPERWEAPONS
Definition item.qh:24
const int FL_TOSSED
Definition constants.qh:86
float time
#define spawn
#define ITEM_SET_EXPIRING(item, expiring)
Sets the item expiring status (i.e.
Definition spawning.qh:65
#define ITEM_SET_LOOT(item, loot)
Sets the item loot status.
Definition spawning.qh:45
bool startitem_failed
Definition spawning.qh:7
#define FOREACH(list, cond, body)
Definition iter.qh:19
float min(float f,...)
@ STATUSEFFECT_REMOVE_CLEAR
Effect is being forcibly removed without calling any additional mechanics.
Definition all.qh:30
float autocvar_g_balance_superweapons_time
Definition items.qh:7
void StatusEffects_remove(StatusEffect this, entity actor, int removal_type)
float StatusEffects_gettime(StatusEffect this, entity actor)
void StatusEffects_update(entity e)
void GiveResource(entity receiver, Resource res_type, float amount)
Gives an entity some resource.
WepSet WEPSET_SUPERWEAPONS
Definition all.qh:345
void weapon_defaultspawnfunc(entity this, Weapon e)
Definition spawning.qc:29
vector WepSet
Definition weapon.qh:14
void W_DropEvent(.void(Weapon, entity actor,.entity) event, entity player, int weapon_type, entity weapon_item,.entity weaponentity)
float weapon_load[REGISTRY_MAX(Weapons)]
Weapon m_weapon
Definition wepent.qh:26
float g_weapon_stay
Definition world.qh:109

References Weapon::ammo_type, autocvar_g_balance_superweapons_time, entity(), FL_TOSSED, FOREACH, g_weapon_stay, GetResource(), GiveResource(), IT_UNLIMITED_SUPERWEAPONS, ITEM_SET_EXPIRING, ITEM_SET_LOOT, m_weapon, min(), navigation_dynamicgoal_init(), org, REGISTRY_GET, SetResource(), spawn, startitem_failed, STAT, STATUSEFFECT_REMOVE_CLEAR, StatusEffects_gettime(), StatusEffects_remove(), StatusEffects_update(), time, vector, W_DropEvent(), weapon_defaultspawnfunc(), weapon_load, Weapons, WepSet_FromWeapon, and WEPSET_SUPERWEAPONS.

Referenced by MUTATOR_HOOKFUNCTION(), SpawnThrownWeapon(), W_Porto_Fail(), and W_ThrowWeapon().

◆ W_ThrowWeapon()

void W_ThrowWeapon ( entity this,
.entity weaponentity,
vector velo,
vector delta,
float doreduce )

Toss current weapon.

Definition at line 129 of file throwing.qc.

130{
131 Weapon w = this.(weaponentity).m_weapon;
132 if (w == WEP_Null)
133 return; // just in case
134 if (time < game_starttime)
135 return;
136 if (MUTATOR_CALLHOOK(ForbidThrowCurrentWeapon, this, this.(weaponentity)))
137 return;
138 if (!autocvar_g_weapon_throwable || this.(weaponentity).state != WS_READY || !W_IsWeaponThrowable(this, w.m_id))
139 return;
140
141 WepSet set = WepSet_FromWeapon(w);
142 if (!(STAT(WEAPONS, this) & set))
143 return;
144 STAT(WEAPONS, this) &= ~set;
145
146 W_SwitchWeapon_Force(this, w_getbestweapon(this, weaponentity), weaponentity);
147 float a = W_ThrowNewWeapon(this, w.m_id, doreduce, this.origin + delta, velo, weaponentity);
148
149 if (a < 0)
150 return;
151 Send_Notification(NOTIF_ONE, this, MSG_MULTI, ITEM_WEAPON_DROP, w.m_id, a);
152}
float game_starttime
Definition stats.qh:82
void W_SwitchWeapon_Force(Player this, Weapon w,.entity weaponentity)
Definition selection.qc:237
int state
void Send_Notification(NOTIF broadcast, entity client, MSG net_type, Notification net_name,...count)
Definition all.qc:1573
#define w_getbestweapon(ent, wepent)
Definition selection.qh:23
bool autocvar_g_weapon_throwable
Definition throwing.qh:6
const int WS_READY
idle frame
Definition weapon.qh:38

References autocvar_g_weapon_throwable, entity(), game_starttime, Weapon::m_id, m_weapon, MUTATOR_CALLHOOK, Send_Notification(), STAT, state, time, vector, w_getbestweapon, W_IsWeaponThrowable(), W_SwitchWeapon_Force(), W_ThrowNewWeapon(), WepSet_FromWeapon, and WS_READY.

Referenced by IMPULSE().

Variable Documentation

◆ autocvar_g_weapon_throwable

bool autocvar_g_weapon_throwable

Definition at line 6 of file throwing.qh.

Referenced by W_ThrowWeapon().