Beispiel #1
0
            private static bool Prefix(TradeShip __instance, Thing toGive, int countToGive, Pawn playerNegotiator, List <Pawn> ___soldPrisoners)
            {
                if (__instance.Map != null)
                {
                    MapParent_PocketDimension mapParent = __instance.Map.info.parent as MapParent_PocketDimension;
                    if (mapParent != null)
                    {
                        Map containingMap = PocketDimensionUtility.GetHighestContainingMap(__instance.Map);

                        // If there was no containing map found (should mean box is in a caravan; could mean the box was nested inside itself, it which case, oh well, give them their goods anyway :P)
                        if (containingMap == __instance.Map)
                        {
                            Building_PocketDimensionExit exit = PocketDimensionUtility.GetExit(mapParent.dimensionSeed);
                            if (exit != null && exit.SpawnedOrAnyParentSpawned)
                            {
                                Thing thing = toGive.SplitOff(countToGive);
                                thing.PreTraded(TradeAction.PlayerBuys, playerNegotiator, __instance);
                                Pawn pawn = thing as Pawn;
                                if (pawn != null)
                                {
                                    ___soldPrisoners.Remove(pawn);
                                }

                                IntVec3 positionHeld = exit.PositionHeld;
                                Map     mapHeld      = exit.MapHeld;
                                GenPlace.TryPlaceThing(thing, positionHeld, mapHeld, ThingPlaceMode.Near);
                                return(false);
                            }
                        }
                    }
                }

                return(true);
            }
        public float CalculateAdditionalMarketValue(float baseValue)
        {
            if (this.doingRecursiveThing)
            {
                Logger.MessageFormat(this, "Counting box wealth again recursively. Skipping...");
                return(0.0f);
            }

            float componentValue = CalculateUsedComponentValue();
            float contentValue   = 0.0f;

            MapParent_PocketDimension innerMapParent = PocketDimensionUtility.GetMapParent(this.dimensionSeed);

            if (innerMapParent != null && innerMapParent.Map != null)
            {
                this.doingRecursiveThing = true;
                try
                {
                    contentValue = innerMapParent.Map.wealthWatcher.WealthTotal;
                }
                finally
                {
                    this.doingRecursiveThing = false;
                }
            }

            Logger.MessageFormat(this, "Adding value to box: {0}, {1} + {2} + {3} = {4}", this.Label, baseValue, contentValue, componentValue, (baseValue + contentValue + componentValue));

            return(contentValue + componentValue);
        }
        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);
            //}
        }
        private void EqualizeTemperatures()
        {
            Building_PocketDimensionExit exit = PocketDimensionUtility.GetExit(this.dimensionSeed);

            if (exit == null)
            {
                return;
            }
            // If the exits vent is not open it means we are loading an old save from before the vents were on both side and synced, so just close the vent to fix
            else if (!exit.VentOpen)
            {
                SetVentOpen(false);
                return;
            }


            RoomGroup thisRoomGroup  = this.GetRoomGroup();
            RoomGroup otherRoomGroup = exit.GetRoomGroup();

            if (thisRoomGroup == null || otherRoomGroup == null || thisRoomGroup == otherRoomGroup)
            {
                return;
            }

            float totalTemperature   = thisRoomGroup.Temperature + otherRoomGroup.Temperature;
            float averageTemperature = totalTemperature / 2.0f;

            float thisRoomChangeAmount    = this.GetTemperatureChangeAmount(thisRoomGroup, averageTemperature);
            float otherRoomChangeAmount   = this.GetTemperatureChangeAmount(otherRoomGroup, averageTemperature);
            float temperatureChangeAmount = Mathf.Min(thisRoomChangeAmount, otherRoomChangeAmount);

            EqualizeTemperatureForRoom(thisRoomGroup, averageTemperature, temperatureChangeAmount);
            EqualizeTemperatureForRoom(otherRoomGroup, averageTemperature, temperatureChangeAmount);
        }
        private void CompTickWhatever()
        {
            if (linkedBatteryShare == null)
            {
                Building_PocketDimensionEntranceBase parentEntrance = this.parent as Building_PocketDimensionEntranceBase;

                if (parentEntrance != null)
                {
                    Building_PocketDimensionEntranceBase otherSide = PocketDimensionUtility.GetOtherSide(parentEntrance);

                    if (otherSide != null)
                    {
                        linkedBatteryShare = otherSide.GetComp <CompPocketDimensionBatteryShare>();
                    }
                }
            }

            if (thisBattery != null && linkedBatteryShare != null && linkedBatteryShare.parent.Map != null)
            {
                float newEnergyOtherSide = linkedBatteryShare.GetEnergyStored(thisBattery.StoredEnergy);
                float maxEnergyOtherSide = linkedBatteryShare.GetEnergyMax();

                // Calculate actual energy percent first
                if (maxEnergyOtherSide > 0.0f)
                {
                    energyPercent = newEnergyOtherSide / maxEnergyOtherSide;
                }
                else
                {
                    energyPercent = 0.0f;
                }

                float maxEnergyTotal = maxEnergyOtherSide + Props.storedEnergyMax;


                if (newEnergyOtherSide > maxEnergyTotal)
                {
                    newEnergyOtherSide = maxEnergyTotal;
                }

                storedEnergyMax = maxEnergyTotal;

                // The props is a single instance shared across all instances of the comp. Just need to make sure it can always hold enough.
                if (thisBattery.Props.storedEnergyMax < maxEnergyTotal)
                {
                    thisBattery.Props.storedEnergyMax = maxEnergyTotal;
                }

                float showEnergyPercent = 1.0f;
                if (thisBattery.Props.storedEnergyMax > 0.0f)
                {
                    showEnergyPercent = newEnergyOtherSide / thisBattery.Props.storedEnergyMax;
                }

                thisBattery.SetStoredEnergyPct(showEnergyPercent);

                //Logger.MessageFormat(this, "Updated battery, energy: {0} ({2}), max: {1} ({3}), {4} - {5}", newEnergy, maxEnergy, thisBattery.StoredEnergy, thisBattery.Props.storedEnergyMax, thisBattery.parent.Label, linkedBatteryShare.parent.Label);
            }
        }
