diff --git a/code/game/machinery/autolathe/autolathe.dm b/code/game/machinery/autolathe/autolathe.dm index b19ee182093..24e06172624 100644 --- a/code/game/machinery/autolathe/autolathe.dm +++ b/code/game/machinery/autolathe/autolathe.dm @@ -174,55 +174,7 @@ if(is_robot_module(O)) return FALSE - //Resources are being loaded. - var/obj/item/eating = O - if(!eating.matter || !eating.recyclable) - to_chat(user, SPAN_WARNING("\The [eating] cannot be recycled by \the [src].")) - return - - var/filltype = 0 // Used to determine message. - var/total_used = 0 // Amount of material used. - var/mass_per_sheet = 0 // Amount of material constituting one sheet. - - for(var/material in eating.matter) - if(isnull(stored_material[material]) || isnull(storage_capacity[material])) - continue - if(stored_material[material] >= storage_capacity[material]) - continue - - var/total_material = eating.matter[material] - - //If it's a stack, we eat multiple sheets. - if(istype(eating, /obj/item/stack)) - var/obj/item/stack/stack = eating - total_material *= stack.get_amount() - - if(stored_material[material] + total_material > storage_capacity[material]) - total_material = storage_capacity[material] - stored_material[material] - filltype = 1 - else - filltype = 2 - - stored_material[material] += total_material - total_used += total_material - mass_per_sheet += eating.matter[material] - - if(!filltype) - to_chat(user, SPAN_WARNING("\The [src] is full. Please remove some material in order to insert more.")) - return - else if(filltype == 1) - to_chat(user, SPAN_NOTICE("You fill \the [src] to capacity with \the [eating].")) - else - to_chat(user, SPAN_NOTICE("You fill \the [src] with \the [eating].")) - - flick("autolathe_o", src) // Plays metal insertion animation. Work out a good way to work out a fitting animation. ~Z - - if(istype(eating, /obj/item/stack)) - var/obj/item/stack/stack = eating - stack.use(max(1, round(total_used / mass_per_sheet))) // Always use at least 1 to prevent infinite materials. - else - user.remove_from_mob(O) - qdel(O) + load_lathe(O, user) updateUsrDialog() return @@ -334,3 +286,64 @@ qdel(S) ..() return TRUE + +#define NO_SPACE "No Space" +#define FILL_COMPLETELY "Fill Completely" +#define FILL_INCOMPLETELY "Fill Incompletely" + +/obj/machinery/autolathe/proc/load_lathe(obj/item/O, mob/user) + + //Resources are being loaded. + var/obj/item/eating = O + if(!eating.matter || !eating.recyclable) + to_chat(user, SPAN_WARNING("\The [eating] cannot be recycled by \the [src].")) + return + + var/list/fill_status = list() // Used to determine message in cases of multiple materials. + var/total_used = 0 // Amount of material used. + var/mass_per_sheet = 0 // Amount of material constituting one sheet. + + for(var/material in eating.matter) + if(isnull(stored_material[material]) || isnull(storage_capacity[material])) + continue + if(stored_material[material] >= storage_capacity[material]) + LAZYADD(fill_status[NO_SPACE], material) + continue + + var/total_material = eating.matter[material] + + //If it's a stack, we eat multiple sheets. + if(istype(eating, /obj/item/stack)) + var/obj/item/stack/stack = eating + total_material *= stack.get_amount() + + if(stored_material[material] + total_material > storage_capacity[material]) + total_material = storage_capacity[material] - stored_material[material] + LAZYADD(fill_status[FILL_COMPLETELY], material) + else + LAZYADD(fill_status[FILL_INCOMPLETELY], material) + + stored_material[material] += total_material + total_used += total_material + mass_per_sheet += eating.matter[material] + + if(fill_status[NO_SPACE]) + to_chat(user, SPAN_WARNING("\The [src] is full of [english_list(fill_status[NO_SPACE])]. Please remove some material in order to insert more.")) + return + else if(fill_status[FILL_COMPLETELY]) + to_chat(user, SPAN_NOTICE("You fill \the [src] to capacity with [english_list(fill_status[FILL_COMPLETELY])] with \the [eating].")) + else if(fill_status[FILL_INCOMPLETELY]) + to_chat(user, SPAN_NOTICE("You fill \the [src] with [english_list(fill_status[FILL_INCOMPLETELY])] \the [eating].")) + + flick("autolathe_o", src) // Plays metal insertion animation. Work out a good way to work out a fitting animation. ~Z + + if(istype(eating, /obj/item/stack)) + var/obj/item/stack/stack = eating + stack.use(min(stack.get_amount(), total_used / mass_per_sheet)) // Prevent maths imprecision from leading to infinite resources + else + user.remove_from_mob(O) + qdel(O) + +#undef NO_SPACE +#undef FILL_COMPLETELY +#undef FILL_INCOMPLETELY \ No newline at end of file diff --git a/code/game/objects/items/stacks/stack.dm b/code/game/objects/items/stacks/stack.dm index 72817c8c91e..403df8e9a66 100644 --- a/code/game/objects/items/stacks/stack.dm +++ b/code/game/objects/items/stacks/stack.dm @@ -213,8 +213,6 @@ update_icon() return 1 else - if(get_amount() < used) - return 0 for(var/i = 1 to charge_costs.len) var/datum/matter_synth/S = synths[i] if(!S.use_charge(charge_costs[i] * used)) // Doesn't need to be deleted diff --git a/html/changelogs/lathe_loading_bugfix.yml b/html/changelogs/lathe_loading_bugfix.yml new file mode 100644 index 00000000000..edd430d7c23 --- /dev/null +++ b/html/changelogs/lathe_loading_bugfix.yml @@ -0,0 +1,6 @@ +author: mikomyazaki +delete-after: True + +changes: + - bugfix: "Fixed issue where trying to load a lathe with <1 of a sheet of something didn't delete the sheet item." + - bugfix: "Fixed issue where loading a lathe with an object consisting of >1 materials could provide incorrect messages about how full it is."