public override Job JobOnThing(Pawn pawn, Thing t, bool forced = false)
        {
            Building_PocketDimensionBox pocketDimensionBox = t as Building_PocketDimensionBox;
            Thing components = FindBestComponents(pawn, pocketDimensionBox);

            return(JobMaker.MakeJob(PocketDimensionDefOf.CM_PocketDimension_Job_SupplyBoxComponents, t, components));
        }
        public override void Tick()
        {
            base.Tick();

            if (this.GetLost)
            {
                return;
            }

            if (this.IsHashIntervalTick(250))
            {
                Building_PocketDimensionBox box = PocketDimensionUtility.GetBox(this.dimensionSeed);
                if (box == null || !box.ExistsInWorld())
                {
                    this.GetLost = true;
                }
            }

            //Building_PocketDimensionEntranceBase box = this.otherSide;

            //if (box != null && this.IsHashIntervalTick(500))
            //{
            //    string thingString = box.GetType().ToString();
            //    if (box.ParentHolder != null)
            //    {
            //        for (IThingHolder parentHolder = box.ParentHolder; parentHolder != null; parentHolder = parentHolder.ParentHolder)
            //        {
            //            thingString = thingString + " - " + parentHolder.GetType().ToString();
            //        }
            //    }

            //    Logger.MessageFormat(this, "Box: {0}", thingString);
            //}
        }
        public override bool HasJobOnThing(Pawn pawn, Thing t, bool forced = false)
        {
            Building_PocketDimensionBox pocketDimensionBox = t as Building_PocketDimensionBox;

            if (pocketDimensionBox == null || !pocketDimensionBox.NeedsComponents)
            {
                return(false);
            }
            if (t.IsBurning())
            {
                return(false);
            }
            if (t.IsForbidden(pawn) || !pawn.CanReserve(t, 1, -1, null, forced))
            {
                return(false);
            }
            if (t.Faction != pawn.Faction)
            {
                return(false);
            }
            if (FindBestComponents(pawn, pocketDimensionBox) == null)
            {
                JobFailReason.Is("CM_PocketDimension_NoComponentsToSupply".Translate(pocketDimensionBox.TryGetComp <CompPocketDimensionCreator>().Props.componentLabel));
                return(false);
            }
            return(true);
        }
Esempio n. 4
0
        public static Building_PocketDimensionBox GetBox(string dimensionSeed)
        {
            Building_PocketDimensionBox box = null;

            if (dimensionSeed != null)
            {
                Boxes.TryGetValue(dimensionSeed, out box);
            }
            return(box);
        }
        private Thing FindBestComponents(Pawn pawn, Building_PocketDimensionBox pocketDimensionBox)
        {
            CompPocketDimensionCreator compCreator = pocketDimensionBox.GetComp <CompPocketDimensionCreator>();

            if (compCreator != null)
            {
                ThingRequest componentRequest = ThingRequest.ForDef(compCreator.Props.componentDef);

                Predicate <Thing> validator = delegate(Thing x) { return(!x.IsForbidden(pawn) && pawn.CanReserve(x)); };
                return(GenClosest.ClosestThingReachable(pawn.Position, pawn.Map, componentRequest, PathEndMode.ClosestTouch, TraverseParms.For(pawn), 9999f, validator));
            }

            return(null);
        }
Esempio n. 6
0
        public override void Tick()
        {
            base.Tick();

            if (this.shouldBeDeleted)
            {
                this.CheckRemoveMapNow();

                Building_PocketDimensionBox box = PocketDimensionUtility.GetBox(this.dimensionSeed);
                if (box != null && !box.BeingDestroyed && !box.GetLost)
                {
                    box.GetLost = true;
                }
            }
        }
