Beispiel #1
0
    public HandleVector <int> .Handle Allocate(ConduitType conduit_type, int conduit_idx, HandleVector <int> .Handle conduit_structure_temperature_handle, ref ConduitFlow.ConduitContents contents)
    {
        StructureTemperaturePayload payload = GameComps.StructureTemperatures.GetPayload(conduit_structure_temperature_handle);
        Element     element = payload.primaryElement.Element;
        BuildingDef def     = payload.building.Def;
        float       conduit_heat_capacity        = def.MassForTemperatureModification * element.specificHeatCapacity;
        float       conduit_thermal_conductivity = element.thermalConductivity * def.ThermalConductivity;
        int         num = ConduitTemperatureManager_Add(contents.temperature, contents.mass, (int)contents.element, payload.simHandleCopy, conduit_heat_capacity, conduit_thermal_conductivity, def.ThermalConductivity < 1f);

        HandleVector <int> .Handle result = default(HandleVector <int> .Handle);
        result.index = num;
        int handleIndex = Sim.GetHandleIndex(num);

        if (handleIndex + 1 > temperatures.Length)
        {
            Array.Resize(ref temperatures, (handleIndex + 1) * 2);
            Array.Resize(ref conduitInfo, (handleIndex + 1) * 2);
        }
        temperatures[handleIndex] = contents.temperature;
        conduitInfo[handleIndex]  = new ConduitInfo
        {
            type = conduit_type,
            idx  = conduit_idx
        };
        return(result);
    }
	public override void DoPostConfigureComplete(GameObject go)
	{
		go.GetComponent<KPrefabID>().prefabSpawnFn += delegate(GameObject game_object)
		{
			HandleVector<int>.Handle handle = GameComps.StructureTemperatures.GetHandle(game_object);
			StructureTemperaturePayload new_data = GameComps.StructureTemperatures.GetPayload(handle);
			int cell = Grid.PosToCell(game_object);
			new_data.OverrideExtents(new Extents(cell, overrideOffsets));
			GameComps.StructureTemperatures.SetPayload(handle, ref new_data);
		};
	}
Beispiel #3
0
 public override void DoPostConfigureComplete(GameObject go)
 {
     BuildingTemplates.DoPostConfigure(go);
     go.GetComponent <KPrefabID>().prefabSpawnFn += (KPrefabID.PrefabFn)(game_object =>
     {
         HandleVector <int> .Handle handle   = GameComps.StructureTemperatures.GetHandle(game_object);
         StructureTemperaturePayload payload = GameComps.StructureTemperatures.GetPayload(handle);
         int cell = Grid.PosToCell(game_object);
         payload.OverrideExtents(new Extents(cell, RadiumFuelConfig.overrideOffsets));
         GameComps.StructureTemperatures.SetPayload(handle, ref payload);
     });
 }
 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);
                 }
             }
         }
     }
 }
Beispiel #5
0
        /// <summary>
        /// Updates the sim with changes to a building's attributes.
        /// </summary>
        /// <param name="payload">The building to modify.</param>
        private static void UpdateSimState(ref StructureTemperaturePayload payload)
        {
            var   def  = payload.building.Def;
            float mass = def.MassForTemperatureModification;
            float overheatTemperature = (payload.overheatable != null) ? payload.overheatable.
                                        OverheatTemperature : Sim.MaxTemperature;

            if (!payload.enabled || payload.bypass)
            {
                mass = 0.0f;
            }
            SimMessages.ModifyBuildingHeatExchange(payload.simHandleCopy, payload.GetExtents(),
                                                   mass, payload.primaryElement.InternalTemperature, def.ThermalConductivity,
                                                   overheatTemperature, payload.OperatingKilowatts, payload.primaryElement.
                                                   Element.idx);
        }
Beispiel #6
0
        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);
        }
Beispiel #7
0
        protected override void OnSpawn()
        {
            base.OnSpawn();

            flutterable.Listening = false;

            controller = new Controller.Instance(this);
            controller.StartSM();

            flutterable.controller = controller;

            // Change heat exchange extents
            HandleVector <int> .Handle  handle = GameComps.StructureTemperatures.GetHandle(gameObject);
            StructureTemperaturePayload data   = GameComps.StructureTemperatures.GetPayload(handle);

            data.OverrideExtents(new Extents((int)transform.position.x - 1, (int)transform.position.y, 3, 2));
            GameComps.StructureTemperatures.SetPayload(handle, ref data);

            SetDefaultCellFlags();
            UpdateState();
            RequestedState = CurrentState;
            ApplyRequestedControlState();
        }
Beispiel #8
0
        /// <summary>
        /// Updates an active building's exhaust and self-heat.
        /// </summary>
        /// <param name="payload">The building being updated.</param>
        /// <param name="dt">The time since the last update in seconds.</param>
        /// <param name="energyCategory">The status item category for heat emission.</param>
        /// <param name="operatingEnergy">The status item to display when emitting heat.</param>
        /// <returns></returns>
        private static bool UpdateActive(ref StructureTemperaturePayload payload, float dt,
                                         StatusItemCategory energyCategory, StatusItem operatingEnergy)
        {
            bool        dirty        = false;
            const float MAX_PRESSURE = StructureTemperatureComponents.MAX_PRESSURE;
            var         operational  = payload.operational;

            if (operational == null || operational.IsActive)
            {
                float exhaust = payload.ExhaustKilowatts;
                if (!payload.isActiveStatusItemSet)
                {
                    // Turn on the "active" status item
                    if (payload.primaryElement.TryGetComponent(out KSelectable selectable))
                    {
                        selectable.SetStatusItem(energyCategory, operatingEnergy,
                                                 payload.simHandleCopy);
                    }
                    payload.isActiveStatusItemSet = true;
                }
                AccumulateProducedEnergy(ref payload.energySourcesKW, payload.
                                         OperatingKilowatts, STRINGS.BUILDING.STATUSITEMS.OPERATINGENERGY.
                                         OPERATING);
                if (exhaust != 0.0f)
                {
                    var   extents = payload.GetExtents();
                    int   h = extents.height, w = extents.width;
                    float kjPerM2 = exhaust * dt / (w * h);
                    int   gw = Grid.WidthInCells, cell = extents.y * gw + extents.x;
                    // Going up one row is +grid width -building width from the last cell of
                    // the previous row
                    gw -= w;
                    for (int y = h; y > 0; y--)
                    {
                        for (int x = w; x > 0; x--)
                        {
                            float mass = Grid.Mass[cell];
                            // Avoid emitting into Vacuum
                            if (mass > 0.0f)
                            {
                                SimMessages.ModifyEnergy(cell, kjPerM2 * Mathf.Min(mass,
                                                                                   MAX_PRESSURE) / MAX_PRESSURE, payload.maxTemperature,
                                                         SimMessages.EnergySourceID.StructureTemperature);
                            }
                            cell++;
                        }
                        cell += gw;
                    }
                    AccumulateProducedEnergy(ref payload.energySourcesKW, exhaust, STRINGS.
                                             BUILDING.STATUSITEMS.OPERATINGENERGY.EXHAUSTING);
                }
                dirty = true;
            }
            else if (payload.isActiveStatusItemSet)
            {
                // Turn off the "active" status item
                if (payload.primaryElement.TryGetComponent(out KSelectable selectable))
                {
                    selectable.SetStatusItem(energyCategory, null, null);
                }
                payload.isActiveStatusItemSet = false;
                dirty = true;
            }
            return(dirty);
        }