Xonotic QuakeC
The free, fast arena FPS with crisp movement and a wide array of weapons
throwing.qc File Reference
Include dependency graph for throwing.qc:
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.

Function Documentation

◆ SpawnThrownWeapon()

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

Definition at line 157 of file throwing.qc.

158{
159 //entity wep = this.(weaponentity).m_weapon;
160
161 if ((STAT(WEAPONS, this) & WepSet_FromWeapon(wep))
162 && W_IsWeaponThrowable(this, wep.m_id))
163 W_ThrowNewWeapon(this, wep.m_id, false, org, randomvec() * 125 + '0 0 200', weaponentity);
164}
int m_id
Definition weapon.qh:37
#define STAT(...)
Definition stats.qh:94
vector randomvec(void)
vector org
Definition self.qh:96
bool W_IsWeaponThrowable(entity this, int w)
Definition throwing.qc:119
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 119 of file throwing.qc.

120{
121 if (MUTATOR_CALLHOOK(ForbidDropCurrentWeapon, this, w))
122 return false;
124 return false;
125 if (w == WEP_Null.m_id)
126 return false;
127
128 return (REGISTRY_GET(Weapons, w)).weaponthrowable;
129}
#define MUTATOR_CALLHOOK(name,...)
Definition base.qh:186
Weapons
Definition guide.qh:113
#define REGISTRY_GET(id, i)
Definition registry.qh:62
int autocvar_g_pickup_items
Definition items.qh:11
@ WEPARENA_OFF
Definition weapon.qh:272
int g_weaponarena_type
Definition world.qh:77

References autocvar_g_pickup_items, entity(), g_weaponarena_type, MUTATOR_CALLHOOK, REGISTRY_GET, Weapons, and WEPARENA_OFF.

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 = colormapPaletteColor(wep.owner.clientcolors & 0x0F, true);
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 wep.itemdef = info.m_pickup;
74 StartItem(wep);
75 if (wasfreed(wep))
76 return -1;
77
78 wep.pickup_anyway = true; // these are ALWAYS pickable
79
80 //wa = W_AmmoItemCode(wpn);
81 if (ammotype == RES_NONE)
82 return 0;
83 else
84 {
85 SetResource(wep, ammotype, WEP_CVAR(info, pickup_ammo));
86
87 if (doreduce && g_weapon_stay == 2)
88 {
89 // if our weapon is loaded, give its load back to the player
90 int i = own.(weaponentity).m_weapon.m_id;
91 if (own.(weaponentity).(weapon_load[i]) > 0)
92 {
93 GiveResource(own, ammotype, own.(weaponentity).(weapon_load[i]));
94 own.(weaponentity).(weapon_load[i]) = -1; // schedule the weapon for reloading
95 }
96 SetResource(wep, ammotype, 0);
97 }
98 else if (doreduce)
99 {
100 // if our weapon is loaded, give its load back to the player
101 int i = own.(weaponentity).m_weapon.m_id;
102 if (own.(weaponentity).(weapon_load[i]) > 0)
103 {
104 GiveResource(own, ammotype, own.(weaponentity).(weapon_load[i]));
105 own.(weaponentity).(weapon_load[i]) = -1; // schedule the weapon for reloading
106 }
107
108 float ownderammo = GetResource(own, ammotype);
109 float thisammo = min(ownderammo, GetResource(wep, ammotype));
110 SetResource(wep, ammotype, thisammo);
111 SetResource(own, ammotype, ownderammo - thisammo);
112
113 return thisammo;
114 }
115 return 0;
116 }
117}
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:36
Resource ammo_type
M: ammotype : main ammo type.
Definition weapon.qh:50
#define colormapPaletteColor(c, isPants)
Definition color.qh:5
const int IT_UNLIMITED_SUPERWEAPONS
Definition item.qh:24
const int FL_TOSSED
Definition constants.qh:78
float time
#define spawn
#define ITEM_SET_EXPIRING(item, expiring)
Sets the item expiring status (i.e.
Definition spawning.qh:63
#define ITEM_SET_LOOT(item, loot)
Sets the item loot status.
Definition spawning.qh:43
#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
void StartItem(entity this)
Definition items.qc:1008
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.
#define WEP_CVAR(wep, name)
Definition all.qh:339
WepSet WEPSET_SUPERWEAPONS
Definition all.qh:347
vector WepSet
Definition weapon.qh:13
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:108

References Weapon::ammo_type, autocvar_g_balance_superweapons_time, colormapPaletteColor, 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(), STAT, STATUSEFFECT_REMOVE_CLEAR, StatusEffects_gettime(), StatusEffects_remove(), StatusEffects_update(), time, vector, W_DropEvent(), weapon_load, Weapons, WEP_CVAR, 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 132 of file throwing.qc.

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

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