private void TransferHopperItems(Building_PocketDimensionEntranceBase otherSide)
 {
     for (int i = 0; i < AdjCellsCardinalInBounds.Count; i++)
     {
         Building_Storage hopper    = null;
         List <Thing>     thingList = AdjCellsCardinalInBounds[i].GetThingList(base.Map);
         for (int j = 0; j < thingList.Count; j++)
         {
             Thing thing = thingList[j];
             if ((thing.def == ThingDefOf.Hopper || thing.def == PocketDimensionDefOf.CM_PocketDimensionHopper) && thing as MinifiedThing == null)
             {
                 hopper = thing as Building_Storage;
                 SlotGroup slotGroup = hopper.GetSlotGroup();
                 if (slotGroup != null && slotGroup.HeldThings != null)
                 {
                     foreach (Thing thing2 in slotGroup.HeldThings)
                     {
                         if (hopper.Accepts(thing2))
                         {
                             thing2.DeSpawn(DestroyMode.Vanish);
                             GenSpawn.Spawn(thing2, otherSide.InteractionCell, otherSide.Map, WipeMode.Vanish);
                         }
                     }
                 }
                 break;
             }
         }
     }
 }
        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);
            }
        }
        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);
                            }
                        }
                    }
                }
            });
Ejemplo n.º 4
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);
        }
        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",
                });
            }
        }
        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);
        }
        private void TransferTransporterItems(Building_PocketDimensionEntranceBase otherSide)
        {
            CompTransporter transporter = this.GetComp <CompTransporter>();

            if (transporter != null)
            {
                Thing first = transporter.innerContainer.FirstOrFallback();

                if (first != null)
                {
                    GenSpawn.Spawn(first, otherSide.InteractionCell, otherSide.Map, WipeMode.Vanish);
                }
                else if (transporter.LoadingInProgressOrReadyToLaunch && !transporter.AnyInGroupHasAnythingLeftToLoad)
                {
                    transporter.CancelLoad();
                }
            }
        }
        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);
            }
        }
Ejemplo n.º 10
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);
                            }
                        }
                    }
                }
            });
            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);
            //}
        }
Ejemplo n.º 15
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;
        }
Ejemplo n.º 16
0
 public Dialog_RenamePocketDimensionEntranceBase(Building_PocketDimensionEntranceBase building)
 {
     this.buildingSeed = building.dimensionSeed;
     curName           = building.uniqueName ?? building.LabelNoCount;
 }