Improve registry API by adding REGISTRY_MAX and REGISTRY_COUNT macros
authorterencehill <piuntn@gmail.com>
Tue, 26 May 2020 13:35:17 +0000 (15:35 +0200)
committerterencehill <piuntn@gmail.com>
Tue, 26 May 2020 13:35:17 +0000 (15:35 +0200)
23 files changed:
qcsrc/client/hud/hud.qc
qcsrc/client/hud/hud.qh
qcsrc/client/hud/hud_config.qc
qcsrc/client/hud/panel/scoreboard.qc
qcsrc/client/hud/panel/weapons.qc
qcsrc/client/view.qc
qcsrc/common/effects/all.qc
qcsrc/common/items/inventory.qh
qcsrc/common/monsters/all.qh
qcsrc/common/mutators/mutator/itemstime/itemstime.qc
qcsrc/common/mutators/mutator/stale_move_negation/sv_stale_move_negation.qc
qcsrc/common/turrets/all.qh
qcsrc/common/turrets/config.qc
qcsrc/common/vehicles/all.qh
qcsrc/common/weapons/all.qc
qcsrc/common/weapons/all.qh
qcsrc/lib/registry.qh
qcsrc/menu/xonotic/dialog_settings_game.qc
qcsrc/server/bot/api.qh
qcsrc/server/bot/default/bot.qc
qcsrc/server/bot/default/havocbot/havocbot.qc
qcsrc/server/defs.qh
qcsrc/server/weapons/accuracy.qh

