public override AcceptanceReport CanDesignateCell(IntVec3 c)
        {
            if (!c.InBounds(base.Map))
            {
                return(false);
            }
            if (!(this.MiniToInstallOrBuildingToReinstall is MinifiedThing) && c.GetThingList(base.Map).Find((Thing x) => x.Position == c && x.Rotation == this.placingRot && x.def == this.PlacingDef) != null)
            {
                return(new AcceptanceReport("IdenticalThingExists".Translate()));
            }
            BuildableDef placingDef = this.PlacingDef;
            IntVec3      c2         = c;
            Rot4         placingRot = this.placingRot;
            Map          map        = base.Map;
            Thing        miniToInstallOrBuildingToReinstall = this.MiniToInstallOrBuildingToReinstall;

            return(GenConstruct.CanPlaceBlueprintAt(placingDef, c2, placingRot, map, false, miniToInstallOrBuildingToReinstall));
        }
        public static bool IsGoodStoreCell(IntVec3 c, Map map, Thing t, Pawn carrier, Faction faction)
        {
            bool result;

            if (carrier != null && c.IsForbidden(carrier))
            {
                result = false;
            }
            else if (!StoreUtility.NoStorageBlockersIn(c, map, t))
            {
                result = false;
            }
            else
            {
                if (carrier != null)
                {
                    if (!carrier.CanReserveNew(c))
                    {
                        return(false);
                    }
                }
                else if (faction != null && map.reservationManager.IsReservedByAnyoneOf(c, faction))
                {
                    return(false);
                }
                if (c.ContainsStaticFire(map))
                {
                    result = false;
                }
                else
                {
                    List <Thing> thingList = c.GetThingList(map);
                    for (int i = 0; i < thingList.Count; i++)
                    {
                        if (thingList[i] is IConstructible && GenConstruct.BlocksConstruction(thingList[i], t))
                        {
                            return(false);
                        }
                    }
                    result = (carrier == null || carrier.Map.reachability.CanReach((!t.SpawnedOrAnyParentSpawned) ? carrier.PositionHeld : t.PositionHeld, c, PathEndMode.ClosestTouch, TraverseParms.For(carrier, Danger.Deadly, TraverseMode.ByPawn, false)));
                }
            }
            return(result);
        }
Example #3
0
        public override void DesignateSingleCell(IntVec3 c)
        {
            if (TutorSystem.TutorialMode && !TutorSystem.AllowAction(new EventPack(base.TutorTagDesignate, c)))
            {
                return;
            }
            if (DebugSettings.godMode || entDef.GetStatValueAbstract(StatDefOf.WorkToBuild, stuffDef) == 0f)
            {
                if (entDef is TerrainDef)
                {
                    base.Map.terrainGrid.SetTerrain(c, (TerrainDef)entDef);
                }
                else
                {
                    Thing thing = ThingMaker.MakeThing((ThingDef)entDef, stuffDef);
                    thing.SetFactionDirect(Faction.OfPlayer);
                    GenSpawn.Spawn(thing, c, base.Map, placingRot);
                }
            }
            else
            {
                GenSpawn.WipeExistingThings(c, placingRot, entDef.blueprintDef, base.Map, DestroyMode.Deconstruct);
                GenConstruct.PlaceBlueprintForBuild(entDef, c, base.Map, placingRot, Faction.OfPlayer, stuffDef);
            }
            MoteMaker.ThrowMetaPuffs(GenAdj.OccupiedRect(c, placingRot, entDef.Size), base.Map);
            ThingDef thingDef = entDef as ThingDef;

            if (thingDef != null && thingDef.IsOrbitalTradeBeacon)
            {
                PlayerKnowledgeDatabase.KnowledgeDemonstrated(ConceptDefOf.BuildOrbitalTradeBeacon, KnowledgeAmount.Total);
            }
            if (TutorSystem.TutorialMode)
            {
                TutorSystem.Notify_Event(new EventPack(base.TutorTagDesignate, c));
            }
            if (entDef.PlaceWorkers != null)
            {
                for (int i = 0; i < entDef.PlaceWorkers.Count; i++)
                {
                    entDef.PlaceWorkers[i].PostPlace(base.Map, entDef, c, placingRot);
                }
            }
        }
