/// <summary> /// Applied before GetFormattedSimple runs. /// </summary> internal static bool Prefix(float num, TimeSlice timeSlice, string formatString, ref string __result) { var text = CACHED_BUILDER; text.Clear(); num = GameUtil.ApplyTimeSlice(num, timeSlice); if (!text.AppendIfInfinite(num)) { if (formatString != null) { AppendSimpleFormat(text, formatString, num); } else if (num == 0.0f) { text.Append('0'); } else { RyuFormat.ToString(text, (double)num, 2, RyuFormatOptions.FixedMode | RyuFormatOptions.SoftPrecision | RyuFormatOptions. ThousandsSeparators); } } __result = text.AppendTimeSlice(timeSlice).ToString(); return(false); }
/// <summary> /// Applied before GetFormattedUnits runs. /// </summary> internal static bool Prefix(float units, TimeSlice timeSlice, bool displaySuffix, string floatFormatOverride, ref string __result) { var text = CACHED_BUILDER; text.Clear(); units = GameUtil.ApplyTimeSlice(units, timeSlice); if (!text.AppendIfInfinite(units)) { if (!floatFormatOverride.IsNullOrWhiteSpace()) { text.AppendFormat(floatFormatOverride, units); } else { units.ToStandardString(text); } } if (displaySuffix) { text.Append(Mathf.Approximately(units, 1.0f) ? UNIT : UNITS); } __result = text.AppendTimeSlice(timeSlice).ToString(); return(false); }
/// <summary> /// Formats the germ quantity into a string buffer to save on allocations. /// </summary> /// <param name="text">The location where the germs will be stored.</param> /// <param name="germs">The number of germs.</param> /// <param name="timeSlice">The time unit, if any.</param> private static void GetFormattedDiseaseAmount(StringBuilder text, int germs, TimeSlice timeSlice = TimeSlice.None) { // /cycle is broken in vanilla, clay please GameUtil.ApplyTimeSlice(germs, timeSlice).ToStandardString(text); text.Append(SUFFIXES.DISEASE.UNITS).AppendTimeSlice(timeSlice); }
/// <summary> /// Applied before GetFormattedPlantGrowth runs. /// </summary> internal static bool Prefix(float percent, TimeSlice timeSlice, ref string __result) { float absP = Mathf.Abs(percent); int precision; var text = CACHED_BUILDER; text.Clear(); if (!text.AppendIfInfinite(percent)) { percent = GameUtil.ApplyTimeSlice(percent, timeSlice); if (absP < 0.1f) { precision = 2; } else if (absP < 1.0f) { precision = 1; } else { precision = 0; } percent.ToRyuSoftString(text, precision); } __result = text.Append(PCT).Append(' ').Append(SUFFIXES.GROWTH). AppendTimeSlice(timeSlice).ToString(); return(false); }
/// <summary> /// Applied before GetFormattedRads runs. /// </summary> internal static bool Prefix(float rads, TimeSlice timeSlice, ref string __result) { var text = CACHED_BUILDER; text.Clear(); if (!text.AppendIfInfinite(rads)) { GameUtil.ApplyTimeSlice(rads, timeSlice).ToStandardString(text); } text.Append(SUFFIXES.RADIATION.RADS); __result = text.AppendTimeSlice(timeSlice).ToString(); return(false); }
/// <summary> /// Applied before GetFormattedInt runs. /// </summary> internal static bool Prefix(float num, TimeSlice timeSlice, ref string __result) { var text = CACHED_BUILDER; text.Clear(); if (!text.AppendIfInfinite(num)) { RyuFormat.ToString(text, (double)GameUtil.ApplyTimeSlice(num, timeSlice), 0, RyuFormatOptions.FixedMode | RyuFormatOptions.ThousandsSeparators); } __result = text.AppendTimeSlice(timeSlice).ToString(); return(false); }
/// <summary> /// Applied before GetFormattedHighEnergyParticles runs. /// </summary> internal static bool Prefix(float units, TimeSlice timeSlice, bool displayUnits, ref string __result) { var text = CACHED_BUILDER; text.Clear(); if (!text.AppendIfInfinite(units)) { GameUtil.ApplyTimeSlice(units, timeSlice).ToRyuSoftString(text, 1); } if (displayUnits) { // That is not how particle is spelled text.Append(Mathf.Approximately(units, 1.0f) ? SUFFIXES. HIGHENERGYPARTICLES.PARTRICLE : SUFFIXES. HIGHENERGYPARTICLES.PARTRICLES); } __result = text.AppendTimeSlice(timeSlice).ToString(); return(false); }
/// <summary> /// Applied before GetFormattedJoules runs. /// </summary> internal static bool Prefix(float joules, string floatFormat, TimeSlice timeSlice, ref string __result) { var text = CACHED_BUILDER; text.Clear(); if (timeSlice == TimeSlice.PerSecond) { GetFormattedWattage(text, joules, GameUtil.WattageFormatterUnit. Automatic, true); } else { var legend = JOULE_LEGEND; joules = GameUtil.ApplyTimeSlice(joules, timeSlice); float absJ = Mathf.Abs(joules); if (text.AppendIfInfinite(joules)) { text.Append(legend[0]); } else if (absJ > 1000000.0f) { text.AppendSimpleFormat(floatFormat, joules * 0.000001f); text.Append(legend[2]); } else if (absJ > 1000.0f) { text.AppendSimpleFormat(floatFormat, joules * 0.001f); text.Append(legend[1]); } else { text.AppendSimpleFormat(floatFormat, joules); text.Append(legend[0]); } text.AppendTimeSlice(timeSlice); } __result = text.ToString(); return(false); }
/// <summary> /// Applied before GetFormattedCalories runs. /// </summary> internal static bool Prefix(float calories, TimeSlice timeSlice, bool forceKcal, ref string __result) { string unit; var text = CACHED_BUILDER; text.Clear(); if (Mathf.Abs(calories) >= 1000.0f || forceKcal) { calories *= 0.001f; unit = SUFFIXES.CALORIES.KILOCALORIE; } else { unit = SUFFIXES.CALORIES.CALORIE; } GameUtil.ApplyTimeSlice(calories, timeSlice).ToStandardString(text); text.Append(unit); text.AppendTimeSlice(timeSlice); __result = text.ToString(); return(false); }
/// <summary> /// Formats the temperature into a string buffer to save on allocations. /// </summary> /// <param name="text">The location where the temperature will be stored.</param> /// <param name="temperature">The temperature in K.</param> /// <param name="timeSlice">The time unit, if any.</param> /// <param name="interpretation">Whether the temperature is a delta, or an absolute value.</param> /// <param name="displayUnits">Whether to display the units.</param> /// <param name="roundOff">Whether to round off the temperature to the nearest degree.</param> internal static void GetFormattedTemperature(StringBuilder text, float temperature, TimeSlice timeSlice = TimeSlice.None, GameUtil.TemperatureInterpretation interpretation = GameUtil.TemperatureInterpretation.Absolute, bool displayUnits = true, bool roundOff = false) { if (interpretation == GameUtil.TemperatureInterpretation.Absolute) { temperature = GameUtil.GetConvertedTemperature(temperature, roundOff); } else if (GameUtil.temperatureUnit == GameUtil.TemperatureUnit.Fahrenheit) { temperature *= 1.8f; } temperature = GameUtil.ApplyTimeSlice(temperature, timeSlice); if (!text.AppendIfInfinite(temperature)) { temperature.ToRyuSoftString(text, Mathf.Abs(temperature) < 0.1f ? 4 : 1); } if (displayUnits) { text.Append(GameUtil.GetTemperatureUnitSuffix()); } text.AppendTimeSlice(timeSlice); }
/// <summary> /// Formats the mass into a string buffer to save on allocations. /// </summary> /// <param name="text">The location where the mass will be stored.</param> /// <param name="mass">The mass in kilograms.</param> /// <param name="timeSlice">The time unit, if any.</param> /// <param name="massFormat">The mass units to use.</param> /// <param name="displaySuffix">Whether to display the units.</param> /// <param name="format">The string format to use, or null for the ONI default /// (1 decimal place soft).</param> internal static void GetFormattedMass(StringBuilder text, float mass, TimeSlice timeSlice = TimeSlice.None, MetricMassFormat massFormat = MetricMassFormat.UseThreshold, bool displaySuffix = true, string format = null) { if (float.IsInfinity(mass) || float.IsNaN(mass) || mass == float.MaxValue) { // Handle inf and NaN text.Append(STRINGS.UI.CALCULATING); } else { // Divide by cycle length if /cycle LocString suffix; float absMass = Mathf.Abs(mass); var legend = MASS_LEGEND; mass = GameUtil.ApplyTimeSlice(mass, timeSlice); if (GameUtil.massUnit == GameUtil.MassUnit.Kilograms) { switch (massFormat) { case MetricMassFormat.UseThreshold: if (absMass > 0.0f) { if (absMass < 5E-06f) { // ug suffix = legend[4]; mass = Mathf.Floor(mass * 1.0E+09f); } else if (absMass < 0.005f) { mass *= 1000000.0f; // mg suffix = legend[3]; } else if (absMass < 5.0f) { mass *= 1000.0f; // g suffix = legend[2]; } else if (absMass < 5000.0f) { // kg suffix = legend[1]; } else { mass /= 1000.0f; // t suffix = legend[0]; } } else { // kg suffix = legend[1]; } break; case MetricMassFormat.Gram: mass *= 1000f; // g suffix = legend[2]; break; case MetricMassFormat.Tonne: mass /= 1000f; // t suffix = legend[0]; break; case MetricMassFormat.Kilogram: default: // kg suffix = legend[1]; break; } } else { mass /= 2.2f; if (massFormat == MetricMassFormat.UseThreshold) { if (absMass < 5.0f && absMass > 0.001f) { mass *= 256.0f; suffix = SUFFIXES.MASS.DRACHMA; } else { mass *= 7000.0f; suffix = SUFFIXES.MASS.GRAIN; } } else { suffix = SUFFIXES.MASS.POUND; } } // Hardcodes for the most common cases in ONI if (format == null || format == "{0:0.#}") { mass.ToRyuSoftString(text, 1); } else if (format == "{0:0.##}") { mass.ToRyuSoftString(text, 2); } else if (format == "{0:0.###}") { mass.ToRyuSoftString(text, 3); } else { text.AppendFormat(format, mass); } if (displaySuffix) { text.Append(suffix).AppendTimeSlice(timeSlice); } } }