Esempio n. 7
0
        public static Building_PocketDimensionEntranceBase GetOtherSide(Building_PocketDimensionEntranceBase thisSide)
        {
            Building_PocketDimensionBox  box  = GetBox(thisSide.dimensionSeed);
            Building_PocketDimensionExit exit = GetExit(thisSide.dimensionSeed);

            if (box != null && box != thisSide)
            {
                return(box);
            }
            else if (exit != null && exit != thisSide)
            {
                return(exit);
            }

            return(null);
        }
Esempio n. 8
0
        protected override void SetName(string name)
        {
            Building_PocketDimensionBox  box  = PocketDimensionUtility.GetBox(buildingSeed);
            Building_PocketDimensionExit exit = PocketDimensionUtility.GetExit(buildingSeed);

            if (box != null)
            {
                box.uniqueName = curName;
            }
            if (exit != null)
            {
                exit.uniqueName = "CM_PocketDimension_ExitName".Translate(curName);
            }

            Messages.Message("CM_RenamePocketDimensionMessage".Translate(curName), MessageTypeDefOf.TaskCompletion);
        }
Esempio n. 9
0
        public void Abandon(bool lost)
        {
            if (!this.shouldBeDeleted)
            {
                TaggedString label = "CM_PocketDimensionDestroyedLetterLabel".Translate();
                TaggedString text  = "CM_PocketDimensionDestroyedLetterText".Translate();

                if (lost)
                {
                    label = "CM_PocketDimensionLostLetterLabel".Translate();
                    text  = "CM_PocketDimensionLostLetterText".Translate();
                }

                Building_PocketDimensionBox box = PocketDimensionUtility.GetBox(this.dimensionSeed);
                if (box != null && !box.BeingDestroyed)
                {
                    Thing thingHolder = box.SpawnedParentOrMe;
                    if (thingHolder != null)
                    {
                        LookTargets lookTarget = new LookTargets(thingHolder.Position, thingHolder.Map);
                        Find.LetterStack.ReceiveLetter(label, text, PocketDimensionDefOf.CM_PocketDimensionBreachedLetter, lookTarget);
                    }
                    else
                    {
                        Find.LetterStack.ReceiveLetter(label, text, PocketDimensionDefOf.CM_PocketDimensionBreachedLetter);
                    }
                }
                else
                {
                    Find.LetterStack.ReceiveLetter(label, text, PocketDimensionDefOf.CM_PocketDimensionBreachedLetter);
                }

                if (box != null)
                {
                    box.GetLost = true;
                }

                Building_PocketDimensionExit exit = PocketDimensionUtility.GetExit(this.dimensionSeed);
                if (exit != null)
                {
                    exit.GetLost = true;
                }
            }

            this.shouldBeDeleted = true;
        }
Esempio n. 10
0
        public static Map GetHighestContainingMap(Map map)
        {
            Map result = map;

            if (map != null)
            {
                MapParent_PocketDimension mapParent = map.info.parent as MapParent_PocketDimension;
                if (mapParent != null)
                {
                    Building_PocketDimensionBox box = PocketDimensionUtility.GetBox(mapParent.dimensionSeed);
                    if (box == null)
                    {
                        Logger.ErrorFormat(map, "Looking for a map containing a box that does not exist!");
                    }
                    else if (box.doingRecursiveThing)
                    {
                        Logger.WarningFormat(map, "Tried to find a containing map for a pocket dimension nested in a loop!");
                    }
                    else if (box.SpawnedOrAnyParentSpawned)
                    {
                        box.doingRecursiveThing = true;
                        try
                        {
                            result = GetHighestContainingMap(box.MapHeld);
                        }
                        finally
                        {
                            box.doingRecursiveThing = false;
                        }
                    }
                    else
                    {
                        //Logger.WarningFormat(map, "Could not find map containing pocket dimension box. Is it in a caravan?");
                    }
                }
                else
                {
                    //Logger.MessageFormat(map, "Not a pocket dimension.");
                }
            }

            return(result);
        }
            public static bool Prefix(MapPawns __instance, Map ___map, ref bool __result)
            {
                // Check all pocket dimensions accessible to this map and allow their contents to block this maps removal
                List <Thing> pocketDimensionBoxes = ___map.listerThings.AllThings.Where(thing => thing as Building_PocketDimensionBox != null).ToList();

                foreach (Thing thing in pocketDimensionBoxes)
                {
                    Building_PocketDimensionBox box = thing as Building_PocketDimensionBox;
                    if (box != null)
                    {
                        Building_PocketDimensionEntranceBase boxExit = PocketDimensionUtility.GetOtherSide(box);
                        if (boxExit != null && boxExit.MapHeld != null && boxExit.MapHeld.mapPawns.AnyPawnBlockingMapRemoval)
                        {
                            __result = true;
                            return(false);
                        }
                    }
                }

                return(true);
            }
