From e7872d4736c0a6b367cd7f40b5a3b9b1c35d4d10 Mon Sep 17 00:00:00 2001 From: mszabo Date: Sat, 2 Nov 2024 05:11:28 +0100 Subject: [PATCH 1/6] Support arbitrary ammosets for siege artillery The vanilla logic around sieges is fairly inflexible -- it mostly assumes that only 81mm mortars are used, which effectively prevents using modded artillery in sieges without hacks like the "raider artillery" in our VFE:S patch that consumes the 81mm ammoset. So, rework our patches around sieges to support artillery pieces with arbitrary ammosets, and remove raider artillery. --- Defs/Ammo/Shell/155mmHowitzer.xml | 1 + .../Ammo_Security.xml | 12 -- .../NewRaiderArtillery.xml | 150 ----------------- .../ThingDefs_Manned.xml | 4 - .../CombatExtended/AmmoUtility.cs | 6 - .../CombatExtended/SiegeUtility.cs | 85 ++++++++++ .../Harmony/Harmony_LordToil_Siege.cs | 151 +++++++++++------- .../Harmony/Harmony_ThingListGroupHelper.cs | 17 -- .../Harmony/Harmony_TurretGunUtility.cs | 110 +++++-------- 9 files changed, 222 insertions(+), 314 deletions(-) delete mode 100644 ModPatches/Vanilla Furniture Expanded - Security/Defs/Vanilla Furniture Expanded - Security/NewRaiderArtillery.xml create mode 100644 Source/CombatExtended/CombatExtended/SiegeUtility.cs delete mode 100644 Source/CombatExtended/Harmony/Harmony_ThingListGroupHelper.cs diff --git a/Defs/Ammo/Shell/155mmHowitzer.xml b/Defs/Ammo/Shell/155mmHowitzer.xml index 553d3d57fb..be54ff53d2 100644 --- a/Defs/Ammo/Shell/155mmHowitzer.xml +++ b/Defs/Ammo/Shell/155mmHowitzer.xml @@ -125,6 +125,7 @@ Smoke Bullet_155mmHowitzerShell_Smoke + false diff --git a/ModPatches/Vanilla Furniture Expanded - Security/Defs/Vanilla Furniture Expanded - Security/Ammo_Security.xml b/ModPatches/Vanilla Furniture Expanded - Security/Defs/Vanilla Furniture Expanded - Security/Ammo_Security.xml index eb93a375cf..81fa8315f3 100644 --- a/ModPatches/Vanilla Furniture Expanded - Security/Defs/Vanilla Furniture Expanded - Security/Ammo_Security.xml +++ b/ModPatches/Vanilla Furniture Expanded - Security/Defs/Vanilla Furniture Expanded - Security/Ammo_Security.xml @@ -22,16 +22,4 @@ true - - - - AmmoSet_RaiderArtillery - - - Bullet_155mmHowitzerShell_HE - Bullet_155mmHowitzerShell_Incendiary - Bullet_81mmMortarShell_Tox - - - \ No newline at end of file diff --git a/ModPatches/Vanilla Furniture Expanded - Security/Defs/Vanilla Furniture Expanded - Security/NewRaiderArtillery.xml b/ModPatches/Vanilla Furniture Expanded - Security/Defs/Vanilla Furniture Expanded - Security/NewRaiderArtillery.xml deleted file mode 100644 index ce9ca84393..0000000000 --- a/ModPatches/Vanilla Furniture Expanded - Security/Defs/Vanilla Furniture Expanded - Security/NewRaiderArtillery.xml +++ /dev/null @@ -1,150 +0,0 @@ - - - - - - - Raider_Turret_Artillery - - A manned artillery that launches all kinds of shells. Capable of inflicting devastating damage to both enemy forces and structures, this military machinery excels at laying down fire support for soldiers in the field.\n\nCapable of targeting other areas of the world within a medium radius. - CombatExtended.Building_TurretGunCE - - Things/Building/Artillery/TurretArtillery_Base - Graphic_Single - (3,3) - - (0.38,0.2,0.56375,0.8) - Damage/Corner - - - (-0.13,-0.87,-0.1) - (0.5,0.4,1.05) - - - - 250 - 3600 - - Industrial - (0,0,-2) - true - (3,3) - - true - false - -
  • Metallic
  • -
    - 100 - - 180 - 9 - - - - Heavy - - false - Raider_Artillery_Weapon - 3 - -
  • Artillery_BaseDestroyer
  • -
    - 1 - 1 - - - -
  • MortarShells
  • -
    - -
  • Shell_Incendiary
  • -
  • Shell_Firefoam
  • -
  • Shell_AntigrainWarhead
  • -
    -
    -
    -
    - Things/Building/Artillery/TurretArtillery_MenuIcon - 0.9 - 5 - -
  • - True -
  • -
    - -
    - - - Raider_Artillery_Weapon - - Artillery cannon capable of long range bombardment. - - Things/Building/Artillery/TurretArtillery_Top - Graphic_Single - - - 0.5 - 8.5 - - -
  • Artillery_BaseDestroyer
  • -
  • TurretGun
  • -
    - -
  • - CombatExtended.Verb_ShootMortarCE - false - true - Bullet_155mmHowitzerShell_HE - 4 - 40 - 1000 - 1 - VFES_Shot_Artillery - 20 - 0.2 - - true - -
  • -
    - -
  • - -
  • 30
  • -
  • 50
  • -
  • 70
  • -
  • 90
  • - - -
  • - 1 - 12 - AmmoSet_RaiderArtillery -
  • -
    - - - - -
  • MortarShells
  • -
    -
    -
    - - - -
  • MortarShells
  • -
    - -
  • Shell_Firefoam
  • -
  • Shell_AntigrainWarhead
  • -
    -
    -
    -
    -
    - -
    \ No newline at end of file diff --git a/ModPatches/Vanilla Furniture Expanded - Security/Patches/Vanilla Furniture Expanded - Security/ThingDefs_Manned.xml b/ModPatches/Vanilla Furniture Expanded - Security/Patches/Vanilla Furniture Expanded - Security/ThingDefs_Manned.xml index 657d816ea8..9a188d0bc9 100644 --- a/ModPatches/Vanilla Furniture Expanded - Security/Patches/Vanilla Furniture Expanded - Security/ThingDefs_Manned.xml +++ b/ModPatches/Vanilla Furniture Expanded - Security/Patches/Vanilla Furniture Expanded - Security/ThingDefs_Manned.xml @@ -254,10 +254,6 @@ - - Defs/ThingDef[defName="VFES_Turret_Artillery"]/building/buildingTags - - Defs/ThingDef[defName="VFES_Turret_Artillery"]/building/turretBurstWarmupTime diff --git a/Source/CombatExtended/CombatExtended/AmmoUtility.cs b/Source/CombatExtended/CombatExtended/AmmoUtility.cs index 4d3b0e76cb..d0a0a77b24 100644 --- a/Source/CombatExtended/CombatExtended/AmmoUtility.cs +++ b/Source/CombatExtended/CombatExtended/AmmoUtility.cs @@ -126,12 +126,6 @@ public static string GetProjectileReadout(this ThingDef projectileDef, Thing wea /// public static float GetExplosionArmorPenetration(this CompProperties_ExplosiveCE props) => props.damageAmountBase * ExplosiveArmorPenetrationMultiplier; - public static bool IsShell(ThingDef def) - { - var ammo = ThingDefOf.Turret_Mortar.building.turretGunDef.GetCompProperties(); - return ammo?.ammoSet.ammoTypes.Any(l => l.ammo == def) ?? false; - } - public static bool IsAmmoSystemActive(AmmoDef def) { if (Controller.settings.EnableAmmoSystem) diff --git a/Source/CombatExtended/CombatExtended/SiegeUtility.cs b/Source/CombatExtended/CombatExtended/SiegeUtility.cs new file mode 100644 index 0000000000..8c57b02017 --- /dev/null +++ b/Source/CombatExtended/CombatExtended/SiegeUtility.cs @@ -0,0 +1,85 @@ +using System.Collections.Generic; +using System.Linq; +using RimWorld; +using Verse; +using Verse.AI.Group; + +namespace CombatExtended +{ + [StaticConstructorOnStartup] + public class SiegeUtility + { + /// + /// The minimum required construction skill to be able to build any potential siege artillery in the game. + /// + public static readonly int MinRequiredConstructionSkill; + + static SiegeUtility() + { + MinRequiredConstructionSkill = DefDatabase.AllDefsListForReading + .Where(def => def.building?.buildingTags.Contains("Artillery_BaseDestroyer") ?? false) + .Select(def => def.constructionSkillPrerequisite) + .Max(); + } + + /// + /// Determine whether the given thing is a valid shell usable by this siege. + /// + /// The thing to check. + /// The siege. + /// true if at least one type of artillery piece taking part in the siege can use this shell, false otherwise. + public static bool IsValidShellType(Thing thing, LordToil_Siege siege) + { + if (thing.def is AmmoDef { spawnAsSiegeAmmo: true } ammoDef) + { + return UniqueArtilleryDefs(siege) + .SelectMany(def => def.building.turretGunDef.comps) + .OfType() + .SelectMany(props => props.ammoSet.ammoTypes) + .Any(ammoLink => ammoLink.ammo == ammoDef); + } + + return false; + } + + /// + /// Supply additional shells for each type of artillery piece taking part in this siege. + /// + /// The siege to resupply. + public static void DropAdditionalShells(LordToil_Siege siege) + { + Lord lord = siege.lord; + + foreach (var artilleryDef in UniqueArtilleryDefs(siege)) + { + // NOTE: Vanilla applies a hardcoded market price cap of 250 here, while we do not. + // Since we already limit the number of shells to be dropped in and also filter by tech level, + // such a hardcoded price cap would only serve to cause issues with modded shells that may be pricier. + var shellDef = TurretGunUtility.TryFindRandomShellDef( + artilleryDef, + allowEMP: false, + allowToxGas: false, + mustHarmHealth: true, + lord.faction.def.techLevel, + allowAntigrainWarhead: false, + faction: lord.faction + ); + + if (shellDef != null) + { + siege.DropSupplies(shellDef, LordToil_Siege.ShellReplenishCount); + } + } + } + + /// + /// Get the unique artillery types taking part in this siege. + /// + /// The siege to get artillery types for. + /// Enumerable of unique artillery defs taking part in this siege. + private static IEnumerable UniqueArtilleryDefs(LordToil_Siege siege) => siege.lord.ownedBuildings + .Select(t => t.def) + .Where(def => def.building.buildingTags.Contains("Artillery_BaseDestroyer")) + .Distinct(); + } +} diff --git a/Source/CombatExtended/Harmony/Harmony_LordToil_Siege.cs b/Source/CombatExtended/Harmony/Harmony_LordToil_Siege.cs index 7200056022..a4af8c5a61 100644 --- a/Source/CombatExtended/Harmony/Harmony_LordToil_Siege.cs +++ b/Source/CombatExtended/Harmony/Harmony_LordToil_Siege.cs @@ -1,6 +1,4 @@ using System.Collections.Generic; -using System.Linq; -using System.Reflection; using System.Reflection.Emit; using HarmonyLib; using RimWorld; @@ -8,66 +6,107 @@ namespace CombatExtended.HarmonyCE { + /// + /// Transpile LordToil_Siege.LordToilTick to support artillery pieces with different ammosets than the 81mm mortar. + /// [HarmonyPatch(typeof(LordToil_Siege), "LordToilTick")] - internal static class Harmony_LordToil_Siege + internal static class Harmony_LordToil_Siege_LordToilTick { - internal static IEnumerable Transpiler(IEnumerable instructions) + internal static IEnumerable Transpiler(IEnumerable instructions, + ILGenerator generator) { - var codes = new List(instructions); - var methodCustomCondition = typeof(Harmony_LordToil_Siege).GetMethod(nameof(CustomCondition), BindingFlags.Static | BindingFlags.Public); - var startIndex = -1; - var endIndex = -1; - MethodInfo targetMethod = AccessTools.Method(typeof(ThingDef), "get_IsShell"); // Start of the if condition - FieldInfo targetField = AccessTools.Field(typeof(DamageDef), "harmsHealth"); // End of the if condition - for (int i = 0; i < codes.Count; i++) - { - if (startIndex == -1) - { - // Find the start of the if statement - if (codes[i].opcode == OpCodes.Callvirt && codes[i].Calls(targetMethod)) - { - startIndex = i - 1; // We want to edit -1 instruction from the call of IsShell - } - } - else if (codes[i].opcode == OpCodes.Ldfld && codes[i].LoadsField(targetField)) - { - endIndex = i; - } - } - if (startIndex == -1 || endIndex == -1) - { - Log.Error("CombatExtended :: Harmony_LordToil_Siege couldn't find code block for patching"); - return codes; // Don't modify as we couldn't find the original code block - } - else - { - codes[startIndex] = new CodeInstruction(OpCodes.Call, methodCustomCondition); // Call the new method for evaluation - codes.RemoveRange(startIndex + 1, endIndex - startIndex); // Remove the default code - return codes; - } + var methodCustomCondition = AccessTools.Method(typeof(SiegeUtility), nameof(SiegeUtility.IsValidShellType)); + var dropAdditionalShells = AccessTools.Method(typeof(SiegeUtility), nameof(SiegeUtility.DropAdditionalShells)); + + var isShellMethod = AccessTools.PropertyGetter(typeof(ThingDef), nameof(ThingDef.IsShell)); + var harmsHealthField = AccessTools.Field(typeof(DamageDef), nameof(DamageDef.harmsHealth)); + var tryFindRandomShellDefMethod = + AccessTools.Method(typeof(TurretGunUtility), nameof(TurretGunUtility.TryFindRandomShellDef)); + + var codeMatcher = new CodeMatcher(instructions, generator); + + var isShellPos = codeMatcher + .Start() + .MatchStartForward(CodeMatch.Calls(isShellMethod)) + .ThrowIfInvalid("CombatExtended :: Harmony_LordToil_Siege_LordToilTick couldn't find call to IsShell") + .Pos; + + var harmsHealthPos = codeMatcher.MatchStartForward(CodeMatch.LoadsField(harmsHealthField)) + .ThrowIfInvalid("CombatExtended :: Harmony_LordToil_Siege_LordToilTick couldn't find harmsHealth") + .Pos; + + // Consider all shell types usable by the siege when assessing how many are available to the siege + codeMatcher + .Advance(isShellPos - harmsHealthPos - 1) + .Insert( + CodeInstruction.LoadArgument(0), + new CodeInstruction(OpCodes.Call, methodCustomCondition) + ) + .RemoveInstructionsInRange(isShellPos + 1, harmsHealthPos + 2); + + var ifBlockStart = codeMatcher.Start() + .MatchStartForward(CodeMatch.Calls(tryFindRandomShellDefMethod)) + .ThrowIfInvalid("CombatExtended :: Harmony_LordToil_Siege_LordToilTick couldn't find call to TryFindRandomShellDef") + .MatchEndBackwards(CodeMatch.Branches()) + .ThrowIfInvalid("CombatExtended :: Harmony_LordToil_Siege_LordToilTick couldn't find start of enclosing if block") + .Pos; + + var ifBlockEndLabel = (Label)codeMatcher.Operand; + + // Drop shells for every type of artillery piece used by the siege + codeMatcher.MatchStartForward(new CodeMatch(instruction => instruction.labels.Contains(ifBlockEndLabel))) + .ThrowIfInvalid("CombatExtended :: Harmony_LordToil_Siege_LordToilTick couldn't find end of enclosing if block") + .Insert( + CodeInstruction.LoadArgument(0), + new CodeInstruction(OpCodes.Call, dropAdditionalShells) + ) + .RemoveInstructionsInRange(ifBlockStart + 1, codeMatcher.Pos - 1); + + return codeMatcher.Instructions(); } - public static bool CustomCondition(Thing thing) + } + + /// + /// Transpile LordToil_Siege.Init to remove the market price cap on the initially dropped shell stacks. + /// + [HarmonyPatch(typeof(LordToil_Siege), nameof(LordToil_Siege.Init))] + internal static class Harmony_LordToil_Siege_Init + { + internal static IEnumerable Transpiler(IEnumerable instructions, + ILGenerator generator) + { + var codeMatcher = new CodeMatcher(instructions, generator); + + codeMatcher.MatchStartForward(CodeMatch.LoadsConstant(250f)) + .ThrowIfInvalid("CombatExtended :: Harmony_LordToil_Siege_Init couldn't find market price cap") + .RemoveInstruction() + .Insert(new CodeInstruction(OpCodes.Ldc_R4, -1f)); + + return codeMatcher.Instructions(); + } + } + + /// + /// Transpile LordToil_Siege.SetAsBuilder to ensure that builders are capable enough to build any siege artillery. + /// + [HarmonyPatch(typeof(LordToil_Siege), nameof(LordToil_Siege.SetAsBuilder))] + internal static class Harmony_LordToil_Siege_SetAsBuilder + { + internal static IEnumerable Transpiler(IEnumerable instructions, + ILGenerator generator) { - // Ensure check is the same here as from CombatExtended.HarmonyCE.Harmony_TurretGunUtility - var ammoDef = thing.def as AmmoDef; - if (ammoDef == null) - { - return false; - } - - // Ignore all non-shell defs. - if (ammoDef == null || !AmmoUtility.IsShell(ammoDef)) - { - return false; - } - - // Check if shell is blacklisted - if (!ammoDef.spawnAsSiegeAmmo) - { - return false; - } - return true; + var codeMatcher = new CodeMatcher(instructions, generator); + + codeMatcher.MatchStartForward( + CodeMatch.LoadsField(AccessTools.Field(typeof(ThingDefOf), nameof(ThingDefOf.Turret_Mortar))), + CodeMatch.LoadsField(AccessTools.Field(typeof(BuildableDef), nameof(BuildableDef.constructionSkillPrerequisite))) + ) + .ThrowIfInvalid("CombatExtended :: Harmony_LordToil_Siege_SetAsBuilder couldn't find required construction skill") + .RemoveInstructions(2) + .Insert(CodeInstruction.LoadField(typeof(SiegeUtility), nameof(SiegeUtility.MinRequiredConstructionSkill))); + + return codeMatcher.Instructions(); } } } diff --git a/Source/CombatExtended/Harmony/Harmony_ThingListGroupHelper.cs b/Source/CombatExtended/Harmony/Harmony_ThingListGroupHelper.cs deleted file mode 100644 index 0692338d76..0000000000 --- a/Source/CombatExtended/Harmony/Harmony_ThingListGroupHelper.cs +++ /dev/null @@ -1,17 +0,0 @@ -using System.Collections.Generic; -using System.Reflection; -using HarmonyLib; -using Verse; - -namespace CombatExtended.HarmonyCE -{ - [HarmonyPatch(typeof(ThingListGroupHelper), "Includes")] - internal static class Harmony_ThingListGroupHelper - { - internal static IEnumerable Transpiler(IEnumerable instructions) - { - return instructions.MethodReplacer(typeof(ThingDef).GetMethod("get_IsShell"), - typeof(AmmoUtility).GetMethod(nameof(AmmoUtility.IsShell), BindingFlags.Public | BindingFlags.Static)); - } - } -} diff --git a/Source/CombatExtended/Harmony/Harmony_TurretGunUtility.cs b/Source/CombatExtended/Harmony/Harmony_TurretGunUtility.cs index 627366c629..00bc5301fb 100644 --- a/Source/CombatExtended/Harmony/Harmony_TurretGunUtility.cs +++ b/Source/CombatExtended/Harmony/Harmony_TurretGunUtility.cs @@ -1,94 +1,66 @@ using System.Linq; using System.Collections.Generic; -using System.Collections; -using System.Reflection; using HarmonyLib; using RimWorld; using Verse; -// ReSharper disable InconsistentNaming -// ReSharper disable InlineOutVariableDeclaration -// ReSharper disable UsePatternMatching - namespace CombatExtended.HarmonyCE { - [HarmonyPatch] + /// + /// Replace to support turrets other than the 81mm mortar. + /// + [HarmonyPatch(typeof(TurretGunUtility), nameof(TurretGunUtility.TryFindRandomShellDef))] public static class Harmony_TurretGunUtility { - const string className = "DisplayClass"; - const string methodName = ""; - - // This should be kept up to date with the check in CombatExtended.HarmonyCE.Harmony_LordToil_Siege - public static void Postfix(object __instance, ThingDef x, ref bool __result, bool ___allowEMP, float ___maxMarketValue) + public static bool Prefix( + ThingDef turret, + bool allowEMP, + bool allowToxGas, + TechLevel techLevel, + bool allowAntigrainWarhead, + ref ThingDef __result + ) { - // Ignore already true results. - if (__result) - { - return; - } - - var ammoDef = x as AmmoDef; - - // Ignore all non-shell defs. - if (ammoDef == null || !AmmoUtility.IsShell(ammoDef)) + if (!TurretGunUtility.NeedsShells(turret)) { - return; + __result = null; + return false; } - // Check if market value is within range. - if (___maxMarketValue >= 0.0f && ammoDef.BaseMarketValue > ___maxMarketValue) + // Fall back to the vanilla logic if we have no ammo configured for this turret (unpatched?) + var ammoUserProps = turret.building.turretGunDef.comps.OfType() + .FirstOrDefault(); + if (ammoUserProps == null) { - return; + return true; } - // Get the explosive damage def. - var explosiveDamageDef = ammoDef.GetCompProperties()?.explosiveDamageType ?? - ammoDef.GetCompProperties()?.explosiveDamageType; + IEnumerable potentialAmmoDefs = from ammoLink in ammoUserProps.ammoSet.ammoTypes + let ammoDef = ammoLink.ammo + where ammoDef.spawnAsSiegeAmmo + let projectileDef = ammoLink.projectile + let explosiveDamageDef = + projectileDef.GetCompProperties()?.explosiveDamageType ?? + projectileDef.GetCompProperties()?.explosiveDamageType + let projectileDamageDef = projectileDef.projectile.damageDef + where explosiveDamageDef != null || projectileDamageDef != null - // Get the projectile damage def via the mortar ammo set. - //var mortarAmmoSet = DefDatabase.GetNamed("AmmoSet_81mmMortarShell"); - var projectileDamageDef = ammoDef.projectile?.damageDef ?? CE_AmmoSetDefOf.AmmoSet_81mmMortarShell.ammoTypes.FirstOrDefault(t => t.ammo == ammoDef)?.projectile?.projectile?.damageDef; + // Only allow EMP or tox gas shells if explicitly allowed and relevant DLC is available + where allowEMP || (explosiveDamageDef != DamageDefOf.EMP && projectileDamageDef != DamageDefOf.EMP) + where (allowToxGas && ModsConfig.BiotechActive) || (explosiveDamageDef != DamageDefOf.ToxGas && + projectileDamageDef != DamageDefOf.ToxGas) - // Ignore shells that don't have damage defs. - if (explosiveDamageDef == null && projectileDamageDef == null) - { - return; - } + // No antigrain warheads + where allowAntigrainWarhead || ammoDef != ThingDefOf.Shell_AntigrainWarhead - // Ignore EMP if not allowed. - if (!___allowEMP && (explosiveDamageDef == DamageDefOf.EMP || projectileDamageDef == DamageDefOf.EMP)) - { - return; - } + // No higher tech shells than the tech level of the requesting faction + where techLevel == TechLevel.Undefined || ammoDef.techLevel <= techLevel + select ammoDef; - // Check if blacklisted - if (!ammoDef.spawnAsSiegeAmmo) - { - return; - } - - __result = true; - } - - public static MethodBase TargetMethod() - { - var classTargets = typeof(TurretGunUtility).GetNestedTypes(AccessTools.all) - .Where(x => x.Name.Contains(className)); - - if (!classTargets.Any()) - { - Log.Error("CombatExtended :: Harmony_TurretGunUtility couldn't find subclass with part `" + className + "`"); - } - - var methodTarget = classTargets.SelectMany(x => x.GetMethods(AccessTools.all)) - .FirstOrDefault(x => x.Name.Contains(methodName)); - - if (methodTarget == null) - { - Log.Error("CombatExtended :: Harmony_TurretGunUtility couldn't find method with part `" + methodName + "` in subclasses with part `" + className + "`"); - } + // Respect individual weighting of matching shells within the ammoset + potentialAmmoDefs.TryRandomElementByWeight(def => def.generateAllowChance, out __result); - return methodTarget; + return false; } } } From 8a5da54b57fc4e6773726e0438c54dce3890712c Mon Sep 17 00:00:00 2001 From: Safairette <71556532+Safairette@users.noreply.github.com> Date: Thu, 7 Nov 2024 18:28:29 +0200 Subject: [PATCH 2/6] Fix soft biotech dependency Thanks Nuff! --- Source/CombatExtended/Harmony/Harmony_TurretGunUtility.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/CombatExtended/Harmony/Harmony_TurretGunUtility.cs b/Source/CombatExtended/Harmony/Harmony_TurretGunUtility.cs index 00bc5301fb..5147f1539e 100644 --- a/Source/CombatExtended/Harmony/Harmony_TurretGunUtility.cs +++ b/Source/CombatExtended/Harmony/Harmony_TurretGunUtility.cs @@ -47,7 +47,7 @@ where ammoDef.spawnAsSiegeAmmo // Only allow EMP or tox gas shells if explicitly allowed and relevant DLC is available where allowEMP || (explosiveDamageDef != DamageDefOf.EMP && projectileDamageDef != DamageDefOf.EMP) - where (allowToxGas && ModsConfig.BiotechActive) || (explosiveDamageDef != DamageDefOf.ToxGas && + where allowToxGas || !ModsConfig.BiotechActive || (explosiveDamageDef != DamageDefOf.ToxGas && projectileDamageDef != DamageDefOf.ToxGas) // No antigrain warheads From e18c3673c2fc556c542dc6a7b61012590e9a9bb6 Mon Sep 17 00:00:00 2001 From: Safairette <71556532+Safairette@users.noreply.github.com> Date: Mon, 11 Nov 2024 23:24:54 +0200 Subject: [PATCH 3/6] Add 'harmsHealth' check --- Source/CombatExtended/Harmony/Harmony_TurretGunUtility.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Source/CombatExtended/Harmony/Harmony_TurretGunUtility.cs b/Source/CombatExtended/Harmony/Harmony_TurretGunUtility.cs index 5147f1539e..1d0d0935ac 100644 --- a/Source/CombatExtended/Harmony/Harmony_TurretGunUtility.cs +++ b/Source/CombatExtended/Harmony/Harmony_TurretGunUtility.cs @@ -16,6 +16,7 @@ public static bool Prefix( ThingDef turret, bool allowEMP, bool allowToxGas, + bool mustHarmHealth, TechLevel techLevel, bool allowAntigrainWarhead, ref ThingDef __result @@ -49,6 +50,8 @@ where ammoDef.spawnAsSiegeAmmo where allowEMP || (explosiveDamageDef != DamageDefOf.EMP && projectileDamageDef != DamageDefOf.EMP) where allowToxGas || !ModsConfig.BiotechActive || (explosiveDamageDef != DamageDefOf.ToxGas && projectileDamageDef != DamageDefOf.ToxGas) + // Filter non-damaging shells + where !mustHarmHealth || projectileDamageDef.harmsHealth // No antigrain warheads where allowAntigrainWarhead || ammoDef != ThingDefOf.Shell_AntigrainWarhead From 6f90dd4647c1bb342f9db939f70650807e75e8e1 Mon Sep 17 00:00:00 2001 From: Safairette <71556532+Safairette@users.noreply.github.com> Date: Tue, 12 Nov 2024 00:58:33 +0200 Subject: [PATCH 4/6] Revert "Add 'harmsHealth' check" This reverts commit e18c3673c2fc556c542dc6a7b61012590e9a9bb6. --- Source/CombatExtended/Harmony/Harmony_TurretGunUtility.cs | 3 --- 1 file changed, 3 deletions(-) diff --git a/Source/CombatExtended/Harmony/Harmony_TurretGunUtility.cs b/Source/CombatExtended/Harmony/Harmony_TurretGunUtility.cs index 1d0d0935ac..5147f1539e 100644 --- a/Source/CombatExtended/Harmony/Harmony_TurretGunUtility.cs +++ b/Source/CombatExtended/Harmony/Harmony_TurretGunUtility.cs @@ -16,7 +16,6 @@ public static bool Prefix( ThingDef turret, bool allowEMP, bool allowToxGas, - bool mustHarmHealth, TechLevel techLevel, bool allowAntigrainWarhead, ref ThingDef __result @@ -50,8 +49,6 @@ where ammoDef.spawnAsSiegeAmmo where allowEMP || (explosiveDamageDef != DamageDefOf.EMP && projectileDamageDef != DamageDefOf.EMP) where allowToxGas || !ModsConfig.BiotechActive || (explosiveDamageDef != DamageDefOf.ToxGas && projectileDamageDef != DamageDefOf.ToxGas) - // Filter non-damaging shells - where !mustHarmHealth || projectileDamageDef.harmsHealth // No antigrain warheads where allowAntigrainWarhead || ammoDef != ThingDefOf.Shell_AntigrainWarhead From ca07cf1582e3ca2992a006d3936b9628d8df1588 Mon Sep 17 00:00:00 2001 From: n7huntsman Date: Mon, 11 Nov 2024 18:05:22 -0500 Subject: [PATCH 5/6] Manually exclude deadlife shells --- Defs/Ammo/Shell/81mmMortar.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/Defs/Ammo/Shell/81mmMortar.xml b/Defs/Ammo/Shell/81mmMortar.xml index ba9a5ffc43..c246cda4d8 100644 --- a/Defs/Ammo/Shell/81mmMortar.xml +++ b/Defs/Ammo/Shell/81mmMortar.xml @@ -217,6 +217,7 @@ Deadlife Bullet_81mmMortarShell_Deadlife + false From 10313e0133a39514ea2eeea730adbecd93e28f9b Mon Sep 17 00:00:00 2001 From: Safairette <71556532+Safairette@users.noreply.github.com> Date: Tue, 12 Nov 2024 01:16:31 +0200 Subject: [PATCH 6/6] Let wasters use gas --- Source/CombatExtended/CombatExtended/SiegeUtility.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Source/CombatExtended/CombatExtended/SiegeUtility.cs b/Source/CombatExtended/CombatExtended/SiegeUtility.cs index 8c57b02017..fd0b2673cf 100644 --- a/Source/CombatExtended/CombatExtended/SiegeUtility.cs +++ b/Source/CombatExtended/CombatExtended/SiegeUtility.cs @@ -49,6 +49,11 @@ public static bool IsValidShellType(Thing thing, LordToil_Siege siege) public static void DropAdditionalShells(LordToil_Siege siege) { Lord lord = siege.lord; + bool allowToxGas = false; + if (ModsConfig.BiotechActive && lord.faction.def == FactionDefOf.PirateWaster) + { + allowToxGas = true; + } foreach (var artilleryDef in UniqueArtilleryDefs(siege)) { @@ -58,7 +63,7 @@ public static void DropAdditionalShells(LordToil_Siege siege) var shellDef = TurretGunUtility.TryFindRandomShellDef( artilleryDef, allowEMP: false, - allowToxGas: false, + allowToxGas: allowToxGas, mustHarmHealth: true, lord.faction.def.techLevel, allowAntigrainWarhead: false,