Beispiel #6
0
 private static void Prefix(ref Map map)
 {
     if (map != null)
     {
         //Logger.MessageFormat(map, "Checking for alternate map target.");
         Map containingMap = PocketDimensionUtility.GetHighestContainingMap(map);
         if (containingMap != null)
         {
             map = containingMap;
             Logger.MessageFormat(map, "Redirecting drop pod to: {0}", containingMap.GetUniqueLoadID());
         }
     }
 }
        protected override IEnumerable <Toil> MakeNewToils()
        {
            this.FailOnDestroyedOrNull(TargetIndex.A);
            this.FailOnDestroyedOrNull(TargetIndex.B);
            this.FailOnAggroMentalState(TargetIndex.A);

            Toil approachPrisoner = Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.ClosestTouch);

            yield return(approachPrisoner);

            Toil collectPrisoner = Toils_Haul.StartCarryThing(TargetIndex.A, false, false, false);

            yield return(collectPrisoner);

            Toil escortPrisoner = Toils_Goto.GotoThing(TargetIndex.B, PathEndMode.InteractionCell);

            //Toil escortPrisoner = Toils_Haul.CarryHauledThingToContainer(.GotoThing(TargetIndex.B, PathEndMode.InteractionCell);
            yield return(escortPrisoner);

            Toil enterPocket = Toils_General.Wait(60, 0);

            ToilEffects.WithProgressBarToilDelay(enterPocket, TargetIndex.B, false, -0.5f);
            ToilFailConditions.FailOnCannotTouch <Toil>(enterPocket, TargetIndex.B, PathEndMode.InteractionCell);
            yield return(enterPocket);

            yield return(new Toil
            {
                initAction = delegate()
                {
                    Thing thing;
                    pawn.carryTracker.TryDropCarriedThing(TargetB.Thing.Position, ThingPlaceMode.Direct, out thing);

                    if (TargetA.Thing is Pawn prisoner && TargetB.Thing is Building_PocketDimensionEntranceBase pocketDimensionEntrance)
                    {
                        Building_PocketDimensionEntranceBase otherSide = PocketDimensionUtility.GetOtherSide(pocketDimensionEntrance);

                        if (otherSide != null && otherSide.Map != null)
                        {
                            IntVec3 position = otherSide.Position;
                            Map map = otherSide.Map;

                            if (position != null && map != null)
                            {
                                prisoner.DeSpawn(DestroyMode.Vanish);
                                GenSpawn.Spawn(prisoner, position, map, WipeMode.Vanish);
                            }
                        }
                    }
                }
            });
