public override bool TryExecute(IncidentParms parms)
        {
            Map     map          = (Map)parms.target;
            int     num          = 0;
            int     countToSpawn = this.CountToSpawn;
            IntVec3 cell         = IntVec3.Invalid;
            float   angle        = Rand.Range(0f, 360f);

            for (int i = 0; i < countToSpawn; i++)
            {
                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));
                };
                IntVec3 intVec;
                if (!CellFinderLoose.TryFindRandomNotEdgeCellWith(14, validator, map, out intVec))
                {
                    break;
                }
                GenExplosion.DoExplosion(intVec, map, 3f, DamageDefOf.Flame, null, null, null, null, null, 0f, 1, false, null, 0f, 1);
                Building_CrashedShipPart building_CrashedShipPart = (Building_CrashedShipPart)GenSpawn.Spawn(this.def.shipPart, intVec, map);
                building_CrashedShipPart.SetFaction(Faction.OfMechanoids, null);
                building_CrashedShipPart.pointsLeft = parms.points * 0.9f;
                if (building_CrashedShipPart.pointsLeft < 300f)
                {
                    building_CrashedShipPart.pointsLeft = 300f;
                }
                IncidentWorker_ShipPartCrash.SpawnShrapnel(ThingDefOf.ChunkSlagSteel, IncidentWorker_ShipPartCrash.ShrapnelMetal.RandomInRange, intVec, map, angle);
                IncidentWorker_ShipPartCrash.SpawnShrapnel(ThingDefOf.SlagRubble, IncidentWorker_ShipPartCrash.ShrapnelRubble.RandomInRange, intVec, map, angle);
                num++;
                cell = intVec;
            }
            if (num > 0)
            {
                if (map == Find.VisibleMap)
                {
                    Find.CameraDriver.shaker.DoShake(1f);
                }
                base.SendStandardLetter(new TargetInfo(cell, map, false), new string[0]);
            }
            return(num > 0);
        }
Esempio n. 2
0
        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_CrashedShipPart building_CrashedShipPart = (Building_CrashedShipPart)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.letterDef, new TargetInfo(vec, map, false), null);
            }
            return(num > 0);
        }