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.
This commit is contained in:
C.L
2022-09-25 00:43:13 -04:00
parent c79ccbc103
commit adc941c700
3 changed files with 99 additions and 59 deletions
+44 -25
View File
@@ -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, "<span class='notice'>You put everything in [src].</span>")
else if(success && (!silent || (silent && contents.len >= max_storage_space)))
to_chat(user, "<span class='notice'>You fill the [src].</span>")
//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, "<span class='notice'>You fill the [src].</span>")
else if(!silent)
to_chat(user, "<span class='notice'>You fail to pick anything up with \the [src].</span>")
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
. += "<span class='notice'>It holds:</span>"
for(var/ore in stored_ore)
. += "<span class='notice'>It holds:</span>"
var/has_ore = 0
for(var/ore in stored_ore)
if(stored_ore[ore] > 0)
. += "<span class='notice'>- [stored_ore[ore]] [ore]</span>"
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
// -----------------------------