//public static bool CanPlaceBlueprintOver(BuildableDef newDef, ThingDef oldDef)
        public static void Postfix(BuildableDef newDef, ThingDef oldDef, ref bool __result)
        {
            if (__result)
            {
                return;
            }

            BuildableDef oldBuildDef = GenConstruct.BuiltDefOf(oldDef);

            if (oldDef.category == ThingCategory.Building || oldDef.IsBlueprint || oldDef.IsFrame)
            {
                //Power conduit sharing is hardcoded, so cooler sharing is hardcoded too
                if ((newDef.IsOverWall() && oldBuildDef.IsWall()) || (newDef.IsWall() && oldBuildDef.IsOverWall()))
                {
                    __result = true;
                }
            }
        }
        public static Blueprint_Install BlueprintInstall(this Thing wanted, Pawn pawn, IntVec3 vec3, Room room,
                                                         Rot4 rot)
        {
            Blueprint_Install bp;

            if (wanted is MinifiedThing minifiedThing)
            {
                bp = GenConstruct.PlaceBlueprintForInstall(minifiedThing, vec3, room.Map, rot,
                                                           pawn.Faction);
            }
            else
            {
                bp = GenConstruct.PlaceBlueprintForReinstall((Building)wanted, vec3, room.Map, rot,
                                                             pawn.Faction);
            }

            return(bp);
        }
Esempio n. 3
0
        public static bool CanPlaceBlueprintAt(IntVec3 spot, ThingDef def, Rot4 rot = default(Rot4))
        {
            if (!spot.IsValid)
            {
                return(false);
            }

            // Cheaty cheaty
            bool isEdifice = def.IsEdifice();

            def.building.isEdifice = true;

            bool result = GenConstruct.CanPlaceBlueprintAt(def, spot, rot, info.map, false, null).Accepted;

            def.building.isEdifice = isEdifice;

            return(result);
        }
        private static IEnumerable <Blueprint_Build> MakeCoverLine(IntVec3 root, Map map, Rot4 growDir, int maxLength, ThingDef coverThing, ThingDef coverStuff)
        {
            var     placedSandbagLocs = (List <IntVec3>)NonPublicFields.SiegeBlueprintPlacer_placedCoverLocs.GetValue(null);
            IntVec3 cur = root;

            for (int i = 0; i < maxLength; i++)
            {
                if (!NonPublicMethods.SiegeBlueprintPlacer_CanPlaceBlueprintAt(cur, Rot4.North, coverThing, map, coverStuff))
                {
                    break;
                }
                yield return(GenConstruct.PlaceBlueprintForBuild(coverThing, cur, map, Rot4.North, (Faction)NonPublicFields.SiegeBlueprintPlacer_faction.GetValue(null), coverStuff));

                placedSandbagLocs.Add(cur);
                cur += growDir.FacingCell;
            }
            yield break;
        }
