public const float MaxExplosionScale = 10f; //as if 1000 shells exploded public static void DoExplosion(IntVec3 center, Map map, float radius, DamageDef damType, Thing instigator, int damAmount = -1, float armorPenetration = -1f, SoundDef explosionSound = null, ThingDef weapon = null, ThingDef projectile = null, Thing intendedTarget = null, ThingDef postExplosionSpawnThingDef = null, float postExplosionSpawnChance = 0f, int postExplosionSpawnThingCount = 1, bool applyDamageToExplosionCellsNeighbors = false, ThingDef preExplosionSpawnThingDef = null, float preExplosionSpawnChance = 0f, int preExplosionSpawnThingCount = 1, float chanceToStartFire = 0f, bool damageFalloff = false, float?direction = null, List <Thing> ignoredThings = null, float height = 0f, float scaleFactor = 1f, bool destroyAfterwards = false, ThingWithComps explosionParentToDestroy = null) { // Allows destroyed things to be exploded with appropriate scaleFactor if (scaleFactor <= 0f) { scaleFactor = 1f; } else { scaleFactor = Mathf.Clamp(scaleFactor, MinExplosionScale, MaxExplosionScale); } if (map == null) { Log.Warning("CombatExtended :: Tried to do explosionCE in a null map."); return; } if (damAmount < 0) { damAmount = damType.defaultDamage; armorPenetration = damType.defaultArmorPenetration; if (damAmount < 0) { Log.ErrorOnce("CombatExtended :: Attempted to trigger an explosionCE without defined damage", 910948823); damAmount = 1; } } explosionSound = explosionSound ?? damType.soundExplosion; if (explosionSound == null) { Log.Error("CombatExtended :: SoundDef was null for DamageDef " + damType.defName + " as well as instigator " + instigator.ThingID); } damAmount = Mathf.RoundToInt(damAmount * scaleFactor); radius *= scaleFactor; armorPenetration *= scaleFactor; ExplosionCE explosion = GenSpawn.Spawn(CE_ThingDefOf.ExplosionCE, center, map) as ExplosionCE; IntVec3? needLOSToCell = null; IntVec3? needLOSToCell2 = null; if (direction.HasValue) { CalculateNeededLOSToCells(center, map, direction.Value, out needLOSToCell, out needLOSToCell2); } explosion.height = height; explosion.radius = radius; explosion.damType = damType; explosion.instigator = instigator; explosion.damAmount = damAmount; explosion.armorPenetration = armorPenetration; explosion.weapon = weapon; explosion.projectile = projectile; explosion.intendedTarget = intendedTarget; explosion.preExplosionSpawnThingDef = preExplosionSpawnThingDef; explosion.preExplosionSpawnChance = preExplosionSpawnChance; explosion.preExplosionSpawnThingCount = preExplosionSpawnThingCount; explosion.postExplosionSpawnThingDef = postExplosionSpawnThingDef; explosion.postExplosionSpawnChance = postExplosionSpawnChance; explosion.postExplosionSpawnThingCount = postExplosionSpawnThingCount; explosion.applyDamageToExplosionCellsNeighbors = applyDamageToExplosionCellsNeighbors; explosion.chanceToStartFire = chanceToStartFire; explosion.damageFalloff = damageFalloff; explosion.needLOSToCell1 = needLOSToCell; explosion.needLOSToCell2 = needLOSToCell2; explosion.StartExplosionCE(explosionSound, ignoredThings); // Needed to allow CompExplosive to use stackCount if (destroyAfterwards && !explosionParentToDestroy.Destroyed) { explosionParentToDestroy?.Kill(); } }