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, ammoType.m_icon, '1 1 0' * mySize.y, iconColor, alpha, DRAWFLAG_NORMAL);
}
int nade_prevstatus;
string notif_arg_item_wepammo(float f1, float f2)
{
- string ammotype = "";
Weapon wep = REGISTRY_GET(Weapons, f1);
- // TODO: registry handles
- switch (wep.ammo_type)
- {
- case RES_SHELLS: ammotype = ITEM_Shells.m_name; break;
- case RES_BULLETS: ammotype = ITEM_Bullets.m_name; break;
- case RES_ROCKETS: ammotype = ITEM_Rockets.m_name; break;
- case RES_CELLS: ammotype = ITEM_Cells.m_name; break;
- case RES_PLASMA: ammotype = ITEM_Plasma.m_name; break;
- case RES_FUEL: ammotype = ITEM_JetpackFuel.m_name; break;
- default: return ""; // doesn't use ammo
- }
+ if(wep.ammo_type == RES_NONE)
+ return ""; // doesn't use ammo
// example for translators: You dropped the Vortex with 5 cells
- return sprintf(_(" with %d %s"), f2, strtolower(ammotype));
+ return sprintf(_(" with %d %s"), f2, strtolower(wep.ammo_type.m_name));
}
// NOTE: ammo resource registration order should match ammo (item) registration order
// see REGISTER_ITEM calls order
+// ALSO make sure m_name and m_icon fields match ammo item registries
REGISTER_RESOURCE(SHELLS, NEW(AmmoResource)) {
this.netname = "shells";
#ifdef GAMEQC
this.m_field = ammo_shells;
#endif
+ this.m_name = _("Shells");
+ this.m_icon = "ammo_shells";
}
REGISTER_RESOURCE(BULLETS, NEW(AmmoResource)) {
this.netname = "bullets";
#ifdef GAMEQC
this.m_field = ammo_nails;
#endif
+ this.m_name = _("Bullets");
+ this.m_icon = "ammo_bullets";
}
REGISTER_RESOURCE(ROCKETS, NEW(AmmoResource)) {
this.netname = "rockets";
#ifdef GAMEQC
this.m_field = ammo_rockets;
#endif
+ this.m_name = _("Rockets");
+ this.m_icon = "ammo_rockets";
}
REGISTER_RESOURCE(CELLS, NEW(AmmoResource)) {
this.netname = "cells";
#ifdef GAMEQC
this.m_field = ammo_cells;
#endif
+ this.m_name = _("Cells");
+ this.m_icon = "ammo_cells";
}
REGISTER_RESOURCE(PLASMA, NEW(AmmoResource)) {
this.netname = "plasma";
#ifdef GAMEQC
this.m_field = ammo_plasma;
#endif
+ this.m_name = _("Plasma");
+ this.m_icon = "ammo_plasma";
#ifdef CSQC
this.m_hidden = true; // WIP ammo type
#endif
#ifdef GAMEQC
this.m_field = ammo_fuel;
#endif
+ this.m_name = _("Fuel");
+ this.m_icon = "ammo_fuel";
#ifdef CSQC
this.m_hidden = true; // displayed in a separate panel
#endif
#ifdef GAMEQC
ATTRIB(Resource, m_field, .float, health);
#endif
+ ATTRIB(Resource, m_name, string, "");
+ ATTRIB(Resource, m_icon, string, "");
ENDCLASS(Resource)
#define REGISTER_RESOURCE(id, inst) REGISTER(Resources, RES, id, m_id, inst)
return result;
}
-// TODO: registry handles for below functions
-string GetAmmoPicture(Resource ammotype)
-{
- switch (ammotype)
- {
- case RES_SHELLS: return ITEM_Shells.m_icon;
- case RES_BULLETS: return ITEM_Bullets.m_icon;
- case RES_ROCKETS: return ITEM_Rockets.m_icon;
- case RES_CELLS: return ITEM_Cells.m_icon;
- case RES_PLASMA: return ITEM_Plasma.m_icon;
- case RES_FUEL: return ITEM_JetpackFuel.m_icon;
- default: return ""; // wtf, no ammo type?
- }
-}
-
-string GetAmmoName(Resource ammotype)
-{
- switch (ammotype)
- {
- case RES_SHELLS: return ITEM_Shells.m_name;
- case RES_BULLETS: return ITEM_Bullets.m_name;
- case RES_ROCKETS: return ITEM_Rockets.m_name;
- case RES_CELLS: return ITEM_Cells.m_name;
- case RES_PLASMA: return ITEM_Plasma.m_name;
- case RES_FUEL: return ITEM_JetpackFuel.m_name;
- default: return "batteries";
- }
-}
-
entity GetAmmoItem(Resource ammotype)
{
- switch (ammotype)
+ FOREACH(Items, it.netname == ammotype.netname,
{
- case RES_SHELLS: return ITEM_Shells;
- case RES_BULLETS: return ITEM_Bullets;
- case RES_ROCKETS: return ITEM_Rockets;
- case RES_CELLS: return ITEM_Cells;
- case RES_PLASMA: return ITEM_Plasma;
- case RES_FUEL: return ITEM_JetpackFuel;
- }
+ return it;
+ });
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
int GetAmmoStat(Resource ammotype)
{
+ // TODO: handle networking via resources
switch (ammotype)
{
case RES_SHELLS: return STAT_SHELLS;
string W_FixWeaponOrder_ForceComplete(string order);
WepSet W_RandomWeapons(entity e, WepSet remaining, int n);
-string GetAmmoPicture(Resource ammotype);
-
-string GetAmmoName(Resource ammotype);
-
entity GetAmmoItem(Resource ammotype);
#ifdef CSQC
string WeaponNameFromWeaponentity(entity this, .entity weaponentity)
{
entity wepent = this.(weaponentity);
- if(!wepent)
- return "none";
+ if(!wepent || !IS_PLAYER(this))
+ return "N/A";
else if(wepent.m_weapon != WEP_Null)
return wepent.m_weapon.m_name;
else if(wepent.m_switchweapon != WEP_Null)
return "none"; //REGISTRY_GET(Weapons, wepent.cnt).m_name;
}
+string AmmoNameFromWeaponentity(entity this, .entity weaponentity)
+{
+ entity wepent = this.(weaponentity);
+ string fallback = "N/A";
+ if(!wepent || !IS_PLAYER(this))
+ return fallback;
+ else if(wepent.m_weapon.ammo_type != RES_NONE)
+ return wepent.m_weapon.ammo_type.m_name;
+ else if(wepent.m_switchweapon.ammo_type != RES_NONE)
+ return wepent.m_switchweapon.ammo_type.m_name;
+ return fallback; // REGISTRY_GET(Weapons, wepent.cnt).ammo_type.m_name;
+}
+
string formatmessage(entity this, string msg)
{
float p, p1, p2;
case "o": replacement = vtos(this.origin); break;
case "O": replacement = sprintf("'%f %f %f'", this.origin.x, this.origin.y, this.origin.z); break;
case "w": replacement = WeaponNameFromWeaponentity(this, weaponentity); break;
- case "W": replacement = GetAmmoName(this.(weaponentity).m_weapon.ammo_type); break;
+ case "W": replacement = AmmoNameFromWeaponentity(this, weaponentity); 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;
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, wep.ammo_type.netname, actor.netname, ammo));
}
SetResource(actor, wep.ammo_type, ammo - ammo_use);
}