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)
void W_ThrowWeapon (entity this,.entity weaponentity, vector velo, vector delta, float doreduce)

Variables

bool autocvar_g_weapon_throwable

Function Documentation

◆ SpawnThrownWeapon()

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

Definition at line 160 of file throwing.qc.

161{
162 //entity wep = this.(weaponentity).m_weapon;
163
164 if(STAT(WEAPONS, this) & WepSet_FromWeapon(wep))
165 if(W_IsWeaponThrowable(this, wep.m_id))
166 W_ThrowNewWeapon(this, wep.m_id, false, org, randomvec() * 125 + '0 0 200', weaponentity);
167}
int m_id
Definition weapon.qh:45
#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:118
float W_ThrowNewWeapon(entity own, float wpn, float doreduce, vector org, vector velo,.entity weaponentity)
Definition throwing.qc:22
#define WepSet_FromWeapon(it)
Definition all.qh:46

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 118 of file throwing.qc.

119{
120 if (MUTATOR_CALLHOOK(ForbidDropCurrentWeapon, this, w))
121 return false;
123 return false;
124 if (g_weaponarena)
125 return false;
126 if (w == WEP_Null.m_id)
127 return false;
128
129 return (REGISTRY_GET(Weapons, w)).weaponthrowable;
130}
#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:10
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 )

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 {
44 wep.superweapons_finished = time + autocvar_g_balance_superweapons_time;
45 }
46 else
47 {
48 int superweapons = 1;
49 FOREACH(Weapons, it != WEP_Null, {
50 WepSet set = it.m_wepset;
51 if((WEPSET_SUPERWEAPONS & STAT(WEAPONS, own)) & set) ++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 {
82 return 0;
83 }
84 else
85 {
86 if(doreduce && g_weapon_stay == 2)
87 {
88 // if our weapon is loaded, give its load back to the player
89 int i = own.(weaponentity).m_weapon.m_id;
90 if(own.(weaponentity).(weapon_load[i]) > 0)
91 {
92 GiveResource(own, ammotype, own.(weaponentity).(weapon_load[i]));
93 own.(weaponentity).(weapon_load[i]) = -1; // schedule the weapon for reloading
94 }
95 SetResource(wep, ammotype, 0);
96 }
97 else if(doreduce)
98 {
99 // if our weapon is loaded, give its load back to the player
100 int i = own.(weaponentity).m_weapon.m_id;
101 if(own.(weaponentity).(weapon_load[i]) > 0)
102 {
103 GiveResource(own, ammotype, own.(weaponentity).(weapon_load[i]));
104 own.(weaponentity).(weapon_load[i]) = -1; // schedule the weapon for reloading
105 }
106
107 float ownderammo = GetResource(own, ammotype);
108 float thisammo = min(ownderammo, GetResource(wep, ammotype));
109 SetResource(wep, ammotype, thisammo);
110 SetResource(own, ammotype, ownderammo - thisammo);
111
112 return thisammo;
113 }
114 return 0;
115 }
116}
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:44
Resource ammo_type
M: ammotype : main ammo type.
Definition weapon.qh:51
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:6
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:329
void weapon_defaultspawnfunc(entity this, Weapon e)
Definition spawning.qc:30
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 )

Definition at line 133 of file throwing.qc.

134{
135 Weapon w = this.(weaponentity).m_weapon;
136 if (w == WEP_Null)
137 return; // just in case
138 if (time < game_starttime)
139 return;
140 if(MUTATOR_CALLHOOK(ForbidThrowCurrentWeapon, this, this.(weaponentity)))
141 return;
143 return;
144 if(this.(weaponentity).state != WS_READY)
145 return;
146 if(!W_IsWeaponThrowable(this, w.m_id))
147 return;
148
149 WepSet set = WepSet_FromWeapon(w);
150 if(!(STAT(WEAPONS, this) & set)) return;
151 STAT(WEAPONS, this) &= ~set;
152
153 W_SwitchWeapon_Force(this, w_getbestweapon(this, weaponentity), weaponentity);
154 float a = W_ThrowNewWeapon(this, w.m_id, doreduce, this.origin + delta, velo, weaponentity);
155
156 if(a < 0) return;
157 Send_Notification(NOTIF_ONE, this, MSG_MULTI, ITEM_WEAPON_DROP, w.m_id, a);
158}
float game_starttime
Definition stats.qh:82
void W_SwitchWeapon_Force(Player this, Weapon w,.entity weaponentity)
Definition selection.qc:246
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:41

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().