public override bool TryExecute(IncidentParms parms) { Map map = (Map)parms.target; int num = 0; int countToSpawn = this.CountToSpawn; IntVec3 vec = IntVec3.Invalid; for (int i = 0; i < countToSpawn; i++) { IntVec3 spawnCell = IntVec3.Invalid; if (map.Biome == Util_CaveBiome.CaveBiomeDef) { TryFindShipCrashSite(map, out spawnCell); } else { Predicate <IntVec3> validator = delegate(IntVec3 c) { if (c.Fogged(map)) { return(false); } foreach (IntVec3 current in GenAdj.CellsOccupiedBy(c, Rot4.North, this.def.shipPart.size)) { if (!current.Standable(map)) { bool result = false; return(result); } if (map.roofGrid.Roofed(current)) { bool result = false; return(result); } } return(map.reachability.CanReachColony(c)); }; if (!CellFinderLoose.TryFindRandomNotEdgeCellWith(14, validator, map, out spawnCell)) { break; } } if (spawnCell.IsValid == false) { break; } GenExplosion.DoExplosion(spawnCell, map, 3f, DamageDefOf.Flame, null, null, null, null, null, 0f, 1, false, null, 0f, 1); Building_CrashedShipPartCopy building_CrashedShipPart = (Building_CrashedShipPartCopy)GenSpawn.Spawn(this.def.shipPart, spawnCell, map); building_CrashedShipPart.SetFaction(Faction.OfMechanoids, null); building_CrashedShipPart.pointsLeft = parms.points * ShipPointsFactor; if (building_CrashedShipPart.pointsLeft < IncidentMinimumPoints) { building_CrashedShipPart.pointsLeft = IncidentMinimumPoints; } num++; vec = spawnCell; } if (num > 0) { Find.CameraDriver.shaker.DoShake(1f); Find.LetterStack.ReceiveLetter(this.def.letterLabel, this.def.letterText, this.def.letterType, new TargetInfo(vec, map, false), null); } return(num > 0); }
public override bool TryExecute(IncidentParms parms) { int num = 0; int countToSpawn = this.CountToSpawn; IntVec3 vec = IntVec3.Invalid; for (int i = 0; i < countToSpawn; i++) { Predicate <IntVec3> validator = delegate(IntVec3 c) { if (c.Fogged()) { return(false); } if (Find.Map.Biome == Util_CaveBiome.CaveBiomeDef) { if (c.GetFirstThing(Util_CaveBiome.CaveWellDef) == null) { Log.Warning("Not in cave well at " + c.ToString()); return(false); } } foreach (IntVec3 current in GenAdj.CellsOccupiedBy(c, Rot4.North, this.def.shipPart.size)) { if (!current.Standable()) { bool result = false; return(result); } if (Find.RoofGrid.Roofed(current)) { bool result = false; return(result); } } return(c.CanReachColony()); }; IntVec3 spawnCell = IntVec3.Invalid; TryFindShipCrashSite(out spawnCell); if (spawnCell.IsValid == false) { break; } GenExplosion.DoExplosion(spawnCell, 3f, DamageDefOf.Flame, null, null, null, null, null, 0f, 1, false, null, 0f, 1); Building_CrashedShipPartCopy building_CrashedShipPart = (Building_CrashedShipPartCopy)GenSpawn.Spawn(this.def.shipPart, spawnCell); building_CrashedShipPart.SetFaction(Faction.OfMechanoids, null); building_CrashedShipPart.pointsLeft = parms.points * ShipPointsFactor; if (building_CrashedShipPart.pointsLeft < IncidentMinimumPoints) { building_CrashedShipPart.pointsLeft = IncidentMinimumPoints; } num++; vec = spawnCell; } if (num > 0) { Find.CameraDriver.shaker.DoShake(1f); Find.LetterStack.ReceiveLetter(this.def.letterLabel, this.def.letterText, this.def.letterType, vec, null); } return(num > 0); }