Beispiel #8
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;
                }
            }
        }
Beispiel #9
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);
        }
        public override IEnumerable <Gizmo> GetGizmos()
        {
            foreach (Gizmo c in base.GetGizmos())
            {
                yield return(c);
            }

            // Rename
            yield return(new Command_Action
            {
                icon = ContentFinder <Texture2D> .Get("UI/Buttons/Rename", true),
                action = () => Find.WindowStack.Add(new Dialog_RenamePocketDimensionEntranceBase(this)),
                defaultLabel = "CM_RenamePocketDimensionLabel".Translate(),
                defaultDesc = "CM_RenamePocketDimensionDescription".Translate()
            });

            Building_PocketDimensionEntranceBase otherSide = PocketDimensionUtility.GetOtherSide(this);

            if (otherSide != null && !otherSide.BeingDestroyed)
            {
                // Select other side
                yield return(new Command_Action
                {
                    action = delegate
                    {
                        if (otherSide != null)
                        {
                            LookTargets otherSideTarget = new LookTargets(otherSide.SpawnedParentOrMe);
                            CameraJumper.TrySelect(otherSideTarget.TryGetPrimaryTarget());
                        }
                    },
                    defaultLabel = this is Building_PocketDimensionBox ? "CM_ViewExitLabel".Translate() : "CM_ViewEntranceLabel".Translate(),
                    defaultDesc = this is Building_PocketDimensionBox ? "CM_ViewExitDescription".Translate() : "CM_ViewEntranceDescription".Translate(),
                    icon = ContentFinder <Texture2D> .Get("UI/Commands/ViewQuest"),
                });
            }

            if (Prefs.DevMode && MapCreated)
            {
                // Fix walls not being owned by player
                yield return(new Command_Action
                {
                    action = () => PocketDimensionUtility.ClaimWalls(PocketDimensionUtility.GetMapParent(this.dimensionSeed).Map, Faction.OfPlayer),
                    defaultLabel = "DEBUG: Claim walls",
                });
            }
        }