Esempio n. 5
0
        public override void Update()
        {
            //Find selected thing or thing to build
            ThingDef def = null;

            if (Find.DesignatorManager.SelectedDesignator is Designator_Place des)
            {
                def = des.PlacingDef as ThingDef;
            }
            if (def == null)
            {
                def = Find.Selector.SingleSelectedThing.GetInnerIfMinified()?.def;
            }
            if (def != null)
            {
                def = GenConstruct.BuiltDefOf(def) as ThingDef;
                foreach (CoverageType cov in types)
                {
                    if (cov.MakeActive(def))
                    {
                        SetDirty();
                        if (cov.active)
                        {
                            activeType = cov;
                        }
                        else
                        {
                            Clear();
                        }
                    }
                }

                if (dirty)                  //From MakeActive or otherwise
                {
                    activeType?.Init();
                }
            }
            else if (activeType != null)
            {
                Clear();
            }

            base.Update();
        }
        public static CompHopperUser        FindHopperUser(IntVec3 cell)
        {
            //var str = string.Format( "CompHopper.FindHopperUser( {0} )", cell.ToString() );
            if (!cell.InBounds())
            {
                //Log.Message( str );
                return(null);
            }
            List <Thing> thingList = null;

            if (Scribe.mode != LoadSaveMode.Inactive)
            {   // Find hopper user in world matching cell
                if (
                    (Find.ThingGrid == null) ||
                    (Find.ThingGrid.ThingsAt(cell).Count() == 0)
                    )
                {
                    //Log.Message( str );
                    return(null);
                }
                thingList = Find.ThingGrid.ThingsAt(cell).ToList();
            }
            else
            {   // Find hopper user in cell
                thingList = cell.GetThingList();
            }
            if (!thingList.NullOrEmpty())
            {
                var hopperUser = thingList.FirstOrDefault((thing) =>
                {
                    var thingDef = GenConstruct.BuiltDefOf(thing.def) as ThingDef;
                    return((thingDef != null) && (thingDef.IsHopperUser()));
                });
                if (hopperUser != null)
                {   // Found a hopper user
                    //str += " = " + hopperUser.ThingID;
                    //Log.Message( str );
                    return(hopperUser.TryGetComp <CompHopperUser>());
                }
            }
            // Nothing found
            //Log.Message( str );
            return(null);
        }
        //public static AcceptanceReport CanPlaceBlueprintAt(BuildableDef entDef, IntVec3 center, Rot4 rot, Map map, bool godMode = false, Thing thingToIgnore = null)
        public static void Postfix(ref AcceptanceReport __result, BuildableDef entDef, IntVec3 center, Rot4 rot, Map map, bool godMode, Thing thingToIgnore)
        {
            if (__result.Reason != "IdenticalThingExists".Translate() &&
                __result.Reason != "IdenticalBlueprintExists".Translate())
            {
                return;
            }

            if (!entDef.MadeFromStuff)
            {
                return;
            }

            ThingDef newStuff = DesignatorContext.stuffDef;

            //It would not be so easy to transpile this part
            //it doesn't simply change __result to true when a replace frame can be placed,
            //it also checks if the replace frame is already there and overrides that with false
            foreach (Thing thing in center.GetThingList(map))
            {
                if (thing.IsNewThingReplacement(out Thing oldThing))
                {
                    __result = false;
                    return;
                }
                if (thing != thingToIgnore && thing.Position == center &&
                    (thing.Rotation == rot || PlacingRotationDoesntMatter(entDef)) &&
                    GenConstruct.BuiltDefOf(thing.def) == entDef)
                {
                    ThingDef oldStuff = thing is Blueprint bp?bp.EntityToBuildStuff() : thing.Stuff;

                    if (thing is ReplaceFrame rf && oldStuff == newStuff)
                    {
                        __result = false;
                        return;
                    }
                    if (newStuff != oldStuff &&
                        GenConstruct.CanBuildOnTerrain(entDef, center, map, rot, thing, newStuff))
                    {
                        __result = true;
                    }
                }
            }
        }
 static void Postfix(BuildableDef newDef, ThingDef oldDef, ref bool __result)
 {
     if (__result == false)
     {
         ThingDef     thingDef     = newDef as ThingDef;
         BuildableDef buildableDef = GenConstruct.BuiltDefOf(oldDef);
         ThingDef     thingDef2    = buildableDef as ThingDef;
         if (oldDef.category == ThingCategory.Building || oldDef.IsBlueprint || oldDef.IsFrame)
         {
             if (thingDef != null)
             {
                 if (thingDef2 != null && WallBehaviourPatch.defNameIsGoblinWall(thingDef2.defName) && thingDef.building != null && thingDef.building.canPlaceOverWall)
                 {
                     __result = true;
                 }
             }
         }
     }
 }
        public void AttemptToPlace(ThingDef thingDef, CellRect rect, Rot4 rotation, Faction faction)
        {
            Map     map = BaseGen.globalSettings.map;
            IntVec3 loc = (from cell in rect.Cells.InRandomOrder()
                           where GenConstruct.CanPlaceBlueprintAt(thingDef, cell, rotation, map).Accepted&& GenAdj.OccupiedRect(cell, rotation, thingDef.Size).AdjacentCellsCardinal.Any((IntVec3 edgeCell) => edgeCell.InBounds(map) && edgeCell.GetThingList(map).Any((Thing thing) => thing.def == ThingDefOf.Ship_Beam))
                           select cell).FirstOrFallback(IntVec3.Invalid);

            if (loc.IsValid)
            {
                Thing thing2 = ThingMaker.MakeThing(thingDef);
                thing2.SetFaction(faction);
                CompHibernatable compHibernatable = thing2.TryGetComp <CompHibernatable>();
                if (compHibernatable != null)
                {
                    compHibernatable.State = HibernatableStateDefOf.Hibernating;
                }
                GenSpawn.Spawn(thing2, loc, BaseGen.globalSettings.map, rotation);
            }
        }
        //public static bool SpawningWipes(BuildableDef newEntDef, BuildableDef oldEntDef)
        public static void Postfix(BuildableDef newEntDef, BuildableDef oldEntDef, ref bool __result)
        {
            if (!__result)
            {
                return;
            }

            ThingDef     newDef      = newEntDef as ThingDef;
            ThingDef     oldDef      = oldEntDef as ThingDef;
            BuildableDef newBuiltDef = GenConstruct.BuiltDefOf(newDef);
            BuildableDef oldBuiltDef = GenConstruct.BuiltDefOf(oldDef);

            //Power conduit sharing is hardcoded, so cooler sharing is hardcoded too
            if ((newBuiltDef.IsOverWall() && oldBuiltDef.IsWall()) ||
                (newBuiltDef.IsWall() && oldBuiltDef.IsOverWall()))
            {
                __result = false;
            }
        }
        //private void UnfogWorker(IntVec3 c)
        public static void Postfix(FogGrid __instance, IntVec3 c, Map ___map)
        {
            Map map = ___map;

            if (c.GetThingList(map).FirstOrDefault(t => t.def.IsBlueprint) is Thing blueprint && !blueprint.IsUnderFog())
            {
                DesignatorContext.designating = true;                 // as good as designating.

                if (!GenConstruct.CanPlaceBlueprintAt(blueprint.def.entityDefToBuild, blueprint.Position, blueprint.Rotation, map, false, blueprint).Accepted)
                {
                    blueprint.Destroy();
                }
                else
                {
                    blueprint.Notify_ColorChanged();                    //does the job, haha.
                }
                DesignatorContext.designating = false;
            }
        }
