3 #include <common/resources/sv_resources.qh>
4 #include <common/weapons/_all.qh>
5 #include <server/items/items.qh>
6 #include <server/items/spawning.qh>
7 #include <server/mutators/_mod.qh>
8 #include <server/weapons/weaponsystem.qh>
9 #include <server/world.qh>
11 .bool m_isreplaced; ///< Holds whether the weapon has been replaced.
13 string W_Apply_Weaponreplace(string in)
16 FOREACH_WORD(in, true, {
17 string replacement = "";
18 Weapon w = Weapon_from_name(it);
21 replacement = w.weaponreplace;
22 if (replacement == "") replacement = it;
24 if (replacement == "0") continue;
25 out = cons(out, replacement);
30 void weapon_defaultspawnfunc(entity this, Weapon wpn)
32 wpn = wpn.m_spawnfunc_hookreplace(wpn, this);
33 this.classname = wpn.m_canonical_spawnfunc;
34 if (!Item_IsLoot(this) && !this.m_isreplaced)
36 if (wpn.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(wpn.netname);
44 MUTATOR_CALLHOOK(SetWeaponreplace, this, wpn, 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 Weapon wep = Weapon_from_name(s);
62 entity replacement = spawn();
63 Item_CopyFields(this, replacement);
64 // DO NOTE USE, causes #2792
65 //copyentity(this, replacement);
66 replacement.m_isreplaced = true;
67 weapon_defaultspawnfunc(replacement, wep);
71 if (t >= 1) // always the case!
74 wpn = Weapon_from_name(s);
79 startitem_failed = true;
84 if(!Item_IsLoot(this))
85 weaponsInMapAll |= WepSet_FromWeapon(wpn);
87 if (!Item_IsDefinitionAllowed(wpn.m_pickup))
90 startitem_failed = true;
94 if (!this.respawntime)
96 if (wpn.spawnflags & WEP_FLAG_SUPERWEAPON)
98 this.respawntime = g_pickup_respawntime_superweapon;
99 this.respawntimejitter = g_pickup_respawntimejitter_superweapon;
103 this.respawntime = g_pickup_respawntime_weapon;
104 this.respawntimejitter = g_pickup_respawntimejitter_weapon;
108 if (wpn.spawnflags & WEP_FLAG_SUPERWEAPON)
109 if (!this.superweapons_finished)
110 this.superweapons_finished = autocvar_g_balance_superweapons_time;
112 // if we don't already have ammo, give us some ammo
113 // TODO: registry handles
114 if ((wpn.ammo_type != RES_NONE) && !GetResource(this, wpn.ammo_type))
117 if (q3compat && this.count > 0)
118 ammo = this.count * GetAmmoConsumptionQ3(wpn.netname);
119 // WEAPONTODO: magazines of MG, rifle and OK weapons are unaccounted for
122 switch (wpn.ammo_type)
124 case RES_SHELLS: ammo = cvar("g_pickup_shells_weapon"); break;
125 case RES_BULLETS: ammo = cvar("g_pickup_nails_weapon"); break;
126 case RES_ROCKETS: ammo = cvar("g_pickup_rockets_weapon"); break;
127 case RES_CELLS: ammo = cvar("g_pickup_cells_weapon"); break;
128 case RES_PLASMA: ammo = cvar("g_pickup_plasma_weapon"); break;
129 case RES_FUEL: ammo = cvar("g_pickup_fuel_weapon"); break;
133 SetResource(this, wpn.ammo_type, ammo);
139 for (int i = 0, j = 1; i < 24; ++i, j <<= 1)
143 ammotype = Item_CounterField(j);
145 this.ammotype = cvar(strcat("g_pickup_", Item_CounterFieldName(j), "_weapon"));
152 if (g_pickup_weapons_anyway)
153 this.pickup_anyway = true;
156 this.glowmod = wpn.wpcolor;
158 this.glowmod = colormapPaletteColor(this.owner.clientcolors & 0x0F, true);
160 GameItem def = wpn.m_pickup;
164 this.respawntime, // defaultrespawntime
165 this.respawntimejitter // defaultrespawntimejitter
168 if (this.modelindex) { // don't precache if this was removed