X-Git-Url: https://de.git.xonotic.org/?a=blobdiff_plain;f=qcsrc%2Fserver%2Fweapons%2Fspawning.qc;h=578c941f7f123528dc29318c2a17dce989e5f805;hb=cac7a0ffc2bb7212fdd92f5c9782b09b65279fe1;hp=be2ca6b50f0c6d734d1903aa9470c6d19f1bb291;hpb=3ae1efa7401791e42e3171f4db2cc2d38adde088;p=xonotic%2Fxonotic-data.pk3dir.git diff --git a/qcsrc/server/weapons/spawning.qc b/qcsrc/server/weapons/spawning.qc index be2ca6b50..17f2ddeee 100644 --- a/qcsrc/server/weapons/spawning.qc +++ b/qcsrc/server/weapons/spawning.qc @@ -1,187 +1,164 @@ #include "spawning.qh" #include "weaponsystem.qh" -#include "../mutators/mutators_include.qh" -#include "../t_items.qh" -#include "../../common/weapons/all.qh" +#include "../resources.qh" +#include "../mutators/_mod.qh" +#include +#include +#include + +.bool m_isreplaced; ///< Holds whether the weapon has been replaced. string W_Apply_Weaponreplace(string in) { - float n = tokenize_console(in); - string out = "", s, replacement; - float i, j; - entity e; - for(i = 0; i < n; ++i) - { - replacement = ""; - s = argv(i); - - for(j = WEP_FIRST; j <= WEP_LAST; ++j) + string out = ""; + FOREACH_WORD(in, true, { + string replacement = ""; + Weapon w = Weapons_fromstr(it); + if (w) { - e = get_weaponinfo(j); - if(e.netname == s) - { - replacement = e.weaponreplace; - } + replacement = w.weaponreplace; + if (replacement == "") replacement = it; } - - if(replacement == "") - out = strcat(out, " ", s); - else if(replacement != "0") - out = strcat(out, " ", replacement); - } - return substring(out, 1, -1); + if (replacement == "0") continue; + out = cons(out, replacement); + }); + return out; } -void weapon_defaultspawnfunc(float wpn) -{SELFPARAM(); - entity e; - float t; - string s; - float i, j; - int f; - - if(self.classname != "droppedweapon" && self.classname != "replacedweapon") +void weapon_defaultspawnfunc(entity this, Weapon e) +{ + Weapon wpn = e; + e = wpn = wpn.m_spawnfunc_hookreplace(wpn, this); + this.classname = wpn.m_canonical_spawnfunc; + if (!Item_IsLoot(this) && !this.m_isreplaced) { - e = get_weaponinfo(wpn); - - if(e.spawnflags & WEP_FLAG_MUTATORBLOCKED) + if (e.spawnflags & WEP_FLAG_MUTATORBLOCKED) { - objerror("Attempted to spawn a mutator-blocked weapon rejected"); + LOG_WARNF("Attempted to spawn a mutator-blocked weapon rejected: prvm_edict server %i", this); startitem_failed = true; return; } - s = W_Apply_Weaponreplace(e.netname); - MUTATOR_CALLHOOK(SetWeaponreplace, self, e, s); - s = ret_string; - if(s == "") + string s = W_Apply_Weaponreplace(e.netname); + MUTATOR_CALLHOOK(SetWeaponreplace, this, e, s); + s = M_ARGV(2, string); + if (s == "") { - remove(self); + delete(this); startitem_failed = true; return; } - t = tokenize_console(s); - if(t >= 2) + int t = tokenize_console(s); + if (t >= 2) { - self.team = --internalteam; - for(i = 1; i < t; ++i) + this.team = --internalteam; + for (int i = 1; i < t; ++i) { s = argv(i); - for(j = WEP_FIRST; j <= WEP_LAST; ++j) - { - e = get_weaponinfo(j); - if(e.netname == s) + FOREACH(Weapons, it != WEP_Null, { + if(it.netname == s) { - setself(spawn()); - copyentity(this, self); - self.classname = "replacedweapon"; - weapon_defaultspawnfunc(j); + entity replacement = spawn(); + copyentity(this, replacement); + replacement.m_isreplaced = true; + weapon_defaultspawnfunc(replacement, it); break; } - } - if(j > WEP_LAST) - { - LOG_INFO("The weapon replace list for ", this.classname, " contains an unknown weapon ", s, ". Skipped.\n"); - } + }); } - setself(this); } - if(t >= 1) // always the case! + if (t >= 1) // always the case! { s = argv(0); - wpn = 0; - for(j = WEP_FIRST; j <= WEP_LAST; ++j) - { - e = get_weaponinfo(j); - if(e.netname == s) + wpn = WEP_Null; + FOREACH(Weapons, it != WEP_Null, { + if(it.netname == s) { - wpn = j; + wpn = it; break; } - } - if(j > WEP_LAST) - { - LOG_INFO("The weapon replace list for ", self.classname, " contains an unknown weapon ", s, ". Skipped.\n"); - } + }); } - if(wpn == 0) + if (wpn == WEP_Null) { - remove(self); + delete(this); startitem_failed = true; return; } } - e = get_weaponinfo(wpn); + if (!Item_IsDefinitionAllowed(wpn.m_pickup)) + { + delete(this); + startitem_failed = true; + return; + } - if(!self.respawntime) + if (!this.respawntime) { - if(e.weapons & WEPSET_SUPERWEAPONS) + if (wpn.spawnflags & WEP_FLAG_SUPERWEAPON) { - self.respawntime = g_pickup_respawntime_superweapon; - self.respawntimejitter = g_pickup_respawntimejitter_superweapon; + this.respawntime = g_pickup_respawntime_superweapon; + this.respawntimejitter = g_pickup_respawntimejitter_superweapon; } else { - self.respawntime = g_pickup_respawntime_weapon; - self.respawntimejitter = g_pickup_respawntimejitter_weapon; + this.respawntime = g_pickup_respawntime_weapon; + this.respawntimejitter = g_pickup_respawntimejitter_weapon; } } - if(e.weapons & WEPSET_SUPERWEAPONS) - if(!self.superweapons_finished) - self.superweapons_finished = autocvar_g_balance_superweapons_time; + if (wpn.spawnflags & WEP_FLAG_SUPERWEAPON) + if (!this.superweapons_finished) + this.superweapons_finished = autocvar_g_balance_superweapons_time; // if we don't already have ammo, give us some ammo - if(!self.(e.ammo_field)) + if ((wpn.ammo_type != RESOURCE_NONE) && !GetResourceAmount(this, wpn.ammo_type)) { - switch(e.ammo_field) + switch (wpn.ammo_type) { - case ammo_shells: self.ammo_shells = cvar("g_pickup_shells_weapon"); break; - case ammo_nails: self.ammo_nails = cvar("g_pickup_nails_weapon"); break; - case ammo_rockets: self.ammo_rockets = cvar("g_pickup_rockets_weapon"); break; - case ammo_cells: self.ammo_cells = cvar("g_pickup_cells_weapon"); break; - case ammo_plasma: self.ammo_plasma = cvar("g_pickup_plasma_weapon"); break; - case ammo_fuel: self.ammo_fuel = cvar("g_pickup_fuel_weapon"); break; + case RESOURCE_SHELLS: SetResourceAmount(this, wpn.ammo_type, cvar("g_pickup_shells_weapon")); break; + case RESOURCE_BULLETS: SetResourceAmount(this, wpn.ammo_type, cvar("g_pickup_nails_weapon")); break; + case RESOURCE_ROCKETS: SetResourceAmount(this, wpn.ammo_type, cvar("g_pickup_rockets_weapon")); break; + case RESOURCE_CELLS: SetResourceAmount(this, wpn.ammo_type, cvar("g_pickup_cells_weapon")); break; + case RESOURCE_PLASMA: SetResourceAmount(this, wpn.ammo_type, cvar("g_pickup_plasma_weapon")); break; + case RESOURCE_FUEL: SetResourceAmount(this, wpn.ammo_type, cvar("g_pickup_fuel_weapon")); break; } } #if 0 // WEAPONTODO - if(e.items) + if (wpn.items) { - for(i = 0, j = 1; i < 24; ++i, j *= 2) + for (int i = 0, j = 1; i < 24; ++i, j <<= 1) { - if(e.items & j) + if (wpn.items & j) { ammotype = Item_CounterField(j); - if(!self.ammotype) - self.ammotype = cvar(strcat("g_pickup_", Item_CounterFieldName(j), "_weapon")); + if (!this.ammotype) + this.ammotype = cvar(strcat("g_pickup_", Item_CounterFieldName(j), "_weapon")); } } } #endif // pickup anyway - if(g_pickup_weapons_anyway) - self.pickup_anyway = true; - - f = FL_WEAPON; - - // no weapon-stay on superweapons - if(e.weapons & WEPSET_SUPERWEAPONS) - f |= FL_NO_WEAPON_STAY; - - // weapon stay isn't supported for teamed weapons - if(self.team) - f |= FL_NO_WEAPON_STAY; - - StartItem(strzone(e.m_model.model_str()), string_null, self.respawntime, self.respawntimejitter, e.message, 0, e.weapon, f, weapon_pickupevalfunc, e.bot_pickupbasevalue); - self.item_pickupsound_ent = SND_WEAPONPICKUP; + if (g_pickup_weapons_anyway) + this.pickup_anyway = true; + + if(!this.owner) + this.glowmod = wpn.wpcolor; + + GameItem def = wpn.m_pickup; + _StartItem( + this, + this.itemdef = def, + this.respawntime, // defaultrespawntime + this.respawntimejitter // defaultrespawntimejitter + ); #if 0 // WEAPONTODO - if (self.modelindex) { // don't precache if self was removed - Weapon w = get_weaponinfo(e.weapon); - w.wr_init(w); + if (this.modelindex) { // don't precache if this was removed + wpn.wr_init(wpn); } #endif }