mirror of
https://github.com/Aurorastation/Aurora.3.git
synced 2026-08-21 20:11:04 +01:00
Continued from #19839 > Part 1 of a refactor to try and make our various fabricators use the same system and basic code. This adds the microlathe as a proof of concept to the whole refactor, ported from Baystation. Currently not mapped anywhere. > This also ports over Nebula's autolathe working sound, however it is adapted to fit our code. As such, I went to the original sound and re-cut it, now including start and stop sounds. Plan is overall to make it much easier to add new types of fabricators. ### Asset Licenses The following assets that **have not** been created by myself are included in this PR: | Path | Original Author | License | | --- | --- | --- | | icons/obj/machinery/fabricators/microlathe.dmi | [BloodyMan](https://github.com/BloodyMan) (Baystation 12) | CC-BY-SA | | sound/machines/fabricators/autolathe/ | [pencilina](https://freesound.org/people/pencilina/) | CC-0 | --------- Co-authored-by: Cody Brittain <cbrittain10@live.com>
75 lines
3.0 KiB
Plaintext
75 lines
3.0 KiB
Plaintext
#define NO_SPACE "No Space"
|
|
#define FILL_COMPLETELY "Fill Completely"
|
|
#define FILL_INCOMPLETELY "Fill Incompletely"
|
|
|
|
///Loads the lathe with materials
|
|
/obj/machinery/fabricator/proc/load_lathe(obj/item/loading_item, mob/user)
|
|
|
|
//Resources are being loaded.
|
|
var/obj/item/eating = loading_item
|
|
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.
|
|
var/is_stack = FALSE //Affects the fill message
|
|
|
|
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
|
|
is_stack = TRUE
|
|
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])][is_stack ? "." : " from \the [eating]."]"))
|
|
else if(fill_status[FILL_INCOMPLETELY])
|
|
to_chat(user, SPAN_NOTICE("You fill \the [src] with [english_list(fill_status[FILL_INCOMPLETELY])][is_stack ? "." : " from \the [eating]."]"))
|
|
|
|
// Plays metal insertion animation.
|
|
if(istype(eating, /obj/item/stack/material) && does_flick)
|
|
var/obj/item/stack/material/sheet = eating
|
|
var/image/adding_mat_overlay = overlay_image(icon, "[icon_state]_mat")
|
|
adding_mat_overlay.color = sheet.material.icon_colour
|
|
AddOverlays(adding_mat_overlay)
|
|
CUT_OVERLAY_IN(adding_mat_overlay, 1 SECOND)
|
|
|
|
// Play the lights animation (even if what we inserted wasn't a stack)
|
|
if(powered() && does_flick)
|
|
flick_overlay_view(mutable_appearance(icon, "[icon_state]_progress"), 1 SECONDS)
|
|
|
|
if(istype(eating, /obj/item/stack))
|
|
var/obj/item/stack/stack = eating
|
|
var/amount_needed = total_used / mass_per_sheet
|
|
stack.use(min(stack.get_amount(), (round(amount_needed) == amount_needed)? amount_needed : round(amount_needed) + 1)) // Prevent maths imprecision from leading to infinite resources
|
|
else
|
|
user.remove_from_mob(loading_item)
|
|
qdel(loading_item)
|
|
|
|
#undef NO_SPACE
|
|
#undef FILL_COMPLETELY
|
|
#undef FILL_INCOMPLETELY
|