Beispiel #11
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;
        }
        public override void Tick()
        {
            base.Tick();

            Building_PocketDimensionEntranceBase otherSide = PocketDimensionUtility.GetOtherSide(this);

            if (otherSide != null && otherSide.Map != null && this.Map != null)
            {
                TransferHopperItems(otherSide);
                TransferTransporterItems(otherSide);
            }

            if (GetLost)
            {
                this.Destroy(DestroyMode.Vanish);
            }
        }
        public override void Draw()
        {
            base.Draw();

            float redness          = 0.0f;
            float relativeCapacity = 0.0f;
            float energyPercent    = 0.0f;

            Building_PocketDimensionEntranceBase otherSide = PocketDimensionUtility.GetOtherSide(this);

            if (otherSide != null)
            {
                float myTemp    = this.PositionHeld.GetTemperature(this.MapHeld);
                float otherTemp = otherSide.PositionHeld.GetTemperature(otherSide.MapHeld);

                redness  = baseRedness;
                redness += (otherTemp - myTemp) * rednessPerDegree;
                redness  = Mathf.Clamp(redness, 0.0f, 1.0f);


                CompPocketDimensionBatteryShare myBatteryShare    = this.GetComp <CompPocketDimensionBatteryShare>();
                CompPocketDimensionBatteryShare otherBatteryShare = otherSide.GetComp <CompPocketDimensionBatteryShare>();

                if (myBatteryShare != null && otherBatteryShare != null)
                {
                    float otherEnergyCapacity = myBatteryShare.StoredEnergyMax;
                    float myEnergyCapacity    = otherBatteryShare.StoredEnergyMax;
                    if (myEnergyCapacity == 0.0f)
                    {
                        relativeCapacity = 0.0f;
                    }
                    else
                    {
                        relativeCapacity = (((otherEnergyCapacity - myEnergyCapacity) / Mathf.Min(myEnergyCapacity, otherEnergyCapacity)) * energyCapacityColorScale) + 0.5f;
                        relativeCapacity = Mathf.Clamp(relativeCapacity, 0.0f, 1.0f);

                        energyPercent = myBatteryShare.EnergyPercent;
                    }
                }
            }

            Color glowColor = new Color(redness, energyPercent, relativeCapacity);

            glowGraphic.GetColoredVersion(ShaderDatabase.Cutout, glowColor, glowColor).Draw(new Vector3(this.DrawPos.x, this.DrawPos.y + 1f, this.DrawPos.z), Rot4.North, this);
        }
        protected override void ReceiveCompSignal(string signal)
        {
            Building_PocketDimensionEntranceBase otherSide = PocketDimensionUtility.GetOtherSide(this);

            if (signal == "CM_PocketDimension_ButtonPressed_On")
            {
                ventOpen = true;
            }
            else if (signal == "CM_PocketDimension_ButtonPressed_Off")
            {
                ventOpen = false;
            }

            if (otherSide != null)
            {
                otherSide.SetVentOpen(ventOpen);
            }
        }
Beispiel #15
0
        protected override IEnumerable <Toil> MakeNewToils()
        {
            yield return(Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.InteractionCell));

            Toil enterPocket = Toils_General.Wait(60, 0);

            ToilEffects.WithProgressBarToilDelay(enterPocket, TargetIndex.A, false, -0.5f);
            ToilFailConditions.FailOnDespawnedNullOrForbidden <Toil>(enterPocket, TargetIndex.A);
            ToilFailConditions.FailOnCannotTouch <Toil>(enterPocket, TargetIndex.A, PathEndMode.InteractionCell);
            yield return(enterPocket);

            yield return(new Toil
            {
                initAction = delegate()
                {
                    Pawn pawn = GetActor();
                    if (TargetA.Thing is Building_PocketDimensionEntranceBase pocketDimensionEntrance)
                    {
                        Building_PocketDimensionEntranceBase otherSide = PocketDimensionUtility.GetOtherSide(pocketDimensionEntrance);

                        if (otherSide != null && otherSide.Map != null)
                        {
                            IntVec3 position = otherSide.Position;
                            Map map = otherSide.Map;

                            // If otherSide is uninstalled...
                            if (otherSide.Map == null && otherSide.holdingOwner != null && otherSide.holdingOwner.Owner != null && (otherSide.holdingOwner.Owner as MinifiedThing) != null)
                            {
                                MinifiedThing miniThing = (otherSide.holdingOwner.Owner as MinifiedThing);
                                position = miniThing.Position;
                                map = miniThing.Map;
                            }

                            if (position != null && map != null)
                            {
                                pawn.ClearAllReservations();
                                pawn.DeSpawn(DestroyMode.Vanish);
                                GenSpawn.Spawn(pawn, position, map, WipeMode.Vanish);
                            }
                        }
                    }
                }
            });
