Skip to content

Commit

Permalink
Condense loading/unloading calls
Browse files Browse the repository at this point in the history
Also cuts the HP of the shelf, and adds a safety check for unloading.
  • Loading branch information
GenericDM committed Oct 5, 2023
1 parent 1ba1ee9 commit 72baf0e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 20 deletions.
18 changes: 10 additions & 8 deletions code/game/objects/structures/crates_lockers/crates.dm
Original file line number Diff line number Diff line change
Expand Up @@ -51,19 +51,21 @@
tear_manifest(user)
return ..()

/obj/structure/closet/crate/MouseDrop(turf/unload_turf, src_location, over_location)
/obj/structure/closet/crate/MouseDrop(atom/drop_atom, src_location, over_location)
. = ..()
var/mob/living/user = usr
if(!isliving(usr))
if(!isliving(user))
return // Ghosts busted.
if(!istype(src.loc, /obj/structure/crate_shelf))
return // If the crate is not in a shelf, don't bother unloading it.
if(!unload_turf || !istype(unload_turf, /turf/open))
return // If the destination turf isn't open, or doesn't exist, don't bother trying.
if(!isturf(user.loc) || user.incapacitated() || user.body_position == LYING_DOWN)
return // If the user is in a weird state, don't bother trying.
var/obj/structure/crate_shelf/shelf = src.loc
return(shelf.unload(src, usr, unload_turf))
if(!drop_atom.Adjacent(user) || !drop_atom.Adjacent(src))
return // If the desired atom isn't adjacent to the user or crate, don't bother.
if(istype(drop_atom, /turf/open) && istype(loc, /obj/structure/crate_shelf))
var/obj/structure/crate_shelf/shelf = loc
return(shelf.unload(src, user, drop_atom)) // If we're being dropped onto a turf, and we're inside of a crate shelf, unload.
if(istype(drop_atom, /obj/structure/crate_shelf) && isturf(loc))
var/obj/structure/crate_shelf/shelf = drop_atom
return(shelf.load(src, user)) // If we're being dropped onto a crate shelf, and we're in a turf, load.

/obj/structure/closet/crate/open(mob/living/user, force = FALSE)
. = ..()
Expand Down
16 changes: 4 additions & 12 deletions code/game/objects/structures/crateshelf.dm
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
icon_state = "shelf_base"
density = TRUE
anchored = TRUE
max_integrity = 50 // Not hard to break

var/capacity = DEFAULT_SHELF_CAPACITY
var/use_delay = DEFAULT_SHELF_USE_DELAY
Expand All @@ -19,7 +20,7 @@

/obj/structure/crate_shelf/Initialize()
. = ..()
shelf_contents = new/list(capacity) // Initialize our shelf's contents list, this will be used later in MouseDrop_T().
shelf_contents = new/list(capacity) // Initialize our shelf's contents list, this will be used later.
var/stack_layer // This is used to generate the sprite layering of the shelf pieces.
var/stack_offset // This is used to generate the vertical offset of the shelf pieces.
for(var/i in 1 to (capacity - 1))
Expand Down Expand Up @@ -69,17 +70,6 @@
return TRUE
return ..()

/obj/structure/crate_shelf/MouseDrop_T(obj/structure/closet/crate/crate, mob/living/user)
if(!istype(crate, /obj/structure/closet/crate))
return FALSE // If it's not a crate, don't put it in!
if(!src.Adjacent(crate))
return FALSE // If it's not next to the shelf, don't put it in!
if(!isturf(user.loc) || user.incapacitated() || user.body_position == LYING_DOWN)
return FALSE // If the user is in a weird position, or incapacitated, don't let them load crates!
if(!isliving(user))
return FALSE // While haunted shelves sound funny, they are quite dangerous in practice. Prevent ghosts from loading into shelves.
return load(crate, user) // Try to load the crate into the shelf.

/obj/structure/crate_shelf/proc/handle_visuals()
vis_contents = contents // It really do be that shrimple.
return
Expand Down Expand Up @@ -116,6 +106,8 @@
unload_turf.balloon_alert(user, "no room!")
return FALSE
if(do_after(user, use_delay, target = crate))
if(!shelf_contents.Find(crate))
return FALSE // If something has happened to the crate while we were waiting, abort!
crate.layer = BELOW_OBJ_LAYER // Reset the crate back to having the default layer, otherwise we might get strange interactions.
crate.pixel_y = 0 // Reset the crate back to having no offset, otherwise it will be floating.
crate.forceMove(unload_turf)
Expand Down

0 comments on commit 72baf0e

Please sign in to comment.