Ejemplo n.º 1
0
        protected override bool CanScatterAt(IntVec3 c, Map map)
        {
            if (!base.CanScatterAt(c, map))
            {
                return(false);
            }
            CellRect rect = CellRect.CenteredOn(c, 10, 10).ClipInsideMap(map);

            if (MapGenerator.TryGetVar <List <CellRect> >("UsedRects", out var var) && var.Any((CellRect x) => rect.Overlaps(x)))
            {
                return(false);
            }
            foreach (IntVec3 cell in rect.Cells)
            {
                if (!GenConstruct.CanBuildOnTerrain(currentParams.sitePart.conditionCauser.def, cell, map, Rot4.North))
                {
                    return(false);
                }
                foreach (Thing thing in cell.GetThingList(map))
                {
                    if (thing.def.building != null)
                    {
                        return(false);
                    }
                }
            }
            return(true);
        }
        protected override bool TryExecuteWorker(IncidentParms parms)
        {
            Map map = (Map)parms.target;
            List <TargetInfo> list        = new List <TargetInfo>();
            ThingDef          shipPartDef = def.mechClusterBuilding;
            IntVec3           intVec      = FindDropPodLocation(map, (IntVec3 spot) => CanPlaceAt(spot));

            if (intVec == IntVec3.Invalid)
            {
                return(false);
            }
            float       points = Mathf.Max(parms.points * 0.9f, 300f);
            List <Pawn> list2  = PawnGroupMakerUtility.GeneratePawns(new PawnGroupMakerParms
            {
                groupKind = PawnGroupKindDefOf.Combat,
                tile      = map.Tile,
                faction   = Faction.OfMechanoids,
                points    = points
            }).ToList();
            Thing thing = ThingMaker.MakeThing(shipPartDef);

            thing.SetFaction(Faction.OfMechanoids);
            LordMaker.MakeNewLord(Faction.OfMechanoids, new LordJob_SleepThenMechanoidsDefend(new List <Thing>
            {
                thing
            }, Faction.OfMechanoids, 28f, intVec, canAssaultColony: false, isMechCluster: false), map, list2);
            DropPodUtility.DropThingsNear(intVec, map, list2.Cast <Thing>());
            foreach (Pawn item in list2)
            {
                item.TryGetComp <CompCanBeDormant>()?.ToSleep();
            }
            list.AddRange(list2.Select((Pawn p) => new TargetInfo(p)));
            GenSpawn.Spawn(SkyfallerMaker.MakeSkyfaller(ThingDefOf.CrashedShipPartIncoming, thing), intVec, map);
            list.Add(new TargetInfo(intVec, map));
            SendStandardLetter(parms, list);
            return(true);

            bool CanPlaceAt(IntVec3 loc)
            {
                CellRect cellRect = GenAdj.OccupiedRect(loc, Rot4.North, shipPartDef.Size);

                if (loc.Fogged(map) || !cellRect.InBounds(map))
                {
                    return(false);
                }
                if (!DropCellFinder.SkyfallerCanLandAt(loc, map, shipPartDef.Size))
                {
                    return(false);
                }
                foreach (IntVec3 item2 in cellRect)
                {
                    RoofDef roof = item2.GetRoof(map);
                    if (roof != null && roof.isNatural)
                    {
                        return(false);
                    }
                }
                return(GenConstruct.CanBuildOnTerrain(shipPartDef, loc, map, Rot4.North));
            }
        }
Ejemplo n.º 3
0
 public override void Tick()
 {
     base.Tick();
     if (!GenConstruct.CanBuildOnTerrain(this.def.entityDefToBuild, base.Position, base.Map, base.Rotation, null))
     {
         this.Destroy(DestroyMode.Cancel);
     }
 }
