]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Improve Ammo guide description code
authorotta8634 <k9wolf@pm.me>
Mon, 23 Dec 2024 03:10:43 +0000 (11:10 +0800)
committerotta8634 <k9wolf@pm.me>
Mon, 23 Dec 2024 03:10:43 +0000 (11:10 +0800)
Also relocated some functions declarations in a header that were properly misplaced.

qcsrc/common/items/item/ammo.qc
qcsrc/common/items/item/ammo.qh
qcsrc/common/weapons/all.qc
qcsrc/common/weapons/all.qh
qcsrc/common/weapons/weapon.qh

index aefe71e46b7d422b72b3ffc83d25f4f735f0bc78..090f8ea6f13d927ec15214d34f4a53bf90276a31 100644 (file)
@@ -4,37 +4,14 @@
 #include <common/colors.qh>
 #include <common/weapons/all.qh>
 
-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
index 342936a2c171afd4440565f68634505080f5ab45..8397f1fcca78255a8a1ad24c149e6298943b00b5 100644 (file)
@@ -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)
 
 
index 66735dd2f6cd6cc22dfee7349088bfa6adf6771a..f782cf5eeee64cf6a97c0e0871b2c86d4acef1c1 100644 (file)
@@ -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)
 {
index 3a4cede4b635db73ee333f9dd9860af8debce2d4..78f4a16fcee014ebed5166d10edfd1b21f3e4aa1 100644 (file)
@@ -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);
index 5554f6b605c333b3153fef7531d3675ab0b96975..5ecfd277e841c33aa24b38cbd1b59767678c1283 100644 (file)
@@ -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);