Beispiel #16
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 void GetOutdoorTemp(ref float __result, Map ___map)
            {
                MapParent_PocketDimension mapParent = ___map.info.parent as MapParent_PocketDimension;

                if (mapParent != null)
                {
                    Building_PocketDimensionEntranceBase box = PocketDimensionUtility.GetBox(mapParent.dimensionSeed);
                    if (box != null)
                    {
                        __result = 21.0f;

                        if (box.Spawned)
                        {
                            __result = GenTemperature.GetTemperatureForCell(box.Position, box.Map);
                        }
                        else if (box.ParentHolder != null)
                        {
                            for (IThingHolder parentHolder = box.ParentHolder; parentHolder != null; parentHolder = parentHolder.ParentHolder)
                            {
                                if (ThingOwnerUtility.TryGetFixedTemperature(parentHolder, box, out __result))
                                {
                                    return;// false;
                                }
                            }
                        }
                        else if (box.SpawnedOrAnyParentSpawned)
                        {
                            __result = GenTemperature.GetTemperatureForCell(box.PositionHeld, box.MapHeld);
                        }
                        else if (box.Tile >= 0)
                        {
                            __result = GenTemperature.GetTemperatureFromSeasonAtTile(GenTicks.TicksAbs, box.Tile);
                        }

                        // Above logic derived from the following function call. Can't call it here due to an edge case which results in infinite loop
                        //__result = box.AmbientTemperature;
                        return;// false;
                    }
                }

                //return true;
            }
            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);
            }
        public override IEnumerable <FloatMenuOption> GetFloatMenuOptions(Pawn selPawn)
        {
            bool isExit = ((this as Building_PocketDimensionBox) == null);
            Building_PocketDimensionEntranceBase otherSide = PocketDimensionUtility.GetOtherSide(this);
            bool otherSideAvailable = (otherSide != null && otherSide.Map != null);

            string goThroughMenuItemText = "";

            if (isExit)
            {
                goThroughMenuItemText = "CM_ExitPocketDimension".Translate(this.Label);
            }
            else
            {
                goThroughMenuItemText = "CM_EnterPocketDimension".Translate(this.Label);
            }



            foreach (var opt in base.GetFloatMenuOptions(selPawn))
            {
                if (opt.Label != goThroughMenuItemText)
                {
                    yield return(opt);
                }
            }

            if (otherSideAvailable)
            {
                Action goThroughAction = delegate
                {
                    Job goThroughJob = JobMaker.MakeJob(PocketDimensionDefOf.CM_EnterPocket, this);
                    selPawn.jobs.TryTakeOrderedJob(goThroughJob);
                };

                FloatMenuOption goThroughOption = new FloatMenuOption(goThroughMenuItemText, goThroughAction, MenuOptionPriority.Default, null, this);
                yield return(goThroughOption);
            }
        }
        private void CompTickWhatever()
        {
            if (linkedBattery == null)
            {
                Building_PocketDimensionEntranceBase parentEntrance = this.parent as Building_PocketDimensionEntranceBase;

                if (parentEntrance != null)
                {
                    Building_PocketDimensionEntranceBase otherSide = PocketDimensionUtility.GetOtherSide(parentEntrance);

                    if (otherSide != null)
                    {
                        linkedBattery = otherSide.GetComp <CompPowerBatteryShare>();
                    }
                }
            }

            if (linkedBattery != null && linkedBattery.parent.Map != null)
            {
                float newEnergy = linkedBattery.GetEnergyStored(this.StoredEnergy);
                float maxEnergy = linkedBattery.GetEnergyMax();

                float energyPercent = 1.0f;

                if (newEnergy != maxEnergy && maxEnergy > 0.0f)
                {
                    energyPercent = newEnergy / maxEnergy;
                }

                this.Props.storedEnergyMax = Mathf.Max(1.0f, maxEnergy); // Can't let the max energy hit 0.0 or we'll get NaN values for StoredEnergyPct which could screw us or some other mod up
                this.SetStoredEnergyPct(energyPercent);
            }
            //else
            //{
            //    this.Props.storedEnergyMax = 0.0f;
            //    this.SetStoredEnergyPct(1.0f);
            //}
        }
        public override void Destroy(DestroyMode mode = DestroyMode.Vanish)
        {
            PocketDimensionUtility.OnCriticalMapObjectDestroyed(this, GetLost);

            base.Destroy(mode);
        }
