]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Weapons: cache WepSet
authorTimePath <andrew.hardaker1995@gmail.com>
Mon, 23 Nov 2015 09:18:16 +0000 (20:18 +1100)
committerTimePath <andrew.hardaker1995@gmail.com>
Mon, 23 Nov 2015 09:18:16 +0000 (20:18 +1100)
13 files changed:
qcsrc/client/hud/panel/weapons.qc
qcsrc/client/scoreboard.qc
qcsrc/client/view.qc
qcsrc/common/mutators/mutator/new_toys/new_toys.qc
qcsrc/common/mutators/mutator/nix/nix.qc
qcsrc/common/weapons/all.qc
qcsrc/common/weapons/all.qh
qcsrc/server/bot/havocbot/havocbot.qc
qcsrc/server/g_damage.qc
qcsrc/server/miscfunctions.qc
qcsrc/server/t_items.qc
qcsrc/server/weapons/selection.qc
qcsrc/server/weapons/throwing.qc

index 4d1d7227b51cf450d5ec406cdd1c49cd69bd1506..818663242adf4098143b4ce33a9eb8ddd362fcfb 100644 (file)
@@ -141,9 +141,8 @@ void HUD_Weapons()
                int nHidden = 0;
                WepSet weapons_stat = WepSet_GetFromStat();
                for (int i = WEP_FIRST; i <= WEP_LAST; ++i) {
-                       WepSet weapons_wep = WepSet_FromWeapon(i);
-                       if (weapons_stat & weapons_wep) continue;
                        Weapon w = get_weaponinfo(i);
+                       if (weapons_stat & w.m_wepset) continue;
                        if (w.spawnflags & WEP_FLAG_MUTATORBLOCKED) nHidden += 1;
                }
                vector table_size = HUD_GetTableSize_BestItemAR((Weapons_COUNT - 1) - nHidden, padded_panel_size, aspect);
index 681183594f2efdc550a08c0147698e1b6cadb871..288c52566991c5484df7267886397067c33ca728 100644 (file)
@@ -1002,12 +1002,14 @@ vector HUD_DrawScoreboardAccuracyStats(vector pos, vector rgb, vector bg_size)
        float initial_posx = pos.x;
        int disownedcnt = 0;
        for (int i = WEP_FIRST; i <= WEP_LAST; ++i) {
-               setself(get_weaponinfo(i));
+               Weapon e = get_weaponinfo(i);
+               setself(e);
                if (!self.weapon) continue;
 
                int weapon_stats = weapon_accuracy[i - WEP_FIRST];
 
-               if (weapon_stats < 0 && !(weapons_stat & WepSet_FromWeapon(i) || weapons_inmap & WepSet_FromWeapon(i)))
+               WepSet set = e.m_wepset;
+               if (weapon_stats < 0 && !(weapons_stat & set || weapons_inmap & set))
                        ++disownedcnt;
        }
 