Esempio n. 12
0
        static bool Prefix(BuildableDef sourceDef, ref IntVec3 center, ref Map map, ref Rot4 rotation, ref Faction faction, ref ThingDef stuff, Precept_ThingStyle styleSource, ThingStyleDef styleDef, ref Blueprint_Build __result)
        {
            if (faction?.IsPlayer != true)
            {
                return(true);
            }
            var toInstall = GetClosestCandidate(sourceDef, center, map, faction, stuff);

            if (toInstall != null)
            {
                GenConstruct.PlaceBlueprintForInstall(toInstall, center, map, rotation, faction);

                // Rimworld 1.3 uses the result to set faction style for new buildings, but the style should already be set since it's an existing building.
                // Might miss style update if the player uninstalls unclaimed buildings, we will have to see when we can test with Ideology
                __result = CreateFakeBlueprintBuild(sourceDef, faction, stuff);
                return(false);
            }
            return(true);
        }
        public static bool CanReplaceStuffFor(ThingDef stuff, Thing thing)
        {
            if (thing.Faction != Faction.OfPlayer && thing.Faction != null)
            {
                return(false);
            }


            if (thing is Blueprint bp)
            {
                if (bp.UIStuff() == stuff)
                {
                    return(false);
                }
            }
            else if (thing is Frame frame)
            {
                if (frame.UIStuff() == stuff)
                {
                    return(false);
                }
            }
            else if (thing.def.HasReplaceFrame())
            {
                if (thing.Stuff == stuff)
                {
                    return(false);
                }
            }
            else
            {
                return(false);
            }

            foreach (ThingDef def in GenStuff.AllowedStuffsFor(GenConstruct.BuiltDefOf(thing.def)))
            {
                if (def == stuff)
                {
                    return(true);
                }
            }
            return(false);
        }
 private bool CanPlaceInRange(CellRect rect, Map map)
 {
     foreach (IntVec3 c in rect.Cells)
     {
         if (c.InBounds(map))
         {
             TerrainDef terrainDef = map.terrainGrid.TerrainAt(c);
             if (terrainDef.HasTag("River"))
             {
                 return(false);
             }
             if (!GenConstruct.CanBuildOnTerrain(ThingDefOf.Wall, c, map, Rot4.North, null, ThingDefOf.Granite))
             {
                 return(false);
             }
         }
     }
     return(true);
 }
