]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Store weapon impulse numbers in a field, exclude special attacks and ball stealer
authorMario <mario.mario@y7mail.com>
Fri, 14 Feb 2025 16:18:20 +0000 (02:18 +1000)
committerMario <mario.mario@y7mail.com>
Fri, 14 Feb 2025 16:18:20 +0000 (02:18 +1000)
qcsrc/common/weapons/all.qh
qcsrc/server/impulse.qc

index 46d5eab17f1c66ae90c64b6e1de417415cb313db..765017feee6decddea0619f3c4ca99e1fd429e31 100644 (file)
@@ -46,6 +46,8 @@ STATIC_INIT(WeaponPickup)
 #define WepSet_FromWeapon(it) ((it).m_wepset)
 WepSet _WepSet_FromWeapon(int i);
 
+.int m_impulse;
+
 #define DEFAULT_FILENAME "weapons_dump.cfg"
 // NOTE: dumpeffectinfo, dumpnotifs, dumpturrets and dumpweapons use similar code
 GENERIC_COMMAND(dumpweapons, "Dump all turrets into " DEFAULT_FILENAME, false) // WEAPONTODO: make this work with other progs than just server
@@ -142,6 +144,12 @@ Weapon Weapon_from_name(string s)
        return WEP_Null;
 }
 
+Weapon Weapon_from_impulse(int imp)
+{
+       FOREACH(Weapons, it != WEP_Null && it.m_impulse == imp, return it);
+       return WEP_Null;
+}
+
 
 #ifdef GAMEQC
 
@@ -329,16 +337,20 @@ REGISTRY_CHECK(Weapons)
 STATIC_INIT(register_weapons_done)
 {
        string inaccessible = "";
+       int imp = WEP_IMPULSE_BEGIN;
        FOREACH(Weapons, true, {
                WepSet set = it.m_wepset = _WepSet_FromWeapon(it.m_id = i);
                WEPSET_ALL |= set;
                if (it.spawnflags & WEP_FLAG_SUPERWEAPON) WEPSET_SUPERWEAPONS |= set;
                if (it == WEP_Null) continue;
-               int imp = WEP_IMPULSE_BEGIN + it.m_id - 1;
+               if ((it.spawnflags & WEP_FLAG_SPECIALATTACK) || (it.spawnflags & WEP_TYPE_OTHER)) continue;
+
+               it.m_impulse = imp;
                if (imp <= WEP_IMPULSE_END)
                        localcmd(sprintf("alias weapon_%s \"impulse %d\"\n", it.netname, imp));
                else
                        inaccessible = strcat(inaccessible, "\n", it.netname);
+               ++imp;
        });
        if (inaccessible != "" && autocvar_developer > 0) LOG_TRACEF("Impulse limit exceeded, weapon(s) will not be directly accessible: %s", inaccessible);
        #ifdef CSQC
index b9f9d7766f200a270d8471f6731db4170af9f4c2..91863cc6f0423f4e98ef6cdf9b41bd214a08fbfe 100644 (file)
@@ -158,7 +158,7 @@ void weapon_byid_handle(entity this, int number, int imp)
        for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
        {
                .entity weaponentity = weaponentities[slot];
-               W_SwitchWeapon_TryOthers(this, REGISTRY_GET(Weapons, WEP_FIRST + number), weaponentity);
+               W_SwitchWeapon_TryOthers(this, Weapon_from_impulse(imp), weaponentity);
                if(autocvar_g_weaponswitch_debug != 1)
                        break;
        }