Xonotic
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)
 
void thrown_wep_think (entity this)
 
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
 
float savenextthink
 

Function Documentation

◆ SpawnThrownWeapon()

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

Definition at line 180 of file throwing.qc.

References Weapon::m_id, randomvec(), W_IsWeaponThrowable(), W_ThrowNewWeapon(), and WepSet_FromWeapon.

Referenced by PlayerDamage().

181 {
182  //entity wep = this.(weaponentity).m_weapon;
183 
184  if(STAT(WEAPONS, this) & WepSet_FromWeapon(wep))
185  if(W_IsWeaponThrowable(this, wep.m_id))
186  W_ThrowNewWeapon(this, wep.m_id, false, org, randomvec() * 125 + '0 0 200', weaponentity);
187 }
float W_ThrowNewWeapon(entity own, float wpn, float doreduce, vector org, vector velo,.entity weaponentity)
Definition: throwing.qc:40
bool W_IsWeaponThrowable(entity this, int w)
Definition: throwing.qc:138
#define WepSet_FromWeapon(it)
Definition: all.qh:38
int m_id
Definition: weapon.qh:42
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ thrown_wep_think()

void thrown_wep_think ( entity  this)

Definition at line 21 of file throwing.qc.

References nextthink, NULL, oldorigin, origin, owner, savenextthink, SUB_SetFade(), SUB_VanishOrRemove(), and time.

Referenced by W_ThrowNewWeapon().

22 {
23  this.nextthink = time;
24  if(this.oldorigin != this.origin)
25  {
26  this.SendFlags |= ISF_LOCATION;
27  this.oldorigin = this.origin;
28  }
29  this.owner = NULL;
30  float timeleft = this.savenextthink - time;
31  if(timeleft > 1)
32  SUB_SetFade(this, this.savenextthink - 1, 1);
33  else if(timeleft > 0)
34  SUB_SetFade(this, time, timeleft);
35  else
36  SUB_VanishOrRemove(this);
37 }
vector oldorigin
Definition: csprogsdefs.qc:102
void SUB_VanishOrRemove(entity ent)
Definition: subs.qc:38
origin
Definition: ent_cs.qc:114
entity owner
Definition: main.qh:73
#define NULL
Definition: post.qh:17
float nextthink
Definition: csprogsdefs.qc:121
float savenextthink
Definition: throwing.qh:8
void SUB_SetFade(entity ent, float vanish_time, float fading_time)
Definition: subs.qc:77
float time
Definition: csprogsdefs.qc:16
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ W_IsWeaponThrowable()

bool W_IsWeaponThrowable ( entity  this,
int  w 
)

Definition at line 138 of file throwing.qc.

References autocvar_g_pickup_items, g_weaponarena, MUTATOR_CALLHOOK, and REGISTRY_GET.

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

139 {
140  if (MUTATOR_CALLHOOK(ForbidDropCurrentWeapon, this, w))
141  return false;
143  return false;
144  if (g_weaponarena)
145  return false;
146  if (w == WEP_Null.m_id)
147  return false;
148 
149  return (REGISTRY_GET(Weapons, w)).weaponthrowable;
150 }
#define REGISTRY_GET(id, i)
Definition: registry.qh:43
#define MUTATOR_CALLHOOK(id,...)
Definition: base.qh:140
int autocvar_g_pickup_items
Definition: items.qh:11
float g_weaponarena
Definition: world.qh:76
+ Here is the caller graph for this function:

◆ W_ThrowNewWeapon()

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

Definition at line 40 of file throwing.qc.

References Weapon::ammo_type, autocvar_g_balance_superweapons_time, entity(), FOREACH, g_weapon_stay, GetResource(), GiveResource(), Item_SetExpiring(), Item_SetLoot(), min(), navigation_dynamicgoal_init(), REGISTRY_GET, setorigin(), SetResource(), setthink, spawn(), startitem_failed, STATUSEFFECT_REMOVE_CLEAR, thrown_wep_think(), time, W_DropEvent(), weapon_defaultspawnfunc(), weapon_load, WepSet_FromWeapon, and WEPSET_SUPERWEAPONS.

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

