Automatic stack merging

When a stock moves onto the same tile as another stack, they merge together. Unless it was being thrown, in which case no, they don't merge. Unless the stack was the original target to begin with, then yes, they do merge.

Just a convenience feature. The one downside is that crowbarring up a floor tile won't merge with other tiles on the floor, but if someone makes that event call Move() like it's supposed to, it should work fine. That would just be out of scope for this PR.
This commit is contained in:
MrPerson
2015-08-01 10:34:50 -07:00
parent 5b7c29073d
commit b0d511eff2
4 changed files with 24 additions and 47 deletions
+24 -43
View File
@@ -133,7 +133,6 @@
if (R.max_res_amount > 1)
var/obj/item/stack/new_item = O
new_item.amount = R.res_amount*multiplier
new_item.add_to_stacks(usr) //try to merge with existing stacks on current tile
if(new_item.amount <= 0)//if the stack is empty, i.e it has been merged with an existing stack and has been garbage collected
return
@@ -196,21 +195,27 @@
src.amount += amount
update_icon()
/obj/item/stack/proc/add_to_stacks(mob/usr)
var/obj/item/stack/oldsrc = src
src = null
for (var/obj/item/stack/item in usr.loc)
if (item==oldsrc)
continue
if (!istype(item, oldsrc.type))
continue
if (item.amount>=item.max_amount)
continue
oldsrc.attackby(item, usr)
usr << "<span class='notice'>You add new [item.singular_name] to the stack. It now contains [item.amount] [item.singular_name]\s.</span>"
if(oldsrc.amount <= 0)
break
oldsrc.update_icon()
/obj/item/stack/proc/merge(obj/item/stack/S) //Merge src into S, as much as possible
var/transfer = get_amount()
if(S.is_cyborg)
transfer = min(transfer, round((S.source.max_energy - S.source.energy) / S.cost))
else
transfer = min(transfer, S.max_amount - S.amount)
if(pulledby)
pulledby.start_pulling(S)
S.copy_evidences(src)
use(transfer)
S.add(transfer)
/obj/item/stack/Crossed(obj/o)
if(istype(o, src.type) && !o.throwing)
merge(o)
return ..()
/obj/item/stack/hitby(atom/movable/AM, skip, hitpush)
if(istype(AM, src.type))
merge(AM)
return ..()
/obj/item/stack/attack_hand(mob/user)
if (user.get_inactive_hand() == src)
@@ -228,34 +233,10 @@
return
/obj/item/stack/attackby(obj/item/W, mob/user, params)
if (istype(W, src.type))
if(zero_amount()) return
if(istype(W, src.type))
var/obj/item/stack/S = W
if (S.is_cyborg)
var/to_transfer = min(src.amount, round((S.source.max_energy - S.source.energy) / S.cost))
S.add(to_transfer)
if (S && usr.machine==S)
spawn(0) S.interact(usr)
src.use(to_transfer)
if (src && usr.machine==src)
spawn(0) src.interact(usr)
else
if (S.amount >= max_amount)
return
var/to_transfer as num
if (user.get_inactive_hand()==src)
to_transfer = 1
else
to_transfer = min(src.amount, S.max_amount-S.amount)
S.amount+=to_transfer
if (S && usr.machine==S)
spawn(0) S.interact(usr)
src.use(to_transfer)
if (src && usr.machine==src)
spawn(0) src.interact(usr)
S.update_icon()
merge(S)
user << "<span class='notice'>Your [S.name] stack now contains [S.get_amount()] [S.singular_name]\s.</span>"
else
..()