Skip to content

Commit

Permalink
Adds Custom Milj Option to Udders (tgstation#61224)
Browse files Browse the repository at this point in the history
  • Loading branch information
ExcessiveUseOfCobblestone authored Sep 7, 2021
1 parent 0132bd3 commit f205e72
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions code/datums/components/udder.dm
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@
///optional proc to callback to when the udder is milked
var/datum/callback/on_milk_callback

/datum/component/udder/Initialize(udder_type = /obj/item/udder, on_milk_callback, on_generate_callback)
//udder_type and reagent_produced_typepath are typepaths, not reference
/datum/component/udder/Initialize(udder_type = /obj/item/udder, on_milk_callback, on_generate_callback, reagent_produced_typepath = /datum/reagent/consumable/milk)
if(!isliving(parent)) //technically is possible to drop this on carbons... but you wouldn't do that to me, would you?
return COMPONENT_INCOMPATIBLE
udder = new udder_type(null, parent, on_generate_callback)
udder = new udder_type(null, parent, on_generate_callback, reagent_produced_typepath)
src.on_milk_callback = on_milk_callback

/datum/component/udder/RegisterWithParent()
Expand Down Expand Up @@ -60,17 +61,20 @@
*/
/obj/item/udder
name = "udder"
///typepath of reagent produced by the udder
var/reagent_produced_typepath = /datum/reagent/consumable/milk
///how much the udder holds
var/size = 50
///mob that has the udder component
var/mob/living/udder_mob
///optional proc to callback to when the udder generates milk
var/datum/callback/on_generate_callback

/obj/item/udder/Initialize(mapload, udder_mob, on_generate_callback)
/obj/item/udder/Initialize(mapload, udder_mob, on_generate_callback, reagent_produced_typepath = /datum/reagent/consumable/milk)
src.udder_mob = udder_mob
src.on_generate_callback = on_generate_callback
create_reagents(size, REAGENT_HOLDER_ALIVE)
src.reagent_produced_typepath = reagent_produced_typepath
initial_conditions()
. = ..()

Expand All @@ -88,15 +92,15 @@
* also useful for changing initial amounts in reagent holder (cows start with milk, gutlunches start empty)
*/
/obj/item/udder/proc/initial_conditions()
reagents.add_reagent(/datum/reagent/consumable/milk, 20)
reagents.add_reagent(reagent_produced_typepath, 20)
START_PROCESSING(SSobj, src)

/**
* Proc called every 2 seconds from SSMobs to add whatever reagent the udder is generating.
*/
/obj/item/udder/proc/generate()
if(prob(5))
reagents.add_reagent(/datum/reagent/consumable/milk, rand(5, 10))
reagents.add_reagent(reagent_produced_typepath, rand(5, 10))
if(on_generate_callback)
on_generate_callback.Invoke(reagents.total_volume, reagents.maximum_volume)

Expand Down

0 comments on commit f205e72

Please sign in to comment.