Ejemplo n.º 4
0
 protected bool CanPlaceAncientBuildingInRange(CellRect rect, Map map)
 {
     foreach (IntVec3 cell in rect.Cells)
     {
         if (cell.InBounds(map))
         {
             TerrainDef terrainDef = map.terrainGrid.TerrainAt(cell);
             if (terrainDef.HasTag("River") || terrainDef.HasTag("Road"))
             {
                 return(false);
             }
             if (!GenConstruct.CanBuildOnTerrain(ThingDefOf.Wall, cell, map, Rot4.North))
             {
                 return(false);
             }
         }
     }
     return(true);
 }
        public static AcceptanceReport CanPlaceBlueprintAt(BuildableDef entDef, IntVec3 center, Rot4 rot, Map map, bool godMode = false, Thing thingToIgnore = null)
        {
            CellRect cellRect = GenAdj.OccupiedRect(center, rot, entDef.Size);

            CellRect.CellRectIterator iterator = cellRect.GetIterator();
            while (!iterator.Done())
            {
                IntVec3 c = iterator.Current;
                if (!c.InBounds(map))
                {
                    return(new AcceptanceReport("OutOfBounds".Translate()));
                }
                if (c.InNoBuildEdgeArea(map) && !DebugSettings.godMode)
                {
                    return("TooCloseToMapEdge".Translate());
                }
                iterator.MoveNext();
            }
            if (center.Fogged(map))
            {
                return("CannotPlaceInUndiscovered".Translate());
            }
            List <Thing> thingList = center.GetThingList(map);

            for (int i = 0; i < thingList.Count; i++)
            {
                Thing thing = thingList[i];
                if (thing != thingToIgnore)
                {
                    if (thing.Position == center && thing.Rotation == rot)
                    {
                        if (thing.def == entDef)
                        {
                            return(new AcceptanceReport("IdenticalThingExists".Translate()));
                        }
                        if (thing.def.entityDefToBuild == entDef)
                        {
                            if (thing is Blueprint)
                            {
                                return(new AcceptanceReport("IdenticalBlueprintExists".Translate()));
                            }
                            return(new AcceptanceReport("IdenticalThingExists".Translate()));
                        }
                    }
                }
            }
            ThingDef thingDef = entDef as ThingDef;

            if (thingDef != null && thingDef.hasInteractionCell)
            {
                IntVec3 c2 = ThingUtility.InteractionCellWhenAt(thingDef, center, rot, map);
                if (!c2.InBounds(map))
                {
                    return(new AcceptanceReport("InteractionSpotOutOfBounds".Translate()));
                }
                List <Thing> list = map.thingGrid.ThingsListAtFast(c2);
                for (int j = 0; j < list.Count; j++)
                {
                    if (list[j] != thingToIgnore)
                    {
                        if (list[j].def.passability == Traversability.Impassable)
                        {
                            return(new AcceptanceReport("InteractionSpotBlocked".Translate(new object[]
                            {
                                list[j].LabelNoCount
                            }).CapitalizeFirst()));
                        }
                        Blueprint blueprint = list[j] as Blueprint;
                        if (blueprint != null && blueprint.def.entityDefToBuild.passability == Traversability.Impassable)
                        {
                            return(new AcceptanceReport("InteractionSpotWillBeBlocked".Translate(new object[]
                            {
                                blueprint.LabelNoCount
                            }).CapitalizeFirst()));
                        }
                    }
                }
            }
            if (entDef.passability == Traversability.Impassable)
            {
                foreach (IntVec3 c3 in GenAdj.CellsAdjacentCardinal(center, rot, entDef.Size))
                {
                    if (c3.InBounds(map))
                    {
                        thingList = c3.GetThingList(map);
                        for (int k = 0; k < thingList.Count; k++)
                        {
                            Thing thing2 = thingList[k];
                            if (thing2 != thingToIgnore)
                            {
                                Blueprint blueprint2 = thing2 as Blueprint;
                                ThingDef  thingDef3;
                                if (blueprint2 != null)
                                {
                                    ThingDef thingDef2 = blueprint2.def.entityDefToBuild as ThingDef;
                                    if (thingDef2 == null)
                                    {
                                        goto IL_37F;
                                    }
                                    thingDef3 = thingDef2;
                                }
                                else
                                {
                                    thingDef3 = thing2.def;
                                }
                                if (thingDef3.hasInteractionCell && cellRect.Contains(ThingUtility.InteractionCellWhenAt(thingDef3, thing2.Position, thing2.Rotation, thing2.Map)))
                                {
                                    return(new AcceptanceReport("WouldBlockInteractionSpot".Translate(new object[]
                                    {
                                        entDef.label,
                                        thingDef3.label
                                    }).CapitalizeFirst()));
                                }
                            }
                            IL_37F :;
                        }
                    }
                }
            }
            TerrainDef terrainDef = entDef as TerrainDef;

            if (terrainDef != null)
            {
                if (map.terrainGrid.TerrainAt(center) == terrainDef)
                {
                    return(new AcceptanceReport("TerrainIsAlready".Translate(new object[]
                    {
                        terrainDef.label
                    })));
                }
                if (map.designationManager.DesignationAt(center, DesignationDefOf.SmoothFloor) != null)
                {
                    return(new AcceptanceReport("SpaceBeingSmoothed".Translate()));
                }
            }
            if (!GenConstruct.CanBuildOnTerrain(entDef, center, map, rot, thingToIgnore))
            {
                return(new AcceptanceReport("TerrainCannotSupport".Translate()));
            }
            if (!godMode)
            {
                CellRect.CellRectIterator iterator2 = cellRect.GetIterator();
                while (!iterator2.Done())
                {
                    thingList = iterator2.Current.GetThingList(map);
                    for (int l = 0; l < thingList.Count; l++)
                    {
                        Thing thing3 = thingList[l];
                        if (thing3 != thingToIgnore)
                        {
                            if (!GenConstruct.CanPlaceBlueprintOver(entDef, thing3.def))
                            {
                                return(new AcceptanceReport("SpaceAlreadyOccupied".Translate()));
                            }
                        }
                    }
                    iterator2.MoveNext();
                }
            }
            if (entDef.PlaceWorkers != null)
            {
                for (int m = 0; m < entDef.PlaceWorkers.Count; m++)
                {
                    AcceptanceReport result = entDef.PlaceWorkers[m].AllowsPlacing(entDef, center, rot, map, thingToIgnore);
                    if (!result.Accepted)
                    {
                        return(result);
                    }
                }
            }
            return(AcceptanceReport.WasAccepted);
        }
