From bbaf6fc73326ad384df5fb68f14c70860979f9ea Mon Sep 17 00:00:00 2001 From: Logan Perkins Date: Sun, 15 Oct 2023 16:09:17 -0700 Subject: [PATCH 1/4] Dynamically add ammo items to vehicle ammo ThingFilter Respects generic ammo, and no ammo modes. --- .../VehiclesCompat/VehiclesCompat.cs | 26 ++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/Source/VehiclesCompat/VehiclesCompat/VehiclesCompat.cs b/Source/VehiclesCompat/VehiclesCompat/VehiclesCompat.cs index 0908ebc746..b700eb75d5 100644 --- a/Source/VehiclesCompat/VehiclesCompat/VehiclesCompat.cs +++ b/Source/VehiclesCompat/VehiclesCompat/VehiclesCompat.cs @@ -13,7 +13,6 @@ namespace CombatExtended.Compatibility.VehiclesCompat { - [StaticConstructorOnStartup] public class VehiclesCompat : IModPart { public Type GetSettingsType() @@ -32,6 +31,31 @@ public void PostLoad(ModContentPack content, ISettingsCE _) VehicleTurret.LookupProjectileCountAndSpreadCE = LookupProjectileCountAndSpreadCE; global::CombatExtended.Compatibility.Patches.RegisterCollisionBodyFactorCallback(_GetCollisionBodyFactors); global::CombatExtended.Compatibility.Patches.UsedAmmoCallbacks.Add(_GetUsedAmmo); + if (Controller.settings.EnableAmmoSystem) + { + foreach (VehicleTurretDef vtd in DefDatabase.AllDefs) + { + CETurretDataDefModExtension cetddme = vtd.GetModExtension(); + if (cetddme.ammoSet != null) + { + AmmoSetDef asd = (AmmoSetDef) LookupAmmosetCE(cetddme.ammoSet); + if (Controller.settings.GenericAmmo && asd?.similarTo != null) + { + asd = asd.similarTo; + } + if (asd != null) + { + cetddme._ammoSet = asd; + HashSet allowedAmmo = (HashSet) vtd.ammunition?.AllowedThingDefs; + allowedAmmo.Clear(); + foreach (var al in asd.ammoTypes) + { + allowedAmmo.Add(al.ammo); + } + } + } + } + } } public static Tuple LookupProjectileCountAndSpreadCE(ThingDef _ammoDef, Def _ammosetDef, float spread) From fd31122c6b2c0ee8be5508563d991cc9b1a33280 Mon Sep 17 00:00:00 2001 From: Logan Perkins Date: Sun, 15 Oct 2023 18:14:59 -0700 Subject: [PATCH 2/4] Whitespace fixes --- .../VehiclesCompat/VehiclesCompat.cs | 50 +++++++++---------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/Source/VehiclesCompat/VehiclesCompat/VehiclesCompat.cs b/Source/VehiclesCompat/VehiclesCompat/VehiclesCompat.cs index b700eb75d5..7134112b04 100644 --- a/Source/VehiclesCompat/VehiclesCompat/VehiclesCompat.cs +++ b/Source/VehiclesCompat/VehiclesCompat/VehiclesCompat.cs @@ -31,31 +31,31 @@ public void PostLoad(ModContentPack content, ISettingsCE _) VehicleTurret.LookupProjectileCountAndSpreadCE = LookupProjectileCountAndSpreadCE; global::CombatExtended.Compatibility.Patches.RegisterCollisionBodyFactorCallback(_GetCollisionBodyFactors); global::CombatExtended.Compatibility.Patches.UsedAmmoCallbacks.Add(_GetUsedAmmo); - if (Controller.settings.EnableAmmoSystem) - { - foreach (VehicleTurretDef vtd in DefDatabase.AllDefs) - { - CETurretDataDefModExtension cetddme = vtd.GetModExtension(); - if (cetddme.ammoSet != null) - { - AmmoSetDef asd = (AmmoSetDef) LookupAmmosetCE(cetddme.ammoSet); - if (Controller.settings.GenericAmmo && asd?.similarTo != null) - { - asd = asd.similarTo; - } - if (asd != null) - { - cetddme._ammoSet = asd; - HashSet allowedAmmo = (HashSet) vtd.ammunition?.AllowedThingDefs; - allowedAmmo.Clear(); - foreach (var al in asd.ammoTypes) - { - allowedAmmo.Add(al.ammo); - } - } - } - } - } + if (Controller.settings.EnableAmmoSystem) + { + foreach (VehicleTurretDef vtd in DefDatabase.AllDefs) + { + CETurretDataDefModExtension cetddme = vtd.GetModExtension(); + if (cetddme.ammoSet != null) + { + AmmoSetDef asd = (AmmoSetDef) LookupAmmosetCE(cetddme.ammoSet); + if (Controller.settings.GenericAmmo && asd?.similarTo != null) + { + asd = asd.similarTo; + } + if (asd != null) + { + cetddme._ammoSet = asd; + HashSet allowedAmmo = (HashSet) vtd.ammunition?.AllowedThingDefs; + allowedAmmo.Clear(); + foreach (var al in asd.ammoTypes) + { + allowedAmmo.Add(al.ammo); + } + } + } + } + } } public static Tuple LookupProjectileCountAndSpreadCE(ThingDef _ammoDef, Def _ammosetDef, float spread) From 0b5d3e66111327c957e59e09526157111258a848 Mon Sep 17 00:00:00 2001 From: Logan Perkins Date: Mon, 16 Oct 2023 23:10:53 -0700 Subject: [PATCH 3/4] Fix Whitespace --- Source/VehiclesCompat/VehiclesCompat/VehiclesCompat.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/VehiclesCompat/VehiclesCompat/VehiclesCompat.cs b/Source/VehiclesCompat/VehiclesCompat/VehiclesCompat.cs index 7134112b04..d75577ecbd 100644 --- a/Source/VehiclesCompat/VehiclesCompat/VehiclesCompat.cs +++ b/Source/VehiclesCompat/VehiclesCompat/VehiclesCompat.cs @@ -38,7 +38,7 @@ public void PostLoad(ModContentPack content, ISettingsCE _) CETurretDataDefModExtension cetddme = vtd.GetModExtension(); if (cetddme.ammoSet != null) { - AmmoSetDef asd = (AmmoSetDef) LookupAmmosetCE(cetddme.ammoSet); + AmmoSetDef asd = (AmmoSetDef)LookupAmmosetCE(cetddme.ammoSet); if (Controller.settings.GenericAmmo && asd?.similarTo != null) { asd = asd.similarTo; @@ -46,7 +46,7 @@ public void PostLoad(ModContentPack content, ISettingsCE _) if (asd != null) { cetddme._ammoSet = asd; - HashSet allowedAmmo = (HashSet) vtd.ammunition?.AllowedThingDefs; + HashSet allowedAmmo = (HashSet)vtd.ammunition?.AllowedThingDefs; allowedAmmo.Clear(); foreach (var al in asd.ammoTypes) { From 148ea8c5b04ff0694daa4cd2e8d5c45f40899831 Mon Sep 17 00:00:00 2001 From: Logan Perkins Date: Wed, 18 Oct 2023 22:43:30 -0700 Subject: [PATCH 4/4] Move VF ammo processing to later in load process --- .../VehiclesCompat/VehiclesCompat.cs | 49 ++++++++----------- 1 file changed, 20 insertions(+), 29 deletions(-) diff --git a/Source/VehiclesCompat/VehiclesCompat/VehiclesCompat.cs b/Source/VehiclesCompat/VehiclesCompat/VehiclesCompat.cs index d75577ecbd..d4dac1e6b8 100644 --- a/Source/VehiclesCompat/VehiclesCompat/VehiclesCompat.cs +++ b/Source/VehiclesCompat/VehiclesCompat/VehiclesCompat.cs @@ -31,31 +31,6 @@ public void PostLoad(ModContentPack content, ISettingsCE _) VehicleTurret.LookupProjectileCountAndSpreadCE = LookupProjectileCountAndSpreadCE; global::CombatExtended.Compatibility.Patches.RegisterCollisionBodyFactorCallback(_GetCollisionBodyFactors); global::CombatExtended.Compatibility.Patches.UsedAmmoCallbacks.Add(_GetUsedAmmo); - if (Controller.settings.EnableAmmoSystem) - { - foreach (VehicleTurretDef vtd in DefDatabase.AllDefs) - { - CETurretDataDefModExtension cetddme = vtd.GetModExtension(); - if (cetddme.ammoSet != null) - { - AmmoSetDef asd = (AmmoSetDef)LookupAmmosetCE(cetddme.ammoSet); - if (Controller.settings.GenericAmmo && asd?.similarTo != null) - { - asd = asd.similarTo; - } - if (asd != null) - { - cetddme._ammoSet = asd; - HashSet allowedAmmo = (HashSet)vtd.ammunition?.AllowedThingDefs; - allowedAmmo.Clear(); - foreach (var al in asd.ammoTypes) - { - allowedAmmo.Add(al.ammo); - } - } - } - } - } } public static Tuple LookupProjectileCountAndSpreadCE(ThingDef _ammoDef, Def _ammosetDef, float spread) @@ -85,13 +60,29 @@ public static Def LookupAmmosetCE(string defName) public static IEnumerable _GetUsedAmmo() { - foreach (VehicleTurretDef vtd in DefDatabase.AllDefs) + if (Controller.settings.EnableAmmoSystem) { - foreach (ThingDef td in vtd?.ammunition?.AllowedThingDefs) + foreach (VehicleTurretDef vtd in DefDatabase.AllDefs) { - if (td is AmmoDef ad) + CETurretDataDefModExtension cetddme = vtd.GetModExtension(); + if (cetddme.ammoSet != null) { - yield return td; + AmmoSetDef asd = (AmmoSetDef)LookupAmmosetCE(cetddme.ammoSet); + if (Controller.settings.GenericAmmo && asd?.similarTo != null) + { + asd = asd.similarTo; + } + if (asd != null) + { + cetddme._ammoSet = asd; + HashSet allowedAmmo = (HashSet)vtd.ammunition?.AllowedThingDefs; + allowedAmmo.Clear(); + foreach (var al in asd.ammoTypes) + { + allowedAmmo.Add(al.ammo); + yield return al.ammo; + } + } } } }