Skip to content

Clean up the priming subroutine for explosives#12452

Open
LatoDiafol wants to merge 3 commits into
cmss13-devs:masterfrom
LatoDiafol:minor_explosive.dm_cleanup
Open

Clean up the priming subroutine for explosives#12452
LatoDiafol wants to merge 3 commits into
cmss13-devs:masterfrom
LatoDiafol:minor_explosive.dm_cleanup

Conversation

@LatoDiafol

@LatoDiafol LatoDiafol commented Jun 15, 2026

Copy link
Copy Markdown

About the pull request

Made the prime() function in explosive.dm more streamlined and robust, this involved:
The removal of the "i" variable and replacing it with that simply counted up as the containers were iterated across the first time and counted down when the second loop then transferred the contents of those containers to the "meta-container" that is used to calculate the actual reaction. This was replaced by a call to find the length of the container array instead of counting up in the first loop, this makes the code more robust by keeping each loop independent while also making the code easier to read and comprehend.

Introduction of an error message should an invalid explosive with 0 or less containers that somehow has reagents contained within, theoretically this code should never fire, but it should catch any edge cases I've missed and aid in debugging.

The change was tested using all of the partticular test cases I could think of, the results of which can be found below.

Explain why it's good for the game

Removes fragility from the procedure which could cause it to break in unexpected ways if modified. Removes an ambiguous variable "i" and replaces it with a usefully named variable "container_count"

Testing Photographs and Procedure

Test Cases:
No containers: Properly makes the dud sound and does not trigger volatiles.
One container of an explosive substance: Sets the volatiles flag properly and detonates. (expected 60 units welding fuel present at the point of explosion and the "Trigger Volatiles" flag set as true, Test successful)
Two containers of explosives: Properly combines both canisters and triggers the detonation as it should. (Two containers of 60 units welding fuel each, saw 120 units of welding fuel at the point of explosion and the Trigger Volatiles flag set as expected.)
One container of non explosives: Produces a whiff of steam as expected, but no actual explosion (Explosive contained 60 units of Watermelon Juice)
One Container of Explosives and one container of non explosives (One bottle of 60u Welding Fuel, One bottle of 60u Watermelon Juice, explosion triggered with identical stats to the grenade containing just 60u welding fuel as expected)

Screenshots & Videos

Not Applicable

Changelog

🆑
code: Streamlined the prime() function for explosives in explosives.dm
/:cl:

@github-project-automation github-project-automation Bot moved this to Awaiting Review in Review Backlog Jun 15, 2026
@cmss13-ci cmss13-ci Bot added the Code Improvement Make the code longer label Jun 15, 2026
@cmss13-ci cmss13-ci Bot added the size/S Denotes a PR that changes 19-49 lines, ignoring generated files. label Jun 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Code Improvement Make the code longer size/S Denotes a PR that changes 19-49 lines, ignoring generated files.

Projects

Status: Awaiting Review

Development

Successfully merging this pull request may close these issues.

1 participant