Ejemplo n.º 6
0
 public override bool CanBuildOnTerrain(IntVec3 at, Map map)
 {
     return(GenConstruct.CanBuildOnTerrain(def, at, map, Rot4.North));
 }
Ejemplo n.º 7
0
 public override void Place(Map map, IntVec3 position, TerrainDef rockDef, IntVec3 origin, GenStep_Roads.DistanceElement[,] distance)
 {
     if (this.onlyIfOriginAllows)
     {
         if (!GenConstruct.CanBuildOnTerrain(this.place, origin, map, Rot4.North, null) && origin.GetTerrain(map) != this.place)
         {
             return;
         }
         bool flag = false;
         for (int i = 0; i < 4; i++)
         {
             IntVec3 c = position + GenAdj.CardinalDirections[i];
             if (c.InBounds(map) && this.chancePerPositionCurve.Evaluate(distance[c.x, c.z].fromRoad) > 0f && (GenConstruct.CanBuildOnTerrain(this.place, c, map, Rot4.North, null) || c.GetTerrain(map) == this.place) && (GenConstruct.CanBuildOnTerrain(this.place, distance[c.x, c.z].origin, map, Rot4.North, null) || distance[c.x, c.z].origin.GetTerrain(map) == this.place))
             {
                 flag = true;
                 break;
             }
         }
         if (!flag)
         {
             return;
         }
     }
     if (!this.suppressOnTerrainTag.NullOrEmpty())
     {
         TerrainDef terrainDef = map.terrainGrid.TerrainAt(position);
         if (terrainDef.HasTag(this.suppressOnTerrainTag))
         {
             return;
         }
     }
     base.Place(map, position, rockDef, origin, distance);
     if (this.place is TerrainDef)
     {
         if (this.proximitySpacing != 0)
         {
             Log.ErrorOnce("Proximity spacing used for road terrain placement; not yet supported", 60936625, false);
         }
         TerrainDef terrainDef2 = map.terrainGrid.TerrainAt(position);
         TerrainDef terrainDef3 = (TerrainDef)this.place;
         if (terrainDef3 == TerrainDefOf.FlagstoneSandstone)
         {
             terrainDef3 = rockDef;
         }
         if (terrainDef3 == TerrainDefOf.Bridge)
         {
             if (terrainDef2 == TerrainDefOf.WaterDeep)
             {
                 map.terrainGrid.SetTerrain(position, TerrainDefOf.WaterShallow);
             }
             if (terrainDef2 == TerrainDefOf.WaterOceanDeep)
             {
                 map.terrainGrid.SetTerrain(position, TerrainDefOf.WaterOceanShallow);
             }
         }
         if (GenConstruct.CanBuildOnTerrain(terrainDef3, position, map, Rot4.North, null) && (!GenConstruct.CanBuildOnTerrain(TerrainDefOf.Bridge, position, map, Rot4.North, null) || terrainDef3 == TerrainDefOf.Bridge) && terrainDef2 != TerrainDefOf.Bridge)
         {
             if (terrainDef2.HasTag("Road") && !terrainDef2.Removable)
             {
                 map.terrainGrid.SetTerrain(position, TerrainDefOf.Gravel);
             }
             map.terrainGrid.SetTerrain(position, terrainDef3);
         }
         if (position.OnEdge(map) && !map.roadInfo.roadEdgeTiles.Contains(position))
         {
             map.roadInfo.roadEdgeTiles.Add(position);
         }
     }
     else if (this.place is ThingDef)
     {
         if (!GenConstruct.CanBuildOnTerrain(this.place, position, map, Rot4.North, null))
         {
             return;
         }
         if (this.proximitySpacing > 0 && GenClosest.ClosestThing_Global(position, map.listerThings.ThingsOfDef((ThingDef)this.place), (float)this.proximitySpacing, null, null) != null)
         {
             return;
         }
         while (position.GetThingList(map).Count > 0)
         {
             position.GetThingList(map)[0].Destroy(DestroyMode.Vanish);
         }
         RoadDefGenStep_DryWithFallback.PlaceWorker(map, position, TerrainDefOf.Gravel);
         GenSpawn.Spawn(ThingMaker.MakeThing((ThingDef)this.place, null), position, map, WipeMode.Vanish);
     }
     else
     {
         Log.ErrorOnce(string.Format("Can't figure out how to place object {0} while building road", this.place), 10785584, false);
     }
 }