@@ -1064,11 +1066,13 @@ vector HUD_DrawScoreboardAccuracyStats(vector pos, vector rgb, vector bg_size)
 
        int column = 0;
        for (int i = WEP_FIRST; i <= WEP_LAST; ++i) {
-               setself(get_weaponinfo(i));
+               Weapon e = get_weaponinfo(i);
+               setself(e);
                if (!self.weapon) continue;
                int weapon_stats = weapon_accuracy[i - WEP_FIRST];
 
-               if (weapon_stats < 0 && !(weapons_stat & WepSet_FromWeapon(i) || weapons_inmap & WepSet_FromWeapon(i)))
+               WepSet set = e.m_wepset;
+               if (weapon_stats < 0 && !(weapons_stat & set || weapons_inmap & set))
                        continue;
 
                float weapon_alpha;
index f7474de586f01dfd64d47b4cea8f55e5390c4e20..0f1a43e2faa21ec3a701a8266a407283f6148396 100644 (file)
@@ -443,7 +443,7 @@ bool WantEventchase()
                        return true;
                if(MUTATOR_CALLHOOK(WantEventchase, self))
                        return true;
-               if(autocvar_cl_eventchase_nexball && gametype == MAPINFO_TYPE_NEXBALL && !(WepSet_GetFromStat() & WepSet_FromWeapon(WEP_NEXBALL.m_id)))
+               if(autocvar_cl_eventchase_nexball && gametype == MAPINFO_TYPE_NEXBALL && !(WepSet_GetFromStat() & WEPSET(NEXBALL)))
                        return true;
                if(autocvar_cl_eventchase_death && (getstati(STAT_HEALTH) <= 0))
                {
index 78904ffae78d75a07f963aa8d33b5fa2e354f0f3..5235e58e62df2c0faac3de32a2550cb51c1c11cc 100644 (file)
@@ -174,15 +174,18 @@ MUTATOR_HOOKFUNCTION(nt, SetStartItems)
 
                n = tokenize_console(nt_GetReplacement(e.netname, autocvar_g_new_toys_autoreplace));
 
-               for(j = 0; j < n; ++j)
-                       for(k = WEP_FIRST; k <= WEP_LAST; ++k)
-                               if(get_weaponinfo(k).netname == argv(j))
+               for (j = 0; j < n; ++j)
+                       for (k = WEP_FIRST; k <= WEP_LAST; ++k)
+                       {
+                               Weapon w = get_weaponinfo(k);
+                               if (w.netname == argv(j))
                                {
-                                       if(start_weapons & WepSet_FromWeapon(i))
-                                               newdefault |= WepSet_FromWeapon(k);
-                                       if(warmup_start_weapons & WepSet_FromWeapon(i))
-                                               warmup_newdefault |= WepSet_FromWeapon(k);
+                                       WepSet seti = e.m_wepset;
+                                       WepSet setk = w.m_wepset;
+                                       if (start_weapons & seti) newdefault |= setk;
+                                       if (warmup_start_weapons & seti) warmup_newdefault |= setk;
                                }
+                       }
        }
 
        newdefault &= start_weapons_defaultmask;
index 1a8089ca6d2b50152b7f2affdd386eff15817884..73b08bce8be60c72eec2e5d062df2d218c832e16 100644 (file)
@@ -83,7 +83,7 @@ bool NIX_CanChooseWeapon(int wpn)
                return false;
        if(g_weaponarena)
        {
-               if(!(g_weaponarena_weapons & WepSet_FromWeapon(wpn)))
+               if(!(g_weaponarena_weapons & e.m_wepset))
                        return false;
        }
        else
@@ -166,8 +166,7 @@ void NIX_GiveCurrentWeapon()
                else
                        Send_Notification(NOTIF_ONE_ONLY, self, MSG_CENTER, CENTER_NIX_NEWWEAPON, nix_weapon);
 
-               Weapon w = get_weaponinfo(nix_weapon);
-               w.wr_resetplayer(w);
+               e.wr_resetplayer(e);
 
                // all weapons must be fully loaded when we spawn
                if(e.spawnflags & WEP_FLAG_RELOADABLE) // prevent accessing undefined cvars
@@ -209,7 +208,7 @@ void NIX_GiveCurrentWeapon()
        self.weapons = '0 0 0';
        if(g_nix_with_blaster)
                self.weapons |= WEPSET(BLASTER);
-       self.weapons |= WepSet_FromWeapon(nix_weapon);
+       self.weapons |= e.m_wepset;
 
        if(self.switchweapon != nix_weapon)
                if(!client_hasweapon(self, self.switchweapon, true, false))
index 452438add97a3c87fa202cc55f9074728cc2717b..fcadd2d43432cc7d2cc996cbb896483d5e1b2aa0 100644 (file)
@@ -53,7 +53,7 @@
 
 // WEAPON PLUGIN SYSTEM
 
-WepSet WepSet_FromWeapon(int a) {
+WepSet _WepSet_FromWeapon(int a) {
        a -= WEP_FIRST;
        if (Weapons_MAX > 24)
        if (a >= 24) {
index 93df313c05f6e75bd38a4d777d6dbad8799fb7bb..8d62426daf61ccf15ccded49523d5d50499c559c 100644 (file)
@@ -7,8 +7,6 @@
 
 // weapon sets
 typedef vector WepSet;
-#define WEPSET(id) WepSet_FromWeapon(WEP_##id.m_id)
-WepSet WepSet_FromWeapon(int a);
 #ifdef SVQC
 void WepSet_AddStat();
 void WepSet_AddStat_InMap();
@@ -40,6 +38,14 @@ REGISTRY(Weapons, 72) // Increase as needed. Can be up to 72.
 REGISTER_REGISTRY(Weapons)
 STATIC_INIT(WeaponPickup) { FOREACH(Weapons, true, LAMBDA(it.m_pickup = NEW(WeaponPickup, it))); }
 
+.WepSet m_wepset;
+#define WEPSET(id) (WEP_##id.m_wepset)
+#define WepSet_FromWeapon(i) (Weapons_from(i).m_wepset)
+WepSet _WepSet_FromWeapon(int i);
+STATIC_INIT(WepSets)
+{
+    FOREACH(Weapons, true, LAMBDA(it.m_wepset = _WepSet_FromWeapon(it.m_id)));
+}
 
 GENERIC_COMMAND(dumpweapons, "Dump all weapons into weapons_dump.txt") // WEAPONTODO: make this work with other progs than just server
 {
@@ -147,7 +153,7 @@ STATIC_INIT(register_weapons_done)
 {
     FOREACH(Weapons, true, LAMBDA(
         it.m_id = i;
-        WepSet set = WepSet_FromWeapon(it.m_id);
+        WepSet set = it.m_wepset;
         WEPSET_ALL |= set;
         if ((it.spawnflags) & WEP_FLAG_SUPERWEAPON) WEPSET_SUPERWEAPONS |= set;
         it.weapon = it.m_id;
index 696de21dcad230f8f95a42ecd9fe49df82d5b479..dd0109ce2fba337275eec28b6eebf69ce9a2a74d 100644 (file)
@@ -174,7 +174,7 @@ void havocbot_ai()
                        for (int i = WEP_FIRST; i <= WEP_LAST; ++i)
                        {
                                entity e = get_weaponinfo(i);
-                               if ((self.weapons & WepSet_FromWeapon(i)) && (e.spawnflags & WEP_FLAG_RELOADABLE) && (self.weapon_load[i] < e.reloading_ammo))
+                               if ((self.weapons & (e.m_wepset)) && (e.spawnflags & WEP_FLAG_RELOADABLE) && (self.weapon_load[i] < e.reloading_ammo))
                                        self.switchweapon = i;
                        }
                }
index 87c28825ac4dfd9f553c07d6b5363e7b03dbf356..dc306eee097ee18631039db4d66ae5104ec74081 100644 (file)
@@ -61,10 +61,8 @@ void GiveFrags (entity attacker, entity targ, float f, int deathtype)
        {
                // after a frag, exchange the current weapon (or the culprit, if detectable) by a new random weapon
                Weapon culprit = DEATH_WEAPONOF(deathtype);
-               if(!culprit)
-                       culprit = get_weaponinfo(attacker.weapon);
-               else if(!(attacker.weapons & WepSet_FromWeapon(culprit.m_id)))
-                       culprit = get_weaponinfo(attacker.weapon);
+               if(!culprit) culprit = get_weaponinfo(attacker.weapon);
+               else if(!(attacker.weapons & (culprit.m_wepset))) culprit = get_weaponinfo(attacker.weapon);
 
                if(g_weaponarena_random_with_blaster && culprit == WEP_BLASTER) // WEAPONTODO: Shouldn't this be in a mutator?
                {
@@ -84,7 +82,7 @@ void GiveFrags (entity attacker, entity targ, float f, int deathtype)
 
                        // all others (including the culprit): remove
                        GiveFrags_randomweapons.weapons &= ~attacker.weapons;
-                       GiveFrags_randomweapons.weapons &= ~WepSet_FromWeapon(culprit.m_id);
+                       GiveFrags_randomweapons.weapons &= ~(culprit.m_wepset);
 
                        // among the remaining ones, choose one by random
                        W_RandomWeapons(GiveFrags_randomweapons, 1);
@@ -92,7 +90,7 @@ void GiveFrags (entity attacker, entity targ, float f, int deathtype)
                        if(GiveFrags_randomweapons.weapons)
                        {
                                attacker.weapons |= GiveFrags_randomweapons.weapons;
-                               attacker.weapons &= ~WepSet_FromWeapon(culprit.m_id);
+                               attacker.weapons &= ~(culprit.m_wepset);
                        }
                }
 
index f03b2e7ceb15dbac4f831b5839a3c97116141055..ddf10818fe520e05b9aade437b41170e3d171781 100644 (file)
@@ -528,7 +528,7 @@ void readplayerstartcvars()
                {
                        e = get_weaponinfo(j);
                        if (!(e.spawnflags & WEP_FLAG_MUTATORBLOCKED))
-                               g_weaponarena_weapons |= WepSet_FromWeapon(j);
+                               g_weaponarena_weapons |= (e.m_wepset);
                }
        }
        else if (s == "most")
@@ -540,7 +540,7 @@ void readplayerstartcvars()
                        e = get_weaponinfo(j);
                        if (!(e.spawnflags & WEP_FLAG_MUTATORBLOCKED))
                                if (e.spawnflags & WEP_FLAG_NORMAL)
-                                       g_weaponarena_weapons |= WepSet_FromWeapon(j);
+                                       g_weaponarena_weapons |= (e.m_wepset);
                }
        }
        else if (s == "none")
@@ -561,7 +561,7 @@ void readplayerstartcvars()
                                e = get_weaponinfo(j);
                                if (e.netname == s)
                                {
-                                       g_weaponarena_weapons |= WepSet_FromWeapon(j);
+                                       g_weaponarena_weapons |= (e.m_wepset);
                                        g_weaponarena_list = strcat(g_weaponarena_list, e.m_name, " & ");
                                        break;
                                }
@@ -592,12 +592,13 @@ void readplayerstartcvars()
                {
                        e = get_weaponinfo(i);
                        int w = want_weapon(e, false);
+                       WepSet s = e.m_wepset;
                        if(w & 1)
-                               start_weapons |= WepSet_FromWeapon(i);
+                               start_weapons |= s;
                        if(w & 2)
-                               start_weapons_default |= WepSet_FromWeapon(i);
+                               start_weapons_default |= s;
                        if(w & 4)
-                               start_weapons_defaultmask |= WepSet_FromWeapon(i);
+                               start_weapons_defaultmask |= s;
                }
        }
 
@@ -654,12 +655,13 @@ void readplayerstartcvars()
                        {
                                e = get_weaponinfo(i);
                                int w = want_weapon(e, g_warmup_allguns);
+                               WepSet s = (e.m_wepset);
                                if(w & 1)
-                                       warmup_start_weapons |= WepSet_FromWeapon(i);
+                                       warmup_start_weapons |= s;
                                if(w & 2)
-                                       warmup_start_weapons_default |= WepSet_FromWeapon(i);
+                                       warmup_start_weapons_default |= s;
                                if(w & 4)
-                                       warmup_start_weapons_defaultmask |= WepSet_FromWeapon(i);
+                                       warmup_start_weapons_defaultmask |= s;
                        }
                }
        }
@@ -682,9 +684,8 @@ void readplayerstartcvars()
        for (i = WEP_FIRST; i <= WEP_LAST; ++i)
        {
                e = get_weaponinfo(i);
-               if(precache_weapons & WepSet_FromWeapon(i)) {
-                       Weapon w = get_weaponinfo(i);
-                       w.wr_init(w);
+               if(precache_weapons & (e.m_wepset)) {
+                       e.wr_init(e);
                }
        }
 
index 4eec262ce8db4b5a87b2433fb3bb0f352611126d..219e483c703af0651f9b53921c62e5ca9067226f 100644 (file)
@@ -922,7 +922,7 @@ float commodity_pickupevalfunc(entity player, entity item)
        {
                wi = get_weaponinfo(i);
 
-               if (!(player.weapons & WepSet_FromWeapon(i)))
+               if (!(player.weapons & (wi.m_wepset)))
                        continue;
 
                if(wi.items & ITEM_Shells.m_itemid)
@@ -1437,7 +1437,7 @@ spawnfunc(target_items)
                                        s = W_UndeprecateName(argv(i));
                                        if(s == e.netname)
                                        {
-                                               self.weapons |= WepSet_FromWeapon(j);
+                                               self.weapons |= (e.m_wepset);
                                                if(self.spawnflags == 0 || self.spawnflags == 2) {
                                                        Weapon w = get_weaponinfo(e.weapon);
                                                        w.wr_init(w);
@@ -1497,7 +1497,7 @@ spawnfunc(target_items)
                {
                        e = get_weaponinfo(j);
                        if(e.weapon)
-                               self.netname = sprintf("%s %s%d %s", self.netname, itemprefix, !!(self.weapons & WepSet_FromWeapon(j)), e.netname);
+                               self.netname = sprintf("%s %s%d %s", self.netname, itemprefix, !!(self.weapons & (e.m_wepset)), e.netname);
                }
        }
        self.netname = strzone(self.netname);
@@ -1553,30 +1553,31 @@ spawnfunc(item_jetpack)
 float GiveWeapon(entity e, float wpn, float op, float val)
 {
        WepSet v0, v1;
-       v0 = (e.weapons & WepSet_FromWeapon(wpn));
+       WepSet s = WepSet_FromWeapon(wpn);
+       v0 = (e.weapons & s);
        switch(op)
        {
                case OP_SET:
                        if(val > 0)
-                               e.weapons |= WepSet_FromWeapon(wpn);
+                               e.weapons |= s;
                        else
-                               e.weapons &= ~WepSet_FromWeapon(wpn);
+                               e.weapons &= ~s;
                        break;
                case OP_MIN:
                case OP_PLUS:
                        if(val > 0)
-                               e.weapons |= WepSet_FromWeapon(wpn);
+                               e.weapons |= s;
                        break;
                case OP_MAX:
                        if(val <= 0)
-                               e.weapons &= ~WepSet_FromWeapon(wpn);
+                               e.weapons &= ~s;
                        break;
                case OP_MINUS:
                        if(val > 0)
-                               e.weapons &= ~WepSet_FromWeapon(wpn);
+                               e.weapons &= ~s;
                        break;
        }
-       v1 = (e.weapons & WepSet_FromWeapon(wpn));
+       v1 = (e.weapons & s);
        return (v0 != v1);
 }
 
@@ -1768,8 +1769,8 @@ float GiveItems(entity e, float beginarg, float endarg)
                if(wi.weapon)
                {
                        POSTGIVE_WEAPON(e, j, SND(WEAPONPICKUP), string_null);
-                       if (!(save_weapons & WepSet_FromWeapon(j)))
-                               if(e.weapons & WepSet_FromWeapon(j)) {
+                       if (!(save_weapons & (wi.m_wepset)))
+                               if(e.weapons & (wi.m_wepset)) {
                                        Weapon w = get_weaponinfo(wi.weapon);
                                        w.wr_init(w);
                                }
index cfa68dc99e38673b99c2a9863565f5d3e47b306c..8efa15b3243ad38faaa14956dda8c9af0ecc64d4 100644 (file)
@@ -140,7 +140,7 @@ float W_GetCycleWeapon(entity pl, string weaponorder, float dir, float imp, floa
        {
                weaponwant = stof(car(rest)); rest = cdr(rest);
                wep = get_weaponinfo(weaponwant);
-               wepset = WepSet_FromWeapon(weaponwant);
+               wepset = wep.m_wepset;
                if(imp >= 0)
                if(wep.impulse != imp)
                        continue;
@@ -148,9 +148,10 @@ float W_GetCycleWeapon(entity pl, string weaponorder, float dir, float imp, floa
                float i, have_other = false;
                for(i = WEP_FIRST; i <= WEP_LAST; ++i)
                {
+                       Weapon e = get_weaponinfo(i);
                        if(i != weaponwant)
-                       if((get_weaponinfo(i)).impulse == imp || imp < 0)
-                       if((pl.weapons & WepSet_FromWeapon(i)) || (weaponsInMap & WepSet_FromWeapon(i)))
+                       if(e.impulse == imp || imp < 0)
+                       if((pl.weapons & (e.m_wepset)) || (weaponsInMap & (e.m_wepset)))
                                have_other = true;
                }
 
@@ -197,7 +198,7 @@ float W_GetCycleWeapon(entity pl, string weaponorder, float dir, float imp, floa
                {
                        weaponwant = stof(car(rest)); rest = cdr(rest);
                        wep = get_weaponinfo(weaponwant);
-                       wepset = WepSet_FromWeapon(weaponwant);
+                       wepset = wep.m_wepset;
                        if(imp >= 0)
                                if(wep.impulse != imp)
                                        continue;
@@ -205,9 +206,10 @@ float W_GetCycleWeapon(entity pl, string weaponorder, float dir, float imp, floa
                        float i, have_other = false;
                        for(i = WEP_FIRST; i <= WEP_LAST; ++i)
                        {
+                               Weapon w = get_weaponinfo(i);
                                if(i != weaponwant)
-                               if((get_weaponinfo(i)).impulse == imp || imp < 0)
-                               if((pl.weapons & WepSet_FromWeapon(i)) || (weaponsInMap & WepSet_FromWeapon(i)))
+                               if(w.impulse == imp || imp < 0)
+                               if((pl.weapons & (w.m_wepset)) || (weaponsInMap & (w.m_wepset)))
                                        have_other = true;
                        }
 
@@ -239,13 +241,13 @@ void W_SwitchWeapon_Force(entity e, float w)
 void W_SwitchToOtherWeapon(entity pl)
 {
        // hack to ensure it switches to an OTHER weapon (in case the other fire mode still has ammo, we want that anyway)
-       float w, ww;
-       w = pl.weapon;
-       if(pl.weapons & WepSet_FromWeapon(w))
+       int ww;
+       WepSet set = WepSet_FromWeapon(pl.weapon);
+       if(pl.weapons & set)
        {
-               pl.weapons &= ~WepSet_FromWeapon(w);
+               pl.weapons &= ~set;
                ww = w_getbestweapon(pl);
-               pl.weapons |= WepSet_FromWeapon(w);
+               pl.weapons |= set;
        }
        else
                ww = w_getbestweapon(pl);
index ef98f69d382e6068cfb50f141ec3bde958fce5ad..6f4546e01c4a26100076628aff9826da5461f0cd 100644 (file)
@@ -57,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(i);
+                               if ((set & WEPSET_SUPERWEAPONS) && (own.weapons & set)) ++superweapons;
+                       }
                        if(superweapons <= 1)
                        {
                                wep.superweapons_finished = own.superweapons_finished;
@@ -177,9 +178,9 @@ void W_ThrowWeapon(vector velo, vector delta, float doreduce)
        if(!W_IsWeaponThrowable(w))
                return;
 
-       if(!(self.weapons & WepSet_FromWeapon(w)))
-               return;
-       self.weapons &= ~WepSet_FromWeapon(w);
+       WepSet set = WepSet_FromWeapon(w);
+       if(!(self.weapons & set)) return;
+       self.weapons &= ~set;
 
        W_SwitchWeapon_Force(self, w_getbestweapon(self));
        string a = W_ThrowNewWeapon(self, w, doreduce, self.origin + delta, velo);