mirror of
https://github.com/Bubberstation/Bubberstation.git
synced 2025-12-10 09:42:29 +00:00
About The Pull Request Fixes #69483 #69432 broke reagent transfer. image As we can see above, we've gone from removing reagents 100% of the time, to removing reagents only when methods is truthy and thus they get added to r_to_send. methods is not always truthy. Infact, more often than not it's NULL. As a result, common reagent transfer methods just broke, duplicating reagents. Sometimes this has interesting consequences, like in reagent reactions: https://tgstation13.org/parsed-logs/terry/data/logs/2022/08/26/round-189263/game.txt image This is what my search bar looked like highlighting the 1000+ explosions. image This adds a unit test to make sure reagent transfer actually works, then fixes the bug by caching reagents to be removed and removing them in a batch later on. Why It's Good For The Game Infinitely looping explosions tend to be loud and obnoxious. This kills the player. This also kills the server. Unit tests are cool because my test is an absolute unit and I'm in awe at the size of that lad. Changelog cl fix: Fixes reagent transfer not properly emptying the source of reagents when transferring to a target. /cl
27 lines
2.0 KiB
Plaintext
27 lines
2.0 KiB
Plaintext
/// Tests transferring reagents between two reagents datums.
|
|
/datum/unit_test/reagent_transfer
|
|
|
|
/datum/unit_test/reagent_transfer/Run()
|
|
var/datum/reagents/source_reagents = allocate(/datum/reagents, 100)
|
|
var/datum/reagents/target_reagents = allocate(/datum/reagents, 100)
|
|
|
|
// Quick test to make sure reagents add properly.
|
|
source_reagents.add_reagent(/datum/reagent/water, 10)
|
|
TEST_ASSERT_EQUAL(length(source_reagents.reagent_list), 1, "Source reagents has [length(source_reagents.reagent_list)] unique reagents (expected 1).")
|
|
TEST_ASSERT_EQUAL(source_reagents.total_volume, 10, "Source reagents has incorrect total_volume [source_reagents.total_volume] (expected 10).")
|
|
|
|
// Test to make sure the water reagent was added correctly.
|
|
var/datum/reagent/water/water_reagent = source_reagents.reagent_list[1]
|
|
TEST_ASSERT(istype(water_reagent), "Incorrect reagent type detected source reagents: [water_reagent.type] (expected /datum/reagent/water).")
|
|
TEST_ASSERT_EQUAL(water_reagent.volume, 10, "Source reagents has [water_reagent.volume] reagent volume (expected 10).")
|
|
|
|
// Test to make sure reagents transfer properly.
|
|
source_reagents.trans_to(target_reagents, 10)
|
|
TEST_ASSERT_EQUAL(length(source_reagents.reagent_list), 0, "Source reagents has [length(source_reagents.reagent_list)] unique reagents after transfer (expected 0, possible duplication?)")
|
|
TEST_ASSERT_EQUAL(length(target_reagents.reagent_list), 1, "Target reagents has [length(target_reagents.reagent_list)] unique reagents after transfer (expected 1).")
|
|
TEST_ASSERT_EQUAL(target_reagents.total_volume, 10, "Target reagents has incorrect total_volume [source_reagents.total_volume] (expected 10).")
|
|
|
|
water_reagent = target_reagents.reagent_list[1]
|
|
TEST_ASSERT(istype(water_reagent), "Incorrect reagent type detected in target reagents after transfer: [water_reagent.type] (should be /datum/reagent/water).")
|
|
TEST_ASSERT_EQUAL(water_reagent.volume, 10, "Target reagents has [water_reagent.volume] reagent volume (expected 10)")
|