public void Close() { openCount = Mathf.Max(0, openCount - 1); if (openCount == 0 && DisplacesGas(doorType)) { StructureTemperatureComponents structureTemperatures = GameComps.StructureTemperatures; HandleVector <int> .Handle handle = structureTemperatures.GetHandle(base.gameObject); PrimaryElement component = GetComponent <PrimaryElement>(); if (handle.IsValid() && !structureTemperatures.IsBypassed(handle)) { float num = component.Temperature = structureTemperatures.GetPayload(handle).Temperature; } } switch (controlState) { case ControlState.Locked: controller.sm.isOpen.Set(false, controller); break; case ControlState.Auto: if (openCount == 0) { controller.sm.isOpen.Set(false, controller); Game.Instance.userMenu.Refresh(base.gameObject); } break; } }
private void OnSimDoorClosed() { if (!((Object)this == (Object)null) && DisplacesGas(doorType)) { StructureTemperatureComponents structureTemperatures = GameComps.StructureTemperatures; HandleVector <int> .Handle handle = structureTemperatures.GetHandle(base.gameObject); structureTemperatures.Bypass(handle); do_melt_check = true; } }
public void Sim200ms(float dt) { if (!((Object)this == (Object)null)) { if (doorOpenLiquidRefreshHack) { doorOpenLiquidRefreshTime -= dt; if (doorOpenLiquidRefreshTime <= 0f) { doorOpenLiquidRefreshHack = false; int[] placementCells = building.PlacementCells; foreach (int cell in placementCells) { Pathfinding.Instance.AddDirtyNavGridCell(cell); } } } if (applyLogicChange) { applyLogicChange = false; ApplyRequestedControlState(false); } if (do_melt_check) { StructureTemperatureComponents structureTemperatures = GameComps.StructureTemperatures; HandleVector <int> .Handle handle = structureTemperatures.GetHandle(base.gameObject); if (handle.IsValid()) { StructureTemperaturePayload payload = structureTemperatures.GetPayload(handle); if (!payload.enabled) { int[] placementCells2 = building.PlacementCells; int num = 0; while (true) { if (num >= placementCells2.Length) { return; } int i2 = placementCells2[num]; if (!Grid.Solid[i2]) { break; } num++; } PrimaryElement component = GetComponent <PrimaryElement>(); StructureTemperatureComponents.DoMelt(component); } } } } }
private void ForceSimUpdate() { //Update the building temperature simulation, so that the conduit as a building itself transfers no heat. //Without this, heat will transfer to/from the conduit's surroudnings from/to the conduit itself (without affecting the conduit contents) StructureTemperatureComponents mgr = GameComps.StructureTemperatures; HandleVector <int> .Handle handle = mgr.GetHandle(gameObject); //Payload contains information such as the building, temperature, and the element the building is made out of StructureTemperaturePayload payload = mgr.GetPayload(handle); //In this instance, the InternalTemperature represents what the temperature of the building was when the save was first loaded. Temperature reprsents the current temperature payload.primaryElement.InternalTemperature = this.primaryElement.Temperature; object[] parameters = { payload }; //The simulation will normally ignore that the payload had its primary element changed except when the game first runs after loading a save. //Force the simulation to update its information by invoking UpdateSimState. Harmony.AccessTools.Method(typeof(StructureTemperatureComponents), "UpdateSimState").Invoke(GameComps.StructureTemperatures, parameters); }
public float Open() { if (openCount == 0 && DisplacesGas(doorType)) { StructureTemperatureComponents structureTemperatures = GameComps.StructureTemperatures; HandleVector <int> .Handle handle = structureTemperatures.GetHandle(base.gameObject); if (handle.IsValid() && structureTemperatures.IsBypassed(handle)) { int[] placementCells = building.PlacementCells; float num = 0f; int num2 = 0; foreach (int i2 in placementCells) { if (Grid.Mass[i2] > 0f) { num2++; num += Grid.Temperature[i2]; } } if (num2 > 0) { num /= (float)placementCells.Length; PrimaryElement component = GetComponent <PrimaryElement>(); KCrashReporter.Assert(num > 0f, "Door has calculated an invalid temperature"); component.Temperature = num; } } } openCount++; float result = 1f; if ((Object)consumer != (Object)null) { result = ((!consumer.IsPowered) ? 0.5f : 1f); } switch (controlState) { case ControlState.Auto: case ControlState.Opened: controller.sm.isOpen.Set(true, controller); break; } return(result); }
/// <summary> /// Applied before Sim200ms runs. /// </summary> internal static bool Prefix(StructureTemperatureComponents __instance, float dt) { __instance.GetDataLists(out List <StructureTemperatureHeader> headers, out List <StructureTemperaturePayload> payloads); int n = headers.Count; var energyCategory = Db.Get().StatusItemCategories.OperatingEnergy; var energyStatus = __instance.operatingEnergyStatusItem; // No allocation required at all! for (int i = 0; i < n; i++) { var header = headers[i]; if (Sim.IsValidHandle(header.simHandle)) { var payload = payloads[i]; bool dirty = false; if (header.dirty) { header.dirty = false; UpdateSimState(ref payload); if (payload.pendingEnergyModifications != 0.0f) { SimMessages.ModifyBuildingEnergy(payload.simHandleCopy, payload. pendingEnergyModifications, Sim.MinTemperature, Sim. MaxTemperature); payload.pendingEnergyModifications = 0.0f; dirty = true; } headers[i] = header; } if (header.isActiveBuilding && !payload.bypass) { dirty |= UpdateActive(ref payload, dt, energyCategory, energyStatus); } if (dirty) { payloads[i] = payload; } } } return(false); }
private static void Postfix(StructureTemperatureComponents __instance) { var operatingEnergyStatusItem = Traverse.Create((object)__instance).Field("operatingEnergyStatusItem").GetValue <StatusItem>(); var handleInstanceMap = Traverse.Create((object)__instance).Field("handleInstanceMap").GetValue <Dictionary <int, HandleVector <int> .Handle> >(); if (operatingEnergyStatusItem == null || handleInstanceMap == null) { return; } operatingEnergyStatusItem.resolveStringCallback = (Func <string, object, string>)((str, ev_data) => { int index = (int)ev_data; StructureTemperatureData data = __instance.GetData(handleInstanceMap[index]); if (str != (string)BUILDING.STATUSITEMS.OPERATINGENERGY.TOOLTIP) { try { str = string.Format(str, GameUtil.GetFormattedWattage((float)(data.TotalEnergyProducedKW * 1000.0 * 0.00499999988824129))); } catch (Exception ex) { Debug.LogWarning(ex, null); Debug.LogWarning(BUILDING.STATUSITEMS.OPERATINGENERGY.TOOLTIP, null); Debug.LogWarning(str, null); } } else { string empty = string.Empty; foreach (StructureTemperatureData.EnergySource energySource in data.energySourcesKW) { empty += string.Format(BUILDING.STATUSITEMS.OPERATINGENERGY.LINEITEM, energySource.source, GameUtil.GetFormattedWattage((float)(energySource.value * 1000.0 * 0.00499999988824129))); } str = string.Format((LocString)"This building is producing {0} of energy\n\nSources:\n{1}", GameUtil.GetFormattedWattage((float)(data.TotalEnergyProducedKW * 1000.0 * 0.00499999988824129)), empty); } return(str); }); }
protected override void OnSpawn() { base.OnSpawn(); KPrefabID component = GetComponent <KPrefabID>(); if ((Object)component != (Object)null) { log = new LoggerFSS("Door", 35); } if (!allowAutoControl && controlState == ControlState.Auto) { controlState = ControlState.Locked; } StructureTemperatureComponents structureTemperatures = GameComps.StructureTemperatures; HandleVector <int> .Handle handle = structureTemperatures.GetHandle(base.gameObject); if (DisplacesGas(doorType)) { structureTemperatures.Bypass(handle); } controller = new Controller.Instance(this); controller.StartSM(); if (doorType == DoorType.Sealed && !hasBeenUnsealed) { Seal(); } UpdateDoorSpeed(operational.IsOperational); Subscribe(-592767678, OnOperationalChangedDelegate); Subscribe(824508782, OnOperationalChangedDelegate); Subscribe(-801688580, OnLogicValueChangedDelegate); requestedState = CurrentState; ApplyRequestedControlState(true); int num = (rotatable.GetOrientation() == Orientation.Neutral) ? (building.Def.WidthInCells * (building.Def.HeightInCells - 1)) : 0; int num2 = (rotatable.GetOrientation() != 0) ? building.Def.HeightInCells : building.Def.WidthInCells; for (int i = 0; i != num2; i++) { int num3 = building.PlacementCells[num + i]; Grid.FakeFloor[num3] = true; Pathfinding.Instance.AddDirtyNavGridCell(num3); } List <int> list = new List <int>(); int[] placementCells = building.PlacementCells; foreach (int num4 in placementCells) { Grid.HasDoor[num4] = true; Grid.HasAccessDoor[num4] = ((Object)GetComponent <AccessControl>() != (Object)null); if (rotatable.IsRotated) { list.Add(Grid.CellAbove(num4)); list.Add(Grid.CellBelow(num4)); } else { list.Add(Grid.CellLeft(num4)); list.Add(Grid.CellRight(num4)); } SimMessages.SetCellProperties(num4, 8); if (DisplacesGas(doorType)) { Grid.RenderedByWorld[num4] = false; } } }