From: otta8634 Date: Mon, 23 Dec 2024 03:10:43 +0000 (+0800) Subject: Improve Ammo guide description code X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=f0023470c4ede6fcfa14a75a1190ca3467fbc233;p=xonotic%2Fxonotic-data.pk3dir.git Improve Ammo guide description code Also relocated some functions declarations in a header that were properly misplaced. --- diff --git a/qcsrc/common/items/item/ammo.qc b/qcsrc/common/items/item/ammo.qc index aefe71e46..090f8ea6f 100644 --- a/qcsrc/common/items/item/ammo.qc +++ b/qcsrc/common/items/item/ammo.qc @@ -4,37 +4,14 @@ #include #include -string _Ammo_generate_description(entity ammo_type_ent, Resource ammo_res) +METHOD(Ammo, describe, string(Ammo this)) { - string s = sprintf(_("The %s ammo type is used by the:"), COLORED_NAME(ammo_type_ent)); - FOREACH(Weapons, true, { - if (it.ammo_type == ammo_res) - s = strcat(s, "\n", COLORED_NAME(it)); + TC(Ammo, this); + entity ammo = GetAmmoResource(this); + string s = sprintf(_("The %s ammo type is used by the:"), COLORED_NAME(this)); + FOREACH(Weapons, it.ammo_type == ammo, { + s = strcat(s, "\n", COLORED_NAME(it)); }); return s; } - -METHOD(Shells, describe, string(Shells this)) -{ - TC(Shells, this); - return _Ammo_generate_description(this, RES_SHELLS); -} - -METHOD(Bullets, describe, string(Bullets this)) -{ - TC(Bullets, this); - return _Ammo_generate_description(this, RES_BULLETS); -} - -METHOD(Rockets, describe, string(Rockets this)) -{ - TC(Rockets, this); - return _Ammo_generate_description(this, RES_ROCKETS); -} - -METHOD(Cells, describe, string(Cells this)) -{ - TC(Cells, this); - return _Ammo_generate_description(this, RES_CELLS); -} #endif diff --git a/qcsrc/common/items/item/ammo.qh b/qcsrc/common/items/item/ammo.qh index 342936a2c..8397f1fcc 100644 --- a/qcsrc/common/items/item/ammo.qh +++ b/qcsrc/common/items/item/ammo.qh @@ -23,13 +23,6 @@ CLASS(Ammo, Pickup) ATTRIB(Ammo, m_respawntimejitter, float(), GET(g_pickup_respawntimejitter_ammo)); ATTRIB(Ammo, m_pickupanyway, float(), GET(g_pickup_ammo_anyway)); #endif -#ifdef MENUQC - METHOD(Ammo, describe, string(Ammo this)) - { - TC(Ammo, this); - return SUPER(Pickup).describe(this); - } -#endif ENDCLASS(Ammo) diff --git a/qcsrc/common/weapons/all.qc b/qcsrc/common/weapons/all.qc index 66735dd2f..f782cf5ee 100644 --- a/qcsrc/common/weapons/all.qc +++ b/qcsrc/common/weapons/all.qc @@ -196,6 +196,16 @@ entity GetAmmoItem(Resource ammotype) return NULL; } +entity GetAmmoResource(Ammo ammotype) +{ + FOREACH(Resources, it.netname == ammotype.netname, + { + return it; + }); + LOG_WARNF("Invalid ammo type %d ", ammotype.m_id); + return NULL; +} + #ifdef CSQC int GetAmmoStat(Resource ammotype) { diff --git a/qcsrc/common/weapons/all.qh b/qcsrc/common/weapons/all.qh index 3a4cede4b..78f4a16fc 100644 --- a/qcsrc/common/weapons/all.qh +++ b/qcsrc/common/weapons/all.qh @@ -424,3 +424,22 @@ string W_FixWeaponOrder_AllowIncomplete(entity this, string order); #endif #endif + +// functions: +string W_FixWeaponOrder(string order, float complete); +string W_NameWeaponOrder(string order); +string W_NumberWeaponOrder(string order); +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); + +entity GetAmmoItem(Resource ammotype); +entity GetAmmoResource(Ammo ammotype); + +#ifdef CSQC +int GetAmmoStat(Resource ammotype); +#endif + +string W_Sound(string w_snd); +string W_Model(string w_mdl); diff --git a/qcsrc/common/weapons/weapon.qh b/qcsrc/common/weapons/weapon.qh index 5554f6b60..5ecfd277e 100644 --- a/qcsrc/common/weapons/weapon.qh +++ b/qcsrc/common/weapons/weapon.qh @@ -220,21 +220,3 @@ const int WEP_FLAG_SPECIALATTACK = BIT(16); // marked as a special attack (not // variables: string weaponorder_byid; - -// functions: -string W_FixWeaponOrder(string order, float complete); -string W_NameWeaponOrder(string order); -string W_NumberWeaponOrder(string order); -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); - -entity GetAmmoItem(Resource ammotype); - -#ifdef CSQC -int GetAmmoStat(Resource ammotype); -#endif - -string W_Sound(string w_snd); -string W_Model(string w_mdl);