From 64e26b2dbd7c54e68727e1d10faabe6a11013681 Mon Sep 17 00:00:00 2001 From: mwerezak Date: Sat, 13 Dec 2014 10:24:04 -0500 Subject: [PATCH] Fixes robot stacks transferability Cleans up transferring between stacks and makes robot stacks transferable with regular ones. --- .../game/objects/items/stacks/sheets/glass.dm | 1 + .../objects/items/stacks/sheets/mineral.dm | 1 + .../items/stacks/sheets/sheet_types.dm | 2 + code/game/objects/items/stacks/stack.dm | 51 +++++++++++++------ 4 files changed, 39 insertions(+), 16 deletions(-) diff --git a/code/game/objects/items/stacks/sheets/glass.dm b/code/game/objects/items/stacks/sheets/glass.dm index ee0aa22a708..71fb87f9ad0 100644 --- a/code/game/objects/items/stacks/sheets/glass.dm +++ b/code/game/objects/items/stacks/sheets/glass.dm @@ -28,6 +28,7 @@ icon_state = "sheet-glass" matter = null created_window = /obj/structure/window/basic + stacktype = /obj/item/stack/sheet/glass /obj/item/stack/sheet/glass/attack_self(mob/user as mob) construct_window(user) diff --git a/code/game/objects/items/stacks/sheets/mineral.dm b/code/game/objects/items/stacks/sheets/mineral.dm index 530c9b5b88e..da53f168940 100644 --- a/code/game/objects/items/stacks/sheets/mineral.dm +++ b/code/game/objects/items/stacks/sheets/mineral.dm @@ -140,6 +140,7 @@ obj/item/stack/sheet/mineral/iron/New() name = "plastic sheets" icon_state = "sheet-plastic" perunit = 2000 + stacktype = /obj/item/stack/sheet/mineral/plastic /obj/item/stack/sheet/mineral/gold name = "gold" diff --git a/code/game/objects/items/stacks/sheets/sheet_types.dm b/code/game/objects/items/stacks/sheets/sheet_types.dm index de2973fc794..2e29f08a993 100644 --- a/code/game/objects/items/stacks/sheets/sheet_types.dm +++ b/code/game/objects/items/stacks/sheets/sheet_types.dm @@ -92,6 +92,7 @@ var/global/list/datum/stack_recipe/metal_recipes = list ( \ icon_state = "sheet-metal" throwforce = 14.0 flags = FPRINT | TABLEPASS | CONDUCT + stacktype = /obj/item/stack/sheet/metal /obj/item/stack/sheet/metal/New(var/loc, var/amount=null) recipes = metal_recipes @@ -152,6 +153,7 @@ var/global/list/datum/stack_recipe/wood_recipes = list ( \ desc = "One can only guess that this is a bunch of wood." singular_name = "wood plank" icon_state = "sheet-wood" + stacktype = /obj/item/stack/sheet/wood /obj/item/stack/sheet/wood/New(var/loc, var/amount=null) recipes = wood_recipes diff --git a/code/game/objects/items/stacks/stack.dm b/code/game/objects/items/stacks/stack.dm index c3fa049b17e..7d0a6b393c9 100644 --- a/code/game/objects/items/stacks/stack.dm +++ b/code/game/objects/items/stacks/stack.dm @@ -16,9 +16,12 @@ var/singular_name var/amount = 1 var/max_amount //also see stack recipes initialisation, param "max_res_amount" must be equal to this max_amount + var/stacktype //determines whether different stack types can merge /obj/item/stack/New(var/loc, var/amount=null) ..() + if (!stacktype) + stacktype = type if (amount) src.amount = amount return @@ -184,7 +187,7 @@ for (var/obj/item/stack/item in usr.loc) if (item==oldsrc) continue - if (!istype(item, oldsrc.type)) + if (item.stacktype != oldsrc.stacktype) continue if (item.amount>=item.max_amount) continue @@ -193,6 +196,23 @@ if(!oldsrc) break +//attempts to transfer amount to S, and returns the amount actually transferred +/obj/item/stack/proc/transfer_to(obj/item/stack/S, var/tamount=null) + if (stacktype != S.stacktype) + return 0 + if (isnull(tamount)) + tamount = src.amount + + var/transfer = min(tamount, src.amount, (S.max_amount - S.amount)) + + if (transfer) + if (prob(transfer/src.amount *100)) + S.copy_evidences(src) //have to do this before use() is called, unfortunately + if (oldsrc.use(transfer)) + S.add(transfer) + + return transfer + /obj/item/stack/attack_hand(mob/user as mob) if (user.get_inactive_hand() == src) var/obj/item/stack/F = new src.type(user, 1) @@ -209,28 +229,27 @@ /obj/item/stack/attackby(obj/item/W as obj, mob/user as mob) ..() - if (istype(W, src.type)) + if (istype(W, /var/obj/item/stack)) var/obj/item/stack/S = W - if (S.amount >= max_amount) - return 1 - var/to_transfer as num - if (user.get_inactive_hand()==src) - to_transfer = 1 + + var/obj/item/stack/oldsrc = src + src = null + if (user.get_inactive_hand()==oldsrc) + oldsrc.transfer_to(S, 1) else - to_transfer = min(src.amount, S.max_amount-S.amount) - S.add(to_transfer) + oldsrc.transfer_to(S) + if (S && usr.machine==S) spawn(0) S.interact(usr) - src.use(to_transfer) - if (src && usr.machine==src) - spawn(0) src.interact(usr) + if (oldsrc && usr.machine==oldsrc) + spawn(0) oldsrc.interact(usr) else return ..() /obj/item/stack/proc/copy_evidences(obj/item/stack/from as obj) - src.blood_DNA = from.blood_DNA - src.fingerprints = from.fingerprints - src.fingerprintshidden = from.fingerprintshidden - src.fingerprintslast = from.fingerprintslast + src.blood_DNA |= from.blood_DNA + src.fingerprints |= from.fingerprints + src.fingerprintshidden |= from.fingerprintshidden + src.fingerprintslast = from.fingerprintslast //TODO bloody overlay /*