Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynamically add ammo items to vehicle ammo ThingFilter #2817

Merged
merged 4 commits into from
Oct 21, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 20 additions & 5 deletions Source/VehiclesCompat/VehiclesCompat/VehiclesCompat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

namespace CombatExtended.Compatibility.VehiclesCompat
{
[StaticConstructorOnStartup]
public class VehiclesCompat : IModPart
{
public Type GetSettingsType()
Expand Down Expand Up @@ -61,13 +60,29 @@ public static Def LookupAmmosetCE(string defName)

public static IEnumerable<ThingDef> _GetUsedAmmo()
{
foreach (VehicleTurretDef vtd in DefDatabase<global::Vehicles.VehicleTurretDef>.AllDefs)
if (Controller.settings.EnableAmmoSystem)
{
foreach (ThingDef td in vtd?.ammunition?.AllowedThingDefs)
foreach (VehicleTurretDef vtd in DefDatabase<global::Vehicles.VehicleTurretDef>.AllDefs)
{
if (td is AmmoDef ad)
CETurretDataDefModExtension cetddme = vtd.GetModExtension<CETurretDataDefModExtension>();
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<ThingDef> allowedAmmo = (HashSet<ThingDef>)vtd.ammunition?.AllowedThingDefs;
allowedAmmo.Clear();
foreach (var al in asd.ammoTypes)
{
allowedAmmo.Add(al.ammo);
yield return al.ammo;
}
}
}
}
}
Expand Down
Loading