From: TimePath Date: Mon, 23 Nov 2015 09:18:16 +0000 (+1100) Subject: Weapons: cache WepSet X-Git-Tag: xonotic-v0.8.2~1636 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=fefc5a02e121922a89f680daf3ad58259896f174;p=xonotic%2Fxonotic-data.pk3dir.git Weapons: cache WepSet --- diff --git a/qcsrc/client/hud/panel/weapons.qc b/qcsrc/client/hud/panel/weapons.qc index 4d1d7227b..818663242 100644 --- a/qcsrc/client/hud/panel/weapons.qc +++ b/qcsrc/client/hud/panel/weapons.qc @@ -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); diff --git a/qcsrc/client/scoreboard.qc b/qcsrc/client/scoreboard.qc index 681183594..288c52566 100644 --- a/qcsrc/client/scoreboard.qc +++ b/qcsrc/client/scoreboard.qc @@ -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; diff --git a/qcsrc/client/view.qc b/qcsrc/client/view.qc index f7474de58..0f1a43e2f 100644 --- a/qcsrc/client/view.qc +++ b/qcsrc/client/view.qc @@ -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)) { diff --git a/qcsrc/common/mutators/mutator/new_toys/new_toys.qc b/qcsrc/common/mutators/mutator/new_toys/new_toys.qc index 78904ffae..5235e58e6 100644 --- a/qcsrc/common/mutators/mutator/new_toys/new_toys.qc +++ b/qcsrc/common/mutators/mutator/new_toys/new_toys.qc @@ -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; diff --git a/qcsrc/common/mutators/mutator/nix/nix.qc b/qcsrc/common/mutators/mutator/nix/nix.qc index 1a8089ca6..73b08bce8 100644 --- a/qcsrc/common/mutators/mutator/nix/nix.qc +++ b/qcsrc/common/mutators/mutator/nix/nix.qc @@ -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)) diff --git a/qcsrc/common/weapons/all.qc b/qcsrc/common/weapons/all.qc index 452438add..fcadd2d43 100644 --- a/qcsrc/common/weapons/all.qc +++ b/qcsrc/common/weapons/all.qc @@ -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) { diff --git a/qcsrc/common/weapons/all.qh b/qcsrc/common/weapons/all.qh index 93df313c0..8d62426da 100644 --- a/qcsrc/common/weapons/all.qh +++ b/qcsrc/common/weapons/all.qh @@ -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; diff --git a/qcsrc/server/bot/havocbot/havocbot.qc b/qcsrc/server/bot/havocbot/havocbot.qc index 696de21dc..dd0109ce2 100644 --- a/qcsrc/server/bot/havocbot/havocbot.qc +++ b/qcsrc/server/bot/havocbot/havocbot.qc @@ -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; } } diff --git a/qcsrc/server/g_damage.qc b/qcsrc/server/g_damage.qc index 87c28825a..dc306eee0 100644 --- a/qcsrc/server/g_damage.qc +++ b/qcsrc/server/g_damage.qc @@ -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); } } diff --git a/qcsrc/server/miscfunctions.qc b/qcsrc/server/miscfunctions.qc index f03b2e7ce..ddf10818f 100644 --- a/qcsrc/server/miscfunctions.qc +++ b/qcsrc/server/miscfunctions.qc @@ -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); } } diff --git a/qcsrc/server/t_items.qc b/qcsrc/server/t_items.qc index 4eec262ce..219e483c7 100644 --- a/qcsrc/server/t_items.qc +++ b/qcsrc/server/t_items.qc @@ -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); } diff --git a/qcsrc/server/weapons/selection.qc b/qcsrc/server/weapons/selection.qc index cfa68dc99..8efa15b32 100644 --- a/qcsrc/server/weapons/selection.qc +++ b/qcsrc/server/weapons/selection.qc @@ -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); diff --git a/qcsrc/server/weapons/throwing.qc b/qcsrc/server/weapons/throwing.qc index ef98f69d3..6f4546e01 100644 --- a/qcsrc/server/weapons/throwing.qc +++ b/qcsrc/server/weapons/throwing.qc @@ -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);