Ejemplo n.º 8
0
        /*
         * // Token: 0x06000EA8 RID: 3752 RVA: 0x0006C2D0 File Offset: 0x0006A6D0
         * protected override bool TryExecuteWorker(IncidentParms parms)
         * {
         *  Map map = (Map)parms.target;
         *  int num = 0;
         *  int countToSpawn = this.CountToSpawn;
         *  List<TargetInfo> list = new List<TargetInfo>();
         *  float shrapnelDirection = Rand.Range(0f, 360f);
         *  Faction faction = null;
         *  Building building_CrashedShipPart = null;
         *  building = (Building)ThingMaker.MakeThing(this.def.mechClusterBuilding, null);
         *  if (faction == null)
         *  {
         *      faction = building_CrashedShipPart.GetComp<CompPawnSpawnerOnDamaged>().OfFaction;
         *  }
         *  for (int i = 0; i < countToSpawn; i++)
         *  {
         *      IntVec3 intVec;
         *      if (!CellFinderLoose.TryFindSkyfallerCell(ThingDefOf.CrashedShipPartIncoming, map, out intVec, 14, default(IntVec3), -1, false, true, true, true, true, false, null))
         *      {
         *          break;
         *      }
         *      building_CrashedShipPart.SetFaction(faction, null);
         *      building_CrashedShipPart.GetComp<CompPawnSpawnerOnDamaged>().pointsLeft = Mathf.Max(parms.points * 0.9f, 300f);
         *
         *      ThingDef faller = building_CrashedShipPart.GetComp<CompPawnSpawnerOnDamaged>().Props.skyFaller != null ? building_CrashedShipPart.GetComp<CompPawnSpawnerOnDamaged>().Props.skyFaller : ThingDefOf.CrashedShipPartIncoming ;
         *      Skyfaller skyfaller = SkyfallerMaker.MakeSkyfaller(faller, building_CrashedShipPart);
         *      skyfaller.shrapnelDirection = shrapnelDirection;
         *      GenSpawn.Spawn(skyfaller, intVec, map, WipeMode.Vanish);
         *      num++;
         *      list.Add(new TargetInfo(intVec, map, false));
         *  }
         *  if (num > 0)
         *  {
         *      base.SendStandardLetter(list, null, new string[0]);
         *  }
         *  return num > 0;
         *
         * }
         */
        // Token: 0x06003A73 RID: 14963 RVA: 0x001328DC File Offset: 0x00130ADC
        protected override bool TryExecuteWorker(IncidentParms parms)
        {
            Map map = (Map)parms.target;
            List <TargetInfo> list        = new List <TargetInfo>();
            ThingDef          shipPartDef = this.def.mechClusterBuilding;
            IntVec3           intVec      = MechClusterUtility.FindDropPodLocation(map, (IntVec3 spot) => !spot.Fogged(map) && GenConstruct.CanBuildOnTerrain(shipPartDef, spot, map, Rot4.North, null, null) && GenConstruct.CanBuildOnTerrain(shipPartDef, new IntVec3(spot.x - Mathf.CeilToInt((float)shipPartDef.size.x / 2f), spot.y, spot.z), map, Rot4.North, null, null), 500, 0f);

            if (intVec == IntVec3.Invalid)
            {
                return(false);
            }
            float    points = Mathf.Max(parms.points * 0.9f, 300f);
            Thing    thing  = ThingMaker.MakeThing(shipPartDef, null);
            Building building_CrashedShipPart = (Building)thing;
            CompPawnSpawnerOnDamaged damaged  = building_CrashedShipPart.TryGetComp <CompPawnSpawnerOnDamaged>();
            Faction faction = damaged.faction ?? Faction.OfMechanoids;

            thing.SetFaction(faction, null);

            /*
             * List<Pawn> list2 = PawnGroupMakerUtility.GeneratePawns(new PawnGroupMakerParms
             * {
             *  groupKind = PawnGroupKindDefOf.Combat,
             *  tile = map.Tile,
             *  faction = faction,
             *  points = points
             * }, true).ToList<Pawn>();
             * LordMaker.MakeNewLord(faction, new LordJob_SleepThenMechanoidsDefend(new List<Thing>
             * {
             *  thing
             * }, faction, 28f, intVec, false, false), map, list2);
             * DropPodUtility.DropThingsNear(intVec, map, list2.Cast<Thing>(), 110, false, false, true, true);
             * foreach (Pawn thing2 in list2)
             * {
             *  CompCanBeDormant compCanBeDormant = thing2.TryGetComp<CompCanBeDormant>();
             *  if (compCanBeDormant != null)
             *  {
             *      compCanBeDormant.ToSleep();
             *  }
             * }
             * list.AddRange(from p in list2
             *            select new TargetInfo(p));
             */
            GenSpawn.Spawn(SkyfallerMaker.MakeSkyfaller(ThingDefOf.CrashedShipPartIncoming, thing), intVec, map, WipeMode.Vanish);
            list.Add(new TargetInfo(intVec, map, false));
            base.SendStandardLetter(parms, list, Array.Empty <NamedArgument>());
            return(true);
        }
Ejemplo n.º 9
0
 private bool EverPossibleToTransmitPowerAt(IntVec3 c, Map map)
 {
     return(c.GetTransmitter(map) != null || GenConstruct.CanBuildOnTerrain(ThingDefOf.PowerConduit, c, map, Rot4.North, null));
 }
Ejemplo n.º 10
0
 public override bool CanBuildOnTerrain(IntVec3 at, Map map)
 {
     return(GenConstruct.CanBuildOnTerrain(def, at, map, rot, null, stuff ?? GenStuff.DefaultStuffFor(def)));
 }