Esempio n. 15
0
        public static bool PlaceThing(this Thing wanted, Pawn pawn, IEnumerable <IntVec3> roomCells, Rot4 rot, Room room,
                                      out Job furnitureJobResult)
        {
            rot = wanted.def.rotatable ? rot: Rot4.North;
            foreach (var vec3 in roomCells.InRandomOrder())
            {
                if (!GenConstruct.CanPlaceBlueprintAt(wanted.GetInnerIfMinified().def, vec3, rot, room.Map)
                    .Accepted)
                {
#if DEBUG
                    Log.Message("Not Place-able");
#endif
                    continue;
                }

                var bp = wanted.BlueprintInstall(pawn, vec3, room, rot);

                if (bp == null)
                {
#if DEBUG
                    Log.Message("Couldn't place blueprint, oops");
#endif
                    continue;
                }

                var job = bp.InstallJob(pawn);

                if (job != null)
                {
                    {
                        furnitureJobResult = job;
                        return(true);
                    }
                }
#if DEBUG
                Log.Message("No job for bp");
#endif
            }

            furnitureJobResult = null;
            return(false);
        }
Esempio n. 16
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;
                IntVec3 c = loc + GenAdj.CardinalDirections[i];
                if (i == 0)
                {
                    c = loc;
                }
                else if (i == 1)
                {
                    c = loc;
                }
                else if (i == 2)
                {
                    c = loc;
                }
                else if (i == 3)
                {
                    c = loc + GenAdj.CardinalDirections[3];
                }
                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)
                        {
                            if (thingDef.building.wantsHopperAdjacent && thing.TryGetComp <CompBeeHouse>().GetIsBeehouse)
                            {
                                return(true);
                            }
                        }
                    }
                }
            }
            return("GU_PlaceNextToBeeHouse".Translate());
        }
Esempio n. 17
0
        public static bool CanReplaceStuffFor(ThingDef stuff, Thing thing)
        {
            if (thing.Faction != Faction.OfPlayer && thing.Faction != null)
            {
                return(false);
            }


            if (thing is Blueprint bp)
            {
                if (bp.EntityToBuildStuff() == stuff)
                {
                    return(false);
                }
            }
            else if (thing is Frame frame)
            {
                if (frame.EntityToBuildStuff() == stuff)
                {
                    return(false);
                }
            }
            else if (thing.def.HasReplaceFrame())
            {
                if (thing.Stuff == stuff)
                {
                    return(false);
                }
            }
            else
            {
                return(false);
            }

            BuildableDef builtDef = GenConstruct.BuiltDefOf(thing.def);

            if (!GenConstruct.CanBuildOnTerrain(builtDef, thing.Position, thing.Map, thing.Rotation, thing, stuff))
            {
                return(false);               //TODO: place bridges under
            }
            return(GenStuff.AllowedStuffsFor(builtDef).Contains(stuff));
        }
