3 #include "weaponsystem.qh"
4 #include "../resources.qh"
5 #include "../mutators/_mod.qh"
6 #include <common/t_items.qh>
7 #include <server/items.qh>
8 #include <common/weapons/_all.qh>
10 .bool m_isreplaced; ///< Holds whether the weapon has been replaced.
12 string W_Apply_Weaponreplace(string in)
15 FOREACH_WORD(in, true, {
16 string replacement = "";
17 Weapon w = Weapons_fromstr(it);
20 replacement = w.weaponreplace;
21 if (replacement == "") replacement = it;
23 if (replacement == "0") continue;
24 out = cons(out, replacement);
29 void weapon_defaultspawnfunc(entity this, Weapon e)
32 e = wpn = wpn.m_spawnfunc_hookreplace(wpn, this);
33 //this.classname = wpn.m_canonical_spawnfunc;
34 if (!Item_IsLoot(this) && !this.m_isreplaced)
36 if (e.spawnflags & WEP_FLAG_MUTATORBLOCKED)
38 LOG_WARNF("Attempted to spawn a mutator-blocked weapon rejected: prvm_edict server %i", this);
39 startitem_failed = true;
43 string s = W_Apply_Weaponreplace(e.netname);
44 MUTATOR_CALLHOOK(SetWeaponreplace, this, e, s);
45 s = M_ARGV(2, string);
49 startitem_failed = true;
52 int t = tokenize_console(s);
55 this.team = --internalteam;
56 for (int i = 1; i < t; ++i)
59 FOREACH(Weapons, it != WEP_Null, {
62 entity replacement = spawn();
63 copyentity(this, replacement);
64 replacement.m_isreplaced = true;
65 weapon_defaultspawnfunc(replacement, it);
71 if (t >= 1) // always the case!
75 FOREACH(Weapons, it != WEP_Null, {
86 startitem_failed = true;
91 if (!this.respawntime)
93 if (wpn.spawnflags & WEP_FLAG_SUPERWEAPON)
95 this.respawntime = g_pickup_respawntime_superweapon;
96 this.respawntimejitter = g_pickup_respawntimejitter_superweapon;
100 this.respawntime = g_pickup_respawntime_weapon;
101 this.respawntimejitter = g_pickup_respawntimejitter_weapon;
105 if (wpn.spawnflags & WEP_FLAG_SUPERWEAPON)
106 if (!this.superweapons_finished)
107 this.superweapons_finished = autocvar_g_balance_superweapons_time;
109 // if we don't already have ammo, give us some ammo
110 if ((wpn.ammo_type != RESOURCE_NONE) && !GetResourceAmount(this, wpn.ammo_type))
112 switch (wpn.ammo_type)
114 case RESOURCE_SHELLS: SetResourceAmount(this, wpn.ammo_type, cvar("g_pickup_shells_weapon")); break;
115 case RESOURCE_BULLETS: SetResourceAmount(this, wpn.ammo_type, cvar("g_pickup_nails_weapon")); break;
116 case RESOURCE_ROCKETS: SetResourceAmount(this, wpn.ammo_type, cvar("g_pickup_rockets_weapon")); break;
117 case RESOURCE_CELLS: SetResourceAmount(this, wpn.ammo_type, cvar("g_pickup_cells_weapon")); break;
118 case RESOURCE_PLASMA: SetResourceAmount(this, wpn.ammo_type, cvar("g_pickup_plasma_weapon")); break;
119 case RESOURCE_FUEL: SetResourceAmount(this, wpn.ammo_type, cvar("g_pickup_fuel_weapon")); break;
126 for (int i = 0, j = 1; i < 24; ++i, j <<= 1)
130 ammotype = Item_CounterField(j);
132 this.ammotype = cvar(strcat("g_pickup_", Item_CounterFieldName(j), "_weapon"));
139 if (g_pickup_weapons_anyway)
140 this.pickup_anyway = true;
143 this.glowmod = wpn.wpcolor;
145 GameItem def = wpn.m_pickup;
149 this.respawntime, // defaultrespawntime
150 this.respawntimejitter // defaultrespawntimejitter
153 if (this.modelindex) { // don't precache if this was removed