Skip to content

Commit

Permalink
Ready-to-test stockpile demo
Browse files Browse the repository at this point in the history
  • Loading branch information
Vladisvell committed Nov 19, 2024
1 parent 4c12490 commit 9203308
Showing 1 changed file with 99 additions and 0 deletions.
99 changes: 99 additions & 0 deletions code/game/objects/items/weapons/storage/stacked.dm
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,103 @@
* - Player can walk over stack.
* - Integrity of stack is determenied by summary of stacked items.
* - One by one items are deleted from stack if stack is damaged by integrity of one stack item.
* - Player can take items from a stack using bags.
* - Icon and icon state is determined by item it is holding.
* - Player can't add items to a stockpile.
*/

/// Abstract stacked item. Do not spawn directly
/obj/stacked_item
name = "Stockpiled item"
desc = "Stockpile of some items."
anchored = TRUE
density = FALSE
var/holding_type
var/list/internal_storage = list()

/obj/stacked_item/Initialize(mapload)
. = ..()

/obj/stacked_item/Destroy()
. = ..()
QDEL_LIST(internal_storage)

/// Enriches the contents of stockpile
/obj/stacked_item/proc/enrich_contents(list/contents_to_add)
if(length(contents_to_add) < 1)
stack_trace("Attempted to make a stockpile from no contents")

for(var/obj/item/item in contents_to_add)
item.forceMove(src)

internal_storage = contents_to_add
var/obj/item/item = internal_storage[1]
holding_type = item.type
obj_integrity = item.max_integrity * length(internal_storage)
max_integrity = item.max_integrity * length(internal_storage)
name = "Stockpile of [item.name]"
desc = "This is a stockpile of [item.name]"

update_icon(ALL)

/obj/stacked_item/update_icon_state()
if(length(internal_storage) < 1)
return

var/obj/item/item = internal_storage[1]
icon = item.icon
icon_state = item.icon_state
appearance = item.appearance
maptext = "<font color='white' face='Small Fonts'>[(length(internal_storage) > 1) ? "[length(internal_storage)]" : ""]</font>"

/obj/stacked_item/update_overlays()
. = ..()


/// Retrieves and removes item from internal storage. Returns reference to removed item.
/obj/stacked_item/proc/remove_item(obj/item/item_to_remove)
internal_storage -= item_to_remove
contents -= item_to_remove
update_icon(ALL)
return item_to_remove

/// Returns item from a stack
/obj/stacked_item/proc/get_item()
if(length(internal_storage) < 1)
return

return internal_storage[length(internal_storage) - 1]

/obj/stacked_item/attack_hand(mob/living/user, list/modifiers)
var/obj/item/item = get_item()
if(user.put_in_active_hand(item, ignore_anim = FALSE))
remove_item(item)
return


/obj/stacked_item/take_damage(damage_amount, damage_type, damage_flag, sound_effect, attack_dir, armour_penetration)
var/cached_integrity = obj_integrity
var/destroy_step = max_integrity / length(internal_storage)
. = ..()
var/resulting_integrity = obj_integrity
var/items_to_destroy = round((cached_integrity - resulting_integrity) / destroy_step)
if(items_to_destroy < 1)
return

for(var/items in items_to_destroy)
remove_item()


/obj/stacked_item_test

/obj/stacked_item_test/Initialize(mapload)
. = ..()
var/obj/stacked_item/stockpile = new /obj/stacked_item(get_turf(src))
var/list/objects_to_add = list()
for(var/i in 1 to 100)
var/item = new /obj/item/reagent_containers/food/snacks/grown/ambrosia/gaia(src)
objects_to_add += item

stockpile.enrich_contents(objects_to_add)

return INITIALIZE_HINT_QDEL

0 comments on commit 9203308

Please sign in to comment.