]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/server/t_items.qc
Weapons: store switchweapon as direct weapon reference
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / t_items.qc
index 3fb6998e9ce43fd3d1640e2376bf93410591a976..2511c69dcad69696cf46686ded6ac3692cdd1871 100644 (file)
@@ -491,7 +491,7 @@ void Item_RespawnCountdown ()
                        MUTATOR_CALLHOOK(Item_RespawnCountdown, string_null, '0 0 0');
                        do {
                                {
-                                       entity wi = get_weaponinfo(self.weapon);
+                                       entity wi = Weapons_from(self.weapon);
                                        if (wi.m_id) {
                                                entity wp = WaypointSprite_Spawn(WP_Weapon, 0, 0, self, '0 0 64', world, 0, self, waypointsprite_attached, true, RADARICON_Weapon);
                                                wp.wp_extra = wi.m_id;
@@ -642,10 +642,10 @@ float Item_GiveTo(entity item, entity player)
        // if the player is using their best weapon before items are given, they
        // probably want to switch to an even better weapon after items are given
        if (player.autoswitch)
-       if (player.switchweapon == w_getbestweapon(player))
+       if (PS(player).m_switchweapon == w_getbestweapon(player))
                _switchweapon = true;
 
-       if (!(player.weapons & WepSet_FromWeapon(player.switchweapon)))
+       if (!(player.weapons & WepSet_FromWeapon(PS(player).m_switchweapon)))
                _switchweapon = true;
 
        pickedup |= Item_GiveAmmoTo(item, player, ammo_fuel, g_pickup_fuel_max, ITEM_MODE_FUEL);
@@ -667,7 +667,7 @@ float Item_GiveTo(entity item, entity player)
                {
                        pickedup = true;
                        for(i = WEP_FIRST; i <= WEP_LAST; ++i)
-                       if(it & WepSet_FromWeapon(i))
+                       if(it & WepSet_FromWeapon(Weapons_from(i)))
                        {
                                W_DropEvent(wr_pickup, player, i, item);
                                W_GiveWeapon(player, i);
@@ -710,12 +710,12 @@ float Item_GiveTo(entity item, entity player)
        // crude hack to enforce switching weapons
        if(g_cts && item.itemdef.instanceOfWeaponPickup)
        {
-               W_SwitchWeapon_Force(player, item.weapon);
+               W_SwitchWeapon_Force(player, Weapons_from(item.weapon));
                return 1;
        }
 
        if (_switchweapon)
-               if (player.switchweapon != w_getbestweapon(player))
+               if (PS(player).m_switchweapon != w_getbestweapon(player))
                        W_SwitchWeapon_Force(player, w_getbestweapon(player));
 
        return 1;
@@ -929,7 +929,7 @@ float commodity_pickupevalfunc(entity player, entity item)
        // Detect needed ammo
        for(i = WEP_FIRST; i <= WEP_LAST ; ++i)
        {
-               wi = get_weaponinfo(i);
+               wi = Weapons_from(i);
 
                if (!(player.weapons & (wi.m_wepset)))
                        continue;
@@ -1023,7 +1023,7 @@ void _StartItem(entity this, entity def, float defaultrespawntime, float default
        }
 
        if(weaponid)
-               this.weapons = WepSet_FromWeapon(weaponid);
+               this.weapons = WepSet_FromWeapon(Weapons_from(weaponid));
 
        this.flags = FL_ITEM | itemflags;
 
@@ -1126,7 +1126,7 @@ void _StartItem(entity this, entity def, float defaultrespawntime, float default
                        this.is_item = true;
                }
 
-               weaponsInMap |= WepSet_FromWeapon(weaponid);
+               weaponsInMap |= WepSet_FromWeapon(Weapons_from(weaponid));
 
                precache_model(this.model);
                precache_sound(this.item_pickupsound);
@@ -1208,10 +1208,10 @@ void StartItem(entity this, GameItem def)
 
 spawnfunc(item_rockets)
 {
-       if(!self.ammo_rockets)
-               self.ammo_rockets = g_pickup_rockets;
-       if(!self.pickup_anyway)
-               self.pickup_anyway = g_pickup_ammo_anyway;
+       if(!this.ammo_rockets)
+               this.ammo_rockets = g_pickup_rockets;
+       if(!this.pickup_anyway)
+               this.pickup_anyway = g_pickup_ammo_anyway;
     StartItem(this, ITEM_Rockets);
 }
 
@@ -1219,7 +1219,7 @@ spawnfunc(item_bullets)
 {
        if(!weaponswapping)
        if(autocvar_sv_q3acompat_machineshotgunswap)
-       if(self.classname != "droppedweapon")
+       if(this.classname != "droppedweapon")
        {
                weaponswapping = true;
                spawnfunc_item_shells(this);
@@ -1227,28 +1227,28 @@ spawnfunc(item_bullets)
                return;
        }
 
-       if(!self.ammo_nails)
-               self.ammo_nails = g_pickup_nails;
-       if(!self.pickup_anyway)
-               self.pickup_anyway = g_pickup_ammo_anyway;
+       if(!this.ammo_nails)
+               this.ammo_nails = g_pickup_nails;
+       if(!this.pickup_anyway)
+               this.pickup_anyway = g_pickup_ammo_anyway;
     StartItem(this, ITEM_Bullets);
 }
 
 spawnfunc(item_cells)
 {
-       if(!self.ammo_cells)
-               self.ammo_cells = g_pickup_cells;
-       if(!self.pickup_anyway)
-               self.pickup_anyway = g_pickup_ammo_anyway;
+       if(!this.ammo_cells)
+               this.ammo_cells = g_pickup_cells;
+       if(!this.pickup_anyway)
+               this.pickup_anyway = g_pickup_ammo_anyway;
        StartItem(this, ITEM_Cells);
 }
 
 spawnfunc(item_plasma)
 {
-       if(!self.ammo_plasma)
-               self.ammo_plasma = g_pickup_plasma;
-       if(!self.pickup_anyway)
-               self.pickup_anyway = g_pickup_ammo_anyway;
+       if(!this.ammo_plasma)
+               this.ammo_plasma = g_pickup_plasma;
+       if(!this.pickup_anyway)
+               this.pickup_anyway = g_pickup_ammo_anyway;
        StartItem(this, ITEM_Plasma);
 }
 
@@ -1256,7 +1256,7 @@ spawnfunc(item_shells)
 {
        if(!weaponswapping)
        if(autocvar_sv_q3acompat_machineshotgunswap)
-       if(self.classname != "droppedweapon")
+       if(this.classname != "droppedweapon")
        {
                weaponswapping = true;
                spawnfunc_item_bullets(this);
@@ -1264,98 +1264,98 @@ spawnfunc(item_shells)
                return;
        }
 
-       if(!self.ammo_shells)
-               self.ammo_shells = g_pickup_shells;
-       if(!self.pickup_anyway)
-               self.pickup_anyway = g_pickup_ammo_anyway;
+       if(!this.ammo_shells)
+               this.ammo_shells = g_pickup_shells;
+       if(!this.pickup_anyway)
+               this.pickup_anyway = g_pickup_ammo_anyway;
        StartItem(this, ITEM_Shells);
 }
 
 spawnfunc(item_armor_small)
 {
-       if(!self.armorvalue)
-               self.armorvalue = g_pickup_armorsmall;
-       if(!self.max_armorvalue)
-               self.max_armorvalue = g_pickup_armorsmall_max;
-       if(!self.pickup_anyway)
-               self.pickup_anyway = g_pickup_armorsmall_anyway;
+       if(!this.armorvalue)
+               this.armorvalue = g_pickup_armorsmall;
+       if(!this.max_armorvalue)
+               this.max_armorvalue = g_pickup_armorsmall_max;
+       if(!this.pickup_anyway)
+               this.pickup_anyway = g_pickup_armorsmall_anyway;
        StartItem(this, ITEM_ArmorSmall);
 }
 
 spawnfunc(item_armor_medium)
 {
-       if(!self.armorvalue)
-               self.armorvalue = g_pickup_armormedium;
-       if(!self.max_armorvalue)
-               self.max_armorvalue = g_pickup_armormedium_max;
-       if(!self.pickup_anyway)
-               self.pickup_anyway = g_pickup_armormedium_anyway;
+       if(!this.armorvalue)
+               this.armorvalue = g_pickup_armormedium;
+       if(!this.max_armorvalue)
+               this.max_armorvalue = g_pickup_armormedium_max;
+       if(!this.pickup_anyway)
+               this.pickup_anyway = g_pickup_armormedium_anyway;
        StartItem(this, ITEM_ArmorMedium);
 }
 
 spawnfunc(item_armor_big)
 {
-       if(!self.armorvalue)
-               self.armorvalue = g_pickup_armorbig;
-       if(!self.max_armorvalue)
-               self.max_armorvalue = g_pickup_armorbig_max;
-       if(!self.pickup_anyway)
-               self.pickup_anyway = g_pickup_armorbig_anyway;
+       if(!this.armorvalue)
+               this.armorvalue = g_pickup_armorbig;
+       if(!this.max_armorvalue)
+               this.max_armorvalue = g_pickup_armorbig_max;
+       if(!this.pickup_anyway)
+               this.pickup_anyway = g_pickup_armorbig_anyway;
        StartItem(this, ITEM_ArmorLarge);
 }
 
 spawnfunc(item_armor_large)
 {
-       if(!self.armorvalue)
-               self.armorvalue = g_pickup_armorlarge;
-       if(!self.max_armorvalue)
-               self.max_armorvalue = g_pickup_armorlarge_max;
-       if(!self.pickup_anyway)
-               self.pickup_anyway = g_pickup_armorlarge_anyway;
+       if(!this.armorvalue)
+               this.armorvalue = g_pickup_armorlarge;
+       if(!this.max_armorvalue)
+               this.max_armorvalue = g_pickup_armorlarge_max;
+       if(!this.pickup_anyway)
+               this.pickup_anyway = g_pickup_armorlarge_anyway;
        StartItem(this, ITEM_ArmorMega);
 }
 
 spawnfunc(item_health_small)
 {
-       if(!self.max_health)
-               self.max_health = g_pickup_healthsmall_max;
-       if(!self.health)
-               self.health = g_pickup_healthsmall;
-       if(!self.pickup_anyway)
-               self.pickup_anyway = g_pickup_healthsmall_anyway;
+       if(!this.max_health)
+               this.max_health = g_pickup_healthsmall_max;
+       if(!this.health)
+               this.health = g_pickup_healthsmall;
+       if(!this.pickup_anyway)
+               this.pickup_anyway = g_pickup_healthsmall_anyway;
        StartItem(this, ITEM_HealthSmall);
 }
 
 spawnfunc(item_health_medium)
 {
-       if(!self.max_health)
-               self.max_health = g_pickup_healthmedium_max;
-       if(!self.health)
-               self.health = g_pickup_healthmedium;
-       if(!self.pickup_anyway)
-               self.pickup_anyway = g_pickup_healthmedium_anyway;
+       if(!this.max_health)
+               this.max_health = g_pickup_healthmedium_max;
+       if(!this.health)
+               this.health = g_pickup_healthmedium;
+       if(!this.pickup_anyway)
+               this.pickup_anyway = g_pickup_healthmedium_anyway;
     StartItem(this, ITEM_HealthMedium);
 }
 
 spawnfunc(item_health_large)
 {
-       if(!self.max_health)
-               self.max_health = g_pickup_healthlarge_max;
-       if(!self.health)
-               self.health = g_pickup_healthlarge;
-       if(!self.pickup_anyway)
-               self.pickup_anyway = g_pickup_healthlarge_anyway;
+       if(!this.max_health)
+               this.max_health = g_pickup_healthlarge_max;
+       if(!this.health)
+               this.health = g_pickup_healthlarge;
+       if(!this.pickup_anyway)
+               this.pickup_anyway = g_pickup_healthlarge_anyway;
        StartItem(this, ITEM_HealthLarge);
 }
 
 spawnfunc(item_health_mega)
 {
-    if(!self.max_health)
-        self.max_health = g_pickup_healthmega_max;
-    if(!self.health)
-        self.health = g_pickup_healthmega;
-    if(!self.pickup_anyway)
-        self.pickup_anyway = g_pickup_healthmega_anyway;
+    if(!this.max_health)
+        this.max_health = g_pickup_healthmega_max;
+    if(!this.health)
+        this.health = g_pickup_healthmega;
+    if(!this.pickup_anyway)
+        this.pickup_anyway = g_pickup_healthmega_anyway;
     StartItem(this, ITEM_HealthMega);
 }
 
@@ -1368,20 +1368,20 @@ spawnfunc(item_health100) { spawnfunc_item_health_mega(this); }
 
 spawnfunc(item_strength)
 {
-               if(!self.strength_finished)
-                       self.strength_finished = autocvar_g_balance_powerup_strength_time;
+               if(!this.strength_finished)
+                       this.strength_finished = autocvar_g_balance_powerup_strength_time;
                StartItem(this, ITEM_Strength);
 }
 
 spawnfunc(item_invincible)
 {
-               if(!self.invincible_finished)
-                       self.invincible_finished = autocvar_g_balance_powerup_invincible_time;
+               if(!this.invincible_finished)
+                       this.invincible_finished = autocvar_g_balance_powerup_invincible_time;
                StartItem(this, ITEM_Shield);
 }
 
 // compatibility:
-spawnfunc(item_quad) { self.classname = "item_strength";spawnfunc_item_strength(this);}
+spawnfunc(item_quad) { this.classname = "item_strength";spawnfunc_item_strength(this);}
 
 void target_items_use()
 {SELFPARAM();
@@ -1442,13 +1442,13 @@ spawnfunc(target_items)
                        {
                                for(j = WEP_FIRST; j <= WEP_LAST; ++j)
                                {
-                                       e = get_weaponinfo(j);
+                                       e = Weapons_from(j);
                                        s = W_UndeprecateName(argv(i));
                                        if(s == e.netname)
                                        {
                                                self.weapons |= (e.m_wepset);
                                                if(self.spawnflags == 0 || self.spawnflags == 2) {
-                                                       Weapon w = get_weaponinfo(e.weapon);
+                                                       Weapon w = Weapons_from(e.weapon);
                                                        w.wr_init(w);
                                                }
                                                break;
@@ -1504,7 +1504,7 @@ spawnfunc(target_items)
                if(self.armorvalue != 0) self.netname = sprintf("%s %s%d %s", self.netname, valueprefix, max(0, self.health), "armor");
                for(j = WEP_FIRST; j <= WEP_LAST; ++j)
                {
-                       e = get_weaponinfo(j);
+                       e = Weapons_from(j);
                        if(e.weapon)
                                self.netname = sprintf("%s %s%d %s", self.netname, itemprefix, !!(self.weapons & (e.m_wepset)), e.netname);
                }
@@ -1517,10 +1517,10 @@ spawnfunc(target_items)
        {
                for(j = WEP_FIRST; j <= WEP_LAST; ++j)
                {
-                       e = get_weaponinfo(j);
+                       e = Weapons_from(j);
                        if(argv(i) == e.netname)
                        {
-                               Weapon w = get_weaponinfo(e.weapon);
+                               Weapon w = Weapons_from(e.weapon);
                                w.wr_init(w);
                                break;
                        }
@@ -1530,10 +1530,10 @@ spawnfunc(target_items)
 
 spawnfunc(item_fuel)
 {
-       if(!self.ammo_fuel)
-               self.ammo_fuel = g_pickup_fuel;
-       if(!self.pickup_anyway)
-               self.pickup_anyway = g_pickup_ammo_anyway;
+       if(!this.ammo_fuel)
+               this.ammo_fuel = g_pickup_fuel;
+       if(!this.pickup_anyway)
+               this.pickup_anyway = g_pickup_ammo_anyway;
        StartItem(this, ITEM_JetpackFuel);
 }
 
@@ -1549,8 +1549,8 @@ spawnfunc(item_fuel_regen)
 
 spawnfunc(item_jetpack)
 {
-       if(!self.ammo_fuel)
-               self.ammo_fuel = g_pickup_fuel_jetpack;
+       if(!this.ammo_fuel)
+               this.ammo_fuel = g_pickup_fuel_jetpack;
        if(start_items & ITEM_Jetpack.m_itemid)
        {
                spawnfunc_item_fuel(this);
@@ -1562,7 +1562,7 @@ spawnfunc(item_jetpack)
 float GiveWeapon(entity e, float wpn, float op, float val)
 {
        WepSet v0, v1;
-       WepSet s = WepSet_FromWeapon(wpn);
+       WepSet s = WepSet_FromWeapon(Weapons_from(wpn));
        v0 = (e.weapons & s);
        switch(op)
        {
@@ -1627,7 +1627,7 @@ float GiveItems(entity e, float beginarg, float endarg)
 
        _switchweapon = false;
        if (e.autoswitch)
-               if (e.switchweapon == w_getbestweapon(e))
+               if (PS(e).m_switchweapon == w_getbestweapon(e))
                        _switchweapon = true;
 
        e.strength_finished = max(0, e.strength_finished - time);
@@ -1688,7 +1688,7 @@ float GiveItems(entity e, float beginarg, float endarg)
                        case "allweapons":
                                for(j = WEP_FIRST; j <= WEP_LAST; ++j)
                                {
-                                       wi = get_weaponinfo(j);
+                                       wi = Weapons_from(j);
                                        if(wi.weapon)
                                                if (!(wi.spawnflags & WEP_FLAG_MUTATORBLOCKED))
                                                        got += GiveWeapon(e, j, op, val);
@@ -1753,7 +1753,7 @@ float GiveItems(entity e, float beginarg, float endarg)
                        default:
                                for(j = WEP_FIRST; j <= WEP_LAST; ++j)
                                {
-                                       wi = get_weaponinfo(j);
+                                       wi = Weapons_from(j);
                                        if(cmd == wi.netname)
                                        {
                                                got += GiveWeapon(e, j, op, val);
@@ -1774,13 +1774,13 @@ float GiveItems(entity e, float beginarg, float endarg)
        POSTGIVE_BIT(e, items, ITEM_Jetpack.m_itemid, SND(ITEMPICKUP), string_null);
        for(j = WEP_FIRST; j <= WEP_LAST; ++j)
        {
-               wi = get_weaponinfo(j);
+               wi = Weapons_from(j);
                if(wi.weapon)
                {
-                       POSTGIVE_WEAPON(e, j, SND(WEAPONPICKUP), string_null);
+                       POSTGIVE_WEAPON(e, Weapons_from(j), SND(WEAPONPICKUP), string_null);
                        if (!(save_weapons & (wi.m_wepset)))
                                if(e.weapons & (wi.m_wepset)) {
-                                       Weapon w = get_weaponinfo(wi.weapon);
+                                       Weapon w = Weapons_from(wi.weapon);
                                        w.wr_init(w);
                                }
                }
@@ -1813,7 +1813,7 @@ float GiveItems(entity e, float beginarg, float endarg)
        else
                e.superweapons_finished += time;
 
-       if (!(e.weapons & WepSet_FromWeapon(e.switchweapon)))
+       if (!(e.weapons & WepSet_FromWeapon(PS(e).m_switchweapon)))
                _switchweapon = true;
        if(_switchweapon)
                W_SwitchWeapon_Force(e, w_getbestweapon(e));