From adc941c7000ec8f9705f889770a1df01c2fdad5b Mon Sep 17 00:00:00 2001 From: "C.L" Date: Sun, 25 Sep 2022 00:43:13 -0400 Subject: [PATCH] Makes ore boxes, bags, and the processing machine use lists. - Makes Ore boxes, ore bags, and the processing machine all use lists. Previously, ore boxes would constantly add ore to the contents of the ore box. This meant that if a miner was constantly adding ore to a crate that has thousands of ores in its contents list, the contents list would be updated numerous times in succession. Updating a list with 10000 ore 25 times in a single tick makes the server cry. Making it use lists completely eliminates this problem and makes the entire process of ore more efficient. It simply adds the amount of ores to a list and transfers them between satchel/bag/processing machine. Using lists means the infinite mining satchel can actually be infinite without worries of constantly dropping & picking up ore and lagging the server. This has been tested and works. The only problem however is that I need to figure out a way to make mining bags able to know if they're full or not. Currently they can hold an infinite value of ores. --- .../objects/items/weapons/storage/bags.dm | 69 +++++++++++------- .../mining/machinery/machine_processing.dm | 16 ++-- code/modules/mining/ore_box.dm | 73 ++++++++++++------- 3 files changed, 99 insertions(+), 59 deletions(-) diff --git a/code/game/objects/items/weapons/storage/bags.dm b/code/game/objects/items/weapons/storage/bags.dm index a31e8f462b9..3e7c63e711b 100644 --- a/code/game/objects/items/weapons/storage/bags.dm +++ b/code/game/objects/items/weapons/storage/bags.dm @@ -98,7 +98,28 @@ max_storage_space = ITEMSIZE_COST_NORMAL * 25 max_w_class = ITEMSIZE_NORMAL can_hold = list(/obj/item/weapon/ore) - var/stored_ore = list() + var/list/stored_ore = list( + "sand" = 0, + "hematite" = 0, + "carbon" = 0, + "raw copper" = 0, + "raw tin" = 0, + "void opal" = 0, + "painite" = 0, + "quartz" = 0, + "raw bauxite" = 0, + "phoron" = 0, + "silver" = 0, + "gold" = 0, + "marble" = 0, + "rutile" = 0, + "uranium" = 0, + "diamond" = 0, + "platinum" = 0, + "lead" = 0, + "mhydrogen" = 0, + "verdantium" = 0, + "rutile" = 0) var/last_update = 0 /obj/item/weapon/storage/bag/ore/holding @@ -128,21 +149,23 @@ /obj/item/weapon/storage/bag/ore/gather_all(turf/T as turf, mob/user as mob, var/silent = 0) var/success = 0 var/failure = 0 - for(var/obj/item/weapon/ore/I in T) //Only ever grabs ores. Doesn't do any extraneous checks, as all ore is the same size. Tons of checks means it causes hanging for up to three seconds. - if(contents.len >= max_storage_space) - failure = 1 - break - I.forceMove(src) + for(var/obj/item/weapon/ore/O in T) //Only ever grabs ores. Doesn't do any extraneous checks, as all ore is the same size. Tons of checks means it causes hanging for up to three seconds. + //if(contents.len >= max_storage_space) //TODO: Find a good way of having it hold a maximum amount of ore. + // failure = 1 + // break + var/obj/item/weapon/ore/ore = O + stored_ore[ore.material]++ + qdel(ore) success = 1 if(success && !failure && !silent) to_chat(user, "You put everything in [src].") - else if(success && (!silent || (silent && contents.len >= max_storage_space))) - to_chat(user, "You fill the [src].") + //else if(success && (!silent || (silent && contents.len >= max_storage_space))) //TODO: Find a good way of having it hold a maximum amount of ore. + // to_chat(user, "You fill the [src].") else if(!silent) to_chat(user, "You fail to pick anything up with \the [src].") if(istype(user.pulling, /obj/structure/ore_box)) //Bit of a crappy way to do this, as it doubles spam for the user, but it works. - var/obj/structure/ore_box/O = user.pulling - O.attackby(src, user) + var/obj/structure/ore_box/OB = user.pulling + OB.attackby(src, user) /obj/item/weapon/storage/bag/ore/equipped(mob/user) ..() @@ -175,24 +198,20 @@ if(istype(user, /mob/living)) add_fingerprint(user) - if(!contents.len) - . += "It is empty." - - else if(world.time > last_update + 10) - update_ore_count() - last_update = world.time - - . += "It holds:" - for(var/ore in stored_ore) + . += "It holds:" + var/has_ore = 0 + for(var/ore in stored_ore) + if(stored_ore[ore] > 0) . += "- [stored_ore[ore]] [ore]" + has_ore = 1 + if(!has_ore) + . += "Nothing." /obj/item/weapon/storage/bag/ore/open(mob/user as mob) //No opening it for the weird UI of having shit-tons of ore inside it. - if(world.time > last_update + 10) - update_ore_count() - last_update = world.time - user.examinate(src) + user.examinate(src) -/obj/item/weapon/storage/bag/ore/proc/update_ore_count() //Stolen from ore boxes. +/* +/obj/item/weapon/storage/bag/ore/proc/update_ore_count() //Stolen from ore boxes. OLD way of storing ore. stored_ore = list() @@ -201,7 +220,7 @@ stored_ore[O.name]++ else stored_ore[O.name] = 1 - +*/ // ----------------------------- // Plant bag // ----------------------------- diff --git a/code/modules/mining/machinery/machine_processing.dm b/code/modules/mining/machinery/machine_processing.dm index a4644035d99..1b06da1422c 100644 --- a/code/modules/mining/machinery/machine_processing.dm +++ b/code/modules/mining/machinery/machine_processing.dm @@ -69,7 +69,7 @@ else data["has_id"] = FALSE - + var/list/ores = list() for(var/ore in machine.ores_processing) if(!machine.ores_stored[ore] && !show_all_ores) @@ -194,7 +194,7 @@ var/ore/OD = GLOB.ore_data[ore] ores_processing[OD.name] = 0 ores_stored[OD.name] = 0 - + // TODO - Eschew input/output machinery and just use dirs ~Leshana //Locate our output and input machinery. for (var/dir in cardinal) @@ -236,11 +236,13 @@ var/list/tick_alloys = list() //Grab some more ore to process this tick. - for(var/obj/item/weapon/ore/O in input.loc) - if(!isnull(ores_stored[O.material])) - ores_stored[O.material]++ - points += (ore_values[O.material]*points_mult) // Give Points! VOREStation Edit - or give lots of points! or less points! or no points! - qdel(O) + for(var/obj/structure/ore_box/OB in input.loc) + for(var/ore in OB.stored_ore) + if(OB.stored_ore[ore] > 0) + var/ore_amount = OB.stored_ore[ore] // How many ores does the box have? + ores_stored[ore] += ore_amount // Add the ore to the machine. + points += (ore_values[ore]*points_mult*ore_amount) // Give Points! VOREStation Edit - or give lots of points! or less points! or no points! + OB.stored_ore[ore] = 0 // Set the value of the ore in the box to 0. if(!active) return diff --git a/code/modules/mining/ore_box.dm b/code/modules/mining/ore_box.dm index 9fddd03e213..b2930992abe 100644 --- a/code/modules/mining/ore_box.dm +++ b/code/modules/mining/ore_box.dm @@ -7,27 +7,52 @@ desc = "A heavy box used for storing ore." density = TRUE var/last_update = 0 - var/list/stored_ore = list() + var/list/stored_ore = list( + "sand" = 0, + "hematite" = 0, + "carbon" = 0, + "raw copper" = 0, + "raw tin" = 0, + "void opal" = 0, + "painite" = 0, + "quartz" = 0, + "raw bauxite" = 0, + "phoron" = 0, + "silver" = 0, + "gold" = 0, + "marble" = 0, + "rutile" = 0, + "uranium" = 0, + "diamond" = 0, + "platinum" = 0, + "lead" = 0, + "mhydrogen" = 0, + "verdantium" = 0, + "rutile" = 0) + + var/list/contained_resources = list() //A list of the ore inside. This is done to reduce lag. + /obj/structure/ore_box/attackby(obj/item/weapon/W as obj, mob/user as mob) if (istype(W, /obj/item/weapon/ore)) - user.remove_from_mob(W) - src.contents += W + var/obj/item/weapon/ore/ore = W + stored_ore[ore.material]++ + qdel(ore) - else if (istype(W, /obj/item/weapon/storage)) - var/obj/item/weapon/storage/S = W - if(!S.contents.len) - return + else if (istype(W, /obj/item/weapon/storage/bag/ore)) + var/obj/item/weapon/storage/bag/ore/S = W S.hide_from(user) - for(var/obj/item/weapon/ore/O in S.contents) - S.remove_from_storage(O, src) //This will move the item to this item's contents + for(var/ore in S.stored_ore) + if(S.stored_ore[ore] > 0) + var/ore_amount = S.stored_ore[ore] // How many ores does the satchel have? + stored_ore[ore] += ore_amount // Add the ore to the machine. + S.stored_ore[ore] = 0 // Set the value of the ore in the satchel to 0. to_chat(user, "You empty the satchel into the box.") - update_ore_count() - return -/obj/structure/ore_box/proc/update_ore_count() +/* +/obj/structure/ore_box/proc/update_ore_count() //OLD way of storing ore. Comment this out once done. stored_ore = list() @@ -37,7 +62,7 @@ stored_ore[O.name]++ else stored_ore[O.name] = 1 - +*/ /obj/structure/ore_box/examine(mob/user) . = ..() @@ -46,19 +71,16 @@ add_fingerprint(user) - if(!contents.len) - . += "It is empty." - return . - - if(world.time > last_update + 10) - update_ore_count() - last_update = world.time - . += "It holds:" + var/has_ore = 0 for(var/ore in stored_ore) - . += "- [stored_ore[ore]] [ore]" + if(stored_ore[ore] > 0) + . += "- [stored_ore[ore]] [ore]" + has_ore = 1 + if(!has_ore) + . += "Nothing." -// /obj/structure/ore_box/verb/empty_box() +// /obj/structure/ore_box/verb/empty_box() //Servercrash.mov // set name = "Empty Ore Box" // set category = "Object" // set src in view(1) @@ -87,9 +109,6 @@ // return /obj/structure/ore_box/ex_act(severity) - if(severity == 1.0 || (severity < 3.0 && prob(50))) - for (var/obj/item/weapon/ore/O in contents) - O.loc = src.loc - O.ex_act(severity++) + if(severity == 1.0 || (severity == 2.0 && prob(50))) qdel(src) return