Esempio n. 18
0
        // RimWorld.SiegeBlueprintPlacer
        public static IntVec3 FindHideyHoleSpot(ThingDef holeDef, Rot4 rot, IntVec3 center, Map map)
        {
            if (GenConstruct.CanPlaceBlueprintAt(holeDef, center, rot, map, false, null).Accepted)
            {
                return(center);
            }
            CellRect cellRect = CellRect.CenteredOn(center, 8);

            cellRect.ClipInsideMap(map);
            IntVec3 randomCell = cellRect.RandomCell;

            if (!CellFinder.TryFindRandomCellNear(center, map, 5, (IntVec3 c) => c.Standable(map) &&
                                                  (GenConstruct.CanPlaceBlueprintAt(holeDef, c, rot, map, false, null).Accepted) &&
                                                  (map?.reachability?.CanReach(c, randomCell, PathEndMode.Touch, TraverseParms.For(TraverseMode.PassDoors, Danger.Deadly, false)) ?? false), out randomCell))
            {
                Log.Error("Found no place to build hideyhole for burning vampire.");
                randomCell = IntVec3.Invalid;
            }
            return(randomCell);
        }
Esempio n. 19
0
        // Token: 0x0600002D RID: 45 RVA: 0x000035EC File Offset: 0x000017EC
        public void PlaceProduct()
        {
            var position = Position;
            var map      = Map;
            var thing    = ThingMaker.MakeThing(ThingDef.Named(compostBinComp.Props.productOne));

            thing.stackCount = compostBinComp.Props.numProductOne;
            GenPlace.TryPlaceThing(thing, position, map, ThingPlaceMode.Near);
            var thing2 = ThingMaker.MakeThing(ThingDef.Named(compostBinComp.Props.productTwo));

            thing2.stackCount = compostBinComp.Props.numProductTwo;
            GenPlace.TryPlaceThing(thing2, position, map, ThingPlaceMode.Near);
            if (def.defName != AYCharcoalKiln)
            {
                var random = new Random();
                var Chance = random.Next(3);
                var num    = random.Next(3);
                if (Chance < 2)
                {
                    GenPlace.TryPlaceThing(ThingMaker.MakeThing(ThingDef.Named("WoodLog")), position, map,
                                           ThingPlaceMode.Near);
                }

                if (num < 1)
                {
                    GenPlace.TryPlaceThing(ThingMaker.MakeThing(ThingDef.Named("WoodLog")), position, map,
                                           ThingPlaceMode.Near);
                }
            }

            ThingDef prevStuff = null;

            if (Stuff != null)
            {
                prevStuff = Stuff;
            }

            Destroy();
            GenConstruct.PlaceBlueprintForBuild(ThingDef.Named(def.defName), position, map, Rot4.North,
                                                Faction.OfPlayer, prevStuff);
        }
        public override void DesignateSingleCell(IntVec3 cell)
        {
            List <Thing> things = cell.GetThingList(Map).FindAll(t => CanReplaceStuffFor(stuffDef, t));

            for (int i = 0; i < things.Count; i++)
            {
                Thing thing = things[i];
                thing.SetFaction(Faction.OfPlayer);
                if (DebugSettings.godMode)
                {
                    ReplaceFrame.FinalizeReplace(thing, stuffDef);
                }
                else
                {
                    Log.Message($"PlaceReplaceFrame on {thing} with {stuffDef}");
                    if (thing is Blueprint_Build blueprint)
                    {
                        blueprint.stuffToUse = stuffDef;
                    }
                    else if (thing is ReplaceFrame replaceFrame)
                    {
                        if (replaceFrame.oldStuff == stuffDef)
                        {
                            replaceFrame.Destroy(DestroyMode.Cancel);
                        }
                        else
                        {
                            replaceFrame.ChangeStuff(stuffDef);
                        }
                    }
                    else if (thing is Frame frame)
                    {
                        GenConstruct.PlaceBlueprintForBuild(frame.def.entityDefToBuild, frame.Position, frame.Map, frame.Rotation, frame.Faction, stuffDef);
                    }
                    else
                    {
                        GenReplace.PlaceReplaceFrame(thing, stuffDef);
                    }
                }
            }
        }
        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;
                if (i == 0)
                {
                    c = loc + GenAdj.CardinalDirections[0] + GenAdj.CardinalDirections[0];
                }
                else if (i == 1)
                {
                    c = loc + GenAdj.CardinalDirections[1] + GenAdj.CardinalDirections[1];
                }
                else if (i == 2)
                {
                    c = loc;
                }
                else if (i == 3)
                {
                    c = loc + GenAdj.CardinalDirections[3];
                }
                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)
                        {
                            if (thingDef.building.wantsHopperAdjacent && ((thingDef.defName == "GU_JuryRiggedFarcasterPortal") || (thingDef.defName == "GU_FarcasterPortal")))
                            {
                                return(true);
                            }
                        }
                    }
                }
            }
            return("GU_PlaceNextToFarcaster".Translate());
        }
        public override AcceptanceReport AllowsPlacing(BuildableDef checkingDef, IntVec3 loc, Rot4 rot, Map map, Thing thingToIgnore = null)
        {
            ThingDef checkThingDef            = checkingDef as ThingDef;
            CompProperties_FlammableLink prop = checkThingDef.GetCompProperties <CompProperties_FlammableLink>();

            if (prop == null)
            {
                return(true);
            }

            List <Thing> things = loc.GetThingList(map);

            for (int i = 0; i < things.Count; i++)
            {
                if (things[i].def == ThingDefOf.Wall || (things[i].def.passability == Traversability.PassThroughOnly && things[i].def.category == ThingCategory.Item))
                {
                    return(false);
                }
                CompProperties_FlammableLink prop2 = things[i].def.GetCompProperties <CompProperties_FlammableLink>();
                if (prop2 != null && prop.connectionID == prop2.connectionID)
                {
                    return(false);
                }

                BuildableDef curBuildDef = GenConstruct.BuiltDefOf(things[i].def);
                if (curBuildDef != null && curBuildDef is ThingDef)
                {
                    ThingDef curDef = (ThingDef)curBuildDef;
                    if (curDef == ThingDefOf.Wall)
                    {
                        return(false);
                    }
                    prop2 = curDef.GetCompProperties <CompProperties_FlammableLink>();
                    if (prop2 != null && prop.connectionID == prop2.connectionID)
                    {
                        return(false);
                    }
                }
            }
            return(true);
        }
 // Token: 0x060000AF RID: 175 RVA: 0x00008EF0 File Offset: 0x000070F0
 public override AcceptanceReport AllowsPlacing(BuildableDef checkingDef, IntVec3 loc, Rot4 rot, Map map, Thing thingToIgnore = null, Thing thingy = null)
 {
     for (int i = 0; i < 4; i++)
     {
         IntVec3 c = loc + PlaceWorker_MSDrugMixHopper.NewMethod(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.defName == "MSDrugMixer" && this.IsCorrectSide(thing, c, rot))
                 {
                     return(true);
                 }
             }
         }
     }
     return("MustPlaceNextToHopperAccepter".Translate());
 }