Example #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);
 }
Example #5
0
 public Thing FirstPermanentBlockerAt(IntVec3 at, Map map)
 {
     foreach (IntVec3 item in GenAdj.OccupiedRect(at, Rot4.North, Buildable.Size))
     {
         if (!item.InBounds(map))
         {
             continue;
         }
         List <Thing> thingList = item.GetThingList(map);
         for (int i = 0; i < thingList.Count; i++)
         {
             if (!thingList[i].def.destroyable && !GenConstruct.CanPlaceBlueprintOver(Buildable, thingList[i].def))
             {
                 return(thingList[i]);
             }
         }
     }
     return(null);
 }
Example #6
0
 public override AcceptanceReport AllowsPlacing(BuildableDef checkingDef, IntVec3 loc, Rot4 rot, Map map, Thing thingToIgnore = null)
 {
     for (int i = 0; i < 4; i++)
     {
         IntVec3 c = loc + GenAdj.CardinalDirections[i];
         if (c.InBounds(map))
         {
             List <Thing> thingList = c.GetThingList(map);
             for (int j = 0; j < thingList.Count; j++)
             {
                 Thing    thing    = thingList[j];
                 ThingDef thingDef = GenConstruct.BuiltDefOf(thing.def) as ThingDef;
                 if (thingDef != null && thingDef.building != null && thingDef.building.wantsHopperAdjacent)
                 {
                     return(true);
                 }
             }
         }
     }
     return("MustPlaceNextToHopperAccepter".Translate());
 }
        public static Thing FirstBlockingThing(Thing constructible, Pawn pawnToIgnore)
        {
            Blueprint blueprint = constructible as Blueprint;
            Thing     thing     = (blueprint == null) ? null : GenConstruct.MiniToInstallOrBuildingToReinstall(blueprint);

            CellRect.CellRectIterator iterator = constructible.OccupiedRect().GetIterator();
            while (!iterator.Done())
            {
                List <Thing> thingList = iterator.Current.GetThingList(constructible.Map);
                for (int i = 0; i < thingList.Count; i++)
                {
                    Thing thing2 = thingList[i];
                    if (GenConstruct.BlocksConstruction(constructible, thing2) && thing2 != pawnToIgnore && thing2 != thing)
                    {
                        return(thing2);
                    }
                }
                iterator.MoveNext();
            }
            return(null);
        }
Example #8
0
        public override bool Spawn(IntVec3 at, Map map, Faction faction, Sketch.SpawnMode spawnMode = Sketch.SpawnMode.Normal, bool wipeIfCollides = false, List <Thing> spawnedThings = null, bool dormant = false)
        {
            if (IsSpawningBlocked(at, map, null, wipeIfCollides))
            {
                return(false);
            }
            switch (spawnMode)
            {
            case Sketch.SpawnMode.Blueprint:
                GenConstruct.PlaceBlueprintForBuild(GetDefFromStuff(), at, map, Rot4.North, faction, null);
                break;

            case Sketch.SpawnMode.Normal:
                map.terrainGrid.SetTerrain(at, GetDefFromStuff());
                break;

            default:
                throw new NotImplementedException(string.Concat("Spawn mode ", spawnMode, " not implemented!"));
            }
            return(true);
        }
Example #9
0
        private static IEnumerable <Blueprint_Build> PlaceArtilleryBlueprints(float points, Map map)
        {
            IEnumerable <ThingDef> artyDefs = DefDatabase <ThingDef> .AllDefs.Where((ThingDef def) => def.building != null && def.building.buildingTags.Contains("Artillery_BaseDestroyer"));

            int numArtillery = Mathf.RoundToInt(points / 60f);

            numArtillery = Mathf.Clamp(numArtillery, 1, 2);
            for (int i = 0; i < numArtillery; i++)
            {
                Rot4     random   = Rot4.Random;
                ThingDef thingDef = artyDefs.RandomElement();
                IntVec3  intVec   = FindArtySpot(thingDef, random, map);
                if (!intVec.IsValid)
                {
                    break;
                }
                yield return(GenConstruct.PlaceBlueprintForBuild(thingDef, intVec, map, random, faction, ThingDefOf.Steel));

                points -= 60f;
            }
        }
