]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/server/weapons/throwing.qc
Impulses: migration pathway
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / weapons / throwing.qc
index 2fb19609eaf71685cc33a15d7d9ca700fb870cc2..652ec92005aba884ea26c3955b42644fb33a6726 100644 (file)
@@ -1,12 +1,13 @@
 #include "throwing.qh"
-#include "../_all.qh"
 
 #include "weaponsystem.qh"
-#include "../mutators/mutators_include.qh"
+#include "../mutators/all.qh"
 #include "../t_items.qh"
 #include "../g_damage.qh"
+#include "../../common/items/item.qh"
 #include "../../common/mapinfo.qh"
 #include "../../common/notifications.qh"
+#include "../../common/triggers/subs.qh"
 #include "../../common/util.qh"
 #include "../../common/weapons/all.qh"
 
@@ -33,20 +34,20 @@ string W_ThrowNewWeapon(entity own, float wpn, float doreduce, vector org, vecto
 {SELFPARAM();
        float thisammo, i;
        string s;
-       var .int ammotype = (get_weaponinfo(wpn)).ammo_field;
+       Weapon info = Weapons_from(wpn);
+       var .int ammotype = info.ammo_field;
 
-       entity wep = spawn();
+       entity wep = new(droppedweapon);
 
        setorigin(wep, org);
-       wep.classname = "droppedweapon";
        wep.velocity = velo;
        wep.owner = wep.enemy = own;
        wep.flags |= FL_TOSSED;
        wep.colormap = own.colormap;
 
-       W_DropEvent(WR_DROP,own,wpn,wep);
+       W_DropEvent(wr_drop,own,wpn,wep);
 
-       if(WepSet_FromWeapon(wpn) & WEPSET_SUPERWEAPONS)
+       if(WepSet_FromWeapon(Weapons_from(wpn)) & WEPSET_SUPERWEAPONS)
        {
                if(own.items & IT_UNLIMITED_SUPERWEAPONS)
                {
@@ -56,9 +57,10 @@ string W_ThrowNewWeapon(entity own, float wpn, float doreduce, vector org, vecto
                {
                        float superweapons = 1;
                        for(i = WEP_FIRST; i <= WEP_LAST; ++i)
-                               if(WepSet_FromWeapon(i) & WEPSET_SUPERWEAPONS)
-                                       if(own.weapons & WepSet_FromWeapon(i))
-                                               ++superweapons;
+                       {
+                               WepSet set = WepSet_FromWeapon(Weapons_from(i));
+                               if ((set & WEPSET_SUPERWEAPONS) && (own.weapons & set)) ++superweapons;
+                       }
                        if(superweapons <= 1)
                        {
                                wep.superweapons_finished = own.superweapons_finished;
@@ -74,7 +76,7 @@ string W_ThrowNewWeapon(entity own, float wpn, float doreduce, vector org, vecto
                }
        }
 
-       WITH(entity, self, wep, weapon_defaultspawnfunc(wpn));
+       weapon_defaultspawnfunc(wep, info);
        if(startitem_failed)
                return string_null;
        wep.glowmod = own.weaponentity_glowmod;
@@ -132,58 +134,56 @@ string W_ThrowNewWeapon(entity own, float wpn, float doreduce, vector org, vecto
        }
 }
 
-float W_IsWeaponThrowable(float w)
+bool W_IsWeaponThrowable(bool w)
 {
+       if (MUTATOR_CALLHOOK(ForbidDropCurrentWeapon))
+               return false;
        if (!autocvar_g_pickup_items)
-               return 0;
+               return false;
        if (g_weaponarena)
                return 0;
        if (g_cts)
                return 0;
-       if (g_nexball && w == WEP_MORTAR.m_id)
-               return 0;
-    if(w == 0)
-        return 0;
+    if(w == WEP_Null.m_id)
+        return false;
 
        #if 0
-       if(start_weapons & WepSet_FromWeapon(w))
+       if(start_weapons & WepSet_FromWeapon(Weapons_from(w)))
        {
                // start weapons that take no ammo can't be dropped (this prevents dropping the laser, as long as it continues to use no ammo)
                if(start_items & IT_UNLIMITED_WEAPON_AMMO)
-                       return 0;
-               if((get_weaponinfo(w)).ammo_field == ammo_none)
-                       return 0;
+                       return false;
+               if((Weapons_from(w)).ammo_field == ammo_none)
+                       return false;
        }
-       return 1;
+       return true;
        #else
-       return (get_weaponinfo(w)).weaponthrowable;
+       return (Weapons_from(w)).weaponthrowable;
        #endif
 }
 
 // toss current weapon
 void W_ThrowWeapon(vector velo, vector delta, float doreduce)
 {SELFPARAM();
-       float w;
-       string a;
-
-       w = self.weapon;
-       if (w == 0)
+       int w = self.weapon;
+       if (w == WEP_Null.m_id)
                return; // just in case
        if(MUTATOR_CALLHOOK(ForbidThrowCurrentWeapon))
                return;
        if(!autocvar_g_weapon_throwable)
                return;
-       if(self.weaponentity.state != WS_READY)
+       .entity weaponentity = weaponentities[0]; // TODO: unhardcode
+       if(self.(weaponentity).state != WS_READY)
                return;
        if(!W_IsWeaponThrowable(w))
                return;
 
-       if(!(self.weapons & WepSet_FromWeapon(w)))
-               return;
-       self.weapons &= ~WepSet_FromWeapon(w);
+       WepSet set = WepSet_FromWeapon(Weapons_from(w));
+       if(!(self.weapons & set)) return;
+       self.weapons &= ~set;
 
        W_SwitchWeapon_Force(self, w_getbestweapon(self));
-       a = W_ThrowNewWeapon(self, w, doreduce, self.origin + delta, velo);
+       string a = W_ThrowNewWeapon(self, w, doreduce, self.origin + delta, velo);
 
        if(!a) return;
        Send_Notification(NOTIF_ONE, self, MSG_MULTI, ITEM_WEAPON_DROP, a, w);
@@ -191,7 +191,7 @@ void W_ThrowWeapon(vector velo, vector delta, float doreduce)
 
 void SpawnThrownWeapon(vector org, float w)
 {SELFPARAM();
-       if(self.weapons & WepSet_FromWeapon(self.weapon))
+       if(self.weapons & WepSet_FromWeapon(Weapons_from(self.weapon)))
                if(W_IsWeaponThrowable(self.weapon))
                        W_ThrowNewWeapon(self, self.weapon, false, org, randomvec() * 125 + '0 0 200');
 }