From: terencehill Date: Thu, 3 Oct 2024 14:56:58 +0000 (+0200) Subject: Refactor code to remove WEP_FLAG_SPECIALATTACK checks if WEP_FLAG_HIDDEN is already... X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=refs%2Fmerge-requests%2F1373%2Fhead;p=xonotic%2Fxonotic-data.pk3dir.git Refactor code to remove WEP_FLAG_SPECIALATTACK checks if WEP_FLAG_HIDDEN is already checked. This refactoring is now possible thanks to the changes of !1344, where all WEP_FLAG_SPECIALATTACK checks have been paired with WEP_FLAG_HIDDEN checks To make sure WEP_FLAG_HIDDEN is always set on special attacks, weapon initialization code triggers a fatal error if WEP_FLAG_SPECIALATTACK is set but WEP_FLAG_HIDDEN is not. --- diff --git a/qcsrc/client/hud/panel/scoreboard.qc b/qcsrc/client/hud/panel/scoreboard.qc index af56134c2..4b14d683e 100644 --- a/qcsrc/client/hud/panel/scoreboard.qc +++ b/qcsrc/client/hud/panel/scoreboard.qc @@ -1760,7 +1760,7 @@ vector Scoreboard_AccuracyStats_Draw(vector pos, vector rgb, vector bg_size) } if (weapon_stats < 0 && !((weapons_stat & set) || (weapons_inmap & set))) { - if (it.spawnflags & (WEP_FLAG_HIDDEN | WEP_FLAG_MUTATORBLOCKED | WEP_FLAG_SPECIALATTACK)) + if (it.spawnflags & (WEP_FLAG_HIDDEN | WEP_FLAG_MUTATORBLOCKED)) ++nHidden; else ++disownedcnt; diff --git a/qcsrc/client/hud/panel/weapons.qc b/qcsrc/client/hud/panel/weapons.qc index 2863f62d9..1b15c5e9e 100644 --- a/qcsrc/client/hud/panel/weapons.qc +++ b/qcsrc/client/hud/panel/weapons.qc @@ -105,7 +105,7 @@ int weaponorder_cmp(int i, int j, entity pass) int nHidden = 0; \ FOREACH(Weapons, it != WEP_Null, { \ if (weapons_stat & WepSet_FromWeapon(it)) continue; \ - if (it.spawnflags & (WEP_FLAG_HIDDEN | WEP_FLAG_MUTATORBLOCKED | WEP_FLAG_SPECIALATTACK)) nHidden += 1; \ + if (it.spawnflags & (WEP_FLAG_HIDDEN | WEP_FLAG_MUTATORBLOCKED)) nHidden += 1; \ }); \ vector table_size = HUD_GetTableSize_BestItemAR((REGISTRY_COUNT(Weapons) - 1) - nHidden, panel_size, aspect); \ columns = table_size.x; \ @@ -499,7 +499,7 @@ void HUD_Weapons() } else { - if ((it.spawnflags & (WEP_FLAG_HIDDEN | WEP_FLAG_MUTATORBLOCKED | WEP_FLAG_SPECIALATTACK)) + if ((it.spawnflags & (WEP_FLAG_HIDDEN | WEP_FLAG_MUTATORBLOCKED)) && !(weapons_stat & WepSet_FromWeapon(it))) continue; } diff --git a/qcsrc/common/weapons/all.qh b/qcsrc/common/weapons/all.qh index 8ac7a20c8..d19d54415 100644 --- a/qcsrc/common/weapons/all.qh +++ b/qcsrc/common/weapons/all.qh @@ -27,7 +27,15 @@ WepSet ReadWepSet(); REGISTRY(Weapons, 72) // Increase as needed. Can be up to 72. REGISTER_REGISTRY(Weapons) -STATIC_INIT(WeaponPickup) { FOREACH(Weapons, true, it.m_pickup = NEW(WeaponPickup, it)); } +STATIC_INIT(WeaponPickup) +{ + FOREACH(Weapons, true, + { + if ((it.spawnflags & WEP_FLAG_SPECIALATTACK) && !(it.spawnflags & WEP_FLAG_HIDDEN)) + error(sprintf("Special attack \"%s\" without WEP_FLAG_HIDDEN flag set.", it.m_name)); + it.m_pickup = NEW(WeaponPickup, it); + }); +} #ifdef SVQC #include diff --git a/qcsrc/common/weapons/weapon.qh b/qcsrc/common/weapons/weapon.qh index 19a81029c..38902ea7e 100644 --- a/qcsrc/common/weapons/weapon.qh +++ b/qcsrc/common/weapons/weapon.qh @@ -210,7 +210,7 @@ const int WEP_FLAG_NODUAL = BIT(12); // weapon doesn't work well with d const int WEP_FLAG_PENETRATEWALLS = BIT(13); // weapon has high calibur bullets that can penetrate thick walls (WEAPONTODO) const int WEP_FLAG_BLEED = BIT(14); // weapon pierces and causes bleeding (used for damage effects) const int WEP_FLAG_NOTRUEAIM = BIT(15); // weapon doesn't aim directly at targets -const int WEP_FLAG_SPECIALATTACK = BIT(16); // marked as a special attack (not a true weapon), hidden from most weapon lists +const int WEP_FLAG_SPECIALATTACK = BIT(16); // special attack (not a true weapon); NOTE: if this flag is set then WEP_FLAG_HIDDEN must be set as well // variables: string weaponorder_byid; diff --git a/qcsrc/menu/xonotic/dialog_multiplayer_create_mutators.qc b/qcsrc/menu/xonotic/dialog_multiplayer_create_mutators.qc index 20f72863e..44dd568d6 100644 --- a/qcsrc/menu/xonotic/dialog_multiplayer_create_mutators.qc +++ b/qcsrc/menu/xonotic/dialog_multiplayer_create_mutators.qc @@ -164,7 +164,7 @@ void XonoticMutatorsDialog_fill(entity me) for(i = WEP_FIRST, j = 0; i <= WEP_LAST; ++i) { w = REGISTRY_GET(Weapons, i); - if (w.spawnflags & (WEP_FLAG_HIDDEN | WEP_FLAG_SPECIALATTACK)) + if (w.spawnflags & WEP_FLAG_HIDDEN) continue; if ((j % 3) == 0) { diff --git a/qcsrc/menu/xonotic/keybinder.qc b/qcsrc/menu/xonotic/keybinder.qc index 918826332..93d245fb9 100644 --- a/qcsrc/menu/xonotic/keybinder.qc +++ b/qcsrc/menu/xonotic/keybinder.qc @@ -69,9 +69,9 @@ void KeyBinds_BuildList() for(int imp = 1; imp <= 9; ++imp) { string w_list = ""; - ADD_TO_W_LIST(!(it.spawnflags & (WEP_FLAG_MUTATORBLOCKED | WEP_FLAG_HIDDEN | WEP_FLAG_SPECIALATTACK | WEP_FLAG_SUPERWEAPON))); + ADD_TO_W_LIST(!(it.spawnflags & (WEP_FLAG_MUTATORBLOCKED | WEP_FLAG_HIDDEN | WEP_FLAG_SUPERWEAPON))); ADD_TO_W_LIST((it.spawnflags & WEP_FLAG_SUPERWEAPON) && !(it.spawnflags & WEP_FLAG_HIDDEN)); - ADD_TO_W_LIST((it.spawnflags & WEP_FLAG_MUTATORBLOCKED) && !(it.spawnflags & (WEP_FLAG_HIDDEN | WEP_FLAG_SPECIALATTACK))); + ADD_TO_W_LIST((it.spawnflags & WEP_FLAG_MUTATORBLOCKED) && !(it.spawnflags & WEP_FLAG_HIDDEN)); if(w_list) KEYBIND_DEF(strcat("weapon_group_", itos(imp)), substring(w_list, 0, -4)); if(imp == 0) diff --git a/qcsrc/server/items/items.qc b/qcsrc/server/items/items.qc index 62d13fb27..0478d8add 100644 --- a/qcsrc/server/items/items.qc +++ b/qcsrc/server/items/items.qc @@ -1648,7 +1648,8 @@ float GiveItems(entity e, float beginarg, float endarg) got += GiveResourceValue(e, RES_HEALTH, op, val); got += GiveResourceValue(e, RES_ARMOR, op, val); case "allweapons": - FOREACH(Weapons, it != WEP_Null && !(it.spawnflags & (WEP_FLAG_MUTATORBLOCKED | WEP_FLAG_HIDDEN | WEP_FLAG_SPECIALATTACK)), got += GiveWeapon(e, it.m_id, op, val)); + FOREACH(Weapons, it != WEP_Null && !(it.spawnflags & (WEP_FLAG_MUTATORBLOCKED | WEP_FLAG_HIDDEN)), + got += GiveWeapon(e, it.m_id, op, val)); //case "allbuffs": // all buffs makes a player god, do not want! //FOREACH(StatusEffect, it.instanceOfBuff, got += GiveBuff(e, it, op, val)); case "allammo": diff --git a/qcsrc/server/world.qc b/qcsrc/server/world.qc index 175f8d683..953e2df39 100644 --- a/qcsrc/server/world.qc +++ b/qcsrc/server/world.qc @@ -1831,9 +1831,9 @@ int want_weapon(entity weaponinfo, int allguns) allow_mutatorblocked = M_ARGV(3, bool); if(allguns == 1) - d = boolean(!(weaponinfo.spawnflags & (WEP_FLAG_HIDDEN | WEP_FLAG_SPECIALATTACK))); + d = boolean(!(weaponinfo.spawnflags & WEP_FLAG_HIDDEN)); else if(allguns == 2) - d = boolean((weaponinfo.spawnflags & WEP_FLAG_NORMAL) && !(weaponinfo.spawnflags & (WEP_FLAG_HIDDEN | WEP_FLAG_SPECIALATTACK))); + d = boolean((weaponinfo.spawnflags & WEP_FLAG_NORMAL) && !(weaponinfo.spawnflags & WEP_FLAG_HIDDEN)); else if(!mutator_returnvalue) d = !(!weaponinfo.weaponstart); @@ -1872,7 +1872,7 @@ WepSet weapons_all() { WepSet ret = '0 0 0'; FOREACH(Weapons, it != WEP_Null, { - if (!(it.spawnflags & (WEP_FLAG_MUTATORBLOCKED | WEP_FLAG_HIDDEN | WEP_FLAG_SPECIALATTACK))) + if (!(it.spawnflags & (WEP_FLAG_MUTATORBLOCKED | WEP_FLAG_HIDDEN))) ret |= it.m_wepset; }); return ret; @@ -1892,7 +1892,7 @@ WepSet weapons_most() { WepSet ret = '0 0 0'; FOREACH(Weapons, it != WEP_Null, { - if ((it.spawnflags & WEP_FLAG_NORMAL) && !(it.spawnflags & (WEP_FLAG_MUTATORBLOCKED | WEP_FLAG_HIDDEN | WEP_FLAG_SPECIALATTACK))) + if ((it.spawnflags & WEP_FLAG_NORMAL) && !(it.spawnflags & (WEP_FLAG_MUTATORBLOCKED | WEP_FLAG_HIDDEN))) ret |= it.m_wepset; }); return ret;