Advertisement
Guest User

SimUtil.cs

a guest
Apr 16th, 2017
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.25 KB | None | 0 0
  1. // Decompiled with JetBrains decompiler
  2. // Type: Klei.SimUtil
  3. // Assembly: Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
  4. // MVID: EFEF928C-40DE-4FF3-B604-02066AAF1D84
  5. // Assembly location: G:\Steam\steamapps\common\OxygenNotIncluded\OxygenNotIncluded_Data\Managed\Assembly-CSharp.dll
  6.  
  7. using System;
  8. using System.Diagnostics;
  9. using UnityEngine;
  10.  
  11. namespace Klei
  12. {
  13.   public static class SimUtil
  14.   {
  15.     public static float CalculateEnergyFlow(float source_temp, float source_thermal_conductivity, float dest_temp, float dest_thermal_conductivity, float surface_area = 1f, float thickness = 1f)
  16.     {
  17.       return (float) ((double) (source_temp - dest_temp) * (double) Math.Min(source_thermal_conductivity, dest_thermal_conductivity) * ((double) surface_area / (double) thickness));
  18.     }
  19.  
  20.     public static float CalculateEnergyFlow(int cell, float dest_temp, float dest_specific_heat_capacity, float dest_thermal_conductivity, float surface_area = 1f, float thickness = 1f)
  21.     {
  22.       if ((double) Grid.Cell[cell].mass <= 0.0)
  23.         return 0.0f;
  24.       Element element = Grid.Element[cell];
  25.       if (element.IsVacuum)
  26.         return 0.0f;
  27.       return SimUtil.CalculateEnergyFlow(Grid.Temperature[cell], element.thermalConductivity, dest_temp, dest_thermal_conductivity, surface_area, thickness) * (1f / 1000f);
  28.     }
  29.  
  30.     public static float ClampEnergyTransfer(float dt, float source_temp, float source_mass, float source_specific_heat_capacity, float dest_temp, float dest_mass, float dest_specific_heat_capacity, float max_watts_transferred)
  31.     {
  32.       return SimUtil.ClampEnergyTransfer(dt, source_temp, source_mass * source_specific_heat_capacity, dest_temp, dest_mass * dest_specific_heat_capacity, max_watts_transferred);
  33.     }
  34.  
  35.     public static float ClampEnergyTransfer(float dt, float source_temp, float source_heat_capacity, float dest_temp, float dest_heat_capacity, float max_watts_transferred)
  36.     {
  37.       float num1 = (float) ((double) max_watts_transferred * (double) dt / 1000.0);
  38.       SimUtil.CheckValidValue(num1);
  39.       float min = Math.Min(source_temp, dest_temp);
  40.       float max = Math.Max(source_temp, dest_temp);
  41.       float num2 = source_temp - num1 / source_heat_capacity;
  42.       float num3 = dest_temp + num1 / dest_heat_capacity;
  43.       SimUtil.CheckValidValue(num2);
  44.       SimUtil.CheckValidValue(num3);
  45.       float num4 = Mathf.Clamp(num2, min, max);
  46.       float num5 = Mathf.Clamp(num3, min, max);
  47.       float num6 = Math.Abs(num4 - source_temp);
  48.       float num7 = Math.Abs(num5 - dest_temp);
  49.       float num8 = Math.Min(num6 * source_heat_capacity, num7 * dest_heat_capacity) * ((double) max_watts_transferred >= 0.0 ? 1f : -1f);
  50.       SimUtil.CheckValidValue(num8);
  51.       return num8;
  52.     }
  53.  
  54.     private static float GetMassAreaScale(Element element)
  55.     {
  56.       return element.IsGas ? 10f : 0.01f;
  57.     }
  58.  
  59.     public static float CalculateEnergyFlowCreatures(int cell, float creature_temperature, float creature_shc, float creature_thermal_conductivity, float creature_surface_area = 1f, float creature_surface_thickness = 1f)
  60.     {
  61.       return SimUtil.CalculateEnergyFlow(cell, creature_temperature, creature_shc, creature_thermal_conductivity, creature_surface_area, creature_surface_thickness);
  62.     }
  63.  
  64.     public static float EnergyFlowToTemperatureDelta(float kilojoules, float specific_heat_capacity, float mass)
  65.     {
  66.       if ((double) kilojoules * (double) specific_heat_capacity * (double) mass == 0.0)
  67.         return 0.0f;
  68.       return kilojoules / (specific_heat_capacity * mass);
  69.     }
  70.  
  71.     public static float CalculateFinalTemperature(float mass1, float temp1, float mass2, float temp2)
  72.     {
  73.       float val2 = (mass1 * temp1 + mass2 * temp2) / (mass1 + mass2);
  74.       float val1_1;
  75.       float val1_2;
  76.       if ((double) temp1 > (double) temp2)
  77.       {
  78.         val1_1 = temp2;
  79.         val1_2 = temp1;
  80.       }
  81.       else
  82.       {
  83.         val1_1 = temp1;
  84.         val1_2 = temp2;
  85.       }
  86.       return Math.Max(val1_1, Math.Min(val1_2, val2));
  87.     }
  88.  
  89.     [Conditional("STRICT_CHECKING")]
  90.     public static void CheckValidValue(float value)
  91.     {
  92.       if (!float.IsNaN(value) && !float.IsInfinity(value))
  93.         return;
  94.       UnityEngine.Assertions.Assert.IsTrue(false);
  95.     }
  96.   }
  97. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement