From ba94d80401cdfe63391b0a6399e09689359a0f87 Mon Sep 17 00:00:00 2001 From: RMROC451 Date: Fri, 5 Sep 2025 10:51:03 -0500 Subject: [PATCH] allows "deprecated" model metadata tag to exlude cars from being utilized for ordering, but will allow them to run out their lives on the rails until they export. Useful for when you mod in a car, and want to remove it without hunting around to find all of them and deleting them. --- .../PrefabStoreExtensions_Random_Patch.cs | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 TweaksAndThings/Patches/PrefabStoreExtensions_Random_Patch.cs diff --git a/TweaksAndThings/Patches/PrefabStoreExtensions_Random_Patch.cs b/TweaksAndThings/Patches/PrefabStoreExtensions_Random_Patch.cs new file mode 100644 index 0000000..98c9b0e --- /dev/null +++ b/TweaksAndThings/Patches/PrefabStoreExtensions_Random_Patch.cs @@ -0,0 +1,42 @@ +using HarmonyLib; +using Helpers; +using Model.Database; +using Model.Definition; +using Model.Definition.Data; +using Model.Ops; +using Serilog; +using System; +using System.Collections.Generic; +using System.Linq; + +namespace RMROC451.TweaksAndThings.Patches; + +[HarmonyPatch(typeof(PrefabStoreExtensions))] +[HarmonyPatch(nameof(PrefabStoreExtensions.Random))] +[HarmonyPatchCategory("RMROC451TweaksAndThings")] +internal static class PrefabStoreExtensions_Random_Patch +{ + public static bool Prefix(IPrefabStore prefabStore, CarTypeFilter carTypeFilter, IndustryContext.CarSizePreference sizePreference, Random rnd, ref TypedContainerItem __result) + { + List> list = + (from p in prefabStore.AllCarDefinitionInfos.ToList().FindAll((TypedContainerItem p) => + carTypeFilter.Matches(p.Definition.CarType) && !p.Metadata.Tags.Any(t => t.Equals("deprecated"))) + orderby p.Definition.WeightEmpty + select p).ToList(); + if (list.Count == 0) + { + Log.Error($"Couldn't find car for condition: {carTypeFilter}"); + __result = null; + } + __result = list.RandomElementUsingNormalDistribution(sizePreference switch + { + IndustryContext.CarSizePreference.Small => 0.2f, + IndustryContext.CarSizePreference.Medium => 0.4f, + IndustryContext.CarSizePreference.Large => 0.6f, + IndustryContext.CarSizePreference.ExtraLarge => 0.8f, + _ => 0.5f, + }, rnd); + + return false; + } +}