Skip to content

Commit

Permalink
Random storage refactoring (TauCetiStation#11503)
Browse files Browse the repository at this point in the history
  • Loading branch information
volas authored Jun 21, 2023
1 parent 5c5422f commit 72ee311
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 21 deletions.
4 changes: 4 additions & 0 deletions code/__HELPERS/logging.dm
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
/proc/error(msg)
world.log << "## ERROR: [msg][log_end]"

//gives us the stack trace from CRASH() without ending the current proc.
/proc/stack_trace(msg)
CRASH(msg)

//print a warning message to world.log
#define WARNING(MSG) warning("[MSG] in [__FILE__] at line [__LINE__] src: [UNLINT(src)] usr: [usr].")
/proc/warning(msg)
Expand Down
4 changes: 0 additions & 4 deletions code/__HELPERS/unsorted.dm
Original file line number Diff line number Diff line change
Expand Up @@ -1520,10 +1520,6 @@ var/global/list/WALLITEMS = typecacheof(list(

return L

//gives us the stack trace from CRASH() without ending the current proc.
/proc/stack_trace(msg)
CRASH(msg)

//Increases delay as the server gets more overloaded,
//as sleeps aren't cheap and sleeping only to wake up and sleep again is wasteful
#define DELTA_CALC max(((max(TICK_USAGE, world.cpu) / 100) * max(Master.sleep_delta - 1, 1)), 1)
Expand Down
4 changes: 3 additions & 1 deletion code/game/objects/items.dm
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@
armor = list()
atom_integrity = max_integrity

if(!isturf(loc))
if(istype(loc, /obj/item/weapon/storage)) // todo: need to catch all spawns in /storage/ objects and make them use handle_item_insertion or forceMove, so we can remove this
flags_2 |= IN_STORAGE

if(item_state_world)
Expand Down Expand Up @@ -368,12 +368,14 @@

// called when this item is removed from a storage item, which is passed on as S. The loc variable is already set to the new destination before this is called.
/obj/item/proc/on_exit_storage(obj/item/weapon/storage/S)
SHOULD_CALL_PARENT(TRUE)
flags_2 &= ~IN_STORAGE
update_world_icon()
return

// called when this item is added into a storage item, which is passed on as S. The loc variable is already set to the storage item.
/obj/item/proc/on_enter_storage(obj/item/weapon/storage/S)
SHOULD_CALL_PARENT(TRUE)
flags_2 |= IN_STORAGE
update_world_icon()
return
Expand Down
1 change: 1 addition & 0 deletions code/game/objects/items/weapons/shields.dm
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@
turn_off()

/obj/item/weapon/shield/energy/on_enter_storage(obj/item/weapon/storage/S)
..()
if(active)
attack_self(usr)

Expand Down
31 changes: 16 additions & 15 deletions code/game/objects/items/weapons/storage/storage.dm
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,11 @@

if(startswith)
for(var/item_path in startswith)
var/list/data = startswith[item_path]
if(islist(data))
var/qty = data[1]
var/list/argsl = data.Copy()
argsl[1] = src
for(var/i in 1 to qty)
new item_path(arglist(argsl))
else
for(var/i in 1 to (isnull(data)? 1 : data))
new item_path(src)
update_icon()
var/quantity = startswith[item_path] || 1
for(var/num in 1 to quantity)
new item_path(src)

update_icon() // todo: some storages that use content as overlays can have problems with world_icons, need to fix it in the furure while adding new world_icons (donut_box and donuts, crayons and crayon box, etc.)

/obj/item/weapon/storage/Destroy()
QDEL_NULL(storage_ui)
Expand Down Expand Up @@ -241,9 +235,17 @@

return TRUE

//This proc handles items being inserted. It does not perform any checks of whether an item can or can't be inserted. That's done by can_be_inserted()
//The stop_warning parameter will stop the insertion message from being displayed. It is intended for cases where you are inserting multiple items at once,
//such as when picking up all the items on a tile with one click.
// low level proc just to handle Move/ForceMove
/obj/item/weapon/storage/Entered(obj/item/mover)
. = ..()

if(istype(mover))
mover.on_enter_storage(src)

// Handles item insertion with related events and user feedback.
// It does not perform any checks of whether an item can or can't be inserted. That's done by can_be_inserted()
// The stop_warning parameter will stop the insertion message from being displayed. It is intended for cases where you are inserting multiple items at once,
// such as when picking up all the items on a tile with one click.
/obj/item/weapon/storage/proc/handle_item_insertion(obj/item/W, prevent_warning = FALSE, NoUpdate = FALSE)
if(!istype(W))
return FALSE
Expand All @@ -256,7 +258,6 @@
else
W.forceMove(src)

W.on_enter_storage(src)
if(usr)
add_fingerprint(usr)

Expand Down
1 change: 1 addition & 0 deletions code/game/objects/items/weapons/swords_axes_etc.dm
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
add_fingerprint(user)

/obj/item/weapon/melee/energy/sword/on_enter_storage(obj/item/weapon/storage/S)
..()
if(active)
attack_self(usr)

Expand Down
9 changes: 9 additions & 0 deletions code/modules/mining/coins.dm
Original file line number Diff line number Diff line change
Expand Up @@ -136,3 +136,12 @@
user.visible_message("[user] has flipped [src]. It lands on [coinflip].",
"<span class='notice'>You flip [src]. It lands on [coinflip].</span>",
"<span class='italics'>You hear the clattering of loose change.</span>")

/obj/item/weapon/coin/update_world_icon()
update_icon()

/obj/item/weapon/coin/update_icon()
if(item_state_world && (flags_2 & IN_INVENTORY || flags_2 & IN_STORAGE)) // big inventory icon, if we have it
icon_state = "coin_[cmineral]_[coinflip]"
else // default or small icon
icon_state = "coin_[cmineral]_[coinflip]_world"
2 changes: 1 addition & 1 deletion code/modules/mob/living/carbon/human/inventory.dm
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@
if(SLOT_IN_BACKPACK)
if(get_active_hand() == W)
remove_from_mob(W)
W.loc = src.back
W.forceMove(src.back)
if(SLOT_TIE)
var/obj/item/clothing/under/uniform = w_uniform
uniform.attach_accessory(W, src)
Expand Down

0 comments on commit 72ee311

Please sign in to comment.