From 0b19b1e0aa16cb58fd56b15edc6abac5c8f583b5 Mon Sep 17 00:00:00 2001 From: otta8634 Date: Sun, 22 Dec 2024 19:50:02 +0800 Subject: [PATCH] Dynamically generate ammo guide descriptions Suggestion by @terencehill. --- qcsrc/common/items/item/ammo.qc | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/qcsrc/common/items/item/ammo.qc b/qcsrc/common/items/item/ammo.qc index 56773d99e..aefe71e46 100644 --- a/qcsrc/common/items/item/ammo.qc +++ b/qcsrc/common/items/item/ammo.qc @@ -2,34 +2,39 @@ #ifdef MENUQC #include -#include -#include +#include + +string _Ammo_generate_description(entity ammo_type_ent, Resource ammo_res) +{ + 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)); + }); + return s; +} METHOD(Shells, describe, string(Shells this)) { TC(Shells, this); - return sprintf(_("The %s ammo type is used by the %s and %s"), - COLORED_NAME(this), COLORED_NAME(WEP_SHOTGUN), COLORED_NAME(WEP_OVERKILL_SHOTGUN)); + return _Ammo_generate_description(this, RES_SHELLS); } METHOD(Bullets, describe, string(Bullets this)) { TC(Bullets, this); - return sprintf(_("The %s ammo type is used by the %s, %s, %s, and %s"), - COLORED_NAME(this), COLORED_NAME(WEP_MACHINEGUN), COLORED_NAME(WEP_RIFLE), COLORED_NAME(WEP_OVERKILL_MACHINEGUN), COLORED_NAME(WEP_OVERKILL_HMG)); + return _Ammo_generate_description(this, RES_BULLETS); } METHOD(Rockets, describe, string(Rockets this)) { TC(Rockets, this); - return sprintf(_("The %s ammo type is used by the %s, %s, %s, %s, %s, and %s"), - COLORED_NAME(this), COLORED_NAME(WEP_DEVASTATOR), COLORED_NAME(WEP_MORTAR), COLORED_NAME(WEP_HAGAR), COLORED_NAME(WEP_MINE_LAYER), COLORED_NAME(WEP_SEEKER), COLORED_NAME(WEP_OVERKILL_RPC)); + return _Ammo_generate_description(this, RES_ROCKETS); } METHOD(Cells, describe, string(Cells this)) { TC(Cells, this); - return sprintf(_("The %s ammo type is used by the %s, %s, %s, %s, %s, and %s"), - COLORED_NAME(this), COLORED_NAME(WEP_VORTEX), COLORED_NAME(WEP_CRYLINK), COLORED_NAME(WEP_ELECTRO), COLORED_NAME(WEP_HLAC), COLORED_NAME(WEP_VAPORIZER), COLORED_NAME(WEP_ARC)); + return _Ammo_generate_description(this, RES_CELLS); } #endif -- 2.39.2