]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/server/weapons/spawning.qc
Merge branch 'Mario/resource_registry' into 'master'
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / weapons / spawning.qc
index d5c79d085685f4c494934b15bd13050ef94fde76..30a2869f399f42b1887a4d7e626364a3f7b81b4e 100644 (file)
@@ -1,11 +1,12 @@
 #include "spawning.qh"
 
-#include "weaponsystem.qh"
-#include "../resources.qh"
-#include <server/mutators/_mod.qh>
-#include <common/t_items.qh>
-#include <server/items.qh>
+#include <common/resources/sv_resources.qh>
 #include <common/weapons/_all.qh>
+#include <server/items/items.qh>
+#include <server/items/spawning.qh>
+#include <server/mutators/_mod.qh>
+#include <server/weapons/weaponsystem.qh>
+#include <server/world.qh>
 
 .bool m_isreplaced; ///< Holds whether the weapon has been replaced.
 
@@ -14,7 +15,7 @@ string W_Apply_Weaponreplace(string in)
        string out = "";
        FOREACH_WORD(in, true, {
                string replacement = "";
-               Weapon w = Weapons_fromstr(it);
+               Weapon w = Weapon_from_name(it);
                if (w)
                {
             replacement = w.weaponreplace;
@@ -26,22 +27,21 @@ string W_Apply_Weaponreplace(string in)
        return out;
 }
 
-void weapon_defaultspawnfunc(entity this, Weapon e)
+void weapon_defaultspawnfunc(entity this, Weapon wpn)
 {
-       Weapon wpn = e;
-       e = wpn = wpn.m_spawnfunc_hookreplace(wpn, this);
+       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)
+               if (wpn.spawnflags & WEP_FLAG_MUTATORBLOCKED)
                {
-                       LOG_WARNF("Attempted to spawn a mutator-blocked weapon rejected: prvm_edict server %i", this);
+                       //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);
+               string s = W_Apply_Weaponreplace(wpn.netname);
+               MUTATOR_CALLHOOK(SetWeaponreplace, this, wpn, s);
                s = M_ARGV(2, string);
                if (s == "")
                {
@@ -56,7 +56,7 @@ void weapon_defaultspawnfunc(entity this, Weapon e)
                        for (int i = 1; i < t; ++i)
                        {
                                s = argv(i);
-                               Weapon wep = Weapons_fromstr(s);
+                               Weapon wep = Weapon_from_name(s);
                                if(wep != WEP_Null)
                                {
                                        entity replacement = spawn();
@@ -69,7 +69,7 @@ void weapon_defaultspawnfunc(entity this, Weapon e)
                if (t >= 1) // always the case!
                {
                        s = argv(0);
-                       wpn = Weapons_fromstr(s);
+                       wpn = Weapon_from_name(s);
                }
                if (wpn == WEP_Null)
                {
@@ -108,17 +108,27 @@ 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
+       // TODO: registry handles
        if ((wpn.ammo_type != RES_NONE) && !GetResource(this, wpn.ammo_type))
        {
-               switch (wpn.ammo_type)
+               int ammo = 0;
+               if (q3compat && this.count > 0)
+                       ammo = this.count * GetAmmoConsumptionQ3(wpn.netname);
+                       // WEAPONTODO: magazines of MG, rifle and OK weapons are unaccounted for
+               else
                {
-                       case RES_SHELLS:  SetResource(this, wpn.ammo_type, cvar("g_pickup_shells_weapon"));  break;
-                       case RES_BULLETS: SetResource(this, wpn.ammo_type, cvar("g_pickup_nails_weapon"));   break;
-                       case RES_ROCKETS: SetResource(this, wpn.ammo_type, cvar("g_pickup_rockets_weapon")); break;
-                       case RES_CELLS:   SetResource(this, wpn.ammo_type, cvar("g_pickup_cells_weapon"));   break;
-                       case RES_PLASMA:  SetResource(this, wpn.ammo_type, cvar("g_pickup_plasma_weapon"));  break;
-                       case RES_FUEL:    SetResource(this, wpn.ammo_type, cvar("g_pickup_fuel_weapon"));    break;
+                       switch (wpn.ammo_type)
+                       {
+                               case RES_SHELLS:  ammo = cvar("g_pickup_shells_weapon");  break;
+                               case RES_BULLETS: ammo = cvar("g_pickup_nails_weapon");   break;
+                               case RES_ROCKETS: ammo = cvar("g_pickup_rockets_weapon"); break;
+                               case RES_CELLS:   ammo = cvar("g_pickup_cells_weapon");   break;
+                               case RES_PLASMA:  ammo = cvar("g_pickup_plasma_weapon");  break;
+                               case RES_FUEL:    ammo = cvar("g_pickup_fuel_weapon");    break;
+                       }
                }
+
+               SetResource(this, wpn.ammo_type, ammo);
        }
 
        #if 0 // WEAPONTODO