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); } } } } });
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); }
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); } }
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 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); //} }
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; }