From 93f26cf5aa23213d8195dcb60b22b1e31e1071b7 Mon Sep 17 00:00:00 2001 From: Contrabang <91113370+Contrabang@users.noreply.github.com> Date: Tue, 14 Feb 2023 00:21:58 -0500 Subject: [PATCH] Adds a cargo crate spawning tool for admins (#20220) * Allows admins to create cargo crates * AA and Miravel review * remove debug text * AA review * Oops * sirryan review * sirryan review 2 * atom to turf --- code/modules/admin/admin_verbs.dm | 3 +- code/modules/admin/verbs/randomverbs.dm | 47 +++++++++++++++++++++++++ code/modules/supply/supply_order.dm | 28 ++++----------- code/modules/supply/supply_pack.dm | 27 ++++++++++++++ 4 files changed, 82 insertions(+), 23 deletions(-) diff --git a/code/modules/admin/admin_verbs.dm b/code/modules/admin/admin_verbs.dm index 43afa96d7a0..ff5fe081505 100644 --- a/code/modules/admin/admin_verbs.dm +++ b/code/modules/admin/admin_verbs.dm @@ -116,7 +116,8 @@ GLOBAL_LIST_INIT(admin_verbs_event, list( GLOBAL_LIST_INIT(admin_verbs_spawn, list( /datum/admins/proc/spawn_atom, /*allows us to spawn instances*/ /client/proc/respawn_character, - /client/proc/admin_deserialize + /client/proc/admin_deserialize, + /client/proc/create_crate )) GLOBAL_LIST_INIT(admin_verbs_server, list( /client/proc/reload_admins, diff --git a/code/modules/admin/verbs/randomverbs.dm b/code/modules/admin/verbs/randomverbs.dm index 34fdb2209b3..ae54ae0f51c 100644 --- a/code/modules/admin/verbs/randomverbs.dm +++ b/code/modules/admin/verbs/randomverbs.dm @@ -1190,3 +1190,50 @@ Traitors and the like can also be revived with the previous role mostly intact. if(!source) return REMOVE_TRAIT(D, chosen_trait, source) + +/client/proc/create_crate(object as text) + set name = "Create Crate" + set desc = "Spawn a crate from a supplypack datum. Append a period to the text in order to exclude subtypes of paths matching the input." + set category = "Event" + + if(!check_rights(R_SPAWN)) + return + + var/list/types = SSeconomy.supply_packs + + var/list/matches = list() + + var/include_subtypes = TRUE + if(copytext(object, -1) == ".") + include_subtypes = FALSE + object = copytext(object, 1, -1) + + if(include_subtypes) + for(var/path in types) + if(findtext("[path]", object)) + matches += path + else + var/needle_length = length(object) + for(var/path in types) + if(copytext("[path]", -needle_length) == object) + matches += path + + if(!length(matches)) + return + + var/chosen = input("Select a supply crate type", "Create Crate", matches[1]) as null|anything in matches + if(!chosen) + return + var/datum/supply_packs/the_pack = new chosen() + + var/spawn_location = get_turf(usr) + if(!spawn_location) + return + var/obj/structure/closet/crate/crate = the_pack.create_package(spawn_location) + crate.admin_spawned = TRUE + for(var/atom/A in crate.contents) + A.admin_spawned = TRUE + qdel(the_pack) + + log_admin("[key_name(usr)] created a '[chosen]' crate at ([usr.x],[usr.y],[usr.z])") + SSblackbox.record_feedback("tally", "admin_verb", 1, "Create Crate") //If you are copy-pasting this, ensure the 2nd parameter is unique to the new proc! diff --git a/code/modules/supply/supply_order.dm b/code/modules/supply/supply_order.dm index ae23a840e07..bd3df469c3d 100644 --- a/code/modules/supply/supply_order.dm +++ b/code/modules/supply/supply_order.dm @@ -27,10 +27,10 @@ return //create the crate - var/obj/structure/closet/crate/crate = new object.containertype(_loc) - crate.name = "[object.containername] [comment ? "([comment])":"" ]" - if(object.access) - crate.req_access = list(text2num(object.access)) + var/obj/structure/closet/crate/crate = object.create_package(_loc) + + if(comment) + crate.name = "[crate.name] ([comment])" //create the manifest slip var/obj/item/paper/manifest/slip = new @@ -52,24 +52,8 @@ slip.info += "[packagesAmt] PACKAGES IN THIS SHIPMENT
" slip.info += "CONTENTS:
" + +/datum/supply_packs/proc/create_package(turf/spawn_location) + var/obj/structure/closet/crate/crate = new containertype(spawn_location) + + crate.name = containername + if(access) + crate.req_access = list(text2num(access)) + + //we now create the actual contents + for(var/typepath in generate_items()) + if(!typepath) + continue + var/atom/A = new typepath(crate) + if(isstack(A)) + var/obj/item/stack/mats = A + mats.amount = amount + + return crate + +/datum/supply_packs/proc/generate_items() + return contains + +/datum/supply_packs/misc/randomised/generate_items() + . = list() + if(length(contains)) + for(var/j in 1 to num_contained) + . += pick(contains)