Skip to content

Commit

Permalink
Merge pull request #3530 from CombatExtended-Continued/remove-raider-…
Browse files Browse the repository at this point in the history
…artillery

Support arbitrary ammosets for siege artillery
  • Loading branch information
N7Huntsman authored Nov 11, 2024
2 parents 85e7359 + 1b4911d commit a3bd2b8
Show file tree
Hide file tree
Showing 10 changed files with 228 additions and 314 deletions.
1 change: 1 addition & 0 deletions Defs/Ammo/Shell/155mmHowitzer.xml
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@
</statBases>
<ammoClass>Smoke</ammoClass>
<detonateProjectile>Bullet_155mmHowitzerShell_Smoke</detonateProjectile>
<spawnAsSiegeAmmo>false</spawnAsSiegeAmmo>
</ThingDef>

<!-- ================== Projectiles ================== -->
Expand Down
1 change: 1 addition & 0 deletions Defs/Ammo/Shell/81mmMortar.xml
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@
</statBases>
<ammoClass>Deadlife</ammoClass>
<detonateProjectile>Bullet_81mmMortarShell_Deadlife</detonateProjectile>
<spawnAsSiegeAmmo>false</spawnAsSiegeAmmo>
</ThingDef>

<!-- ================== Projectiles ================== -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,4 @@
<applyDamageToExplosionCellsNeighbors>true</applyDamageToExplosionCellsNeighbors>
</projectile>
</ThingDef>

<!-- ========== Raider Artillery (To circumvent the issue with vanilla shells.) ========== -->
<CombatExtended.AmmoSetDef>
<defName>AmmoSet_RaiderArtillery</defName>
<label>Raider Artillery</label>
<ammoTypes>
<Shell_HighExplosive>Bullet_155mmHowitzerShell_HE</Shell_HighExplosive>
<Shell_Incendiary>Bullet_155mmHowitzerShell_Incendiary</Shell_Incendiary>
<Shell_Toxic MayRequire="Ludeon.RimWorld.Biotech">Bullet_81mmMortarShell_Tox</Shell_Toxic>
</ammoTypes>
</CombatExtended.AmmoSetDef>

</Defs>

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -254,10 +254,6 @@
</value>
</Operation>

<Operation Class="PatchOperationRemove">
<xpath>Defs/ThingDef[defName="VFES_Turret_Artillery"]/building/buildingTags</xpath>
</Operation>

<Operation Class="PatchOperationReplace">
<xpath>Defs/ThingDef[defName="VFES_Turret_Artillery"]/building/turretBurstWarmupTime</xpath>
<value>
Expand Down
6 changes: 0 additions & 6 deletions Source/CombatExtended/CombatExtended/AmmoUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,6 @@ public static string GetProjectileReadout(this ThingDef projectileDef, Thing wea
/// </summary>
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<CompProperties_AmmoUser>();
return ammo?.ammoSet.ammoTypes.Any(l => l.ammo == def) ?? false;
}

public static bool IsAmmoSystemActive(AmmoDef def)
{
if (Controller.settings.EnableAmmoSystem)
Expand Down
90 changes: 90 additions & 0 deletions Source/CombatExtended/CombatExtended/SiegeUtility.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
using System.Collections.Generic;
using System.Linq;
using RimWorld;
using Verse;
using Verse.AI.Group;

namespace CombatExtended
{
[StaticConstructorOnStartup]
public class SiegeUtility
{
/// <summary>
/// The minimum required construction skill to be able to build any potential siege artillery in the game.
/// </summary>
public static readonly int MinRequiredConstructionSkill;

static SiegeUtility()
{
MinRequiredConstructionSkill = DefDatabase<ThingDef>.AllDefsListForReading
.Where(def => def.building?.buildingTags.Contains("Artillery_BaseDestroyer") ?? false)
.Select(def => def.constructionSkillPrerequisite)
.Max();
}

/// <summary>
/// Determine whether the given thing is a valid shell usable by this siege.
/// </summary>
/// <param name="thing">The thing to check.</param>
/// <param name="siege">The siege.</param>
/// <returns>true if at least one type of artillery piece taking part in the siege can use this shell, false otherwise.</returns>
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<CompProperties_AmmoUser>()
.SelectMany(props => props.ammoSet.ammoTypes)
.Any(ammoLink => ammoLink.ammo == ammoDef);
}

return false;
}

/// <summary>
/// Supply additional shells for each type of artillery piece taking part in this siege.
/// </summary>
/// <param name="siege">The siege to resupply.</param>
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))
{
// 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: allowToxGas,
mustHarmHealth: true,
lord.faction.def.techLevel,
allowAntigrainWarhead: false,
faction: lord.faction
);

if (shellDef != null)
{
siege.DropSupplies(shellDef, LordToil_Siege.ShellReplenishCount);
}
}
}

/// <summary>
/// Get the unique artillery types taking part in this siege.
/// </summary>
/// <param name="siege">The siege to get artillery types for.</param>
/// <returns>Enumerable of unique artillery defs taking part in this siege.</returns>
private static IEnumerable<ThingDef> UniqueArtilleryDefs(LordToil_Siege siege) => siege.lord.ownedBuildings
.Select(t => t.def)
.Where(def => def.building.buildingTags.Contains("Artillery_BaseDestroyer"))
.Distinct();
}
}
Loading

0 comments on commit a3bd2b8

Please sign in to comment.