From 61704462bb3c8ce7bfa7f815dcd62e6ff3189c82 Mon Sep 17 00:00:00 2001 From: TimePath Date: Tue, 6 Oct 2015 20:41:12 +1100 Subject: [PATCH] Weapons: rename registry globals --- qcsrc/client/hud.qc | 12 ++--- qcsrc/client/hud.qh | 2 +- qcsrc/client/scoreboard.qc | 4 +- qcsrc/common/weapons/all.qc | 53 ++++++++------------- qcsrc/common/weapons/all.qh | 56 ++++++++--------------- qcsrc/lib/registry.qh | 2 +- qcsrc/server/bot/bot.qc | 12 ++--- qcsrc/server/bot/bot.qh | 6 +-- qcsrc/server/bot/havocbot/havocbot.qc | 6 +-- qcsrc/server/defs.qh | 4 +- qcsrc/server/mutators/mutator_overkill.qh | 2 +- qcsrc/server/weapons/accuracy.qh | 10 ++-- 12 files changed, 66 insertions(+), 103 deletions(-) diff --git a/qcsrc/client/hud.qc b/qcsrc/client/hud.qc index a47ccd7a0..cd1c6efee 100644 --- a/qcsrc/client/hud.qc +++ b/qcsrc/client/hud.qc @@ -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; diff --git a/qcsrc/client/hud.qh b/qcsrc/client/hud.qh index 62b5ec6fd..ebde4b12b 100644 --- a/qcsrc/client/hud.qh +++ b/qcsrc/client/hud.qh @@ -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; diff --git a/qcsrc/client/scoreboard.qc b/qcsrc/client/scoreboard.qc index 3c331fd49..a1d9a50dc 100644 --- a/qcsrc/client/scoreboard.qc +++ b/qcsrc/client/scoreboard.qc @@ -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; diff --git a/qcsrc/common/weapons/all.qc b/qcsrc/common/weapons/all.qc index 10911e4cd..8552f9730 100644 --- a/qcsrc/common/weapons/all.qc +++ b/qcsrc/common/weapons/all.qc @@ -58,56 +58,45 @@ // 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) { diff --git a/qcsrc/common/weapons/all.qh b/qcsrc/common/weapons/all.qh index e403f03e5..baba31192 100644 --- a/qcsrc/common/weapons/all.qh +++ b/qcsrc/common/weapons/all.qh @@ -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)); } diff --git a/qcsrc/lib/registry.qh b/qcsrc/lib/registry.qh index b74c4783b..942c5b2bb 100644 --- a/qcsrc/lib/registry.qh +++ b/qcsrc/lib/registry.qh @@ -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 diff --git a/qcsrc/server/bot/bot.qc b/qcsrc/server/bot/bot.qc index a6762c76d..00051cadb 100644 --- a/qcsrc/server/bot/bot.qc +++ b/qcsrc/server/bot/bot.qc @@ -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; diff --git a/qcsrc/server/bot/bot.qh b/qcsrc/server/bot/bot.qh index a796dc12d..d5a279400 100644 --- a/qcsrc/server/bot/bot.qh +++ b/qcsrc/server/bot/bot.qh @@ -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; diff --git a/qcsrc/server/bot/havocbot/havocbot.qc b/qcsrc/server/bot/havocbot/havocbot.qc index 060766891..f69527916 100644 --- a/qcsrc/server/bot/havocbot/havocbot.qc +++ b/qcsrc/server/bot/havocbot/havocbot.qc @@ -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) ) { diff --git a/qcsrc/server/defs.qh b/qcsrc/server/defs.qh index a8c23b26e..09e6becaf 100644 --- a/qcsrc/server/defs.qh +++ b/qcsrc/server/defs.qh @@ -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; diff --git a/qcsrc/server/mutators/mutator_overkill.qh b/qcsrc/server/mutators/mutator_overkill.qh index 0b418be40..10f89c08e 100644 --- a/qcsrc/server/mutators/mutator_overkill.qh +++ b/qcsrc/server/mutators/mutator_overkill.qh @@ -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; diff --git a/qcsrc/server/weapons/accuracy.qh b/qcsrc/server/weapons/accuracy.qh index 03f002f6a..e8d22d98b 100644 --- a/qcsrc/server/weapons/accuracy.qh +++ b/qcsrc/server/weapons/accuracy.qh @@ -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 -- 2.39.2