string s = cvar_string(thiscvar);
if (thiscvar == "cl_weaponpriority")
- s = W_FixWeaponOrder(W_NumberWeaponOrder(s), 1);
+ s = W_FIXWEAPONORDER(W_NUMBERWEAPONORDER(s), 1);
else if (substring(thiscvar, 0, 17) == "cl_weaponpriority" && strlen(thiscvar) == 18)
- s = W_FixWeaponOrder(W_NumberWeaponOrder(s), 0);
+ s = W_FIXWEAPONORDER(W_NUMBERWEAPONORDER(s), 0);
localcmd("cmd sentcvar ", thiscvar, " \"", s, "\"\n");
strfree(thiscvar);
ammo = 60;
}
else
- ammo = getstati(GetAmmoStat(ammoType));
+ ammo = getstati(GETAMMOSTAT(ammoType));
if(!isCurrent)
{
if(autocvar_hud_panel_ammo_text)
drawstring_aspect(textPos, text, eX * (2/3) * mySize.x + eY * mySize.y, textColor, alpha, DRAWFLAG_NORMAL);
- drawpic_aspect_skin(iconPos, GetAmmoPicture(ammoType), '1 1 0' * mySize.y, iconColor, alpha, DRAWFLAG_NORMAL);
+ drawpic_aspect_skin(iconPos, GETAMMOPICTURE(ammoType), '1 1 0' * mySize.y, iconColor, alpha, DRAWFLAG_NORMAL);
}
int nade_prevstatus;
//FOREACH(Resources, it.instanceOfAmmoResource && !it.m_hidden,
for(int j = 0; j < AMMO_COUNT; ++j)
{
- Resource ammotype = GetAmmoTypeFromNum(j);
+ Resource ammotype = GETAMMOTYPEFROMNUM(j);
DrawAmmoItem(
pos + vec2(column * (ammo_size.x + offset.x), row * (ammo_size.y + offset.y)),
ammo_size,
{
weapons_orderbyimpulse_old = autocvar_hud_panel_weapons_orderbyimpulse;
strcpy(cl_weaponpriority_old, autocvar_cl_weaponpriority);
- string weporder = W_FixWeaponOrder_ForceComplete(W_NumberWeaponOrder(cl_weaponpriority_old));
+ string weporder = W_FIXWEAPNORDER_FORCECOMPLETE(W_NUMBERWEAPONORDER(cl_weaponpriority_old));
if(autocvar_hud_panel_weapons_orderbyimpulse)
{
weporder = W_FixWeaponOrder_BuildImpulseList(weporder);
if(!infinite_ammo && autocvar_hud_panel_weapons_ammo && (it.ammo_type != RES_NONE))
{
float ammo_full;
- a = getstati(GetAmmoStat(it.ammo_type)); // how much ammo do we have?
+ a = getstati(GETAMMOSTAT(it.ammo_type)); // how much ammo do we have?
if(a > 0)
{
{
string ammoitems = "";
Weapon wep = REGISTRY_GET(Weapons, f1);
- // TODO: registry handles
- switch (wep.ammo_type)
- {
- case RES_SHELLS: ammoitems = ITEM_Shells.m_name; break;
- case RES_BULLETS: ammoitems = ITEM_Bullets.m_name; break;
- case RES_ROCKETS: ammoitems = ITEM_Rockets.m_name; break;
- case RES_CELLS: ammoitems = ITEM_Cells.m_name; break;
- case RES_PLASMA: ammoitems = ITEM_Plasma.m_name; break;
- case RES_FUEL: ammoitems = ITEM_JetpackFuel.m_name; break;
- default: return ""; // doesn't use ammo
- }
+ if (wep.ammo_type.m_name)
+ ammoitems = wep.ammo_type.m_name;
return sprintf(_(" with %d %s"), f2, ammoitems);
}
}
#endif
-string W_FixWeaponOrder(string order, float complete)
-{
- return fixPriorityList(order, WEP_FIRST, WEP_LAST, WEP_IMPULSE_BEGIN - WEP_FIRST, complete);
-}
string W_NameWeaponOrder_MapFunc(string s)
{
int i = stof(s);
}
return s;
}
-
-string W_UndeprecateName(string s)
-{
- switch (s)
- {
- case "nex": return "vortex";
- case "rocketlauncher": return "devastator";
- case "laser": return "blaster";
- case "minstanex": return "vaporizer";
- case "grenadelauncher": return "mortar";
- case "uzi": return "machinegun";
- case "hmg": return "okhmg";
- case "rpc": return "okrpc";
- default: return s;
- }
-}
-string W_NameWeaponOrder(string order)
-{
- return mapPriorityList(order, W_NameWeaponOrder_MapFunc);
-}
string W_NumberWeaponOrder_MapFunc(string s)
{
if (s == "0" || stof(s)) return s;
- s = W_UndeprecateName(s);
+ s = W_UNDEPRECATENAME(s);
FOREACH(Weapons, it != WEP_Null && it.netname == s, return ftos(i));
return s;
}
-string W_NumberWeaponOrder(string order)
-{
- return mapPriorityList(order, W_NumberWeaponOrder_MapFunc);
-}
float W_FixWeaponOrder_BuildImpulseList_buf[REGISTRY_MAX(Weapons)];
string W_FixWeaponOrder_BuildImpulseList_order;
string W_FixWeaponOrder_AllowIncomplete(entity this, string order)
{
- return W_FixWeaponOrder(order, 0);
-}
-
-string W_FixWeaponOrder_ForceComplete(string order)
-{
- if (order == "") order = W_NumberWeaponOrder(cvar_defstring("cl_weaponpriority"));
- return W_FixWeaponOrder(order, 1);
+ return W_FIXWEAPONORDER(order, 0);
}
WepSet W_RandomWeapons(entity e, WepSet remaining, int n)
}
// TODO: registry handles for below functions
+// drjaska: made these functions into macros in
+// common/weapons/weapon.qh
+// instead of registry handles
+#if 0
string GetAmmoPicture(Resource ammotype)
{
switch (ammotype)
default: return "batteries";
}
}
+#endif
entity GetAmmoItem(Resource ammotype)
{
LOG_WARNF("Invalid ammo type %d ", ammotype.m_id);
return NULL;
// WEAPONTODO: use this generic func to reduce duplication ?
- // GetAmmoPicture GetAmmoName notif_arg_item_wepammo ammo_pickupevalfunc ?
-}
-
-#ifdef CSQC
-Resource GetAmmoTypeFromNum(int i)
-{
- switch (i)
- {
- case 0: return RES_SHELLS;
- case 1: return RES_BULLETS;
- case 2: return RES_ROCKETS;
- case 3: return RES_CELLS;
- case 4: return RES_PLASMA;
- case 5: return RES_FUEL;
- default: return RES_NONE;
- }
+ // GETAMMOPICTURE GETAMMONAME notif_arg_item_wepammo ammo_pickupevalfunc ?
}
-int GetAmmoStat(Resource ammotype)
-{
- switch (ammotype)
- {
- case RES_SHELLS: return STAT_SHELLS;
- case RES_BULLETS: return STAT_NAILS;
- case RES_ROCKETS: return STAT_ROCKETS;
- case RES_CELLS: return STAT_CELLS;
- case RES_PLASMA: return STAT_PLASMA.m_id;
- case RES_FUEL: return STAT_FUEL.m_id;
- default: return -1;
- }
-}
-#endif
-
string W_Sound(string w_snd)
{
string output = strcat("weapons/", w_snd);
#endif
#ifdef SVQC
-string W_FixWeaponOrder_ForceComplete_AndBuildImpulseList(entity this, string wo)
+string W_FIXWEAPNORDER_FORCECOMPLETE_AndBuildImpulseList(entity this, string wo)
{
- string o = W_FixWeaponOrder_ForceComplete(wo);
+ string o = W_FIXWEAPNORDER_FORCECOMPLETE(wo);
strcpy(CS_CVAR(this).weaponorder_byimpulse, W_FixWeaponOrder_BuildImpulseList(o));
return o;
}
REPLICATE(cvar_cl_weapon_switch_reload, bool, "cl_weapon_switch_reload");
REPLICATE(cvar_cl_weapon_switch_fallback_to_impulse, bool, "cl_weapon_switch_fallback_to_impulse");
REPLICATE(cvar_cl_weaponimpulsemode, int, "cl_weaponimpulsemode");
-REPLICATE(cvar_cl_weaponpriority, string, "cl_weaponpriority", W_FixWeaponOrder_ForceComplete_AndBuildImpulseList);
+REPLICATE(cvar_cl_weaponpriority, string, "cl_weaponpriority", W_FIXWEAPNORDER_FORCECOMPLETE_AndBuildImpulseList);
REPLICATE(cvar_cl_weaponpriorities[0], string, "cl_weaponpriority0", W_FixWeaponOrder_AllowIncomplete);
REPLICATE(cvar_cl_weaponpriorities[1], string, "cl_weaponpriority1", W_FixWeaponOrder_AllowIncomplete);
REPLICATE(cvar_cl_weaponpriorities[2], string, "cl_weaponpriority2", W_FixWeaponOrder_AllowIncomplete);
void W_MuzzleFlash(Weapon thiswep, entity actor, .entity weaponentity, vector shotorg, vector shotdir);
-string W_FixWeaponOrder_ForceComplete_AndBuildImpulseList(entity this, string wo);
+string W_FIXWEAPNORDER_FORCECOMPLETE_AndBuildImpulseList(entity this, string wo);
string W_FixWeaponOrder_AllowIncomplete(entity this, string order);
#endif
string weaponorder_byid;
// functions:
-string W_FixWeaponOrder(string order, float complete);
-string W_UndeprecateName(string s);
-string W_NameWeaponOrder(string order);
-string W_NumberWeaponOrder(string order);
+#define W_FIXWEAPONORDER(order, complete) fixPriorityList(order, WEP_FIRST, WEP_LAST, WEP_IMPULSE_BEGIN - WEP_FIRST, complete)
+
+#define W_UNDEPRECATENAME(s) \
+ (s == "nex" ? "vortex" : \
+ s == "rocketlauncher" ? "devastator" : \
+ s == "laser" ? "blaster" : \
+ s == "minstanex" ? "vaporizer" : \
+ s == "grenadelauncher" ? "mortar" : \
+ s == "uzi" ? "machinegun" : \
+ s == "hmg" ? "okhmg" : \
+ s == "rpc" ? "okrpc" : s)
+
+string W_NameWeaponOrder_MapFunc(string s);
+string W_NumberWeaponOrder_MapFunc(string s);
+#define W_NAMEWEAPONORDER(order) mapPriorityList(order, W_NameWeaponOrder_MapFunc)
+#define W_NUMBERWEAPONORDER(order) mapPriorityList(order, W_NumberWeaponOrder_MapFunc)
string W_FixWeaponOrder_BuildImpulseList(string o);
string W_FixWeaponOrder_AllowIncomplete(entity this, string order);
-string W_FixWeaponOrder_ForceComplete(string order);
WepSet W_RandomWeapons(entity e, WepSet remaining, int n);
+#define W_FIXWEAPNORDER_FORCECOMPLETE(order) \
+ W_FIXWEAPONORDER(((order == "") ? W_NUMBERWEAPONORDER(cvar_defstring("cl_weaponpriority")) : order), 1)
-string GetAmmoPicture(Resource ammotype);
-
-string GetAmmoName(Resource ammotype);
-
+#define GETAMMOPICTURE(ammotype) GetAmmoItem(ammotype).m_icon
+#define GETAMMONAME(ammotype) GetAmmoItem(ammotype).m_name
entity GetAmmoItem(Resource ammotype);
#ifdef CSQC
-Resource GetAmmoTypeFromNum(int i);
+#define GETAMMOTYPEFROMNUM(i) \
+ i == 0 ? RES_SHELLS : \
+ i == 1 ? RES_BULLETS : \
+ i == 2 ? RES_ROCKETS : \
+ i == 3 ? RES_CELLS : \
+ i == 4 ? RES_PLASMA : \
+ i == 5 ? RES_FUEL : RES_NONE
-int GetAmmoStat(Resource ammotype);
+#define GETAMMOSTAT(res) \
+ res == RES_SHELLS ? STAT_SHELLS : \
+ res == RES_BULLETS ? STAT_NAILS : \
+ res == RES_ROCKETS ? STAT_ROCKETS : \
+ res == RES_CELLS ? STAT_CELLS : \
+ res == RES_PLASMA ? STAT_PLASMA.m_id : \
+ res == RES_FUEL ? STAT_FUEL.m_id : -1
#endif
string W_Sound(string w_snd);
{
// read in cvar?
string s, t;
- s = W_NumberWeaponOrder(cvar_string("cl_weaponpriority"));
- t = W_FixWeaponOrder(s, 1);
+ s = W_NUMBERWEAPONORDER(cvar_string("cl_weaponpriority"));
+ t = W_FIXWEAPONORDER(s, 1);
if(t != s)
- cvar_set("cl_weaponpriority", W_NameWeaponOrder(t));
+ cvar_set("cl_weaponpriority", W_NAMEWEAPONORDER(t));
me.nItems = tokenize_console(t);
SUPER(XonoticWeaponsList).draw(me);
}
float n, i;
string s;
entity e;
- n = tokenize_console(W_NumberWeaponOrder(cvar_string("cl_weaponpriority")));
+ n = tokenize_console(W_NUMBERWEAPONORDER(cvar_string("cl_weaponpriority")));
s = "";
for(i = 0; i < n; ++i)
{
#define PARSE_WEAPON_PRIORITIES(dist) MACRO_BEGIN \
if (bot_priority_##dist##_prev != autocvar_bot_ai_custom_weapon_priority_##dist) { \
strcpy(bot_priority_##dist##_prev, autocvar_bot_ai_custom_weapon_priority_##dist); \
- tokens = tokenizebyseparator(W_NumberWeaponOrder(autocvar_bot_ai_custom_weapon_priority_##dist)," "); \
+ tokens = tokenizebyseparator(W_NUMBERWEAPONORDER(autocvar_bot_ai_custom_weapon_priority_##dist)," "); \
bot_weapons_##dist[0] = -1; \
c = 0; \
for(i = 0; i < tokens && c < REGISTRY_COUNT(Weapons); ++i) { \
case "y": replacement = NearestLocation(cursor); break;
case "d": replacement = NearestLocation(this.death_origin); break;
case "w": replacement = WeaponNameFromWeaponentity(this, weaponentity); break;
- case "W": replacement = GetAmmoName(this.(weaponentity).m_weapon.ammo_type); break;
+ case "W": replacement = GETAMMONAME(this.(weaponentity).m_weapon.ammo_type); break;
case "x": replacement = ((cursor_ent.netname == "" || !cursor_ent) ? "nothing" : cursor_ent.netname); break;
case "s": replacement = ftos(vlen(this.velocity - this.velocity_z * '0 0 1')); break;
case "S": replacement = ftos(vlen(this.velocity)); break;
{
entity ammo = NULL;
if(GetResource(item, RES_SHELLS)) { need_shells = true; ammo = ITEM_Shells; }
- else if(GetResource(item, RES_BULLETS)) { need_nails = true; ammo = ITEM_Bullets; }
+ else if(GetResource(item, RES_BULLETS)) { need_nails = true; ammo = ITEM_Bullets; }
else if(GetResource(item, RES_ROCKETS)) { need_rockets = true; ammo = ITEM_Rockets; }
else if(GetResource(item, RES_CELLS)) { need_cells = true; ammo = ITEM_Cells; }
else if(GetResource(item, RES_PLASMA)) { need_plasma = true; ammo = ITEM_Plasma; }
}
});
FOREACH(Weapons, it != WEP_Null, {
- string s = W_UndeprecateName(argv(j));
+ string s = W_UNDEPRECATENAME(argv(j));
if(s == it.netname)
{
STAT(WEAPONS, this) |= (it.m_wepset);
n = tokenize_console(this.netname);
for(int j = 0; j < n; ++j)
{
- FOREACH(Weapons, it != WEP_Null && W_UndeprecateName(argv(j)) == it.netname, {
+ FOREACH(Weapons, it != WEP_Null && W_UNDEPRECATENAME(argv(j)) == it.netname, {
it.wr_init(it);
break;
});
got += GiveBuff(e, it, op, val);
break;
});
- FOREACH(Weapons, it != WEP_Null && W_UndeprecateName(cmd) == it.netname, {
+ FOREACH(Weapons, it != WEP_Null && W_UNDEPRECATENAME(cmd) == it.netname, {
got += GiveWeapon(e, it.m_id, op, val);
break;
});
backtrace(sprintf(
"W_DecreaseAmmo(%.2f): '%s' subtracted too much %s from '%s', resulting with '%.2f' left... "
"Please notify the developers immediately with a copy of this backtrace!\n",
- ammo_use, wep.netname, GetAmmoPicture(wep.ammo_type), actor.netname, ammo));
+ ammo_use, wep.netname, GETAMMOPICTURE(wep.ammo_type), actor.netname, ammo));
}
SetResource(actor, wep.ammo_type, ammo - ammo_use);
}