Xonotic
spawning.qh File Reference
+ Include dependency graph for spawning.qh:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

string W_Apply_Weaponreplace (string in)
 
void weapon_defaultspawnfunc (entity this, Weapon e)
 

Function Documentation

◆ W_Apply_Weaponreplace()

string W_Apply_Weaponreplace ( string  in)

Definition at line 13 of file spawning.qc.

References cons(), FOREACH_WORD, and Weapon_from_name().

Referenced by MUTATOR_HOOKFUNCTION(), and weapon_defaultspawnfunc().

14 {
15  string out = "";
16  FOREACH_WORD(in, true, {
17  string replacement = "";
18  Weapon w = Weapon_from_name(it);
19  if (w)
20  {
21  replacement = w.weaponreplace;
22  if (replacement == "") replacement = it;
23  }
24  if (replacement == "0") continue;
25  out = cons(out, replacement);
26  });
27  return out;
28 }
#define FOREACH_WORD(words, cond, body)
Definition: iter.qh:33
ERASEABLE string cons(string a, string b)
Definition: string.qh:257
fields which are explicitly/manually set are marked with "M", fields set automatically are marked wit...
Definition: weapon.qh:41
Weapon Weapon_from_name(string s)
Definition: all.qh:134
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ weapon_defaultspawnfunc()

void weapon_defaultspawnfunc ( entity  this,
Weapon  e 
)

Definition at line 30 of file spawning.qc.

References _StartItem(), ammo, Weapon::ammo_type, argv(), autocvar_g_balance_superweapons_time, classname, copyentity(), count, cvar(), entity(), g_pickup_weapons_anyway, GetAmmoConsumptionQ3(), GetResource(), glowmod, internalteam, Item_IsDefinitionAllowed(), Item_IsLoot(), itemdef, M_ARGV, m_isreplaced, modelindex, MUTATOR_CALLHOOK, Weapon::netname, owner, pickup_anyway, q3compat, respawntime, respawntimejitter, SetResource(), spawn(), Weapon::spawnflags, startitem_failed, strcat(), superweapons_finished, team, tokenize_console, W_Apply_Weaponreplace(), weapon_defaultspawnfunc(), Weapon_from_name(), WEP_FLAG_MUTATORBLOCKED, WEP_FLAG_SUPERWEAPON, WepSet_FromWeapon, and Weapon::wpcolor.

Referenced by W_ThrowNewWeapon(), Weapon::Weapon ::display(), and weapon_defaultspawnfunc().