index 3a13048..dd91dbd 100644 (file)
@@ -667,18 +667,18 @@ void HUD_Main()
 
        // cache the panel order into the panel_order array
        if(autocvar__hud_panelorder != hud_panelorder_prev) {
-               for(i = 0; i < hud_panels_COUNT; ++i)
+               for(i = 0; i < REGISTRY_COUNT(hud_panels); ++i)
                        panel_order[i] = -1;
                string s = "";
                int p_num;
                bool warning = false;
                int argc = tokenize_console(autocvar__hud_panelorder);
-               if (argc > hud_panels_COUNT)
+               if (argc > REGISTRY_COUNT(hud_panels))
                        warning = true;
                //first detect wrong/missing panel numbers
-               for(i = 0; i < hud_panels_COUNT; ++i) {
+               for(i = 0; i < REGISTRY_COUNT(hud_panels); ++i) {
                        p_num = stoi(argv(i));
-                       if (p_num >= 0 && p_num < hud_panels_COUNT) { //correct panel number?
+                       if (p_num >= 0 && p_num < REGISTRY_COUNT(hud_panels)) { //correct panel number?
                                if (panel_order[p_num] == -1) //found for the first time?
                                        s = strcat(s, ftos(p_num), " ");
                                panel_order[p_num] = 1; //mark as found
@@ -686,7 +686,7 @@ void HUD_Main()
                        else
                                warning = true;
                }
-               for(i = 0; i < hud_panels_COUNT; ++i) {
+               for(i = 0; i < REGISTRY_COUNT(hud_panels); ++i) {
                        if (panel_order[i] == -1) {
                                warning = true;
                                s = strcat(s, ftos(i), " "); //add missing panel number
@@ -700,14 +700,14 @@ void HUD_Main()
 
                //now properly set panel_order
                tokenize_console(s);
-               for(i = 0; i < hud_panels_COUNT; ++i) {
+               for(i = 0; i < REGISTRY_COUNT(hud_panels); ++i) {
                        panel_order[i] = stof(argv(i));
                }
        }
 
        hud_draw_maximized = 0;
        // draw panels in the order specified by panel_order array
-       for(i = hud_panels_COUNT - 1; i >= 0; --i)
+       for(i = REGISTRY_COUNT(hud_panels) - 1; i >= 0; --i)
                HUD_Panel_Draw(hud_panels_from(panel_order[i]));
 
        HUD_Vehicle();
index 2c12a61..c0a3222 100644 (file)
@@ -43,7 +43,7 @@ REGISTER_REGISTRY(hud_panels)
                ); \
 MACRO_END
 
-int panel_order[hud_panels_MAX];
+int panel_order[REGISTRY_MAX(hud_panels)];
 string hud_panelorder_prev;
 
 bool hud_draw_maximized;
@@ -89,7 +89,7 @@ float highlightedAction; // 0 = nothing, 1 = move, 2 = resize
 
 const float BORDER_MULTIPLIER = 4;
 float scoreboard_bottom;
-int weapon_accuracy[Weapons_MAX];
+int weapon_accuracy[REGISTRY_MAX(Weapons)];
 
 entity complain_weapon;
 int complain_weapon_type;
index c4ae095..61f0d4d 100644 (file)
@@ -60,7 +60,7 @@ void HUD_Panel_ExportCfg(string cfgname)
                HUD_Write("\n");
 
                // common cvars for all panels
-               for (int i = 0; i < hud_panels_COUNT; ++i)
+               for (int i = 0; i < REGISTRY_COUNT(hud_panels); ++i)
                {
                        panel = hud_panels_from(i);
 
@@ -102,7 +102,7 @@ vector HUD_Panel_CheckMove(vector myPos, vector mySize)
        vector myCenter, targCenter;
        vector myTarget = myPos;
        int i;
-       for (i = 0; i < hud_panels_COUNT; ++i) {
+       for (i = 0; i < REGISTRY_COUNT(hud_panels); ++i) {
                panel = hud_panels_from(i);
                if(!(panel.panel_configflags & PANEL_CONFIG_MAIN)) continue;
                if(panel == highlightedPanel) continue;
@@ -199,7 +199,7 @@ vector HUD_Panel_CheckResize(vector mySize, vector resizeorigin) {
        vector dist;
        float ratio = mySize.x/mySize.y;
        int i;
-       for (i = 0; i < hud_panels_COUNT; ++i) {
+       for (i = 0; i < REGISTRY_COUNT(hud_panels); ++i) {
                panel = hud_panels_from(i);
                if(!(panel.panel_configflags & PANEL_CONFIG_MAIN)) continue;
                if(panel == highlightedPanel) continue;
@@ -500,13 +500,13 @@ void HUD_Panel_Arrow_Action(float nPrimary)
        }
 }
 
-entity tab_panels[hud_panels_MAX];
+entity tab_panels[REGISTRY_MAX(hud_panels)];
 entity tab_panel;
 vector tab_panel_pos;
 float tab_backward;
 void reset_tab_panels()
 {
-       for (int i = 0; i < hud_panels_COUNT; ++i)
+       for (int i = 0; i < REGISTRY_COUNT(hud_panels); ++i)
                tab_panels[i] = NULL;
 }
 float HUD_Panel_InputEvent(float bInputType, float nPrimary, float nSecondary)
@@ -645,7 +645,7 @@ LABEL(find_tab_panel)
                k=0;
                while(++k)
                {
-                       for(i = 0; i < hud_panels_COUNT; ++i)
+                       for(i = 0; i < REGISTRY_COUNT(hud_panels); ++i)
                        {
                                panel = hud_panels_from(i);
                                if(!(panel.panel_configflags & PANEL_CONFIG_MAIN))
@@ -794,7 +794,7 @@ LABEL(find_tab_panel)
 int HUD_Panel_Check_Mouse_Pos(bool allow_move)
 {
        int i, j = 0;
-       while(j < hud_panels_COUNT)
+       while(j < REGISTRY_COUNT(hud_panels))
        {
                i = panel_order[j];
                j += 1;
@@ -840,7 +840,7 @@ void HUD_Panel_FirstInDrawQ(float id)
        int i;
        int place = -1;
        // find out where in the array our current id is, save into place
-       for(i = 0; i < hud_panels_COUNT; ++i)
+       for(i = 0; i < REGISTRY_COUNT(hud_panels); ++i)
        {
                if(panel_order[i] == id)
                {
@@ -850,7 +850,7 @@ void HUD_Panel_FirstInDrawQ(float id)
        }
        // place last if we didn't find a place for it yet (probably new panel, or screwed up cvar)
        if(place == -1)
-               place = hud_panels_COUNT - 1;
+               place = REGISTRY_COUNT(hud_panels) - 1;
 
        // move all ids up by one step in the array until "place"
        for(i = place; i > 0; --i)
@@ -862,7 +862,7 @@ void HUD_Panel_FirstInDrawQ(float id)
 
        // let's save them into the cvar by some strcat trickery
        string s = "";
-       for(i = 0; i < hud_panels_COUNT; ++i)
+       for(i = 0; i < REGISTRY_COUNT(hud_panels); ++i)
        {
                s = strcat(s, ftos(panel_order[i]), " ");
        }
@@ -874,7 +874,7 @@ void HUD_Panel_Highlight(float allow_move)
 {
        int i, j = 0;
 
-       while(j < hud_panels_COUNT)
+       while(j < REGISTRY_COUNT(hud_panels))
        {
                i = panel_order[j];
                j += 1;
@@ -1082,7 +1082,7 @@ void HUD_Configure_Frame()
                if(!hud_configure_prev)
                {
                        hudShiftState = 0;
-                       for(i = hud_panels_COUNT - 1; i >= 0; --i)
+                       for(i = REGISTRY_COUNT(hud_panels) - 1; i >= 0; --i)
                                hud_panels_from(panel_order[i]).update_time = time;
                }
 
index 9627590..a7efc18 100644 (file)
@@ -1192,11 +1192,11 @@ vector Scoreboard_AccuracyStats_Draw(vector pos, vector rgb, vector bg_size)
                }
        });
 
-       int weapon_cnt = (Weapons_COUNT - 1) - disownedcnt - nHidden;
+       int weapon_cnt = (REGISTRY_COUNT(Weapons) - 1) - disownedcnt - nHidden;
        if (weapon_cnt <= 0) return pos;
 
        int rows = 1;
-       if (autocvar_hud_panel_scoreboard_accuracy_doublerows && weapon_cnt >= floor((Weapons_COUNT - nHidden - 1) * 0.5))
+       if (autocvar_hud_panel_scoreboard_accuracy_doublerows && weapon_cnt >= floor((REGISTRY_COUNT(Weapons) - nHidden - 1) * 0.5))
                rows = 2;
        int columnns = ceil(weapon_cnt / rows);
 
index f7444da..633e37b 100644 (file)
@@ -37,7 +37,7 @@ void HUD_Weapons_Export(int fh)
        HUD_Write_Cvar("hud_panel_weapons_selection_speed");
 }
 
-entity weaponorder[Weapons_MAX];
+entity weaponorder[REGISTRY_MAX(Weapons)];
 void weaponorder_swap(int i, int j, entity pass)
 {
        TC(int, i); TC(int, j);
@@ -61,7 +61,7 @@ int weaponorder_cmp(int i, int j, entity pass)
                if (weapons_stat & WepSet_FromWeapon(it)) continue; \
                if (it.spawnflags & (WEP_FLAG_HIDDEN | WEP_FLAG_MUTATORBLOCKED | WEP_FLAG_SPECIALATTACK)) nHidden += 1; \
        }); \
-       vector table_size = HUD_GetTableSize_BestItemAR((Weapons_COUNT - 1) - nHidden, panel_size, aspect); \
+       vector table_size = HUD_GetTableSize_BestItemAR((REGISTRY_COUNT(Weapons) - 1) - nHidden, panel_size, aspect); \
        columns = table_size.x; \
        rows = table_size.y; \
        weapon_size.x = panel_size.x / columns; \
@@ -135,7 +135,7 @@ void HUD_Weapons()
 
                int weapon_cnt = 0;
                FOREACH(Weapons, it != WEP_Null && it.impulse >= 0, weaponorder[weapon_cnt++] = it);
-               for(i = weapon_cnt; i < Weapons_MAX; ++i)
+               for(i = weapon_cnt; i < REGISTRY_MAX(Weapons); ++i)
                        weaponorder[i] = NULL;
                heapsort(weapon_cnt, weaponorder_swap, weaponorder_cmp, NULL);
 
@@ -178,8 +178,8 @@ void HUD_Weapons()
                                if (it.spawnflags & WEP_FLAG_MUTATORBLOCKED) nHidden += 1;
                        });
                        weapons_stat = '0 0 0';
-                       float countw = 1 + floor((floor(time * cvar("wep_add"))) % ((Weapons_COUNT - 1) - nHidden));
-                       for(i = 0, j = 0; i <= (Weapons_COUNT - 1) && j < countw; ++i)
+                       float countw = 1 + floor((floor(time * cvar("wep_add"))) % ((REGISTRY_COUNT(Weapons) - 1) - nHidden));
+                       for(i = 0, j = 0; i <= (REGISTRY_COUNT(Weapons) - 1) && j < countw; ++i)
                        {
                                if(weaponorder[i].spawnflags & WEP_FLAG_MUTATORBLOCKED)
                                        continue;
@@ -272,7 +272,7 @@ void HUD_Weapons()
                        panel_pos.y += (old_panel_size.y - panel_size.y) / 2;
        }
        else
-               weapon_count = (Weapons_COUNT - 1);
+               weapon_count = (REGISTRY_COUNT(Weapons) - 1);
 
        // animation for fading in/out the panel respectively when not in use
        if(!autocvar__hud_configure)
index 57cd15a..c5de3ae 100644 (file)
@@ -1538,7 +1538,7 @@ void SpecialCommand()
                        {
                                slot.x = bound(0, (random() * vid_conwidth + 1), vid_conwidth);
                                slot.y = 1; // start it off 0 so we can use it
-                               slot.z = floor(random() * Weapons_MAX);
+                               slot.z = floor(random() * REGISTRY_MAX(Weapons));
                                sc_spawntime = time + bound(0.4, random(), 0.75); // prevent spawning another one for this amount of time!
                                vector newcolor = randomvec() * 2;
                                newcolor.x = bound(0.4, newcolor.x, 1);
index 9732be2..99849de 100644 (file)
@@ -4,7 +4,7 @@ REGISTER_NET_TEMP(net_effect)
 #ifdef CSQC
 NET_HANDLE(net_effect, bool isNew)
 {
-       int net_name = (Effects_COUNT >= 255) ? ReadShort() : ReadByte();
+       int net_name = (REGISTRY_COUNT(Effects) >= 255) ? ReadShort() : ReadByte();
 
        entity eff = Effects_from(net_name);
 
@@ -34,7 +34,7 @@ bool Net_Write_Effect(entity this, entity client, int sf)
        int channel = MSG_ONE;
        msg_entity = client;
        WriteHeader(channel, net_effect);
-       (Effects_COUNT >= 255)
+       (REGISTRY_COUNT(Effects) >= 255)
        ? WriteShort(channel, this.m_id)
        : WriteByte(channel, this.m_id);
        WriteVector(channel, this.eent_net_location);
index 9f0a43a..29a0204 100644 (file)
@@ -5,7 +5,7 @@
 #ifdef GAMEQC
 CLASS(Inventory, Object)
     /** Stores counts of items, the id being the index */
-    ATTRIBARRAY(Inventory, inv_items, int, Items_MAX);
+    ATTRIBARRAY(Inventory, inv_items, int, REGISTRY_MAX(Items));
     /** Previous state */
     ATTRIB(Inventory, inventory, Inventory);
 ENDCLASS(Inventory)
@@ -16,7 +16,7 @@ ENDCLASS(Inventory)
 REGISTER_NET_LINKED(ENT_CLIENT_INVENTORY)
 
 const int Inventory_groups_minor = 8; // exactly 1 byte
-const int Inventory_groups_major = 3; // ceil(Items_MAX / Inventory_groups_minor)
+const int Inventory_groups_major = 3; // ceil(REGISTRY_MAX(Items) / Inventory_groups_minor)
 
 #define G_MAJOR(id) (floor((id) / Inventory_groups_minor))
 #define G_MINOR(id) ((id) % Inventory_groups_minor)
index c9e5ad3..e31fd0b 100644 (file)
@@ -8,7 +8,7 @@ REGISTRY(Monsters, BITS(5))
 REGISTER_REGISTRY(Monsters)
 REGISTRY_CHECK(Monsters)
 const int MON_FIRST = 1;
-#define MON_LAST (Monsters_COUNT - 1)
+#define MON_LAST (REGISTRY_COUNT(Monsters) - 1)
 #define REGISTER_MONSTER(id, inst) REGISTER(Monsters, MON, id, monsterid, inst)
 
 #include "monster.qh"
index 78a5624..e99a6af 100644 (file)
@@ -16,8 +16,8 @@ void IT_Write(entity e, int i, float f) {
 
 #ifdef CSQC
 // reserve one more spot for superweapons time
-float ItemsTime_time[Items_MAX + 1];
-float ItemsTime_availableTime[Items_MAX + 1];
+float ItemsTime_time[REGISTRY_MAX(Items) + 1];
+float ItemsTime_availableTime[REGISTRY_MAX(Items) + 1];
 NET_HANDLE(itemstime, bool isNew)
 {
     int i = ReadByte();
@@ -33,7 +33,7 @@ STATIC_INIT(ItemsTime_Init) {
        FOREACH(Items, true, {
                ItemsTime_time[it.m_id] = -1;
        });
-       ItemsTime_time[Items_MAX] = -1;
+       ItemsTime_time[REGISTRY_MAX(Items)] = -1;
 }
 
 int autocvar_hud_panel_itemstime = 2;
@@ -71,13 +71,13 @@ bool Item_ItemsTime_Allow(GameItem it)
 #ifdef SVQC
 
 // reserve one more spot for superweapons time
-float it_times[Items_MAX + 1];
+float it_times[REGISTRY_MAX(Items) + 1];
 
 STATIC_INIT(ItemsTime_Init) {
        FOREACH(Items, Item_ItemsTime_Allow(it), {
                it_times[it.m_id] = -1;
        });
-       it_times[Items_MAX] = -1;
+       it_times[REGISTRY_MAX(Items)] = -1;
 }
 
 void Item_ItemsTime_ResetTimes()
@@ -85,7 +85,7 @@ void Item_ItemsTime_ResetTimes()
     FOREACH(Items, Item_ItemsTime_Allow(it), {
         it_times[it.m_id] = (it_times[it.m_id] == -1) ? -1 : 0;
     });
-    it_times[Items_MAX] = (it_times[Items_MAX] == -1) ? -1 : 0;
+    it_times[REGISTRY_MAX(Items)] = (it_times[REGISTRY_MAX(Items)] == -1) ? -1 : 0;
 }
 
 void Item_ItemsTime_ResetTimesForPlayer(entity e)
@@ -93,7 +93,7 @@ void Item_ItemsTime_ResetTimesForPlayer(entity e)
     FOREACH(Items, Item_ItemsTime_Allow(it), {
         IT_Write(e, it.m_id, (it_times[it.m_id] == -1) ? -1 : 0);
     });
-    IT_Write(e, Items_MAX, (it_times[Items_MAX] == -1) ? -1 : 0);
+    IT_Write(e, REGISTRY_MAX(Items), (it_times[REGISTRY_MAX(Items)] == -1) ? -1 : 0);
 }
 
 void Item_ItemsTime_SetTimesForPlayer(entity e)
@@ -101,7 +101,7 @@ void Item_ItemsTime_SetTimesForPlayer(entity e)
     FOREACH(Items, Item_ItemsTime_Allow(it), {
         IT_Write(e, it.m_id, it_times[it.m_id]);
     });
-    IT_Write(e, Items_MAX, it_times[Items_MAX]);
+    IT_Write(e, REGISTRY_MAX(Items), it_times[REGISTRY_MAX(Items)]);
 }
 
 void Item_ItemsTime_SetTime(entity e, float t)
@@ -115,7 +115,7 @@ void Item_ItemsTime_SetTime(entity e, float t)
                if (!item.instanceOfWeaponPickup)
                        it_times[item.m_id] = t;
                else if (STAT(WEAPONS, e) & WEPSET_SUPERWEAPONS)
-                       it_times[Items_MAX] = t;
+                       it_times[REGISTRY_MAX(Items)] = t;
     }
 }
 
@@ -295,21 +295,21 @@ void HUD_ItemsTime()
         FOREACH(Items, Item_ItemsTime_Allow(it), {
             count += (Item_ItemsTime_GetTime(it.m_id) > time || -Item_ItemsTime_GetTime(it.m_id) > time);
         });
-        count += (Item_ItemsTime_GetTime(Items_MAX) > time || -Item_ItemsTime_GetTime(Items_MAX) > time);
+        count += (Item_ItemsTime_GetTime(REGISTRY_MAX(Items)) > time || -Item_ItemsTime_GetTime(REGISTRY_MAX(Items)) > time);
     }
     else if (autocvar_hud_panel_itemstime_hidespawned == 2)
     {
         FOREACH(Items, Item_ItemsTime_Allow(it), {
             count += (Item_ItemsTime_GetTime(it.m_id) > time);
         });
-        count += (Item_ItemsTime_GetTime(Items_MAX) > time);
+        count += (Item_ItemsTime_GetTime(REGISTRY_MAX(Items)) > time);
     }
     else
     {
         FOREACH(Items, Item_ItemsTime_Allow(it), {
             count += (Item_ItemsTime_GetTime(it.m_id) != -1);
         });
-        count += (Item_ItemsTime_GetTime(Items_MAX) != -1);
+        count += (Item_ItemsTime_GetTime(REGISTRY_MAX(Items)) != -1);
     }
     if (count == 0)
         return;
@@ -426,13 +426,13 @@ LABEL(iteration)
             row = 0;
             column = column + 1;
         }
-        if(id == Items_MAX) // can happen only in the last fake iteration
+        if(id == REGISTRY_MAX(Items)) // can happen only in the last fake iteration
                break;
     });
     // add another fake iteration for superweapons time
-    if(id < Items_MAX && Item_ItemsTime_GetTime(Items_MAX) != -1)
+    if(id < REGISTRY_MAX(Items) && Item_ItemsTime_GetTime(REGISTRY_MAX(Items)) != -1)
     {
-               id = Items_MAX;
+               id = REGISTRY_MAX(Items);
                icon = "superweapons";
                goto iteration;
     }
index c54a8a6..04785f8 100644 (file)
@@ -14,7 +14,7 @@ MUTATOR_HOOKFUNCTION(mutator_smneg, BuildMutatorsPrettyString) {
     M_ARGV(0, string) = strcat(M_ARGV(0, string), ", Stale-move negation");
 }
 
-.float x_smneg_weight[Weapons_MAX];
+.float x_smneg_weight[REGISTRY_MAX(Weapons)];
 
 float smneg_multiplier(float weight) {
     float a = autocvar_g_smneg_bonus_asymptote;
index 9dedc89..ee0e191 100644 (file)
@@ -112,7 +112,7 @@ GENERIC_COMMAND(dumpturrets, "Dump all turrets into turrets_dump.txt", false)
 
 
 const int TUR_FIRST = 1;
-#define TUR_LAST (Turrets_COUNT - 1)
+#define TUR_LAST (REGISTRY_COUNT(Turrets) - 1)
 
 #define REGISTER_TURRET(id, inst) REGISTER(Turrets, TUR, id, m_id, inst)
 
index 19b64ff..8ecd190 100644 (file)
@@ -77,7 +77,7 @@ void Dump_Turret_Settings()
 
        // extra information
        if (TUR_CONFIG_COUNT <= MAX_CONFIG_SETTINGS - 1)
-               LOG_INFOF("Totals: %d turrets, %d settings", (Turrets_COUNT - 1), totalsettings);
+               LOG_INFOF("Totals: %d turrets, %d settings", (REGISTRY_COUNT(Turrets) - 1), totalsettings);
 
        // clear queue now that we're finished
        TUR_CONFIG_COUNT = 0;
index ed44be7..94af40c 100644 (file)
@@ -8,7 +8,7 @@ REGISTER_REGISTRY(Vehicles)
 REGISTRY_CHECK(Vehicles)
 
 const int VEH_FIRST = 1;
-#define VEH_LAST (Vehicles_COUNT - 1)
+#define VEH_LAST (REGISTRY_COUNT(Vehicles) - 1)
 
 #define REGISTER_VEHICLE(id, inst) REGISTER(Vehicles, VEH, id, vehicleid, inst)
 
index a8d1376..45ba229 100644 (file)
 WepSet _WepSet_FromWeapon(int a)
 {
        a -= WEP_FIRST;
-       if (Weapons_MAX > 24)
+       if (REGISTRY_MAX(Weapons) > 24)
                if (a >= 24)
                {
                        a -= 24;
-                       if (Weapons_MAX > 48)
+                       if (REGISTRY_MAX(Weapons) > 48)
                                if (a >= 24)
                                {
                                        a -= 24;
@@ -76,8 +76,8 @@ WepSet _WepSet_FromWeapon(int a)
 #ifdef SVQC
        void WriteWepSet(float dst, WepSet w)
        {
-               if (Weapons_MAX > 48) WriteInt72_t(dst, w);
-               else if (Weapons_MAX > 24) WriteInt48_t(dst, w);
+               if (REGISTRY_MAX(Weapons) > 48) WriteInt72_t(dst, w);
+               else if (REGISTRY_MAX(Weapons) > 24) WriteInt48_t(dst, w);
                else WriteInt24_t(dst, w.x);
        }
 #endif
@@ -92,8 +92,8 @@ WepSet _WepSet_FromWeapon(int a)
        }
        WepSet ReadWepSet()
        {
-               if (Weapons_MAX > 48) return ReadInt72_t();
-               if (Weapons_MAX > 24) return ReadInt48_t();
+               if (REGISTRY_MAX(Weapons) > 48) return ReadInt72_t();
+               if (REGISTRY_MAX(Weapons) > 24) return ReadInt48_t();
                return ReadInt24_t() * '1 0 0';
        }
 #endif
@@ -144,7 +144,7 @@ string W_NumberWeaponOrder(string order)
        return mapPriorityList(order, W_NumberWeaponOrder_MapFunc);
 }
 
-float W_FixWeaponOrder_BuildImpulseList_buf[Weapons_MAX];
+float W_FixWeaponOrder_BuildImpulseList_buf[REGISTRY_MAX(Weapons)];
 string W_FixWeaponOrder_BuildImpulseList_order;
 void W_FixWeaponOrder_BuildImpulseList_swap(int i, int j, entity pass)
 {
index 26b4008..e82dce3 100644 (file)
@@ -297,7 +297,7 @@ const .float reloading_time = reload_time;
 #define WEP_CVAR_BOTH(wepname, isprimary, name) ((isprimary) ? WEP_CVAR_PRI(wepname, name) : WEP_CVAR_SEC(wepname, name))
 
 const int WEP_FIRST = 1;
-#define WEP_LAST (Weapons_COUNT - 1)
+#define WEP_LAST (REGISTRY_COUNT(Weapons) - 1)
 WepSet WEPSET_ALL;
 WepSet WEPSET_SUPERWEAPONS;
 
@@ -308,7 +308,7 @@ WepSet WEPSET_SUPERWEAPONS;
 
 // TODO: invert after 0.8.2. Will require moving 'best weapon' impulses
 #define WEP_IMPULSE_BEGIN 230
-#define WEP_IMPULSE_END bound(WEP_IMPULSE_BEGIN, WEP_IMPULSE_BEGIN + (Weapons_COUNT - 1) - 1, 253)
+#define WEP_IMPULSE_END bound(WEP_IMPULSE_BEGIN, WEP_IMPULSE_BEGIN + (REGISTRY_COUNT(Weapons) - 1) - 1, 253)
 
 REGISTRY_SORT(Weapons, WEP_HARDCODED_IMPULSES + 1)
 REGISTRY_CHECK(Weapons)
@@ -332,7 +332,7 @@ STATIC_INIT(register_weapons_done)
     FOREACH(Weapons, true, it.wr_init(it));
     #endif
     weaponorder_byid = "";
-    for (int i = Weapons_MAX - 1; i >= 1; --i)
+    for (int i = REGISTRY_MAX(Weapons) - 1; i >= 1; --i)
         if (Weapons_from(i))
             weaponorder_byid = strcat(weaponorder_byid, " ", ftos(i));
     weaponorder_byid = strzone(substring(weaponorder_byid, 1, -1));
index a48e83a..b25878c 100644 (file)
@@ -14,6 +14,8 @@
        #define _R_DEL(r)
 #endif
 
+#define REGISTRY_MAX(id) id##_MAX
+#define REGISTRY_COUNT(id) id##_COUNT
 /**
  * Declare a new registry.
  *
@@ -129,14 +131,14 @@ MACRO_END
                entity a = _R_GET(_##id, i), b = _R_GET(_##id, j); \
                _R_SET(_##id, i, b); \
                _R_SET(_##id, j, a); \
-        \
+               \
                entity a_next = a.REGISTRY_NEXT, b_next = b.REGISTRY_NEXT; \
                a.REGISTRY_NEXT = b_next; \
                b.REGISTRY_NEXT = a_next; \
-        \
+               \
                if (i == 0) id##_first = b; \
                else _R_GET(_##id, i - 1).REGISTRY_NEXT = b; \
-        \
+               \
                if (j == 0) id##_first = a; \
                else _R_GET(_##id, j - 1).REGISTRY_NEXT = a; \
        } \
@@ -201,6 +203,6 @@ void Registry_send(string id, string hash);
        ENDCLASS(id##Registry) \
        REGISTER(Registries, REGISTRY, id, m_id, NEW(id##Registry)); \
        METHOD(id##Registry, m_reload, void()) { \
-           id##_state = 0; \
+               id##_state = 0; \
                Register##id(); \
        }
index ba10d27..fc0790d 100644 (file)
@@ -16,7 +16,7 @@ METHOD(SettingSource, getEntryTooltip, entity(entity this, int i, void(string th
     if (returns) returns(it.titleTooltip);
     return it;
 }
-METHOD(SettingSource, reload, int(entity this, string filter)) { return Settings_COUNT; }
+METHOD(SettingSource, reload, int(entity this, string filter)) { return REGISTRY_COUNT(Settings); }
 
 string XonoticRegisteredSettingsList_cb_name;
 string XonoticRegisteredSettingsList_cb_tooltip;
index f8285f6..81baa2c 100644 (file)
@@ -25,9 +25,9 @@ const int WAYPOINTFLAG_NORELINK__DEPRECATED = BIT(20);
 const int WPFLAGMASK_NORELINK = (WAYPOINTFLAG_TELEPORT | WAYPOINTFLAG_LADDER | WAYPOINTFLAG_JUMP | WAYPOINTFLAG_CUSTOM_JP | WAYPOINTFLAG_SUPPORT);
 
 float bot_custom_weapon;
-float bot_weapons_close[Weapons_MAX];
-float bot_weapons_far[Weapons_MAX];
-float bot_weapons_mid[Weapons_MAX];
+float bot_weapons_close[REGISTRY_MAX(Weapons)];
+float bot_weapons_far[REGISTRY_MAX(Weapons)];
+float bot_weapons_mid[REGISTRY_MAX(Weapons)];
 float skill;
 
 .float bot_tracewalk_time;
index 7b30b62..57de9f0 100644 (file)
@@ -350,14 +350,14 @@ void bot_custom_weapon_priority_setup()
                        tokens = tokenizebyseparator(W_NumberWeaponOrder(autocvar_bot_ai_custom_weapon_priority_##dist)," "); \
                        bot_weapons_##dist[0] = -1; \
                        c = 0; \
-                       for(i = 0; i < tokens && c < Weapons_COUNT; ++i) { \
+                       for(i = 0; i < tokens && c < REGISTRY_COUNT(Weapons); ++i) { \
                                w = stof(argv(i)); \
                                if (w >= WEP_FIRST && w <= WEP_LAST) { \
                                        bot_weapons_##dist[c] = w; \
                                        ++c; \
                                } \
                        } \
-                       if (c < Weapons_COUNT) \
+                       if (c < REGISTRY_COUNT(Weapons)) \
                                bot_weapons_##dist[c] = -1; \
                } \
        MACRO_END
index 6515cc4..3d744f7 100644 (file)
@@ -1476,7 +1476,7 @@ void havocbot_chooseweapon(entity this, .entity weaponentity)
 
                // Choose weapons for far distance
                if ( distance > bot_distance_far ) {
-                       for(i=0; i < Weapons_COUNT && bot_weapons_far[i] != -1 ; ++i){
+                       for(i=0; i < REGISTRY_COUNT(Weapons) && bot_weapons_far[i] != -1 ; ++i){
                                w = bot_weapons_far[i];
                                if ( client_hasweapon(this, Weapons_from(w), weaponentity, true, false) )
                                {
@@ -1490,7 +1490,7 @@ void havocbot_chooseweapon(entity this, .entity weaponentity)
 
                // Choose weapons for mid distance
                if ( distance > bot_distance_close) {
-                       for(i=0; i < Weapons_COUNT && bot_weapons_mid[i] != -1 ; ++i){
+                       for(i=0; i < REGISTRY_COUNT(Weapons) && bot_weapons_mid[i] != -1 ; ++i){
                                w = bot_weapons_mid[i];
                                if ( client_hasweapon(this, Weapons_from(w), weaponentity, true, false) )
                                {
@@ -1503,7 +1503,7 @@ void havocbot_chooseweapon(entity this, .entity weaponentity)
                }
 
                // Choose weapons for close distance
-               for(i=0; i < Weapons_COUNT && bot_weapons_close[i] != -1 ; ++i){
+               for(i=0; i < REGISTRY_COUNT(Weapons) && bot_weapons_close[i] != -1 ; ++i){
                        w = bot_weapons_close[i];
                        if ( client_hasweapon(this, Weapons_from(w), weaponentity, true, false) )
                        {
index 9d74219..a8ec779 100644 (file)
@@ -195,7 +195,7 @@ void FixClientCvars(entity e);
 
 float bot_waypoints_for_items;
 
-.float attack_finished_for[Weapons_MAX * MAX_WEAPONSLOTS];
+.float attack_finished_for[REGISTRY_MAX(Weapons) * MAX_WEAPONSLOTS];
 .float attack_finished_single[MAX_WEAPONSLOTS];
 #if INDEPENDENT_ATTACK_FINISHED
 #define ATTACK_FINISHED_FOR(ent, w, slot) ((ent).(attack_finished_for[((w) - WEP_FIRST) * MAX_WEAPONSLOTS + (slot)]))
@@ -296,7 +296,7 @@ string matchid;
 
 bool radar_showennemies;
 
-.float weapon_load[Weapons_MAX];
+.float weapon_load[REGISTRY_MAX(Weapons)];
 .int ammo_none; // used by the reloading system, must always be 0
 .int clip_load;
 .int old_clip_load;
index 627698a..5d10e85 100644 (file)
@@ -9,12 +9,12 @@ REPLICATE(cvar_cl_accuracy_data_share, bool, "cl_accuracy_data_share");
 REPLICATE(cvar_cl_accuracy_data_receive, bool, "cl_accuracy_data_receive");
 
 .entity accuracy;
-.float accuracy_frags[Weapons_MAX];
+.float accuracy_frags[REGISTRY_MAX(Weapons)];
 
-.float accuracy_hit[Weapons_MAX];
-.float accuracy_fired[Weapons_MAX];
-.float accuracy_cnt_hit[Weapons_MAX];
-.float accuracy_cnt_fired[Weapons_MAX];
+.float accuracy_hit[REGISTRY_MAX(Weapons)];
+.float accuracy_fired[REGISTRY_MAX(Weapons)];
+.float accuracy_cnt_hit[REGISTRY_MAX(Weapons)];
+.float accuracy_cnt_fired[REGISTRY_MAX(Weapons)];
 
 
 // init/free