Skip to content

Commit

Permalink
Merge pull request #8840 from Spookerton/spkrtn/cng/rock-and-stone
Browse files Browse the repository at this point in the history
fixed assorted ore bag/box bugs and perf issues
  • Loading branch information
Atermonera committed Dec 11, 2022
2 parents 0c30170 + 2a2cd51 commit 6ae04e1
Show file tree
Hide file tree
Showing 5 changed files with 237 additions and 208 deletions.
115 changes: 0 additions & 115 deletions code/game/objects/items/weapons/storage/bags.dm
Original file line number Diff line number Diff line change
Expand Up @@ -73,121 +73,6 @@
can_hold = list() // any
cant_hold = list(/obj/item/disk/nuclear)

// -----------------------------
// Mining Satchel
// -----------------------------
/*
* Mechoid - Orebags are the most common quick-gathering thing, and also have tons of lag associated with it. Their checks are going to be hyper-simplified due to this, and their INCREDIBLY singular target contents.
*/

/obj/item/storage/bag/ore
name = "mining satchel"
desc = "This little bugger can be used to store and transport ores."
icon = 'icons/obj/mining.dmi'
icon_state = "satchel"
slot_flags = SLOT_BELT | SLOT_POCKET
w_class = ITEMSIZE_NORMAL
max_storage_space = ITEMSIZE_COST_NORMAL * 25
max_w_class = ITEMSIZE_NORMAL
can_hold = list(/obj/item/ore)
var/stored_ore = list()
var/last_update = 0

/obj/item/storage/bag/ore/remove_from_storage(obj/item/W as obj, atom/new_location)
if(!istype(W)) return 0

if(new_location)
if(ismob(loc))
W.dropped(usr)
if(ismob(new_location))
W.hud_layerise()
else
W.reset_plane_and_layer()
W.forceMove(new_location)
else
W.forceMove(get_turf(src))

W.on_exit_storage(src)
update_icon()
return 1

/obj/item/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/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)
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(!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)

/obj/item/storage/bag/ore/equipped(mob/user)
..()
if(user.get_inventory_slot(src) == slot_wear_suit || slot_l_hand || slot_l_hand || slot_belt) //Basically every place they can go. Makes sure it doesn't unregister if moved to other slots.
GLOB.moved_event.register(user, src, /obj/item/storage/bag/ore/proc/autoload, user)

/obj/item/storage/bag/ore/dropped(mob/user)
..()
if(user.get_inventory_slot(src) == slot_wear_suit || slot_l_hand || slot_l_hand || slot_belt) //See above. This should really be a define.
GLOB.moved_event.register(user, src, /obj/item/storage/bag/ore/proc/autoload, user)
else
GLOB.moved_event.unregister(user, src)

/obj/item/storage/bag/ore/proc/autoload(mob/user)
var/obj/item/ore/O = locate() in get_turf(src)
if(O)
gather_all(get_turf(src), user)

/obj/item/storage/bag/ore/proc/rangedload(atom/A, mob/user)
var/obj/item/ore/O = locate() in get_turf(A)
if(O)
gather_all(get_turf(A), user)

/obj/item/storage/bag/ore/examine(mob/user)
. = ..()

if(!Adjacent(user)) //Can only check the contents of ore bags if you can physically reach them.
return .

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'>- [stored_ore[ore]] [ore]</span>"

/obj/item/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)

/obj/item/storage/bag/ore/proc/update_ore_count() //Stolen from ore boxes.

stored_ore = list()

for(var/obj/item/ore/O in contents)
if(stored_ore[O.name])
stored_ore[O.name]++
else
stored_ore[O.name] = 1

// -----------------------------
// Plant bag
// -----------------------------
Expand Down
115 changes: 115 additions & 0 deletions code/game/objects/items/weapons/storage/bags/ore.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
/obj/item/storage/bag/ore
name = "mining satchel"
desc = "A handy-dandy container for your rock collection. Gneiss."
icon = 'icons/obj/mining.dmi'
icon_state = "satchel"
slot_flags = SLOT_BELT | SLOT_POCKET
w_class = ITEMSIZE_NORMAL
max_storage_space = ITEMSIZE_COST_NORMAL * 25
max_w_class = ITEMSIZE_NORMAL
can_hold = list(/obj/item/ore)

/// Rebuild stored_ore if true. Becomes true when contents changes.
var/stored_ore_dirty

/// The current ore contents of the bag formatted by english_list.
var/stored_ore


/obj/item/storage/bag/ore/examine(mob/user)
. = ..()
if (!Adjacent(user) && !isobserver(user))
return
if (isliving(user))
add_fingerprint(user)
if (stored_ore_dirty)
stored_ore_dirty = FALSE
stored_ore = null
var/list/ores = list()
for (var/obj/item/ore/ore in contents)
++ores[ore.name]
var/list/chunks = list()
for (var/name in ores)
chunks += "[ores[name]] [name]"
if (length(chunks))
var/full = length(contents) >= max_storage_space
stored_ore = "[full ? "It is <b>full</b>! " : ""]It contains [english_list(chunks)]"
. += SPAN_ITALIC(stored_ore || "It is empty.")


/obj/item/storage/bag/ore/equipped(mob/living/user, into_slot)
..()
switch (into_slot)
if (slot_wear_suit, slot_l_hand, slot_r_hand, slot_belt)
GLOB.moved_event.register(user, src, /obj/item/storage/bag/ore/proc/autoload, user)


/obj/item/storage/bag/ore/dropped(mob/living/user)
..()
switch (user.get_inventory_slot(src))
if (slot_wear_suit, slot_l_hand, slot_r_hand, slot_belt)
. = . //noop
else
GLOB.moved_event.unregister(user, src)


/obj/item/storage/bag/ore/remove_from_storage(obj/item/item, atom/into)
if (!istype(item))
return FALSE
if (isloc(into))
if (ismob(loc))
item.dropped(usr)
if (ismob(into))
item.hud_layerise()
else
item.reset_plane_and_layer()
else
item.forceMove(get_turf(src))
item.on_exit_storage(src)
stored_ore_dirty = TRUE
update_icon()
return TRUE


/obj/item/storage/bag/ore/gather_all(turf/from, mob/living/user, silent, autoload)
var/obj/structure/ore_box/box = user.pulling
if (istype(box))
var/gathered = length(contents)
if (gathered)
box.contents += contents
stored_ore_dirty = TRUE
for (var/obj/item/ore/ore in from)
box.contents += ore
++gathered
if (gathered)
box.stored_ore_dirty = TRUE
if (!silent)
to_chat(user, SPAN_ITALIC("You collect all the ore into \the [box]."))
return
if (length(contents) >= max_storage_space)
if (!autoload && !silent)
to_chat(user, SPAN_WARNING("\The [src] is full."))
return
var/gathered = 0
var/available_space = max_storage_space - length(contents)
for (var/obj/item/ore/ore in from)
contents += ore
if (--available_space < 1)
if (!silent)
to_chat(user, SPAN_ITALIC("You completely fill \the [src] with ore."))
return
++gathered
if (gathered)
stored_ore_dirty = TRUE
if (!silent)
to_chat(user, SPAN_ITALIC("You collect all the ore with \the [src]."))
else if (!autoload && !silent)
to_chat(user, SPAN_WARNING("There's no ore there to collect."))


/obj/item/storage/bag/ore/open(mob/living/user)
user.examinate(src)


/obj/item/storage/bag/ore/proc/autoload(mob/living/user)
gather_all(get_turf(src), user, FALSE, TRUE)
Loading

0 comments on commit 6ae04e1

Please sign in to comment.