Example #10
0
        public override Job JobOnThing(Pawn pawn, Thing t, bool forced = false)
        {
            if (t.Faction != pawn.Faction)
            {
                return(null);
            }
            Blueprint blueprint = t as Blueprint;

            if (blueprint == null)
            {
                return(null);
            }
            if (GenConstruct.FirstBlockingThing(blueprint, pawn) != null)
            {
                return(GenConstruct.HandleBlockingThingJob(blueprint, pawn, forced));
            }
            if (!GenConstruct.CanConstruct(blueprint, pawn, forced))
            {
                return(null);
            }
            Job job = base.RemoveExistingFloorJob(pawn, blueprint);

            if (job != null)
            {
                return(job);
            }
            Job job2 = base.ResourceDeliverJobFor(pawn, blueprint, true);

            if (job2 != null)
            {
                return(job2);
            }
            Job job3 = this.NoCostFrameMakeJobFor(pawn, blueprint);

            if (job3 != null)
            {
                return(job3);
            }
            return(null);
        }
        public static Job HandleBlockingThingJob(Thing constructible, Pawn worker, bool forced = false)
        {
            Thing thing = GenConstruct.FirstBlockingThing(constructible, worker);

            if (thing == null)
            {
                return(null);
            }
            if (thing.def.category == ThingCategory.Plant)
            {
                LocalTargetInfo target    = thing;
                PathEndMode     peMode    = PathEndMode.ClosestTouch;
                Danger          maxDanger = worker.NormalMaxDanger();
                if (worker.CanReserveAndReach(target, peMode, maxDanger, 1, -1, null, forced))
                {
                    return(new Job(JobDefOf.CutPlant, thing));
                }
            }
            else if (thing.def.category == ThingCategory.Item)
            {
                if (thing.def.EverHaulable)
                {
                    return(HaulAIUtility.HaulAsideJobFor(worker, thing));
                }
                Log.ErrorOnce("Never haulable " + thing + " blocking " + constructible.ToStringSafe() + " at " + constructible.Position, 6429262);
            }
            else if (thing.def.category == ThingCategory.Building)
            {
                LocalTargetInfo target    = thing;
                PathEndMode     peMode    = PathEndMode.Touch;
                Danger          maxDanger = worker.NormalMaxDanger();
                if (worker.CanReserveAndReach(target, peMode, maxDanger, 1, -1, null, forced))
                {
                    Job job = new Job(JobDefOf.Deconstruct, thing);
                    job.ignoreDesignations = true;
                    return(job);
                }
            }
            return(null);
        }
		public override Job JobOnThing(Pawn pawn, Thing t, bool forced = false)
		{
			if (t.Faction != pawn.Faction)
			{
				return null;
			}
			Frame frame = t as Frame;
			if (frame == null)
			{
				return null;
			}
			if (GenConstruct.FirstBlockingThing(frame, pawn) != null)
			{
				return GenConstruct.HandleBlockingThingJob(frame, pawn, forced);
			}
			bool checkConstructionSkill = def.workType == WorkTypeDefOf.Construction;
			if (!GenConstruct.CanConstruct(frame, pawn, checkConstructionSkill, forced))
			{
				return null;
			}
			return ResourceDeliverJobFor(pawn, frame);
		}
Example #13
0
        public override Job JobOnThing(Pawn pawn, Thing t, bool forced = false)
        {
            if (t.Faction != pawn.Faction)
            {
                return(null);
            }
            Frame frame = t as Frame;

            if (frame == null)
            {
                return(null);
            }
            if (GenConstruct.FirstBlockingThing(frame, pawn) != null)
            {
                return(GenConstruct.HandleBlockingThingJob(frame, pawn, forced));
            }
            if (!GenConstruct.CanConstruct(frame, pawn, forced))
            {
                return(null);
            }
            return(base.ResourceDeliverJobFor(pawn, frame, true));
        }