Esempio n. 12
0
            public static void addContentValue(Thing thing, StatDef stat, ref float __result)
            {
                // We'll just get an error if not in the play state
                if (Current.ProgramState != ProgramState.Playing)
                {
                    return;
                }

                if (stat.defName != "MarketValue" && stat.defName != "MarketValueIgnoreHp")
                {
                    return;
                }

                // Don't check for a minified thing! Minified objects will end up calling this function again
                Building_PocketDimensionBox innerBox = thing as Building_PocketDimensionBox;

                if (innerBox != null)
                {
                    __result += innerBox.CalculateAdditionalMarketValue(__result);
                }
            }
        public override void Generate(Map map, GenStepParams parms)
        {
            MapParent_PocketDimension mapParent = map.Parent as MapParent_PocketDimension;
            List <IntVec3>            list      = new List <IntVec3>();
            TerrainGrid terrainGrid             = map.terrainGrid;
            RoofGrid    roofGrid = map.roofGrid;

            string   terrainDefName = "CM_PocketDimensionFloor";
            ThingDef boxStuffDef    = null;

            // Build terrain defname
            Building_PocketDimensionBox box = PocketDimensionUtility.GetBox(mapParent.dimensionSeed);

            if (box != null && box.Stuff != null)
            {
                boxStuffDef = box.Stuff;
                if (boxStuffDef.stuffProps.categories.Contains(StuffCategoryDefOf.Metallic))
                {
                    terrainDefName += "Metal";
                }
                else if (boxStuffDef.stuffProps.categories.Contains(StuffCategoryDefOf.Stony))
                {
                    terrainDefName += "Stone";
                }
                else if (boxStuffDef.stuffProps.categories.Contains(StuffCategoryDefOf.Woody))
                {
                    terrainDefName += "Wood";
                }

                terrainDefName += "_" + boxStuffDef.defName;
            }

            // If that terrain was not found, use default metal terrain
            TerrainDef terrainDef = DefDatabase <TerrainDef> .GetNamedSilentFail(terrainDefName);

            if (terrainDef == null)
            {
                terrainDef = PocketDimensionDefOf.CM_PocketDimensionFloorMetal;
            }

            foreach (IntVec3 current in map.AllCells)
            {
                terrainGrid.SetTerrain(current, terrainDef);

                if (current.OnEdge(map))
                {
                    Thing wall = ThingMaker.MakeThing(PocketDimensionDefOf.CM_PocketDimensionWall, boxStuffDef);
                    wall.SetFaction(Faction.OfPlayer);
                    GenSpawn.Spawn(wall, current, map);
                }

                roofGrid.SetRoof(current, PocketDimensionDefOf.CM_PocketDimensionRoof);
            }
            MapGenFloatGrid elevation = MapGenerator.Elevation;

            foreach (IntVec3 allCell in map.AllCells)
            {
                elevation[allCell] = 0.0f;
            }
            MapGenFloatGrid fertility = MapGenerator.Fertility;

            foreach (IntVec3 allCell2 in map.AllCells)
            {
                fertility[allCell2] = 0.0f;
            }
        }