mirror of
https://github.com/Bubberstation/Bubberstation.git
synced 2026-08-23 05:00:55 +01:00
103 lines
4.0 KiB
Plaintext
103 lines
4.0 KiB
Plaintext
/// Atoms that can be microwaved from one type to another.
|
|
/datum/element/microwavable
|
|
element_flags = ELEMENT_BESPOKE
|
|
argument_hash_start_idx = 2
|
|
/// Resulting atom typepath on a completed microwave.
|
|
var/atom/result_typepath
|
|
/// Reagents that should be added to the result
|
|
var/list/added_reagents
|
|
|
|
/datum/element/microwavable/Attach(obj/item/target, microwave_type, list/reagents, bad_recipe = FALSE)
|
|
. = ..()
|
|
if(!istype(target))
|
|
return ELEMENT_INCOMPATIBLE
|
|
if(!microwave_type)
|
|
CRASH("microwavable element attached without a microwave_type arg")
|
|
|
|
result_typepath = microwave_type
|
|
added_reagents = reagents
|
|
if(!bad_recipe)
|
|
ADD_TRAIT(target, TRAIT_MICROWAVABLE, REF(src))
|
|
RegisterSignal(target, COMSIG_ATOM_EXAMINE, PROC_REF(on_examine))
|
|
|
|
RegisterSignal(target, COMSIG_ITEM_MICROWAVE_ACT, PROC_REF(on_microwaved))
|
|
|
|
if(!PERFORM_ALL_TESTS(focus_only/check_materials_when_processed) || bad_recipe || !target.custom_materials || isstack(target))
|
|
return
|
|
|
|
var/atom/result = new result_typepath
|
|
if(!target.compare_materials(result))
|
|
var/warning = "custom_materials of [result.type] when microwaved compared to just spawned don't match"
|
|
var/what_it_should_be = target.transcribe_materials_list()
|
|
stack_trace("[warning]. should be: custom_materials = [what_it_should_be].")
|
|
qdel(result)
|
|
|
|
/datum/element/microwavable/Detach(datum/source)
|
|
UnregisterSignal(source, list(COMSIG_ITEM_MICROWAVE_ACT, COMSIG_ATOM_EXAMINE))
|
|
return ..()
|
|
|
|
/**
|
|
* Signal proc for [COMSIG_ITEM_MICROWAVE_ACT].
|
|
* Handles the actual microwaving part.
|
|
*/
|
|
/datum/element/microwavable/proc/on_microwaved(atom/source, obj/machinery/microwave/used_microwave, mob/microwaver, randomize_pixel_offset)
|
|
SIGNAL_HANDLER
|
|
|
|
var/atom/result
|
|
var/turf/result_loc = get_turf(used_microwave || source)
|
|
if(isstack(source))
|
|
var/obj/item/stack/stack_source = source
|
|
result = new result_typepath(result_loc, stack_source.amount)
|
|
else
|
|
result = new result_typepath(result_loc)
|
|
result.set_custom_materials(source.custom_materials)
|
|
|
|
var/efficiency = istype(used_microwave) ? used_microwave.efficiency : 1
|
|
|
|
if(IS_EDIBLE(result) && HAS_TRAIT(source, TRAIT_MICROWAVABLE))
|
|
BLACKBOX_LOG_FOOD_MADE(result.type)
|
|
|
|
if(istype(source, /obj/item/food) && istype(result, /obj/item/food))
|
|
var/obj/item/food/original_food = source
|
|
var/obj/item/food/microwaved_food = result
|
|
LAZYADD(microwaved_food.intrinsic_food_materials, original_food.intrinsic_food_materials)
|
|
|
|
if(microwaver && microwaver.mind)
|
|
ADD_TRAIT(result, TRAIT_HANDMADE, REF(microwaver.mind))
|
|
|
|
//make space and tranfer reagents if it has any, also let any bad result handle removing or converting the transferred reagents on its own terms
|
|
if(result.reagents && source.reagents)
|
|
result.reagents.clear_reagents()
|
|
source.reagents.trans_to(result, source.reagents.total_volume)
|
|
if(added_reagents) // Add any new reagents that should be added
|
|
result.reagents.add_reagent_list(added_reagents)
|
|
|
|
SEND_SIGNAL(source, COMSIG_ITEM_MICROWAVE_COOKED, result, efficiency)
|
|
SEND_SIGNAL(result, COMSIG_ITEM_MICROWAVE_COOKED_RESULT, source, efficiency)
|
|
|
|
var/recipe_result = COMPONENT_MICROWAVE_SUCCESS
|
|
if(!HAS_TRAIT(source, TRAIT_MICROWAVABLE))
|
|
recipe_result |= COMPONENT_MICROWAVE_BAD_RECIPE
|
|
|
|
qdel(source)
|
|
|
|
if(randomize_pixel_offset && isitem(result))
|
|
var/obj/item/result_item = result
|
|
if(!(result_item.item_flags & NO_PIXEL_RANDOM_DROP))
|
|
result_item.pixel_x = result_item.base_pixel_x + rand(-6, 6)
|
|
result_item.pixel_y = result_item.base_pixel_y + rand(-5, 6)
|
|
|
|
return recipe_result
|
|
|
|
/**
|
|
* Signal proc for [COMSIG_ATOM_EXAMINE].
|
|
* Lets examiners know we can be microwaved if we're not the default mess type
|
|
*/
|
|
/datum/element/microwavable/proc/on_examine(atom/source, mob/user, list/examine_list)
|
|
SIGNAL_HANDLER
|
|
|
|
if(initial(result_typepath.gender) == PLURAL)
|
|
examine_list += span_notice("[source] can be [span_bold("microwaved")] into some [initial(result_typepath.name)].")
|
|
else
|
|
examine_list += span_notice("[source] can be [span_bold("microwaved")] into \a [initial(result_typepath.name)].")
|