[Ready] Polishes some space checks in material containers (#50951)

* Mostly fixes material containers

* Please enter the commit message for your changes. Lines starting

* Reverts previous commit since that didn't work

This reverts commit c1da35c62912ce1173696e9bfe6e35aed4cdefea.

* finally working

* travis please

Co-authored-by: TerraGS <TerraGS@users.noreply.github.com>
This commit is contained in:
TerraGS
2020-05-25 07:20:43 +02:00
committed by GitHub
co-authored by TerraGS
parent 78d18318f4
commit 5dc9ec3901
+33 -18
View File
@@ -1,6 +1,5 @@
/*!
This datum should be used for handling mineral contents of machines and whatever else is supposed to hold minerals and make use of them.
Variables:
amount - raw amount of the mineral this container is holding, calculated by the defined value MINERAL_MATERIAL_AMOUNT=2000.
max_amount - max raw amount of mineral this container can hold.
@@ -73,7 +72,7 @@
if(!material_amount)
to_chat(user, "<span class='warning'>[I] does not contain sufficient materials to be accepted by [parent].</span>")
return
if(!has_space(material_amount))
if((!istype(I, /obj/item/stack) && !has_space(material_amount)) || (!has_space(MINERAL_MATERIAL_AMOUNT)))
to_chat(user, "<span class='warning'>[parent] is full. Please remove materials from [parent] in order to insert more.</span>")
return
user_insert(I, user)
@@ -83,46 +82,62 @@
set waitfor = FALSE
var/requested_amount
var/active_held = user.get_active_held_item() // differs from I when using TK
if(istype(I, /obj/item/stack) && precise_insertion)
var/atom/current_parent = parent
var/obj/item/stack/S = I
requested_amount = input(user, "How much do you want to insert?", "Inserting [S.singular_name]s") as num|null
if(isnull(requested_amount) || (requested_amount <= 0))
return
if(QDELETED(I) || QDELETED(user) || QDELETED(src) || parent != current_parent || user.physical_can_use_topic(current_parent) < UI_INTERACTIVE || user.get_active_held_item() != active_held)
return
if(istype(I, /obj/item/stack))
if(precise_insertion)
var/atom/current_parent = parent
var/obj/item/stack/S = I
requested_amount = input(user, "How much do you want to insert?", "Inserting [S.singular_name]s") as num|null
if(isnull(requested_amount) || (requested_amount <= 0))
return
if(QDELETED(I) || QDELETED(user) || QDELETED(src) || parent != current_parent || user.physical_can_use_topic(current_parent) < UI_INTERACTIVE || user.get_active_held_item() != active_held)
return
else
if((total_amount + get_item_material_amount(I)) <= max_amount)
requested_amount = get_item_material_amount(I)
else
requested_amount = (max_amount-total_amount)
if(!user.temporarilyRemoveItemFromInventory(I))
to_chat(user, "<span class='warning'>[I] is stuck to you and cannot be placed into [parent].</span>")
return
var/inserted = insert_item(I, stack_amt = requested_amount)
var/inserted = insert_item(I, amt = requested_amount)
if(inserted)
to_chat(user, "<span class='notice'>You insert a material total of [inserted] into [parent].</span>")
qdel(I)
if(get_item_material_amount(I) - inserted)
user.put_in_active_hand(I)
if(istype(I, /obj/item/stack))
var/obj/item/stack/S = I
S.use(inserted / MINERAL_MATERIAL_AMOUNT)
I = S
else
qdel(I)
if(after_insert)
after_insert.Invoke(I, last_inserted_id, inserted)
else if(I == active_held)
user.put_in_active_hand(I)
/// Proc specifically for inserting items, returns the amount of materials entered.
/datum/component/material_container/proc/insert_item(obj/item/I, var/multiplier = 1, stack_amt)
/datum/component/material_container/proc/insert_item(obj/item/I, var/multiplier = 1, amt)
if(!I)
return FALSE
multiplier = CEILING(multiplier, 0.01)
var/material_amount = get_item_material_amount(I)
if(!material_amount || !has_space(material_amount))
if(!amt)
return FALSE
if(!istype(I, /obj/item/stack) && !has_space(amt))
return FALSE
if(istype(I, /obj/item/stack))
amt = amount2sheet(amt) * MINERAL_MATERIAL_AMOUNT
last_inserted_id = insert_item_materials(I, multiplier)
return material_amount
return amt
/datum/component/material_container/proc/insert_item_materials(obj/item/I, multiplier = 1)
var/primary_mat
var/max_mat_value = 0
for(var/MAT in materials)
materials[MAT] += I.custom_materials[MAT] * multiplier
total_amount += I.custom_materials[MAT] * multiplier
materials[MAT] += can_insert_amount_mat(I.custom_materials[MAT] * multiplier, MAT)
total_amount += can_insert_amount_mat(I.custom_materials[MAT] * multiplier, MAT)
if(I.custom_materials[MAT] > max_mat_value)
primary_mat = MAT
return primary_mat