Esempio n. 24
0
        public static Toil JumpToCarryToNextContainerIfPossible(Toil carryToContainerToil, TargetIndex primaryTargetInd)
        {
            Toil toil = new Toil();

            toil.initAction = delegate
            {
                Pawn actor  = toil.actor;
                Job  curJob = actor.jobs.curJob;
                if (actor.carryTracker.CarriedThing != null && curJob.targetQueueB != null && curJob.targetQueueB.Count > 0)
                {
                    Thing             primaryTarget = curJob.GetTarget(primaryTargetInd).Thing;
                    bool              hasSpareItems = actor.carryTracker.CarriedThing.stackCount > GenConstruct.AmountNeededByOf((IConstructible)primaryTarget, actor.carryTracker.CarriedThing.def);
                    Predicate <Thing> validator     = delegate(Thing th)
                    {
                        if (!GenConstruct.CanConstruct(th, actor, false))
                        {
                            return(false);
                        }
                        if (!((IConstructible)th).MaterialsNeeded().Any((ThingCountClass need) => need.thingDef == actor.carryTracker.CarriedThing.def))
                        {
                            return(false);
                        }
                        if (th != primaryTarget && !hasSpareItems)
                        {
                            return(false);
                        }
                        return(true);
                    };
                    Thing nextTarget = GenClosest.ClosestThing_Global_Reachable(actor.Position, actor.Map, from targ in curJob.targetQueueB
                                                                                select targ.Thing, PathEndMode.Touch, TraverseParms.For(actor, Danger.Deadly, TraverseMode.ByPawn, false), 99999f, validator, null);
                    if (nextTarget != null)
                    {
                        curJob.targetQueueB.RemoveAll((LocalTargetInfo targ) => targ.Thing == nextTarget);
                        curJob.targetB = nextTarget;
                        actor.jobs.curDriver.JumpToToil(carryToContainerToil);
                    }
                }
            };
            return(toil);
        }
