Skip to content

Commit

Permalink
added description documentation, moved remove owner to behaviour dele…
Browse files Browse the repository at this point in the history
…gate and owner cleanup on qdel
  • Loading branch information
Birdtalon committed Nov 9, 2023
1 parent 3fa2ce2 commit 9ea31d9
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 28 deletions.
27 changes: 9 additions & 18 deletions code/modules/cm_aliens/structures/egg.dm
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ SPECIAL EGG USED BY EGG CARRIER
/obj/effect/alien/egg/carrier_egg
name = "fragile egg"
desc = "It looks like a weird, fragile egg."
var/owner = null
var/mob/living/carbon/xenomorph/carrier/owner = null
var/last_refreshed = null
var/life_timer = null

Expand All @@ -319,33 +319,22 @@ SPECIAL EGG USED BY EGG CARRIER
start_unstoppable_decay()
else
//Die after maximum lifetime
life_timer = addtimer(CALLBACK(src, PROC_REF(remove_owner_and_decay)), CARRIER_EGG_MAXIMUM_LIFE, TIMER_STOPPABLE)
life_timer = addtimer(CALLBACK(src, PROC_REF(start_unstoppable_decay)), CARRIER_EGG_MAXIMUM_LIFE, TIMER_STOPPABLE)
set_owner(planter)

/obj/effect/alien/egg/carrier_egg/Destroy()
. = ..()
remove_owner()
if(life_timer)
deltimer(life_timer)

/obj/effect/alien/egg/carrier_egg/proc/set_owner(mob/living/carbon/xenomorph/carrier/planter)
var/datum/behavior_delegate/carrier_eggsac/my_delegate = planter.behavior_delegate
my_delegate.eggs_sustained += src
owner = planter
RegisterSignal(owner, COMSIG_PARENT_QDELETING, PROC_REF(cleanup_owner))

/obj/effect/alien/egg/carrier_egg/proc/remove_owner()
if(owner)
var/mob/living/carbon/xenomorph/carrier/my_owner = owner
var/datum/behavior_delegate/carrier_eggsac/my_delegate = my_owner.behavior_delegate
my_delegate.eggs_sustained -= src
owner = null

/obj/effect/alien/egg/carrier_egg/proc/remove_owner_and_decay()
remove_owner()
start_unstoppable_decay()

///Check the last refreshed time and burst the egg if we're over the lifetime of the egg
/obj/effect/alien/egg/carrier_egg/proc/check_decay()
//Check the last refreshed time and burst the egg if we're over the lifetime of the egg
if(last_refreshed + CARRIER_EGG_UNSUSTAINED_LIFE < world.time)
start_unstoppable_decay()

Expand All @@ -356,8 +345,10 @@ SPECIAL EGG USED BY EGG CARRIER

/obj/effect/alien/egg/carrier_egg/Burst(kill, instant_trigger, mob/living/carbon/xenomorph/X, is_hugger_player_controlled)
. = ..()
remove_owner()
owner = null


/obj/effect/alien/egg/carrier_egg/proc/cleanup_owner()
SIGNAL_HANDLER
owner = null

#undef CARRIER_EGG_UNSUSTAINED_LIFE
#undef CARRIER_EGG_MAXIMUM_LIFE
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#define EGGSAC_OFF_WEED_EGGCAP 4

/datum/xeno_mutator/eggsac
name = "STRAIN: Carrier - Eggsac"
description = "In exchange for your ability to store huggers and place traps, you gain larger plasma stores, strong pheromones, and the ability to lay eggs by using your plasma stores. In addition, you can now carry twelve eggs at once and can place eggs one pace further than normal. You can also place a limited number of eggs on normal weeds."
description = "In exchange for your ability to store huggers and place traps, you gain larger plasma stores, strong pheromones, and the ability to lay eggs by using your plasma stores. In addition, you can now carry twelve eggs at once and can place eggs one pace further than normal. \n\nYou can also place a small number of fragile eggs on normal weeds. These eggs have a lifetime of five minutes while you remain within 14 tiles. Or one minute if you leave this range."
flavor_description = "An egg is always an adventure; the next one may be different."
cost = MUTATOR_COST_EXPENSIVE
individual_only = TRUE
Expand Down Expand Up @@ -47,7 +49,7 @@
/datum/behavior_delegate/carrier_eggsac
name = "Eggsac Carrier Behavior Delegate"
var/list/eggs_sustained = list()
var/egg_sustain_cap = 4
var/egg_sustain_cap = EGGSAC_OFF_WEED_EGGCAP
var/sustain_distance = 14

/datum/behavior_delegate/carrier_eggsac/append_to_stat()
Expand All @@ -56,8 +58,9 @@
/datum/behavior_delegate/carrier_eggsac/on_life()
if(length(eggs_sustained) > egg_sustain_cap)
var/obj/effect/alien/egg/carrier_egg/my_egg = eggs_sustained[1]
my_egg.remove_owner_and_decay()
to_chat(bound_xeno, SPAN_XENOWARNING("You can only sustain [egg_sustain_cap] eggs off hive weeds! Your last placed egg is decaying rapidly."))
remove_egg_owner(my_egg)
my_egg.start_unstoppable_decay()
to_chat(bound_xeno, SPAN_XENOWARNING("You can only sustain [egg_sustain_cap] eggs off hive weeds! Your oldest placed egg is decaying rapidly."))

for(var/obj/effect/alien/egg/carrier_egg/my_egg as anything in eggs_sustained)
//Get the distance from us to our sustained egg
Expand All @@ -66,14 +69,17 @@
else
my_egg.check_decay()

/datum/behavior_delegate/carrier_eggsac/handle_death(mob/M)
for(var/obj/effect/alien/egg/carrier_egg/my_egg as anything in eggs_sustained)
my_egg.remove_owner_and_decay()
///Remove owner of egg
/datum/behavior_delegate/carrier_eggsac/proc/remove_egg_owner(obj/effect/alien/egg/carrier_egg/egg)
if(!egg.owner || egg.owner != bound_xeno)
return
eggs_sustained -= egg
egg.owner = null

/datum/behavior_delegate/carrier_eggsac/Destroy(force, ...)
/datum/behavior_delegate/carrier_eggsac/handle_death(mob/M)
for(var/obj/effect/alien/egg/carrier_egg/my_egg as anything in eggs_sustained)
my_egg.remove_owner_and_decay()
return ..()
remove_egg_owner(my_egg)
my_egg.start_unstoppable_decay()

/datum/action/xeno_action/active_toggle/generate_egg
name = "Generate Eggs (50)"
Expand Down Expand Up @@ -110,3 +116,5 @@
xeno.eggs_cur++
to_chat(xeno, SPAN_XENONOTICE("You generate a egg. Now sheltering: [xeno.eggs_cur] / [xeno.eggs_max]."))
xeno.update_icons()

#undef EGGSAC_OFF_WEED_EGGCAP

0 comments on commit 9ea31d9

Please sign in to comment.