Make stack amount var private

This commit is contained in:
Aronai Sieyes
2021-08-19 21:06:46 -04:00
parent ab7b3fcad9
commit e52031d6aa
72 changed files with 241 additions and 297 deletions
+1 -2
View File
@@ -29,8 +29,7 @@
to_chat(user, "<span class='warning'>There is another network terminal here.</span>")
return
else
var/obj/item/stack/cable_coil/C = new /obj/item/stack/cable_coil(loc)
C.amount = 10
new /obj/item/stack/cable_coil(loc, 10)
to_chat(user, "You cut the cables and disassemble the unused power terminal.")
qdel(T)
new /obj/machinery/power/apc(loc, ndir, 1)
@@ -127,7 +127,7 @@ var/list/marker_beacon_colors = list(
if(istype(I, /obj/item/stack/marker_beacon))
var/obj/item/stack/marker_beacon/M = I
to_chat(user, "<span class='notice'>You start picking [src] up...</span>")
if(do_after(user, remove_speed, target = src) && M.amount + 1 <= M.max_amount)
if(do_after(user, remove_speed, target = src) && M.get_amount() + 1 <= M.max_amount)
M.add(1)
playsound(src, 'sound/items/deconstruct.ogg', 50, 1)
qdel(src)
+42 -6
View File
@@ -17,7 +17,7 @@
center_of_mass = null
var/list/datum/stack_recipe/recipes
var/singular_name
var/amount = 1
VAR_PROTECTED/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
var/build_type = null //used when directly applied to a turf
@@ -33,8 +33,10 @@
. = ..()
if(!stacktype)
stacktype = type
if(amount)
src.amount = amount
if(!isnull(amount)) // Could be 0
if(amount < 0)
amount = max_amount
set_amount(amount, TRUE)
update_icon()
/obj/item/stack/Destroy()
@@ -229,12 +231,15 @@
//Return 1 if an immediate subsequent call to use() would succeed.
//Ensures that code dealing with stacks uses the same logic
/obj/item/stack/proc/can_use(var/used)
if (get_amount() < used)
if(used < 0 || used % 1)
stack_trace("Tried to use a bad stack amount: [used]")
return 0
if(get_amount() < used)
return 0
return 1
/obj/item/stack/proc/use(var/used)
if (!can_use(used))
if(!can_use(used))
return 0
if(!uses_charge)
amount -= used
@@ -251,6 +256,9 @@
return 1
/obj/item/stack/proc/add(var/extra)
if(extra < 0 || extra % 1)
stack_trace("Tried to add a bad stack amount: [extra]")
return 0
if(!uses_charge)
if(amount + extra > get_max_amount())
return 0
@@ -265,6 +273,27 @@
var/datum/matter_synth/S = synths[i]
S.add_charge(charge_costs[i] * extra)
/obj/item/stack/proc/set_amount(var/new_amount, var/no_limits = FALSE)
if(new_amount < 0 || new_amount % 1)
stack_trace("Tried to set a bad stack amount: [new_amount]")
return 0
// Clean up the new amount
new_amount = max(round(new_amount), 0)
// Can exceed max if you really want
if(new_amount > max_amount && !no_limits)
new_amount = max_amount
amount = new_amount
// Can set it to 0 without qdel if you really want
if(amount == 0 && !no_limits)
qdel(src)
return FALSE
return TRUE
/*
The transfer and split procs work differently than use() and add().
Whereas those procs take no action if the desired amount cannot be added or removed these procs will try to transfer whatever they can.
@@ -282,6 +311,10 @@
if (isnull(tamount))
tamount = src.get_amount()
if(tamount < 0 || tamount % 1)
stack_trace("Tried to transfer a bad stack amount: [tamount]")
return 0
var/transfer = max(min(tamount, src.get_amount(), (S.get_max_amount() - S.get_amount())), 0)
@@ -302,7 +335,10 @@
if(uses_charge)
return null
tamount = round(tamount)
if(tamount < 0 || tamount % 1)
stack_trace("Tried to split a bad stack amount: [tamount]")
return null
var/transfer = max(min(tamount, src.amount, initial(max_amount)), 0)
var/orig_amount = src.amount
@@ -130,10 +130,10 @@
/obj/item/weapon/card/emag/attackby(obj/item/O as obj, mob/user as mob)
if(istype(O, /obj/item/stack/telecrystal))
var/obj/item/stack/telecrystal/T = O
if(T.amount < 1)
if(T.get_amount() < 1)
to_chat(usr, "<span class='notice'>You are not adding enough telecrystals to fuel \the [src].</span>")
return
uses += T.amount/2 //Gives 5 uses per 10 TC
uses += T.get_amount()*0.5 //Gives 5 uses per 10 TC
uses = CEILING(uses, 1) //Ensures no decimal uses nonsense, rounds up to be nice
to_chat(usr, "<span class='notice'>You add \the [O] to \the [src]. Increasing the uses of \the [src] to [uses].</span>")
qdel(O)
@@ -13,7 +13,7 @@
/obj/item/weapon/whetstone/attackby(obj/item/I, mob/user)
if(istype(I, /obj/item/stack/material))
var/obj/item/stack/material/M = I
if(M.amount >= 5)
if(M.get_amount() >= 5)
to_chat(user, "You begin to refine the [src] with [M]...")
if(do_after(user, 70))
M.use(5)
+23 -25
View File
@@ -245,7 +245,7 @@
return 0
var/current = 0
for(var/obj/item/stack/material/S in contents)
current += S.amount
current += S.get_amount()
if(capacity == current)//If it's full, you're done
if(!stop_messages)
to_chat(usr, "<span class='warning'>The snatcher is full.</span>")
@@ -262,29 +262,27 @@
var/inserted = 0
var/current = 0
for(var/obj/item/stack/material/S2 in contents)
current += S2.amount
if(capacity < current + S.amount)//If the stack will fill it up
current += S2.get_amount()
if(capacity < current + S.get_amount())//If the stack will fill it up
amount = capacity - current
else
amount = S.amount
amount = S.get_amount()
for(var/obj/item/stack/material/sheet in contents)
if(S.type == sheet.type) // we are violating the amount limitation because these are not sane objects
sheet.amount += amount // they should only be removed through procs in this file, which split them up.
S.amount -= amount
if(S.type == sheet.type)
// we are violating the amount limitation because these are not sane objects
sheet.set_amount(sheet.get_amount() + amount, TRUE)
S.use(amount) // will qdel() if we use it all
inserted = 1
break
if(!inserted || !S.amount)
if(!inserted)
usr.remove_from_mob(S)
usr.update_icons() //update our overlays
if (usr.client && usr.s_active != src)
usr.client.screen -= S
S.dropped(usr)
if(!S.amount)
qdel(S)
else
S.loc = src
S.loc = src
orient2hud(usr)
if(usr.s_active)
@@ -305,7 +303,7 @@
for(var/obj/item/stack/material/I in contents)
adjusted_contents++
var/datum/numbered_display/D = new/datum/numbered_display(I)
D.number = I.amount
D.number = I.get_amount()
numbered_contents.Add( D )
var/row_num = 0
@@ -319,14 +317,14 @@
/obj/item/weapon/storage/bag/sheetsnatcher/quick_empty()
var/location = get_turf(src)
for(var/obj/item/stack/material/S in contents)
while(S.amount)
var/obj/item/stack/material/N = new S.type(location)
var/stacksize = min(S.amount,N.max_amount)
N.amount = stacksize
S.amount -= stacksize
N.update_icon()
if(!S.amount)
qdel(S) // todo: there's probably something missing here
var/cur_amount = S.get_amount()
var/full_stacks = round(cur_amount / S.max_amount) // Floor of current/max is amount of full stacks we make
var/remainder = cur_amount % S.max_amount // Current mod max is remainder after full sheets removed
for(var/i = 1 to full_stacks)
new S.type(location, S.max_amount)
if(remainder)
new S.type(location, remainder)
S.set_amount(0)
orient2hud(usr)
if(usr.s_active)
usr.s_active.show_to(usr)
@@ -342,10 +340,10 @@
//Therefore, make a new stack internally that has the remainder.
// -Sayu
if(S.amount > S.max_amount)
var/obj/item/stack/material/temp = new S.type(src)
temp.amount = S.amount - S.max_amount
S.amount = S.max_amount
if(S.get_amount() > S.max_amount)
var/newstack_amt = S.get_amount() - S.max_amount
new S.type(src, newstack_amt) // The one we'll keep to replace the one we give
S.set_amount(S.max_amount) // The one we hand to the clicker
return ..(S,new_location)
@@ -116,7 +116,6 @@
for(var/i = 0, i<2, i++)
for(var/res in resources)
var/obj/item/stack/R = new res(src)
R.amount = R.max_amount
new res(src, -1)
return ..()
+1 -2
View File
@@ -43,8 +43,7 @@
to_chat(user, "<span class='notice'>You start to cut the shower curtains.</span>")
if(do_after(user, 10))
to_chat(user, "<span class='notice'>You cut the shower curtains.</span>")
var/obj/item/stack/material/plastic/A = new /obj/item/stack/material/plastic( src.loc )
A.amount = 3
new /obj/item/stack/material/plastic(src.loc, 3)
qdel(src)
return
else
+1 -2
View File
@@ -113,8 +113,7 @@
if(finished)
to_chat(user, "<span class='notice'>You start breaking down \the [src].</span>")
if(do_after(user, 10 SECONDS, src, exclusive = TASK_ALL_EXCLUSIVE))
var/obj/item/stack/S = new /obj/item/stack/material/plasteel(loc)
S.amount = 10
new /obj/item/stack/material/plasteel(loc, 10)
playsound(user, O.usesound, 50, 1)
qdel(src)
else
+1 -2
View File
@@ -101,8 +101,7 @@
return
if(product && product_amount) // Make wooden logs.
var/obj/item/stack/material/M = new product(get_turf(src))
M.amount = product_amount
var/obj/item/stack/material/M = new product(get_turf(src), product_amount)
M.update_icon()
visible_message("<span class='danger'>\The [src] is felled!</span>")
stump()
+1 -2
View File
@@ -22,8 +22,7 @@
to_chat(user, "<span class='notice'>You start to cut the plastic flaps.</span>")
if(do_after(user, 10 * P.toolspeed))
to_chat(user, "<span class='notice'>You cut the plastic flaps.</span>")
var/obj/item/stack/material/plastic/A = new /obj/item/stack/material/plastic( src.loc )
A.amount = 4
new /obj/item/stack/material/plastic(src.loc, 4)
qdel(src)
return
else
+1 -1
View File
@@ -297,7 +297,7 @@
visible_message("<span class='notice'>[user] dismantles \the [src].</span>")
var/obj/item/stack/material/mats = new glasstype(loc)
if(is_fulltile())
mats.amount = 4
mats.set_amount(4)
qdel(src)
else if(istype(W, /obj/item/stack/cable_coil) && reinf && state == 0 && !istype(src, /obj/structure/window/reinforced/polarized))
var/obj/item/stack/cable_coil/C = W