Esempio n. 25
0
        public void ScheduleReplacement(CompAutoReplaceable replaceableComp)
        {
            var building  = replaceableComp.parent;
            var blueprint = GenConstruct.PlaceBlueprintForBuild(building.def, replaceableComp.ParentPosition, map, replaceableComp.ParentRotation, Faction.OfPlayer, null);
            var entry     = new ReplacementEntry {
                position     = replaceableComp.ParentPosition,
                unforbidTick = Find.TickManager.TicksGame + RemoteExplosivesController.Instance.BlueprintForbidDuration * GenTicks.TicksPerRealSecond
            };
            var explosive = building as Building_RemoteExplosive;

            if (explosive != null)
            {
                entry.armed   = explosive.IsArmed;
                entry.channel = explosive.CurrentChannel;
            }
            pendingSettings.Add(entry);
            if (RemoteExplosivesController.Instance.BlueprintForbidDuration > 0)
            {
                blueprint.SetForbidden(true, false);
                pendingForbiddenBlueprints.Add(entry);
            }
        }
        public override void DesignateSingleCell(IntVec3 c)
        {
            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);
                }
            }
        }
        public override AcceptanceReport AllowsPlacing(BuildableDef checkingDef, IntVec3 loc, Rot4 rot, Map map, Thing thingToIgnore = null, Thing thing = null)
        {
            List <OreNode> Nodes        = map.GetComponent <OreMapComponent>().GetNodes;
            List <IntVec3> CellsToCheck = null;

            foreach (OreNode Node in Nodes)
            {
                if (Node.GetCells.Contains(loc) && Node.HasResource)
                {
                    CellsToCheck = Node.GetCells;
                    break;
                }
            }

            if (CellsToCheck == null)
            {
                return("There is no resource here!");
            }

            for (int i = 0; i < CellsToCheck.Count; i++)
            {
                List <Thing> ThingsOnC = CellsToCheck[i].GetThingList(map);
                for (int j = 0; j < ThingsOnC.Count; j++)
                {
                    Thing    rzecz    = ThingsOnC[j];
                    ThingDef thingDef = GenConstruct.BuiltDefOf(rzecz.def) as ThingDef;

                    if (thingDef != null && thingDef.building != null)
                    {
                        if (thingDef == ThingDef.Named("MiningPlatform") || thingDef == ThingDef.Named("Blueprint_MiningPlatform") || thingDef == ThingDef.Named("Frame_MiningPlatform"))
                        {
                            return("There is aleady mine on that node!");
                        }
                    }
                }
            }

            return(true);
        }