31 {
32  wpn = wpn.m_spawnfunc_hookreplace(wpn, this);
33  this.classname = wpn.m_canonical_spawnfunc;
34  if (!Item_IsLoot(this) && !this.m_isreplaced)
35  {
36  if (wpn.spawnflags & WEP_FLAG_MUTATORBLOCKED)
37  {
38  //LOG_WARNF("Attempted to spawn a mutator-blocked weapon rejected: prvm_edict server %i", this);
39  startitem_failed = true;
40  return;
41  }
42 
43  string s = W_Apply_Weaponreplace(wpn.netname);
44  MUTATOR_CALLHOOK(SetWeaponreplace, this, wpn, s);
45  s = M_ARGV(2, string);
46  if (s == "")
47  {
48  delete(this);
49  startitem_failed = true;
50  return;
51  }
52  int t = tokenize_console(s);
53  if (t >= 2)
54  {
55  this.team = --internalteam;
56  for (int i = 1; i < t; ++i)
57  {
58  s = argv(i);
59  Weapon wep = Weapon_from_name(s);
60  if(wep != WEP_Null)
61  {
62  entity replacement = spawn();
63  copyentity(this, replacement);
64  replacement.m_isreplaced = true;
65  weapon_defaultspawnfunc(replacement, wep);
66  }
67  }
68  }
69  if (t >= 1) // always the case!
70  {
71  s = argv(0);
72  wpn = Weapon_from_name(s);
73  }
74  if (wpn == WEP_Null)
75  {
76  delete(this);
77  startitem_failed = true;
78  return;
79  }
80  }
81 
82  if(!Item_IsLoot(this))
83  weaponsInMapAll |= WepSet_FromWeapon(wpn);
84 
85  if (!Item_IsDefinitionAllowed(wpn.m_pickup))
86  {
87  delete(this);
88  startitem_failed = true;
89  return;
90  }
91 
92  if (!this.respawntime)
93  {
94  if (wpn.spawnflags & WEP_FLAG_SUPERWEAPON)
95  {
96  this.respawntime = g_pickup_respawntime_superweapon;
97  this.respawntimejitter = g_pickup_respawntimejitter_superweapon;
98  }
99  else
100  {
101  this.respawntime = g_pickup_respawntime_weapon;
102  this.respawntimejitter = g_pickup_respawntimejitter_weapon;
103  }
104  }
105 
106  if (wpn.spawnflags & WEP_FLAG_SUPERWEAPON)
107  if (!this.superweapons_finished)
109 
110  // if we don't already have ammo, give us some ammo
111  // TODO: registry handles
112  if ((wpn.ammo_type != RES_NONE) && !GetResource(this, wpn.ammo_type))
113  {
114  int ammo = 0;
115  if (q3compat && this.count > 0)
116  ammo = this.count * GetAmmoConsumptionQ3(wpn.netname);
117  // WEAPONTODO: magazines of MG, rifle and OK weapons are unaccounted for
118  else
119  {
120  switch (wpn.ammo_type)
121  {
122  case RES_SHELLS: ammo = cvar("g_pickup_shells_weapon"); break;
123  case RES_BULLETS: ammo = cvar("g_pickup_nails_weapon"); break;
124  case RES_ROCKETS: ammo = cvar("g_pickup_rockets_weapon"); break;
125  case RES_CELLS: ammo = cvar("g_pickup_cells_weapon"); break;
126  case RES_PLASMA: ammo = cvar("g_pickup_plasma_weapon"); break;
127  case RES_FUEL: ammo = cvar("g_pickup_fuel_weapon"); break;
128  }
129  }
130 
131  SetResource(this, wpn.ammo_type, ammo);
132  }
133 
134  #if 0 // WEAPONTODO
135  if (wpn.items)
136  {
137  for (int i = 0, j = 1; i < 24; ++i, j <<= 1)
138  {
139  if (wpn.items & j)
140  {
141  ammotype = Item_CounterField(j);
142  if (!this.ammotype)
143  this.ammotype = cvar(strcat("g_pickup_", Item_CounterFieldName(j), "_weapon"));
144  }
145  }
146  }
147  #endif
148 
149  // pickup anyway
151  this.pickup_anyway = true;
152 
153  if(!this.owner)
154  this.glowmod = wpn.wpcolor;
155 
156  GameItem def = wpn.m_pickup;
157  _StartItem(
158  this,
159  this.itemdef = def,
160  this.respawntime, // defaultrespawntime
161  this.respawntimejitter // defaultrespawntimejitter
162  );
163  #if 0 // WEAPONTODO
164  if (this.modelindex) { // don't precache if this was removed
165  wpn.wr_init(wpn);
166  }
167  #endif
168 }
void weapon_defaultspawnfunc(entity this, Weapon wpn)
Definition: spawning.qc:30
float autocvar_g_balance_superweapons_time
Definition: items.qh:6
float respawntimejitter
Definition: items.qh:37
float respawntime
Definition: items.qh:36
bool Item_IsDefinitionAllowed(entity definition)
Checks whether the items with the specified definition are allowed to spawn.
Definition: spawning.qc:55
string W_Apply_Weaponreplace(string in)
Definition: spawning.qc:13
float modelindex
Definition: csprogsdefs.qc:91
float g_pickup_weapons_anyway
Definition: world.qh:75
int team
Definition: main.qh:157
entity() spawn
string classname
Definition: csprogsdefs.qc:107
entity owner
Definition: main.qh:73
void _StartItem(entity this, entity def, float defaultrespawntime, float defaultrespawntimejitter)
Definition: items.qc:925
float ammo
Definition: sv_turrets.qh:44
int q3compat
Definition: quake3.qh:3
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
spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 f1 s1 strcat(_("Level %s: "), "^BG%s\3\, _("^BGPress ^F2%s^BG to enter the game"))
entity itemdef
Definition: items.qh:94
float pickup_anyway
Definition: items.qh:32
int GetAmmoConsumptionQ3(string netname)
Definition: quake3.qc:337
#define M_ARGV(x, type)
Definition: events.qh:17
#define tokenize_console
Definition: dpextensions.qh:24
float superweapons_finished
Definition: items.qh:44
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 count
Definition: powerups.qc:22
#define MUTATOR_CALLHOOK(id,...)
Definition: base.qh:140
bool Item_IsLoot(entity item)
Returns whether the item is loot.
Definition: spawning.qc:121
const int WEP_FLAG_MUTATORBLOCKED
Definition: weapon.qh:203
#define WepSet_FromWeapon(it)
Definition: all.qh:38
vector glowmod
fields which are explicitly/manually set are marked with "M", fields set automatically are marked wit...
Definition: weapon.qh:41
Weapon Weapon_from_name(string s)
Definition: all.qh:134
bool m_isreplaced
Holds whether the weapon has been replaced.
Definition: spawning.qc:11
const int WEP_FLAG_SUPERWEAPON
Definition: weapon.qh:202
float internalteam
Definition: weaponsystem.qh:20
+ Here is the call graph for this function:
+ Here is the caller graph for this function: