]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Weapons: rename registry globals
authorTimePath <andrew.hardaker1995@gmail.com>
Tue, 6 Oct 2015 09:41:12 +0000 (20:41 +1100)
committerTimePath <andrew.hardaker1995@gmail.com>
Tue, 6 Oct 2015 09:41:12 +0000 (20:41 +1100)
12 files changed:
qcsrc/client/hud.qc
qcsrc/client/hud.qh
qcsrc/client/scoreboard.qc
qcsrc/common/weapons/all.qc
qcsrc/common/weapons/all.qh
qcsrc/lib/registry.qh
qcsrc/server/bot/bot.qc
qcsrc/server/bot/bot.qh
qcsrc/server/bot/havocbot/havocbot.qc
qcsrc/server/defs.qh
qcsrc/server/mutators/mutator_overkill.qh
qcsrc/server/weapons/accuracy.qh

index a47ccd7a0f418158c72d071f066bff8d4de462da..cd1c6efee469a440314f01ff9e08a85f2663af22 100644 (file)
@@ -334,7 +334,7 @@ void HUD_Panel_DrawHighlight(vector pos, vector mySize, vector color, float theA
 
 // Weapon icons (#0)
 //
-entity weaponorder[WEP_MAXCOUNT];
+entity weaponorder[Weapons_MAX];
 void weaponorder_swap(int i, int j, entity pass)
 {
        entity h = weaponorder[i];
@@ -420,7 +420,7 @@ void HUD_Weapons(void)
                                ++weapon_cnt;
                        }
                }
-               for(i = weapon_cnt; i < WEP_MAXCOUNT; ++i)
+               for(i = weapon_cnt; i < Weapons_MAX; ++i)
                        weaponorder[i] = world;
                heapsort(weapon_cnt, weaponorder_swap, weaponorder_cmp, world);
 
@@ -441,7 +441,7 @@ void HUD_Weapons(void)
                if(cvar("wep_add"))
                {
                        weapons_stat = '0 0 0';
-                       float countw = 1 + floor((floor(time * cvar("wep_add"))) % (WEP_COUNT - 1));
+                       float countw = 1 + floor((floor(time * cvar("wep_add"))) % (Weapons_COUNT - 1));
                        for(i = WEP_FIRST; i <= countw; ++i)
                                weapons_stat |= WepSet_FromWeapon(i);
                }
@@ -480,7 +480,7 @@ void HUD_Weapons(void)
                        Weapon w = get_weaponinfo(i);
                        if (w.spawnflags & WEP_FLAG_MUTATORBLOCKED) nHidden += 1;
                }
-               vector table_size = HUD_GetTableSize_BestItemAR((WEP_COUNT - 1) - nHidden, padded_panel_size, aspect);
+               vector table_size = HUD_GetTableSize_BestItemAR((Weapons_COUNT - 1) - nHidden, padded_panel_size, aspect);
                columns = table_size.x;
                rows = table_size.y;
                weapon_size.x = padded_panel_size.x / columns;
@@ -535,7 +535,7 @@ void HUD_Weapons(void)
                        panel_pos.y += (old_panel_size.y - panel_size.y) / 2;
        }
        else
-               weapon_count = (WEP_COUNT - 1);
+               weapon_count = (Weapons_COUNT - 1);
 
        // animation for fading in/out the panel respectively when not in use
        if(!autocvar__hud_configure)
@@ -640,7 +640,7 @@ void HUD_Weapons(void)
 
        if(!rows) // if rows is > 0 onlyowned code has already updated these vars
        {
-               vector table_size = HUD_GetTableSize_BestItemAR((WEP_COUNT - 1), panel_size, aspect);
+               vector table_size = HUD_GetTableSize_BestItemAR((Weapons_COUNT - 1), panel_size, aspect);
                columns = table_size.x;
                rows = table_size.y;
                weapon_size.x = panel_size.x / columns;
index 62b5ec6fd3675e5cf6f41ff0066e41a6c5c9fcb9..ebde4b12b8c4e81abca18085b68c31afea751b26 100644 (file)
@@ -46,7 +46,7 @@ float highlightedAction; // 0 = nothing, 1 = move, 2 = resize
 
 const float BORDER_MULTIPLIER = 0.25;
 float scoreboard_bottom;
-int weapon_accuracy[WEP_MAXCOUNT];
+int weapon_accuracy[Weapons_MAX];
 
 int complain_weapon;
 string complain_weapon_name;
index 3c331fd49470424ca4e81a2dd968bc855a250d5b..a1d9a50dcd5aeb1943a3fc896cd0d46e440e07bc 100644 (file)
@@ -994,13 +994,13 @@ vector HUD_DrawScoreboardAccuracyStats(vector pos, vector rgb, vector bg_size)
                        ++disownedcnt;
        }
 
-       int weapon_cnt = (WEP_COUNT - 1) - disownedcnt;
+       int weapon_cnt = (Weapons_COUNT - 1) - disownedcnt;
 
        if(weapon_cnt <= 0)
                return pos;
 
        int rows;
-       if(autocvar_scoreboard_accuracy_doublerows && weapon_cnt >= floor((WEP_COUNT - 1) * 0.5))
+       if(autocvar_scoreboard_accuracy_doublerows && weapon_cnt >= floor((Weapons_COUNT - 1) * 0.5))
                rows = 2;
        else
                rows = 1;
index 10911e4cdbd40bb1ef79fadc02a51a26ebc57e55..8552f97300f70be6b51e85e5bd2af76787fe1e95 100644 (file)
 
 // WEAPON PLUGIN SYSTEM
 
-#if WEP_MAXCOUNT > 72
-# error Kein Weltraum links auf dem Gerät
-#endif
-
 WepSet WepSet_FromWeapon(int a) {
        a -= WEP_FIRST;
-#if WEP_MAXCOUNT > 24
-       if(a >= 24) {
+       if (Weapons_MAX > 24)
+       if (a >= 24) {
                a -= 24;
-#if WEP_MAXCOUNT > 48
-               if(a >= 24) {
+               if (Weapons_MAX > 48)
+               if (a >= 24) {
                        a -= 24;
                        return '0 0 1' * power2of(a);
                }
-#endif
                return '0 1 0' * power2of(a);
        }
-#endif
        return '1 0 0' * power2of(a);
 }
 #ifdef SVQC
 void WepSet_AddStat()
 {
        addstat(STAT_WEAPONS, AS_INT, weapons_x);
-#if WEP_MAXCOUNT > 24
+       if (Weapons_MAX > 24)
        addstat(STAT_WEAPONS2, AS_INT, weapons_y);
-#if WEP_MAXCOUNT > 48
+       if (Weapons_MAX > 48)
        addstat(STAT_WEAPONS3, AS_INT, weapons_z);
-#endif
-#endif
 }
 void WepSet_AddStat_InMap()
 {
        addstat(STAT_WEAPONSINMAP, AS_INT, weaponsinmap_x);
-#if WEP_MAXCOUNT > 24
+       if (Weapons_MAX > 24)
        addstat(STAT_WEAPONSINMAP2, AS_INT, weaponsinmap_y);
-#if WEP_MAXCOUNT > 48
+       if (Weapons_MAX > 48)
        addstat(STAT_WEAPONSINMAP3, AS_INT, weaponsinmap_z);
-#endif
-#endif
 }
 void WriteWepSet(float dst, WepSet w)
 {
-#if WEP_MAXCOUNT > 48
+       if (Weapons_MAX > 48)
        WriteInt72_t(dst, w);
-#elif WEP_MAXCOUNT > 24
+       else if (Weapons_MAX > 24)
        WriteInt48_t(dst, w);
-#else
+       else
        WriteInt24_t(dst, w.x);
-#endif
 }
 #endif
 #ifdef CSQC
@@ -115,35 +104,29 @@ WepSet WepSet_GetFromStat()
 {
        WepSet w = '0 0 0';
        w.x = getstati(STAT_WEAPONS);
-#if WEP_MAXCOUNT > 24
+       if (Weapons_MAX > 24)
        w.y = getstati(STAT_WEAPONS2);
-#if WEP_MAXCOUNT > 48
+       if (Weapons_MAX > 48)
        w.z = getstati(STAT_WEAPONS3);
-#endif
-#endif
        return w;
 }
 WepSet WepSet_GetFromStat_InMap()
 {
        WepSet w = '0 0 0';
        w_x = getstati(STAT_WEAPONSINMAP);
-#if WEP_MAXCOUNT > 24
+       if (Weapons_MAX > 24)
        w_y = getstati(STAT_WEAPONSINMAP2);
-#if WEP_MAXCOUNT > 48
+       if (Weapons_MAX > 48)
        w_z = getstati(STAT_WEAPONSINMAP3);
-#endif
-#endif
        return w;
 }
 WepSet ReadWepSet()
 {
-#if WEP_MAXCOUNT > 48
+       if (Weapons_MAX > 48)
        return ReadInt72_t();
-#elif WEP_MAXCOUNT > 24
+       if (Weapons_MAX > 24)
        return ReadInt48_t();
-#else
        return ReadInt24_t() * '1 0 0';
-#endif
 }
 #endif
 
@@ -196,7 +179,7 @@ string W_NumberWeaponOrder(string order)
        return mapPriorityList(order, W_NumberWeaponOrder_MapFunc);
 }
 
-float W_FixWeaponOrder_BuildImpulseList_buf[WEP_MAXCOUNT];
+float W_FixWeaponOrder_BuildImpulseList_buf[Weapons_MAX];
 string W_FixWeaponOrder_BuildImpulseList_order;
 void W_FixWeaponOrder_BuildImpulseList_swap(int i, int j, entity pass)
 {
index e403f03e5bf55bf922f4fdf4b9292f70e180f230..baba311922d3bc6cac5f0f6ba97b7326c41051ef 100644 (file)
@@ -30,21 +30,13 @@ WepSet ReadWepSet();
 #include "../../server/bot/aim.qh"
 #endif
 
-const int WEP_FIRST = 1;
-#define WEP_MAXCOUNT 72 // Increase as needed. Can be up to 72.
-int WEP_COUNT;
-#define WEP_LAST (WEP_FIRST + (WEP_COUNT - 1) - 1)
-WepSet WEPSET_ALL;
-WepSet WEPSET_SUPERWEAPONS;
-
-void RegisterWeapons();
+REGISTRY(Weapons, 72) // Increase as needed. Can be up to 72.
 REGISTER_REGISTRY(RegisterWeapons)
-entity weapon_info[WEP_MAXCOUNT], weapon_info_first, weapon_info_last;
 entity get_weaponinfo(int id);
 
 #define REGISTER_WEAPON(id, inst) \
        /* WepSet WEPSET_##id; */ \
-       REGISTER(RegisterWeapons, WEP, weapon_info, WEP_COUNT, id, m_id, inst)
+       REGISTER(RegisterWeapons, WEP, Weapons, Weapons_COUNT, id, m_id, inst)
 
 // create cvars for weapon settings
 #define WEP_ADD_CVAR_NONE(wepname,name) [[last]] float autocvar_g_balance_##wepname##_##name;
@@ -72,49 +64,37 @@ entity get_weaponinfo(int id);
 #define WEP_SKIP_CVAR(unuseda,unusedb,unusedc,unusedd) /* skip cvars */
 #define WEP_SET_PROP(wepid,wepname,type,prop,name) WEP_##wepid.prop = autocvar_g_balance_##wepname##_##name;
 
+const int WEP_FIRST = 1;
+#define WEP_LAST (Weapons_COUNT - 1)
+WepSet WEPSET_ALL;
+WepSet WEPSET_SUPERWEAPONS;
+
 REGISTER_WEAPON(Null, NEW(Weapon));
 
 #include "all.inc"
 
 entity get_weaponinfo(int id)
 {
-       if(id < WEP_FIRST || id > WEP_LAST)
-               return WEP_Null;
-       Weapon w = weapon_info[id];
-       if(w)
-               return w;
+       if (id >= WEP_FIRST && id <= WEP_LAST) {
+               Weapon w = Weapons[id];
+               if (w) return w;
+       }
        return WEP_Null;
 }
 
 // TODO: remove after 0.8.2. Retains impulse number compatibility because 0.8.1 clients don't reload the weapons.cfg
 #define WEP_HARDCODED_IMPULSES 22
 
-void _REGISTRY_SWAP(int i, int j, entity pass)
-{
-       i += WEP_HARDCODED_IMPULSES + 1; j += WEP_HARDCODED_IMPULSES + 1;
-       entity e = weapon_info[i];
-       weapon_info[i] = weapon_info[j];
-       weapon_info[j] = e;
-}
-
-float _REGISTRY_CMP(int i, int j, entity pass)
-{
-       i += WEP_HARDCODED_IMPULSES + 1; j += WEP_HARDCODED_IMPULSES + 1;
-       string a = weapon_info[i].netname;
-       string b = weapon_info[j].netname;
-       return strcasecmp(a, b);
-}
-
 // 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 + (WEP_COUNT - 1) - 1, 253)
+#define WEP_IMPULSE_END bound(WEP_IMPULSE_BEGIN, WEP_IMPULSE_BEGIN + (Weapons_COUNT - 1) - 1, 253)
+
+REGISTRY_SORT(Weapons, netname, WEP_HARDCODED_IMPULSES + 1)
 
 STATIC_INIT(register_weapons_done)
 {
-       // Sort all extra weapons not #included in all.inc by their netname so it doesn't matter when they were initialized
-       heapsort(WEP_COUNT - (1 /* WEP_Null */ + WEP_HARDCODED_IMPULSES), _REGISTRY_SWAP, _REGISTRY_CMP, NULL);
-       for (int i = 0; i < WEP_COUNT; ++i) {
-               Weapon it = weapon_info[i];
+       for (int i = 0; i < Weapons_COUNT; ++i) {
+               Weapon it = Weapons[i];
                it.m_id = i;
                WepSet set = WepSet_FromWeapon(it.m_id);
                WEPSET_ALL |= set;
@@ -131,8 +111,8 @@ STATIC_INIT(register_weapons_done)
                        LOG_TRACEF(_("Impulse limit exceeded, weapon will not be directly accessible: %s\n"), it.netname);
        }
        weaponorder_byid = "";
-       for (int i = WEP_MAXCOUNT - 1; i >= 1; --i)
-               if (weapon_info[i])
+       for (int i = Weapons_MAX - 1; i >= 1; --i)
+               if (Weapons[i])
                        weaponorder_byid = strcat(weaponorder_byid, " ", ftos(i));
        weaponorder_byid = strzone(substring(weaponorder_byid, 1, strlen(weaponorder_byid) - 1));
 }
index b74c4783b9285debdd37b718561ddafaf5287a27..942c5b2bba5858921b8a1c19615cefb3905099e0 100644 (file)
@@ -68,7 +68,7 @@
         return strcasecmp(a, b);                                \
     }                                                           \
     STATIC_INIT(Registry_sort_##id) {                           \
-        heapsort(id##_COUNT, _REGISTRY_SWAP_##id, _REGISTRY_CMP_##id, NULL); \
+        heapsort(id##_COUNT - (skip), _REGISTRY_SWAP_##id, _REGISTRY_CMP_##id, NULL); \
     }
 
 #endif
index a6762c76d0996c7e5db33ec098dcc77eada42e19..00051cadb9cbdeee1b806ac9a7f8ec104a97f4ff 100644 (file)
@@ -300,42 +300,42 @@ void bot_custom_weapon_priority_setup()
        tokens = tokenizebyseparator(W_NumberWeaponOrder(autocvar_bot_ai_custom_weapon_priority_far)," ");
 
        int c = 0;
-       for(i=0; i < tokens && c < WEP_COUNT; ++i){
+       for(i=0; i < tokens && c < Weapons_COUNT; ++i){
                w = stof(argv(i));
                if ( w >= WEP_FIRST && w <= WEP_LAST) {
                        bot_weapons_far[c] = w;
                        ++c;
                }
        }
-       if(c < WEP_COUNT)
+       if(c < Weapons_COUNT)
                bot_weapons_far[c] = -1;
 
        // Parse mid distance weapon priorities
        tokens = tokenizebyseparator(W_NumberWeaponOrder(autocvar_bot_ai_custom_weapon_priority_mid)," ");
 
        c = 0;
-       for(i=0; i < tokens && c < WEP_COUNT; ++i){
+       for(i=0; i < tokens && c < Weapons_COUNT; ++i){
                w = stof(argv(i));
                if ( w >= WEP_FIRST && w <= WEP_LAST) {
                        bot_weapons_mid[c] = w;
                        ++c;
                }
        }
-       if(c < WEP_COUNT)
+       if(c < Weapons_COUNT)
                bot_weapons_mid[c] = -1;
 
        // Parse close distance weapon priorities
        tokens = tokenizebyseparator(W_NumberWeaponOrder(autocvar_bot_ai_custom_weapon_priority_close)," ");
 
        c = 0;
-       for(i=0; i < tokens && i < WEP_COUNT; ++i){
+       for(i=0; i < tokens && i < Weapons_COUNT; ++i){
                w = stof(argv(i));
                if ( w >= WEP_FIRST && w <= WEP_LAST) {
                        bot_weapons_close[c] = w;
                        ++c;
                }
        }
-       if(c < WEP_COUNT)
+       if(c < Weapons_COUNT)
                bot_weapons_close[c] = -1;
 
        bot_custom_weapon = true;
index a796dc12d5220c870db79f9c1dd6c44b4b9754ed..d5a2794008019675759858141e47bdf83ef9e03c 100644 (file)
@@ -48,9 +48,9 @@ float bot_custom_weapon;
 float bot_distance_far;
 float bot_distance_close;
 
-float bot_weapons_far[WEP_MAXCOUNT];
-float bot_weapons_mid[WEP_MAXCOUNT];
-float bot_weapons_close[WEP_MAXCOUNT];
+float bot_weapons_far[Weapons_MAX];
+float bot_weapons_mid[Weapons_MAX];
+float bot_weapons_close[Weapons_MAX];
 
 entity bot_list;
 entity player_list;
index 06076689134f5c7afbf18eed37df77a68e6297fb..f69527916ce512ad8c3d94ac61e798883716f459 100644 (file)
@@ -1067,7 +1067,7 @@ void havocbot_chooseweapon()
 
                // Choose weapons for far distance
                if ( distance > bot_distance_far ) {
-                       for(i=0; i < WEP_COUNT && bot_weapons_far[i] != -1 ; ++i){
+                       for(i=0; i < Weapons_COUNT && bot_weapons_far[i] != -1 ; ++i){
                                w = bot_weapons_far[i];
                                if ( client_hasweapon(self, w, true, false) )
                                {
@@ -1081,7 +1081,7 @@ void havocbot_chooseweapon()
 
                // Choose weapons for mid distance
                if ( distance > bot_distance_close) {
-                       for(i=0; i < WEP_COUNT && bot_weapons_mid[i] != -1 ; ++i){
+                       for(i=0; i < Weapons_COUNT && bot_weapons_mid[i] != -1 ; ++i){
                                w = bot_weapons_mid[i];
                                if ( client_hasweapon(self, w, true, false) )
                                {
@@ -1094,7 +1094,7 @@ void havocbot_chooseweapon()
                }
 
                // Choose weapons for close distance
-               for(i=0; i < WEP_COUNT && bot_weapons_close[i] != -1 ; ++i){
+               for(i=0; i < Weapons_COUNT && bot_weapons_close[i] != -1 ; ++i){
                        w = bot_weapons_close[i];
                        if ( client_hasweapon(self, w, true, false) )
                        {
index a8c23b26edfaa72f50aaf2907a2e3995b3c06eb8..09e6becafcdc0df38afc3f2c9537173f92b87a57 100644 (file)
@@ -261,7 +261,7 @@ WepSet weaponsInMap;
 
 float bot_waypoints_for_items;
 
-.float attack_finished_for[WEP_MAXCOUNT];
+.float attack_finished_for[Weapons_MAX];
 .float attack_finished_single;
 #ifdef INDEPENDENT_ATTACK_FINISHED
 #define ATTACK_FINISHED_FOR(ent,w) ((ent).(attack_finished_for[(w) - WEP_FIRST]))
@@ -466,7 +466,7 @@ float client_cefc_accumulator;
 float client_cefc_accumulatortime;
 #endif
 
-.float weapon_load[WEP_MAXCOUNT];
+.float weapon_load[Weapons_MAX];
 .int ammo_none; // used by the reloading system, must always be 0
 .float clip_load;
 .float old_clip_load;
index 0b418be40b0b71f07f46c53b952c790b42b0eb86..10f89c08e0978a2993e2a009e81ea1148ff5cdda 100644 (file)
@@ -7,7 +7,7 @@
 .float ok_item;
 
 .float ok_notice_time;
-.float ammo_charge[WEP_MAXCOUNT];
+.float ammo_charge[Weapons_MAX];
 .float ok_use_ammocharge;
 .float ok_ammo_charge;
 
index 03f002f6a9fd59d8576de2050ab60c0dc2aa96d0..e8d22d98b19db76ac1f14935aee31b2f3ce2c96d 100644 (file)
@@ -5,12 +5,12 @@
 .float cvar_cl_accuracy_data_receive;
 
 .entity accuracy;
-.float accuracy_frags[WEP_MAXCOUNT];
+.float accuracy_frags[Weapons_MAX];
 
-.float accuracy_hit[WEP_MAXCOUNT];
-.float accuracy_fired[WEP_MAXCOUNT];
-.float accuracy_cnt_hit[WEP_MAXCOUNT];
-.float accuracy_cnt_fired[WEP_MAXCOUNT];
+.float accuracy_hit[Weapons_MAX];
+.float accuracy_fired[Weapons_MAX];
+.float accuracy_cnt_hit[Weapons_MAX];
+.float accuracy_cnt_fired[Weapons_MAX];
 
 
 // init/free