Beispiel #22
0
        private void CompTickWhatever()
        {
            if (thisBattery == null)
            {
                Logger.MessageFormat(this, "No battery found.");
            }

            if (otherSharer == null)
            {
                Building_PocketDimensionEntranceBase parentEntrance = this.parent as Building_PocketDimensionEntranceBase;

                if (parentEntrance != null)
                {
                    Building_PocketDimensionEntranceBase otherSide = PocketDimensionUtility.GetOtherSide(parentEntrance);

                    if (otherSide != null)
                    {
                        SetOtherThing(otherSide);
                    }
                }
            }

            if (thisBattery != null && otherSharer != null && otherSharer.parent.Map != null)
            {
                float newEnergy = otherSharer.GetEnergyStored(thisBattery.StoredEnergy);
                float maxEnergy = otherSharer.GetEnergyMax();

                float energyPercent = 1.0f;

                if (newEnergy != maxEnergy && maxEnergy > 0.0f)
                {
                    energyPercent = newEnergy / maxEnergy;
                }

                thisBattery.Props.storedEnergyMax = maxEnergy;
                thisBattery.SetStoredEnergyPct(energyPercent);
            }
            else if (thisBattery != null)
            {
                thisBattery.Props.storedEnergyMax = 0.0f;
                thisBattery.SetStoredEnergyPct(1.0f);
            }

            //if (otherSharer != null && otherSharer.parent.Map != null)
            //{
            //    this.PowerTransferAmount = otherSharer.GetExcessEnergy();
            //}
            //else
            //{
            //    this.PowerTransferAmount = 0.0f;
            //}


            ////this.UpdateDesiredPowerOutput();
            //// Using refuelable to add components breaks the normal UpdatedDesiredPowerOutput logic, reproduced and circumvented here
            //if ((breakdownableComp != null && breakdownableComp.BrokenDown) || /*(refuelableComp != null && !refuelableComp.HasFuel) ||*/ (flickableComp != null && !flickableComp.SwitchIsOn) || !base.PowerOn)
            //{
            //    base.PowerOutput = 0.0f;
            //}
            //else
            //{
            //    base.PowerOutput = DesiredPowerOutput;
            //}

            base.PowerOutput = 0.0f;
        }
        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;
            }
        }
        public override void SpawnSetup(Map map, bool respawningAfterLoad)
        {
            base.SpawnSetup(map, respawningAfterLoad);

            Logger.MessageFormat(this, "Spawning");

            compCreator     = this.GetComp <CompPocketDimensionCreator>();
            compTransporter = this.GetComp <CompTransporter>();

            if (mapSize == 0)
            {
                mapSize = 1;
            }

            if (fuel >= 1.0f)
            {
                if (compCreator != null)
                {
                    compCreator.AddComponents((int)Mathf.Round(fuel));
                    fuel = 0.0f;

                    if (compCreator.SupplyCount > desiredComponentCount)
                    {
                        int amountToRefund = compCreator.SupplyCount - desiredComponentCount;
                        if (compCreator.ConsumeComponents(amountToRefund))
                        {
                            ThingDef thingToRefundDef = compCreator.Props.componentDef;

                            RefundComponents(thingToRefundDef, amountToRefund);
                        }
                    }
                }
                else
                {
                    ThingDef thingToRefundDef = ThingDefOf.ComponentSpacer;

                    int amountToRefund = (int)Mathf.Round(fuel);
                    fuel = 0.0f;

                    RefundComponents(thingToRefundDef, amountToRefund);
                }
            }

            // Reconfigure runtime-set comp property values
            SetDesiredMapSize(desiredMapSize);

            if (MapCreated)
            {
                MapParent_PocketDimension dimensionMapParent = PocketDimensionUtility.GetMapParent(this.dimensionSeed);

                // Looks like we just got installed somewhere. Make sure map tile is the same as our current tile
                if (this.Map != null && dimensionMapParent != null)
                {
                    dimensionMapParent.Tile = this.Map.Parent.Tile;
                }
            }
            else
            {
                if (compCreator != null && compCreator.Props.preMadeMapSize > 0)
                {
                    SetDesiredMapSize(compCreator.Props.preMadeMapSize);
                    mapSize = desiredMapSize;
                    CreateMap(this.MapDiameter);
                }
            }
        }