Files
Bubberstation/code/datums/components/egg_layer.dm
AnturK 4d6a8bc537 515 Compatibility (#71161)
Makes the code compatible with 515.1594+

Few simple changes and one very painful one.
Let's start with the easy:
* puts call behind `LIBCALL` define, so call_ext is properly used in 515
* Adds `NAMEOF_STATIC(_,X)` macro for nameof in static definitions since
src is now invalid there.
* Fixes tgui and devserver. From 515 onward the tmp3333{procid} cache
directory is not appened to base path in browser controls so we don't
check for it in base js and put the dev server dummy window file in
actual directory not the byond root.
* Renames the few things that had /final/ in typepath to ultimate since
final is a new keyword

And the very painful change:
`.proc/whatever` format is no longer valid, so we're replacing it with
new nameof() function. All this wrapped in three new macros.
`PROC_REF(X)`,`TYPE_PROC_REF(TYPE,X)`,`GLOBAL_PROC_REF(X)`. Global is
not actually necessary but if we get nameof that does not allow globals
it would be nice validation.
This is pretty unwieldy but there's no real alternative.
If you notice anything weird in the commits let me know because majority
was done with regex replace.

@tgstation/commit-access Since the .proc/stuff is pretty big change.

Co-authored-by: san7890 <the@san7890.com>
Co-authored-by: Mothblocks <35135081+Mothblocks@users.noreply.github.com>
2022-11-15 03:50:11 +00:00

90 lines
3.2 KiB
Plaintext

/**
* # egg layer component!
*
* Component that manages how many eggs to lay, what can be fed to the mob to make them lay more, and what is actually laid.
* Since the only real interaction with the component is an attackby, the nice part is that we're able to make this an atom level proc.
* egg_layer will loudly fail if you do not provide it the arguments, as to encourage explicicy(?)
*/
/datum/component/egg_layer
/// item laid by the mob
var/egg_type
/// items that can be fed to the mob to make it lay more eggs
var/list/food_types
/// messages sent when fed
var/list/feed_messages
/// messages sent when laying an egg
var/list/lay_messages
/// how many eggs left to lay
var/eggs_left
/// how many eggs to lay given from food
var/eggs_added_from_eating
/// how many eggs can be stored
var/max_eggs_held
/// callback to a proc that allows the parent to modify their new eggs
var/datum/callback/egg_laid_callback
/datum/component/egg_layer/Initialize(egg_type, food_types, feed_messages, lay_messages, eggs_left, eggs_added_from_eating, max_eggs_held, egg_laid_callback)
if(!isatom(parent)) //yes, you could make a tameable toolbox.
return COMPONENT_INCOMPATIBLE
src.egg_type = egg_type
src.food_types = food_types
src.feed_messages = feed_messages
src.lay_messages = lay_messages
src.eggs_left = eggs_left
src.eggs_added_from_eating = eggs_added_from_eating
src.max_eggs_held = max_eggs_held
src.egg_laid_callback = egg_laid_callback
START_PROCESSING(SSobj, src)
/datum/component/egg_layer/RegisterWithParent()
. = ..()
RegisterSignal(parent, COMSIG_PARENT_ATTACKBY, PROC_REF(feed_food))
/datum/component/egg_layer/UnregisterFromParent()
. = ..()
UnregisterSignal(parent, COMSIG_PARENT_ATTACKBY)
/datum/component/egg_layer/Destroy(force, silent)
. = ..()
STOP_PROCESSING(SSobj, src)
/datum/component/egg_layer/proc/feed_food(datum/source, obj/item/food, mob/living/attacker, params)
SIGNAL_HANDLER
var/atom/at_least_atom = parent
if(!is_type_in_list(food, food_types))
return
if(isliving(at_least_atom))
var/mob/living/potentially_dead_horse = at_least_atom
if(potentially_dead_horse.stat == DEAD)
to_chat(attacker, span_warning("[parent] is dead!"))
return COMPONENT_CANCEL_ATTACK_CHAIN
if(eggs_left > max_eggs_held)
to_chat(attacker, span_warning("[parent] doesn't seem hungry!"))
return COMPONENT_CANCEL_ATTACK_CHAIN
attacker.visible_message(span_notice("[attacker] hand-feeds [food] to [parent]."), span_notice("You hand-feed [food] to [parent]."))
at_least_atom.visible_message(pick(feed_messages))
qdel(food)
eggs_left += min(eggs_left + eggs_added_from_eating, max_eggs_held)
return COMPONENT_CANCEL_ATTACK_CHAIN
/datum/component/egg_layer/process(delta_time = SSOBJ_DT)
var/atom/at_least_atom = parent
if(isliving(at_least_atom))
var/mob/living/potentially_dead_horse = at_least_atom
if(potentially_dead_horse.stat != CONSCIOUS)
return
if(!eggs_left || !DT_PROB(1.5, delta_time))
return
at_least_atom.visible_message(span_alertalien("[at_least_atom] [pick(lay_messages)]"))
eggs_left--
var/obj/item/egg = new egg_type(get_turf(at_least_atom))
egg.pixel_x = rand(-6, 6)
egg.pixel_y = rand(-6, 6)
egg_laid_callback?.Invoke(egg)