Files
SkyratBot 46cca54219 [MIRROR] Planetary atmos fix [MDB IGNORE] (#23946)
* Planetary atmos fix (#78602)

<!-- Write **BELOW** The Headers and **ABOVE** The comments else it may
not be viewable. -->
<!-- You can view Contributing.MD for a detailed description of the pull
request process. -->

## About The Pull Request

The code for generating random atmospheres for lavaland and icemoon has
variables that define the minimum and maximum pressure that the
atmosphere can be. However, due to an oversight, it was possible for the
actual pressure to be below this minimum. This caused problems for the
flight potion wings, as the wings will not work if the pressure is lower
than the minimum lavaland/icemoon pressure.

I tested this by making a quick test proc that would generate lavaland
atmos 100 times, and count how often the final pressure was lower than
the minimum pressure. I ran it a few times after making my changes, and
it returned 0 failures every time, so I'm confident that my code works.

<!-- Describe The Pull Request. Please be sure every change is
documented or this can delay review and even discourage maintainers from
merging your PR! -->

## Why It's Good For The Game

I think its good practice for minimums and maximums variables like this
to actually be hard limits. Furthermore, if there's _one_ place that
mining loot should actually be useful, then its outside where you mine.

<!-- Argue for the merits of your changes and how they benefit the game,
especially if they are controversial and/or far reaching. If you can't
actually explain WHY what you are doing will improve the game, then it
probably isn't good for the game in the first place. -->

## Changelog

<!-- If your PR modifies aspects of the game that can be concretely
observed by players or admins you should add a changelog. If your change
does NOT meet this description, remove this section. Be sure to properly
mark your PRs to prevent unnecessary GBP loss. You can read up on GBP
and it's effects on PRs in the tgstation guides for contributors. Please
note that maintainers freely reserve the right to remove and add tags
should they deem it appropriate. You can attempt to finagle the system
all you want, but it's best to shoot for clear communication right off
the bat. -->

🆑
fix: The flight potion wings will no longer fail to work on
lavaland/icemoon on rare occasions.
/🆑

<!-- Both 🆑's are required for the changelog to work! You can put
your name to the right of the first 🆑 if you want to overwrite your
GitHub username as author ingame. -->
<!-- You can use multiple of the same prefix (they're only used for the
icon ingame) and delete the unneeded ones. Despite some of the tags,
changelogs should generally represent how a player might be affected by
the changes rather than a summary of the PR's contents. -->

* Planetary atmos fix

---------

Co-authored-by: GPeckman <21979502+GPeckman@users.noreply.github.com>
2023-09-27 02:24:02 -04:00

71 lines
2.6 KiB
Plaintext

/datum/atmosphere
var/gas_string
var/id
var/list/base_gases // A list of gases to always have
var/list/normal_gases // A list of allowed gases:base_amount
var/list/restricted_gases // A list of allowed gases like normal_gases but each can only be selected a maximum of one time
var/restricted_chance = 10 // Chance per iteration to take from restricted gases
var/minimum_pressure
var/maximum_pressure
var/minimum_temp
var/maximum_temp
/datum/atmosphere/New()
generate_gas_string()
/datum/atmosphere/proc/generate_gas_string()
var/list/spicy_gas = restricted_gases.Copy()
var/target_pressure = rand(minimum_pressure, maximum_pressure)
var/pressure_scalar = target_pressure / maximum_pressure
if(HAS_TRAIT(SSstation, STATION_TRAIT_UNNATURAL_ATMOSPHERE))
restricted_chance = restricted_chance + 40
// First let's set up the gasmix and base gases for this template
// We make the string from a gasmix in this proc because gases need to calculate their pressure
var/datum/gas_mixture/gasmix = new
var/list/gaslist = gasmix.gases
gasmix.temperature = rand(minimum_temp, maximum_temp)
for(var/i in base_gases)
ADD_GAS(i, gaslist)
gaslist[i][MOLES] = base_gases[i]
// Now let the random choices begin
var/datum/gas/gastype
var/amount
while(gasmix.return_pressure() < target_pressure)
if(!prob(restricted_chance) || !length(spicy_gas))
gastype = pick(normal_gases)
amount = normal_gases[gastype]
else
gastype = pick(spicy_gas)
amount = spicy_gas[gastype]
spicy_gas -= gastype //You can only pick each restricted gas once
amount *= rand(50, 200) / 100 // Randomly modifes the amount from half to double the base for some variety
amount *= pressure_scalar // If we pick a really small target pressure we want roughly the same mix but less of it all
amount = CEILING(amount, 0.1)
ASSERT_GAS_IN_LIST(gastype, gaslist)
gaslist[gastype][MOLES] += amount
// Ensure that minimum_pressure is actually a hard lower limit
target_pressure = clamp(target_pressure, minimum_pressure + (gaslist[gastype][MOLES] * 0.1), maximum_pressure)
// That last one put us over the limit, remove some of it
while(gasmix.return_pressure() > target_pressure)
gaslist[gastype][MOLES] -= gaslist[gastype][MOLES] * 0.1
gaslist[gastype][MOLES] = FLOOR(gaslist[gastype][MOLES], 0.1)
gasmix.garbage_collect()
// Now finally lets make that string
var/list/gas_string_builder = list()
for(var/i in gaslist)
var/list/gas = gaslist[i]
gas_string_builder += "[gas[GAS_META][META_GAS_ID]]=[gas[MOLES]]"
gas_string_builder += "TEMP=[gasmix.temperature]"
gas_string = gas_string_builder.Join(";")