]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/server/weapons/spawning.qc
Merge branch 'master' into terencehill/accuracy_shotgun
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / weapons / spawning.qc
index 578c941f7f123528dc29318c2a17dce989e5f805..d47351cb37a727aab87f100d2ccb61ddd98a5824 100644 (file)
@@ -1,9 +1,13 @@
 #include "spawning.qh"
 
 #include "weaponsystem.qh"
-#include "../mutators/all.qh"
+#include "../resources.qh"
+#include "../mutators/_mod.qh"
 #include <common/t_items.qh>
-#include <common/weapons/all.qh>
+#include <server/items.qh>
+#include <common/weapons/_all.qh>
+
+.bool m_isreplaced; ///< Holds whether the weapon has been replaced.
 
 string W_Apply_Weaponreplace(string in)
 {
@@ -25,21 +29,23 @@ string W_Apply_Weaponreplace(string in)
 void weapon_defaultspawnfunc(entity this, Weapon e)
 {
        Weapon wpn = e;
-       if (this.classname != "droppedweapon" && this.classname != "replacedweapon")
+       e = wpn = wpn.m_spawnfunc_hookreplace(wpn, this);
+       this.classname = wpn.m_canonical_spawnfunc;
+       if (!Item_IsLoot(this) && !this.m_isreplaced)
        {
                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;
                }
 
                string s = W_Apply_Weaponreplace(e.netname);
                MUTATOR_CALLHOOK(SetWeaponreplace, this, e, s);
-               s = ret_string;
+               s = M_ARGV(2, string);
                if (s == "")
                {
-                       remove(this);
+                       delete(this);
                        startitem_failed = true;
                        return;
                }
@@ -50,33 +56,33 @@ void weapon_defaultspawnfunc(entity this, Weapon e)
                        for (int i = 1; i < t; ++i)
                        {
                                s = argv(i);
-                               FOREACH(Weapons, it != WEP_Null, LAMBDA(
+                               FOREACH(Weapons, it != WEP_Null, {
                                        if(it.netname == s)
                                        {
                                                entity replacement = spawn();
                                                copyentity(this, replacement);
-                                               replacement.classname = "replacedweapon";
+                                               replacement.m_isreplaced = true;
                                                weapon_defaultspawnfunc(replacement, it);
                                                break;
                                        }
-                               ));
+                               });
                        }
                }
                if (t >= 1) // always the case!
                {
                        s = argv(0);
                        wpn = WEP_Null;
-                       FOREACH(Weapons, it != WEP_Null, LAMBDA(
+                       FOREACH(Weapons, it != WEP_Null, {
                                if(it.netname == s)
                                {
                                        wpn = it;
                                        break;
                                }
-                       ));
+                       });
                }
                if (wpn == WEP_Null)
                {
-                       remove(this);
+                       delete(this);
                        startitem_failed = true;
                        return;
                }
@@ -101,16 +107,16 @@ void weapon_defaultspawnfunc(entity this, Weapon e)
                        this.superweapons_finished = autocvar_g_balance_superweapons_time;
 
        // if we don't already have ammo, give us some ammo
-       if (!this.(wpn.ammo_field))
+       if ((wpn.ammo_type != RESOURCE_NONE) && !GetResourceAmount(this, wpn.ammo_type))
        {
-               switch (wpn.ammo_field)
+               switch (wpn.ammo_type)
                {
-                       case ammo_shells:  this.ammo_shells  = cvar("g_pickup_shells_weapon");  break;
-                       case ammo_nails:   this.ammo_nails   = cvar("g_pickup_nails_weapon");   break;
-                       case ammo_rockets: this.ammo_rockets = cvar("g_pickup_rockets_weapon"); break;
-                       case ammo_cells:   this.ammo_cells   = cvar("g_pickup_cells_weapon");   break;
-                       case ammo_plasma:  this.ammo_plasma  = cvar("g_pickup_plasma_weapon");  break;
-                       case ammo_fuel:    this.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;
                }
        }
 
@@ -133,6 +139,9 @@ void weapon_defaultspawnfunc(entity this, Weapon e)
        if (g_pickup_weapons_anyway)
                this.pickup_anyway = true;
 
+       if(!this.owner)
+               this.glowmod = wpn.wpcolor;
+
        GameItem def = wpn.m_pickup;
        _StartItem(
                this,