Esempio n. 28
0
        public static bool Prefix(BuildableDef newDef, ThingDef oldDef, ref bool __result)
        {
            ThingDef thingDef  = newDef as ThingDef;
            ThingDef thingDef1 = oldDef;

            if (thingDef == null || thingDef1 == null)
            {
                return(true);
            }
            BuildableDef buildableDef = GenConstruct.BuiltDefOf(oldDef);
            ThingDef     thingDef2    = buildableDef as ThingDef;

            if (thingDef.building != null && thingDef.building.canPlaceOverWall && thingDef2 != null)
            {
                if (thingDef2.defName.Equals("RFFConcreteWall") || thingDef2.defName.Equals("RFFReinforcedConcreteWall") || thingDef2.defName.Equals("RFFPlasticreteWall"))
                {
                    __result = true;
                    return(false);
                }
            }
            return(true);
        }
Esempio n. 29
0
        private static void ResolveDeadLock(RemoveRoofModel model)
        {
            foreach (Thing thing in model.WaitingThings.ToList())
            {
                Thing        lastFound   = thing;
                List <Thing> foundThings = new List <Thing>()
                {
                    lastFound
                };

                while (true)
                {
                    IntVec3        spawnCell = GetDeltaCell(lastFound, model.MousePos, model.GhostPosition);
                    List <IntVec3> rect      = GenAdj.OccupiedRect(spawnCell, lastFound.Rotate(model.Rotation), lastFound.def.size).ToList();
                    if (lastFound.def.hasInteractionCell)
                    {
                        rect.Add(Verse.ThingUtility.InteractionCellWhenAt(lastFound.def, spawnCell, lastFound.Rotate(model.Rotation), lastFound.MapHeld));
                    }
                    IEnumerable <Thing> thingsOnCell = rect.SelectMany(c => c.GetThingList(lastFound.MapHeld).Where(t => t.def.blueprintDef != null && t.def.Minifiable));
                    lastFound = thingsOnCell.FirstOrDefault(t => GenConstruct.BlocksConstruction(lastFound, t) && model.WaitingThings.Contains(t))
                                ?? ThingUtility.BlockAdjacentInteractionCell(lastFound, spawnCell, lastFound.Rotate(model.Rotation));
                    if (lastFound == null || foundThings.Contains(lastFound))
                    {
                        break;
                    }

                    foundThings.Add(lastFound);
                }

                if (lastFound == null)
                {
                    continue;
                }
                else
                {
                    thing.Map.designationManager.AddDesignation(new Designation(thing, DesignationDefOf.Uninstall));
                }
            }
        }
Esempio n. 30
0
        public override Job JobOnThing(Pawn pawn, Thing t, bool forced = false)
        {
            // Different factions
            if (t.Faction != pawn.Faction)
            {
                return(null);
            }

            // Not upgradable
            var upgradableComp = t.TryGetComp <CompUpgradable>();

            if (upgradableComp == null)
            {
                return(null);
            }

            // Not designated to be upgraded
            if (t.Map.designationManager.DesignationOn(t, DesignationDefOf.UpgradeTurret) == null)
            {
                return(null);
            }

            // Blocked
            if (GenConstruct.FirstBlockingThing(t, pawn) != null)
            {
                return(GenConstruct.HandleBlockingThingJob(t, pawn, forced));
            }

            // Construction skill
            var checkSkill = def.workType == WorkTypeDefOf.Construction;

            if (checkSkill && pawn.skills.GetSkill(SkillDefOf.Construction).Level < upgradableComp.Props.constructionSkillPrerequisite)
            {
                return(null);
            }

            return(ResourceDeliverJobFor(pawn, upgradableComp, false));
        }