Example #14
0
        private static IEnumerable <Blueprint_Build> PlaceArtilleryBlueprints(float points, Map map)
        {
            IEnumerable <ThingDef> artyDefs = from def in DefDatabase <ThingDef> .AllDefs
                                              where def.building != null && def.building.buildingTags.Contains("Artillery_BaseDestroyer")
                                              select def;
            int numArtillery = Mathf.RoundToInt(points / 60f);

            numArtillery = Mathf.Clamp(numArtillery, 1, 2);
            for (int i = 0; i < numArtillery; i++)
            {
                Rot4     rot      = Rot4.Random;
                ThingDef artyDef  = artyDefs.RandomElement <ThingDef>();
                IntVec3  artySpot = SiegeBlueprintPlacer.FindArtySpot(artyDef, rot, map);
                if (!artySpot.IsValid)
                {
                    break;
                }
                yield return(GenConstruct.PlaceBlueprintForBuild(artyDef, artySpot, map, rot, SiegeBlueprintPlacer.faction, ThingDefOf.Steel));

                points -= 60f;
            }
        }
        public override Job JobOnThing(Pawn pawn, Thing t, bool forced = false)
        {
            Job result;

            if (t.Faction != pawn.Faction)
            {
                result = null;
            }
            else
            {
                Frame frame = t as Frame;
                if (frame == null)
                {
                    result = null;
                }
                else if (frame.MaterialsNeeded().Count > 0)
                {
                    result = null;
                }
                else if (GenConstruct.FirstBlockingThing(frame, pawn) != null)
                {
                    result = GenConstruct.HandleBlockingThingJob(frame, pawn, forced);
                }
                else
                {
                    Frame t2 = frame;
                    if (!GenConstruct.CanConstruct(t2, pawn, true, forced))
                    {
                        result = null;
                    }
                    else
                    {
                        result = new Job(JobDefOf.FinishFrame, frame);
                    }
                }
            }
            return(result);
        }
Example #16
0
        private static IEnumerable <Blueprint_Build> PlaceArtilleryBlueprints(float points, Map map)
        {
            IEnumerable <ThingDef> artyDefs = from def in DefDatabase <ThingDef> .AllDefs
                                              where def.building != null && def.building.buildingTags.Contains("Artillery_BaseDestroyer")
                                              select def;
            int numArtillery2 = Mathf.RoundToInt((float)(points / 60.0));

            numArtillery2 = Mathf.Clamp(numArtillery2, 1, 2);
            int i = 0;

            if (i < numArtillery2)
            {
                Rot4     rot      = Rot4.Random;
                ThingDef artyDef  = artyDefs.RandomElement();
                IntVec3  artySpot = SiegeBlueprintPlacer.FindArtySpot(artyDef, rot, map);
                if (artySpot.IsValid)
                {
                    yield return(GenConstruct.PlaceBlueprintForBuild(artyDef, artySpot, map, rot, SiegeBlueprintPlacer.faction, ThingDefOf.Steel));

                    /*Error: Unable to find new state assignment for yield return*/;
                }
            }
        }
