From 9a73dabdc0c140e0a68137d6a2c96d61da39809a Mon Sep 17 00:00:00 2001 From: SkyratBot <59378654+SkyratBot@users.noreply.github.com> Date: Tue, 27 Oct 2020 09:39:40 +0100 Subject: [PATCH] [MIRROR] Canister max. pressure capacity display fix (#1477) * Canister max. pressure capacity display fix (#54600) Atmos canisters now display their correct max. pressure capacity. Game code always expects kPa, code for SI-prefix-generation only expects the base unit (here: Pa), so the displayed value was always off by the factor 1000. * Canister max. pressure capacity display fix Co-authored-by: MadMedicineMan <65600900+MadMedicineMan@users.noreply.github.com> --- code/__HELPERS/text.dm | 13 +++++++++++ .../machinery/portable/canister.dm | 2 +- code/modules/unit_tests/siunit.dm | 22 +++++++++---------- 3 files changed, 25 insertions(+), 12 deletions(-) diff --git a/code/__HELPERS/text.dm b/code/__HELPERS/text.dm index b29ea1d55fc..a32b8326298 100644 --- a/code/__HELPERS/text.dm +++ b/code/__HELPERS/text.dm @@ -894,6 +894,8 @@ GLOBAL_LIST_INIT(binary, list("0","1")) * * value - The number to convert to text. Can be positive or negative. * * unit - The base unit of the number, such as "Pa" or "W". * * maxdecimals - Maximum amount of decimals to display for the final number. Defaults to 1. + * * + * * For pressure conversion, use proc/siunit_pressure() below */ /proc/siunit(value, unit, maxdecimals=1) var/static/list/prefixes = list("f","p","n","μ","m","","k","M","G","T","P") @@ -918,6 +920,17 @@ GLOBAL_LIST_INIT(binary, list("0","1")) var/prefix = prefixes[prefix_index] return "[coefficient] [prefix][unit]" + +/** The game code never uses Pa, but kPa, since 1 Pa is too small to reasonably handle + * Thus, to ensure correct conversion from any kPa in game code, this value needs to be multiplied by 10e3 to get Pa, which the siunit() proc expects + * Args: + * * value_in_kpa - Value that should be converted to readable text in kPa + * * maxdecimals - maximum number of decimals that are displayed, defaults to 1 in proc/siunit() + */ +/proc/siunit_pressure(value_in_kpa, maxdecimals) + var/pressure_adj = value_in_kpa * 1000 //to adjust for using kPa instead of Pa + return siunit(pressure_adj, "Pa", maxdecimals) + /// Slightly expensive proc to scramble a message using equal probabilities of character replacement from a list. DOES NOT SUPPORT HTML! /proc/scramble_message_replace_chars(original, replaceprob = 25, list/replacementchars = list("$", "@", "!", "#", "%", "^", "&", "*"), replace_letters_only = FALSE, replace_whitespace = FALSE) var/list/out = list() diff --git a/code/modules/atmospherics/machinery/portable/canister.dm b/code/modules/atmospherics/machinery/portable/canister.dm index c662842181f..e91f397c12f 100644 --- a/code/modules/atmospherics/machinery/portable/canister.dm +++ b/code/modules/atmospherics/machinery/portable/canister.dm @@ -81,7 +81,7 @@ /obj/machinery/portable_atmospherics/canister/examine(user) . = ..() if(mode) - . += "This canister is [mode]. A sticker on its side says MAX PRESSURE: [siunit(pressure_limit, "Pa", 0)]." + . += "This canister is [mode]. A sticker on its side says MAX PRESSURE: [siunit_pressure(pressure_limit, 0)]." /obj/machinery/portable_atmospherics/canister/nitrogen name = "Nitrogen canister" diff --git a/code/modules/unit_tests/siunit.dm b/code/modules/unit_tests/siunit.dm index 3ad2ee93d68..3a7a25a98d3 100644 --- a/code/modules/unit_tests/siunit.dm +++ b/code/modules/unit_tests/siunit.dm @@ -1,15 +1,15 @@ /datum/unit_test/siunit/Run() - TEST_ASSERT_EQUAL(siunit(1234, "Pa", 1), "1.2 kPa", "") - TEST_ASSERT_EQUAL(siunit(1234, "Pa", 2), "1.23 kPa", "") - TEST_ASSERT_EQUAL(siunit(1234, "Pa", 3), "1.234 kPa", "") TEST_ASSERT_EQUAL(siunit(0.5345, "A", 0), "535 mA", "") TEST_ASSERT_EQUAL(siunit(0.5344, "A", 0), "534 mA", "") TEST_ASSERT_EQUAL(siunit(-0.5344, "A", 0), "-534 mA", "") - TEST_ASSERT_EQUAL(siunit(1000, "Pa", 4), "1 kPa", "") - TEST_ASSERT_EQUAL(siunit(0, "Pa"), "0 Pa", "") - TEST_ASSERT_EQUAL(siunit(1e6, "Pa"), "1 MPa", "") - TEST_ASSERT_EQUAL(siunit(999e6, "Pa"), "999 MPa", "") - TEST_ASSERT_EQUAL(siunit(999.9e6, "Pa"), "999.9 MPa" , "") - TEST_ASSERT_EQUAL(siunit(999.9e6, "Pa", 0), "1 GPa", "") - TEST_ASSERT_EQUAL(siunit(1e9, "Pa"), "1 GPa", "") - TEST_ASSERT_EQUAL(siunit(3e20, "Pa"), "300000 PPa", "") + TEST_ASSERT_EQUAL(siunit_pressure(1.234, 1), "1.2 kPa", "") // test for pascal require *10e-3, as the game thinks in kPa, the proc siunit in Pa + TEST_ASSERT_EQUAL(siunit_pressure(1.234, 2), "1.23 kPa", "") + TEST_ASSERT_EQUAL(siunit_pressure(1.234, 3), "1.234 kPa", "") + TEST_ASSERT_EQUAL(siunit_pressure(1, 4), "1 kPa", "") + TEST_ASSERT_EQUAL(siunit_pressure(0), "0 Pa", "") + TEST_ASSERT_EQUAL(siunit_pressure(1e3), "1 MPa", "") + TEST_ASSERT_EQUAL(siunit_pressure(999e3), "999 MPa", "") + TEST_ASSERT_EQUAL(siunit_pressure(999.9e3), "999.9 MPa" , "") + TEST_ASSERT_EQUAL(siunit_pressure(999.9e3, 0), "1 GPa", "") + TEST_ASSERT_EQUAL(siunit_pressure(1e6), "1 GPa", "") + TEST_ASSERT_EQUAL(siunit_pressure(3e17), "300000 PPa", "")