public override void CompTick() { if (parent.Faction != Faction.OfPlayer) { TryResolveArtilleryCount(); if (Attacking) { // Try and bombard player settlements if (artilleryCooldownTicks > 0) { artilleryCooldownTicks--; } else if (Targets.Select(t => t.WorldObject).Cast <Settlement>().TryRandomElementByWeight(s => StorytellerUtility.DefaultThreatPointsNow(s.Map), out Settlement targetSettlement)) { if (artilleryWarmupTicks < 0) { artilleryWarmupTicks = ArtilleryDef.building.turretBurstWarmupTime.SecondsToTicks(); } else { artilleryWarmupTicks--; if (artilleryWarmupTicks == -1) { var shell = ArtilleryStrikeUtility.GetRandomShellFor(ArtilleryGunDef, parent.Faction.def); if (shell != null) { float missRadius = ArtilleryStrikeUtility.FinalisedMissRadius(ArtilleryGunDef.Verbs[0].forcedMissRadius, ArtilleryProps.maxForcedMissRadiusFactor, parent.Tile, targetSettlement.Tile, ArtilleryProps.worldTileRange); var map = targetSettlement.Map; var strikeCells = ArtilleryStrikeUtility.PotentialStrikeCells(map, missRadius); for (int i = 0; i < artilleryCount; i++) { ArtilleryStrikeUtility.SpawnArtilleryStrikeSkyfaller(shell, map, strikeCells.RandomElement()); } artilleryCooldownTicks = ArtilleryDef.building.turretBurstCooldownTime.SecondsToTicks(); } else { Log.ErrorOnce($"Tried to get shell for bombardment but got null instead (artilleryGunDef={ArtilleryGunDef}, factionDef={parent.Faction.def})", 8173352); } } } } else { artilleryWarmupTicks = -1; } // Reduce the duration of the bombardment bombardmentDurationTicks--; if (bombardmentDurationTicks == 0) { EndBombardment(); } } } }
public override void Arrived(List <ActiveArtilleryStrike> artilleryStrikes, int tile) { // Boom var map = mapParent.Map; if (map != null) { for (int i = 0; i < artilleryStrikes.Count; i++) { var strike = artilleryStrikes[i]; var potentialCells = ArtilleryStrikeUtility.PotentialStrikeCells(map, strike.missRadius); for (int j = 0; j < strike.shellCount; j++) { ArtilleryStrikeUtility.SpawnArtilleryStrikeSkyfaller(strike.shellDef, map, potentialCells.RandomElement()); } } } else { ArtilleryComp.ResetForcedTarget(); } }