// Weapon icons (#0)
//
-entity weaponorder[WEP_MAXCOUNT];
+entity weaponorder[Weapons_MAX];
void weaponorder_swap(int i, int j, entity pass)
{
entity h = weaponorder[i];
++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);
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);
}
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;
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)
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;
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;
++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;
// 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
{
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
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)
{
#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;
#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;
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));
}
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
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;
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;
// 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) )
{
// 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) )
{
}
// 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) )
{
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]))
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;
.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;
.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