41 {
42  Weapon info = REGISTRY_GET(Weapons, wpn);
43  Resource ammotype = info.ammo_type;
44 
45  entity wep = spawn();
46  Item_SetLoot(wep, true);
47  setorigin(wep, org);
48  wep.velocity = velo;
49  wep.owner = wep.enemy = own;
50  wep.flags |= FL_TOSSED;
51  wep.colormap = own.colormap;
52  wep.glowmod = weaponentity_glowmod(info, own, own.clientcolors, own.(weaponentity));
53  navigation_dynamicgoal_init(wep, false);
54 
55  W_DropEvent(wr_drop,own,wpn,wep,weaponentity);
56 
58  {
59  Item_SetExpiring(wep, true);
60  if(own.items & IT_UNLIMITED_SUPERWEAPONS)
61  {
62  wep.superweapons_finished = time + autocvar_g_balance_superweapons_time;
63  }
64  else
65  {
66  int superweapons = 1;
67  FOREACH(Weapons, it != WEP_Null, {
68  WepSet set = it.m_wepset;
69  if((set & WEPSET_SUPERWEAPONS) && (STAT(WEAPONS, own) & set)) ++superweapons;
70  });
71  if(superweapons <= 1)
72  {
73  wep.superweapons_finished = StatusEffects_gettime(STATUSEFFECT_Superweapons, own);
74  StatusEffects_remove(STATUSEFFECT_Superweapons, own, STATUSEFFECT_REMOVE_CLEAR);
75  }
76  else
77  {
78  float timeleft = StatusEffects_gettime(STATUSEFFECT_Superweapons, own) - time;
79  float weptimeleft = timeleft / superweapons;
80  wep.superweapons_finished = time + weptimeleft;
81  if(own.statuseffects)
82  {
83  // TODO: this doesn't explicitly enable the effect, use apply here?
84  own.statuseffects.statuseffect_time[STATUSEFFECT_Superweapons.m_id] -= weptimeleft;
85  StatusEffects_update(own);
86  }
87  }
88  }
89  }
90 
91  weapon_defaultspawnfunc(wep, info);
93  return -1;
95  wep.savenextthink = wep.nextthink;
96  wep.nextthink = min(wep.nextthink, time + 0.5);
97  wep.pickup_anyway = true; // these are ALWAYS pickable
98 
99  //wa = W_AmmoItemCode(wpn);
100  if(ammotype == RES_NONE)
101  {
102  return 0;
103  }
104  else
105  {
106  if(doreduce && g_weapon_stay == 2)
107  {
108  // if our weapon is loaded, give its load back to the player
109  int i = own.(weaponentity).m_weapon.m_id;
110  if(own.(weaponentity).(weapon_load[i]) > 0)
111  {
112  GiveResource(own, ammotype, own.(weaponentity).(weapon_load[i]));
113  own.(weaponentity).(weapon_load[i]) = -1; // schedule the weapon for reloading
114  }
115  SetResource(wep, ammotype, 0);
116  }
117  else if(doreduce)
118  {
119  // if our weapon is loaded, give its load back to the player
120  int i = own.(weaponentity).m_weapon.m_id;
121  if(own.(weaponentity).(weapon_load[i]) > 0)
122  {
123  GiveResource(own, ammotype, own.(weaponentity).(weapon_load[i]));
124  own.(weaponentity).(weapon_load[i]) = -1; // schedule the weapon for reloading
125  }
126 
127  float ownderammo = GetResource(own, ammotype);
128  float thisammo = min(ownderammo, GetResource(wep, ammotype));
129  SetResource(wep, ammotype, thisammo);
130  SetResource(own, ammotype, ownderammo - thisammo);
131 
132  return thisammo;
133  }
134  return 0;
135  }
136 }
vector WepSet
Definition: weapon.qh:11
void weapon_defaultspawnfunc(entity this, Weapon wpn)
Definition: spawning.qc:30
WepSet WEPSET_SUPERWEAPONS
Definition: all.qh:307
float weapon_load[REGISTRY_MAX(Weapons)]
Definition: weaponsystem.qh:29
float autocvar_g_balance_superweapons_time
Definition: items.qh:6
entity() spawn
#define REGISTRY_GET(id, i)
Definition: registry.qh:43
void navigation_dynamicgoal_init(entity this, bool initially_static)
Definition: navigation.qc:76
void W_DropEvent(.void(Weapon, entity actor,.entity) event, entity player, float weapon_type, entity weapon_item,.entity weaponentity)
Effect is being forcibly removed without calling any additional mechanics.
Definition: all.qh:27
void SetResource(entity e, Resource res_type, float amount)
Sets the current amount of resource the given entity will have.
Definition: cl_resources.qc:26
Resource ammo_type
M: ammotype : main ammo type.
Definition: weapon.qh:48
void thrown_wep_think(entity this)
Definition: throwing.qc:21
void GiveResource(entity receiver, Resource res_type, float amount)
Gives an entity some resource.
float GetResource(entity e, Resource res_type)
Returns the current amount of resource the given entity has.
Definition: cl_resources.qc:10
bool startitem_failed
Definition: spawning.qh:7
float g_weapon_stay
Definition: world.qh:112
setorigin(ent, v)
#define setthink(e, f)
#define WepSet_FromWeapon(it)
Definition: all.qh:38
fields which are explicitly/manually set are marked with "M", fields set automatically are marked wit...
Definition: weapon.qh:41
float time
Definition: csprogsdefs.qc:16
void Item_SetExpiring(entity item, bool expiring)
Sets the item expiring status (i.e.
Definition: spawning.qc:141
#define FOREACH(list, cond, body)
Definition: iter.qh:19
void Item_SetLoot(entity item, bool loot)
Sets the item loot status.
Definition: spawning.qc:126
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ W_ThrowWeapon()

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

Definition at line 153 of file throwing.qc.

References autocvar_g_weapon_throwable, Weapon::m_id, MUTATOR_CALLHOOK, time, w_getbestweapon, W_IsWeaponThrowable(), W_SwitchWeapon_Force(), W_ThrowNewWeapon(), WepSet_FromWeapon, and WS_READY.

Referenced by IMPULSE().

154 {
155  Weapon w = this.(weaponentity).m_weapon;
156  if (w == WEP_Null)
157  return; // just in case
158  if (time < game_starttime)
159  return;
160  if(MUTATOR_CALLHOOK(ForbidThrowCurrentWeapon, this, this.(weaponentity)))
161  return;
163  return;
164  if(this.(weaponentity).state != WS_READY)
165  return;
166  if(!W_IsWeaponThrowable(this, w.m_id))
167  return;
168 
169  WepSet set = WepSet_FromWeapon(w);
170  if(!(STAT(WEAPONS, this) & set)) return;
171  STAT(WEAPONS, this) &= ~set;
172 
173  W_SwitchWeapon_Force(this, w_getbestweapon(this, weaponentity), weaponentity);
174  float a = W_ThrowNewWeapon(this, w.m_id, doreduce, this.origin + delta, velo, weaponentity);
175 
176  if(a < 0) return;
177  Send_Notification(NOTIF_ONE, this, MSG_MULTI, ITEM_WEAPON_DROP, w.m_id, a);
178 }
vector WepSet
Definition: weapon.qh:11
void W_SwitchWeapon_Force(Player this, Weapon w,.entity weaponentity)
Definition: selection.qc:243
#define w_getbestweapon(ent, wepent)
Definition: selection.qh:23
const int WS_READY
idle frame
Definition: weapon.qh:38
float W_ThrowNewWeapon(entity own, float wpn, float doreduce, vector org, vector velo,.entity weaponentity)
Definition: throwing.qc:40
bool W_IsWeaponThrowable(entity this, int w)
Definition: throwing.qc:138
#define MUTATOR_CALLHOOK(id,...)
Definition: base.qh:140
bool autocvar_g_weapon_throwable
Definition: throwing.qh:6
#define WepSet_FromWeapon(it)
Definition: all.qh:38
fields which are explicitly/manually set are marked with "M", fields set automatically are marked wit...
Definition: weapon.qh:41
float time
Definition: csprogsdefs.qc:16
int m_id
Definition: weapon.qh:42
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Variable Documentation

◆ autocvar_g_weapon_throwable

bool autocvar_g_weapon_throwable

Definition at line 6 of file throwing.qh.

Referenced by W_ThrowWeapon().

◆ savenextthink

float savenextthink

Definition at line 8 of file throwing.qh.

Referenced by thrown_wep_think().