diff --git a/Source/VehiclesCompat/VehiclesCompat/VehiclesCompat.cs b/Source/VehiclesCompat/VehiclesCompat/VehiclesCompat.cs index d4dac1e6b8..3437e71126 100644 --- a/Source/VehiclesCompat/VehiclesCompat/VehiclesCompat.cs +++ b/Source/VehiclesCompat/VehiclesCompat/VehiclesCompat.cs @@ -64,23 +64,25 @@ public static IEnumerable _GetUsedAmmo() { foreach (VehicleTurretDef vtd in DefDatabase.AllDefs) { - CETurretDataDefModExtension cetddme = vtd.GetModExtension(); - if (cetddme.ammoSet != null) + if (vtd.GetModExtension() is CETurretDataDefModExtension cetddme) { - AmmoSetDef asd = (AmmoSetDef)LookupAmmosetCE(cetddme.ammoSet); - if (Controller.settings.GenericAmmo && asd?.similarTo != null) + if (cetddme.ammoSet != null) { - asd = asd.similarTo; - } - if (asd != null) - { - cetddme._ammoSet = asd; - HashSet allowedAmmo = (HashSet)vtd.ammunition?.AllowedThingDefs; - allowedAmmo.Clear(); - foreach (var al in asd.ammoTypes) + AmmoSetDef asd = (AmmoSetDef)LookupAmmosetCE(cetddme.ammoSet); + if (Controller.settings.GenericAmmo && asd?.similarTo != null) + { + asd = asd.similarTo; + } + if (asd != null) { - allowedAmmo.Add(al.ammo); - yield return al.ammo; + 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; + } } } }