private static void UpdateGasColour(TextureRegion region, int x0, int y0, int x1, int y1) { for (int i = y0; i <= y1; i++) { for (int j = x0; j <= x1; j++) { int num = Grid.XYToCell(j, i); Element element = Grid.Element[num]; if (element.IsGas) { region.SetBytes(j, i, element.substance.colour.r, element.substance.colour.g, element.substance.colour.b, byte.MaxValue); } else if (element.IsLiquid) { int cell = Grid.CellAbove(num); if (Grid.IsValidCell(cell)) { region.SetBytes(j, i, element.substance.colour.r, element.substance.colour.g, element.substance.colour.b, byte.MaxValue); } else { region.SetBytes(j, i, 0, 0, 0, 0); } } else { region.SetBytes(j, i, 0, 0, 0, 0); } } } }
private static void UpdateWorldLight(TextureRegion region, int x0, int y0, int x1, int y1) { if (!instance.ForceLightEverywhere) { for (int i = y0; i <= y1; i++) { int num = Grid.XYToCell(x0, i); int num2 = Grid.XYToCell(x1, i); int num3 = num; int num4 = x0; while (num3 <= num2) { Color32 color = (Grid.LightCount[num3] <= 0) ? new Color32(0, 0, 0, byte.MaxValue) : Lighting.Instance.Settings.LightColour; region.SetBytes(num4, i, color.r, color.g, color.b, (byte)((color.r + color.g + color.b > 0) ? 255 : 0)); num3++; num4++; } } } else { for (int j = y0; j <= y1; j++) { for (int k = x0; k <= x1; k++) { region.SetBytes(k, j, byte.MaxValue, byte.MaxValue, byte.MaxValue); } } } }
private static void UpdateLiquid(TextureRegion region, int x0, int y0, int x1, int y1) { for (int i = x0; i <= x1; i++) { int num = Grid.XYToCell(i, y1); Element element = Grid.Element[num]; for (int num2 = y1; num2 >= y0; num2--) { int num3 = Grid.XYToCell(i, num2); Element element2 = Grid.Element[num3]; if (element2.IsLiquid) { Color32 colour = element2.substance.colour; float liquidMaxMass = Lighting.Instance.Settings.LiquidMaxMass; float liquidAmountOffset = Lighting.Instance.Settings.LiquidAmountOffset; float num4; if (element.IsLiquid || element.IsSolid) { num4 = 1f; } else { num4 = liquidAmountOffset + (1f - liquidAmountOffset) * Mathf.Min(Grid.Mass[num3] / liquidMaxMass, 1f); num4 = Mathf.Pow(Mathf.Min(Grid.Mass[num3] / liquidMaxMass, 1f), 0.45f); } region.SetBytes(i, num2, (byte)(num4 * 255f), colour.r, colour.g, colour.b); } else { region.SetBytes(i, num2, 0, 0, 0, 0); } element = element2; } } }
private static void UpdateSolidLiquidGasMass(TextureRegion region, int x0, int y0, int x1, int y1) { for (int i = y0; i <= y1; i++) { for (int j = x0; j <= x1; j++) { int num = Grid.XYToCell(j, i); Element element = Grid.Element[num]; byte b = 0; byte b2 = 0; byte b3 = 0; if (element.IsSolid) { b = byte.MaxValue; } else if (element.IsLiquid) { b2 = byte.MaxValue; } else if (element.IsGas || element.IsVacuum) { b3 = byte.MaxValue; } float num2 = Grid.Mass[num]; float num3 = Mathf.Min(1f, num2 / 2000f); if (num2 > 0f) { num3 = Mathf.Max(0.003921569f, num3); } region.SetBytes(j, i, b, b2, b3, (byte)(num3 * 255f)); } } }
private static void UpdateSolidDigAmount(TextureRegion region, int x0, int y0, int x1, int y1) { int elementIndex = ElementLoader.GetElementIndex(SimHashes.Void); for (int i = y0; i <= y1; i++) { int num = Grid.XYToCell(x0, i); int num2 = Grid.XYToCell(x1, i); int num3 = num; int num4 = x0; while (num3 <= num2) { byte b = 0; byte b2 = 0; byte b3 = 0; if (Grid.ElementIdx[num3] != elementIndex) { b3 = byte.MaxValue; } if (Grid.Solid[num3]) { b = byte.MaxValue; b2 = (byte)(255f * Grid.Damage[num3]); } region.SetBytes(num4, i, b, b2, b3); num3++; num4++; } } }
private static void UpdateStateChange(TextureRegion region, int x0, int y0, int x1, int y1) { float temperatureStateChangeRange = instance.TemperatureStateChangeRange; for (int i = y0; i <= y1; i++) { for (int j = x0; j <= x1; j++) { int num = Grid.XYToCell(j, i); float num2 = 0f; Element element = Grid.Element[num]; if (!element.IsVacuum) { float num3 = Grid.Temperature[num]; float num4 = element.lowTemp * temperatureStateChangeRange; float num5 = Mathf.Abs(num3 - element.lowTemp); float a = num5 / num4; float num6 = element.highTemp * temperatureStateChangeRange; float num7 = Mathf.Abs(num3 - element.highTemp); float b = num7 / num6; num2 = Mathf.Max(num2, 1f - Mathf.Min(a, b)); } region.SetBytes(j, i, (byte)(num2 * 255f)); } } }
private static void UpdatePressure(TextureRegion region, int x0, int y0, int x1, int y1) { Vector2 pressureRange = instance.PressureRange; float minPressureVisibility = instance.MinPressureVisibility; float num = pressureRange.y - pressureRange.x; for (int i = y0; i <= y1; i++) { for (int j = x0; j <= x1; j++) { int num2 = Grid.XYToCell(j, i); float num3 = 0f; Element element = Grid.Element[num2]; if (element.IsGas) { float num4 = Grid.Pressure[num2]; float b = (!(num4 > 0f)) ? 0f : minPressureVisibility; num3 = Mathf.Max(Mathf.Clamp01((num4 - pressureRange.x) / num), b); } else if (element.IsLiquid) { int num5 = Grid.CellAbove(num2); if (Grid.IsValidCell(num5) && Grid.Element[num5].IsGas) { float num6 = Grid.Pressure[num5]; float b2 = (!(num6 > 0f)) ? 0f : minPressureVisibility; num3 = Mathf.Max(Mathf.Clamp01((num6 - pressureRange.x) / num), b2); } } region.SetBytes(j, i, (byte)(num3 * 255f)); } } }
private static void UpdateFogOfWar(TextureRegion region, int x0, int y0, int x1, int y1) { byte[] visible = Grid.Visible; for (int i = y0; i <= y1; i++) { for (int j = x0; j <= x1; j++) { int num = Grid.XYToCell(j, i); region.SetBytes(j, i, visible[num]); } } }
private static void UpdateDanger(TextureRegion region, int x0, int y0, int x1, int y1) { for (int i = y0; i <= y1; i++) { for (int j = x0; j <= x1; j++) { int num = Grid.XYToCell(j, i); Element element = Grid.Element[num]; byte b = (byte)((element.id != SimHashes.Oxygen) ? 255 : 0); region.SetBytes(j, i, b); } } }
private static void UpdateTemperature(TextureRegion region, int x0, int y0, int x1, int y1) { Vector2 cold_range = instance.coldRange; Vector2 hot_range = instance.hotRange; for (int i = y0; i <= y1; i++) { for (int j = x0; j <= x1; j++) { int i2 = Grid.XYToCell(j, i); float num = Grid.Temperature[i2]; GetTemperatureAlpha(num, cold_range, hot_range, out byte cold_alpha, out byte hot_alpha); byte b = (byte)(255f * Mathf.Pow(Mathf.Clamp(num / 1000f, 0f, 1f), 0.45f)); region.SetBytes(j, i, cold_alpha, hot_alpha, b); } } }
public static bool Prefix(TextureRegion region, int x0, int y0, int x1, int y1) { if (!_lightsOut) { return(true); } var config = ConfigManager.Config; byte[] visible = Grid.Visible; var lightIntensityIndexer = Grid.LightIntensity; var lowestFogVal = config.LowestFog; var gameCycle = GameClock.Instance.GetCycle(); if (lowestFogVal == 0 && gameCycle < 3) { lowestFogVal = Math.Max(0, (3 - gameCycle) * 10); } for (var y = y0; y <= y1; ++y) { for (var x = x0; x <= x1; ++x) { var cell = Grid.XYToCell(x, y); if (visible[cell] == 0) { region.SetBytes(x, y, 0); continue; } var lux = lightIntensityIndexer[cell]; if (lux == 0) { var neighboringCells = new List <int>(); if (Grid.IsValidCell(Grid.CellAbove(cell))) { neighboringCells.Add(Grid.CellAbove(cell)); } if (Grid.IsValidCell(Grid.CellUpRight(cell))) { neighboringCells.Add(Grid.CellUpRight(cell)); } if (Grid.IsValidCell(Grid.CellRight(cell))) { neighboringCells.Add(Grid.CellRight(cell)); } if (Grid.IsValidCell(Grid.CellDownRight(cell))) { neighboringCells.Add(Grid.CellDownRight(cell)); } if (Grid.IsValidCell(Grid.CellBelow(cell))) { neighboringCells.Add(Grid.CellBelow(cell)); } if (Grid.IsValidCell(Grid.CellDownLeft(cell))) { neighboringCells.Add(Grid.CellDownLeft(cell)); } if (Grid.IsValidCell(Grid.CellLeft(cell))) { neighboringCells.Add(Grid.CellLeft(cell)); } if (Grid.IsValidCell(Grid.CellUpLeft(cell))) { neighboringCells.Add(Grid.CellUpLeft(cell)); } var light = 0; foreach (var c in neighboringCells) { light += Grid.LightIntensity[c]; } lux = light / neighboringCells.Count; } var luxMapped = Math.Min(lux, config.LuxThreshold); var output = Remap(luxMapped, 0, config.LuxThreshold, lowestFogVal, config.HighestFog); region.SetBytes(x, y, (byte)output); } } return(false); }