Example #17
0
 private bool IsNewValidNearbyNeeder(Thing t, HashSet <Thing> nearbyNeeders, IConstructible constructible, Pawn pawn)
 {
     return(t is IConstructible && t != constructible && !(t is Blueprint_Install) && t.Faction == pawn.Faction && !t.IsForbidden(pawn) && !nearbyNeeders.Contains(t) && GenConstruct.CanConstruct(t, pawn, false, false));
 }
        public static Job HandleBlockingThingJob(Thing constructible, Pawn worker, bool forced = false)
        {
            Thing thing = GenConstruct.FirstBlockingThing(constructible, worker);

            if (thing == null)
            {
                return(null);
            }
            if (thing.def.category == ThingCategory.Plant)
            {
                LocalTargetInfo target    = thing;
                PathEndMode     peMode    = PathEndMode.ClosestTouch;
                Danger          maxDanger = worker.NormalMaxDanger();
                if (worker.CanReserveAndReach(target, peMode, maxDanger, 1, -1, null, forced))
                {
                    return(new Job(JobDefOf.CutPlant, thing));
                }
            }
            else if (thing.def.category == ThingCategory.Item)
            {
                if (thing.def.EverHaulable)
                {
                    return(HaulAIUtility.HaulAsideJobFor(worker, thing));
                }
                Log.ErrorOnce(string.Concat(new object[]
                {
                    "Never haulable ",
                    thing,
                    " blocking ",
                    constructible.ToStringSafe <Thing>(),
                    " at ",
                    constructible.Position
                }), 6429262, false);
            }
            else if (thing.def.category == ThingCategory.Building)
            {
                if (((Building)thing).DeconstructibleBy(worker.Faction))
                {
                    if (worker.story != null && worker.story.WorkTypeIsDisabled(WorkTypeDefOf.Construction))
                    {
                        JobFailReason.Is(GenConstruct.IncapableOfDeconstruction, null);
                        return(null);
                    }
                    LocalTargetInfo target    = thing;
                    PathEndMode     peMode    = PathEndMode.Touch;
                    Danger          maxDanger = worker.NormalMaxDanger();
                    if (worker.CanReserveAndReach(target, peMode, maxDanger, 1, -1, null, forced))
                    {
                        return(new Job(JobDefOf.Deconstruct, thing)
                        {
                            ignoreDesignations = true
                        });
                    }
                }
                if (thing.def.mineable)
                {
                    if (worker.story != null && worker.story.WorkTypeIsDisabled(WorkTypeDefOf.Mining))
                    {
                        JobFailReason.Is(GenConstruct.IncapableOfMining, null);
                        return(null);
                    }
                    LocalTargetInfo target    = thing;
                    PathEndMode     peMode    = PathEndMode.Touch;
                    Danger          maxDanger = worker.NormalMaxDanger();
                    if (worker.CanReserveAndReach(target, peMode, maxDanger, 1, -1, null, forced))
                    {
                        return(new Job(JobDefOf.Mine, thing)
                        {
                            ignoreDesignations = true
                        });
                    }
                }
            }
            return(null);
        }
        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);
        }
 private bool IsNewValidNearbyNeeder(Thing t, HashSet <Thing> nearbyNeeders, IConstructible constructible, Pawn pawn)
 {
     if (!(t is IConstructible) || t == constructible || t is Blueprint_Install || t.Faction != pawn.Faction || t.IsForbidden(pawn) || nearbyNeeders.Contains(t) || !GenConstruct.CanConstruct(t, pawn, checkConstructionSkill: false))
     {
         return(false);
     }
     return(true);
 }
Example #21
0
 public override bool CanBuildOnTerrain(IntVec3 at, Map map)
 {
     return(GenConstruct.CanBuildOnTerrain(def, at, map, Rot4.North));
 }
Example #22
0
 private static bool CanPlaceBlueprintAt(IntVec3 root, Rot4 rot, ThingDef buildingDef, Map map)
 {
     return(GenConstruct.CanPlaceBlueprintAt(buildingDef, root, rot, map, false, null).Accepted);
 }
 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);
     }
 }
Example #24
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);
        }
        public override Job JobOnThing(Pawn pawn, Thing t, bool forced = false)
        {
            Job result;

            if (t.Faction != pawn.Faction)
            {
                result = null;
            }
            else
            {
                Blueprint blueprint = t as Blueprint;
                if (blueprint == null)
                {
                    result = null;
                }
                else if (GenConstruct.FirstBlockingThing(blueprint, pawn) != null)
                {
                    result = GenConstruct.HandleBlockingThingJob(blueprint, pawn, forced);
                }
                else
                {
                    bool flag = this.def.workType == WorkTypeDefOf.Construction;
                    if (!GenConstruct.CanConstruct(blueprint, pawn, flag, forced))
                    {
                        result = null;
                    }
                    else if (!flag && WorkGiver_ConstructDeliverResources.ShouldRemoveExistingFloorFirst(pawn, blueprint))
                    {
                        result = null;
                    }
                    else
                    {
                        Job job = base.RemoveExistingFloorJob(pawn, blueprint);
                        if (job != null)
                        {
                            result = job;
                        }
                        else
                        {
                            Job job2 = base.ResourceDeliverJobFor(pawn, blueprint, true);
                            if (job2 != null)
                            {
                                result = job2;
                            }
                            else
                            {
                                Job job3 = this.NoCostFrameMakeJobFor(pawn, blueprint);
                                if (job3 != null)
                                {
                                    result = job3;
                                }
                                else
                                {
                                    result = null;
                                }
                            }
                        }
                    }
                }
            }
            return(result);
        }
Example #26
0
 public override AcceptanceReport CanDesignateCell(IntVec3 c)
 {
     return(GenConstruct.CanPlaceBlueprintAt(entDef, c, placingRot, base.Map, DebugSettings.godMode, null, null, stuffDef));
 }
        public static bool CanPlaceBlueprintOver(BuildableDef newDef, ThingDef oldDef)
        {
            bool result;

            if (oldDef.EverHaulable)
            {
                result = true;
            }
            else
            {
                TerrainDef terrainDef = newDef as TerrainDef;
                if (terrainDef != null)
                {
                    if (oldDef.category == ThingCategory.Building && !terrainDef.affordances.Contains(oldDef.terrainAffordanceNeeded))
                    {
                        return(false);
                    }
                    if ((oldDef.IsBlueprint || oldDef.IsFrame) && !terrainDef.affordances.Contains(oldDef.entityDefToBuild.terrainAffordanceNeeded))
                    {
                        return(false);
                    }
                }
                ThingDef     thingDef     = newDef as ThingDef;
                BuildableDef buildableDef = GenConstruct.BuiltDefOf(oldDef);
                ThingDef     thingDef2    = buildableDef as ThingDef;
                if (oldDef == ThingDefOf.SteamGeyser && !newDef.ForceAllowPlaceOver(oldDef))
                {
                    result = false;
                }
                else if (oldDef.category == ThingCategory.Plant && oldDef.passability == Traversability.Impassable && thingDef != null && thingDef.category == ThingCategory.Building && !thingDef.building.canPlaceOverImpassablePlant)
                {
                    result = false;
                }
                else if (oldDef.category == ThingCategory.Building || oldDef.IsBlueprint || oldDef.IsFrame)
                {
                    if (thingDef != null)
                    {
                        if (!thingDef.IsEdifice())
                        {
                            return((oldDef.building == null || oldDef.building.canBuildNonEdificesUnder) && (!thingDef.EverTransmitsPower || !oldDef.EverTransmitsPower));
                        }
                        if (thingDef.IsEdifice() && oldDef != null && oldDef.category == ThingCategory.Building && !oldDef.IsEdifice())
                        {
                            return(thingDef.building == null || thingDef.building.canBuildNonEdificesUnder);
                        }
                        if (thingDef2 != null && thingDef2 == ThingDefOf.Wall && thingDef.building != null && thingDef.building.canPlaceOverWall)
                        {
                            return(true);
                        }
                        if (newDef != ThingDefOf.PowerConduit && buildableDef == ThingDefOf.PowerConduit)
                        {
                            return(true);
                        }
                    }
                    result = ((newDef is TerrainDef && buildableDef is ThingDef && ((ThingDef)buildableDef).CoexistsWithFloors) || (buildableDef is TerrainDef && !(newDef is TerrainDef)));
                }
                else
                {
                    result = true;
                }
            }
            return(result);
        }
Example #28
0
 public override bool CanBuildOnTerrain(IntVec3 at, Map map)
 {
     return(GenConstruct.CanBuildOnTerrain(def, at, map, rot, null, stuff ?? GenStuff.DefaultStuffFor(def)));
 }
Example #29
0
 private bool EverPossibleToTransmitPowerAt(IntVec3 c, Map map)
 {
     return(c.GetTransmitter(map) != null || GenConstruct.CanBuildOnTerrain(ThingDefOf.PowerConduit, c, map, Rot4.North, null));
 }