diff --git a/code/modules/mob/living/simple_animal/hostile/hivebots/hivebot.dm b/code/modules/mob/living/simple_animal/hostile/hivebots/hivebot.dm index 6e93b20cf3d..55aed40526d 100644 --- a/code/modules/mob/living/simple_animal/hostile/hivebots/hivebot.dm +++ b/code/modules/mob/living/simple_animal/hostile/hivebots/hivebot.dm @@ -48,22 +48,38 @@ */ var/mob/living/simple_animal/hostile/hivebotbeacon/linked_parent = null -/mob/living/simple_animal/hostile/hivebot/Initialize(mapload,mob/living/simple_animal/hostile/hivebot/hivebotbeacon) +/mob/living/simple_animal/hostile/hivebot/Initialize(mapload,mob/living/simple_animal/hostile/hivebotbeacon/beacon) . = ..() - if(hivebotbeacon) - linked_parent = hivebotbeacon - + do_link(beacon) if(!mapload) spark(get_turf(src), 2, GLOB.alldirs) /mob/living/simple_animal/hostile/hivebot/Destroy() - if(linked_parent) - linked_parent.linked_bots -= src - linked_parent = null - + unlink() . = ..() +/mob/living/simple_animal/hostile/hivebot/proc/do_link(mob/living/simple_animal/hostile/hivebotbeacon/beacon) + if(QDELETED(beacon)) + return + + if(linked_parent) + if(linked_parent == beacon) + return + unlink() + + linked_parent = beacon + beacon.do_link(src) + RegisterSignal(linked_parent, COMSIG_QDELETING, PROC_REF(unlink)) + +/mob/living/simple_animal/hostile/hivebot/proc/unlink() + SIGNAL_HANDLER + if(!linked_parent) + return + linked_parent.unlink(src) + UnregisterSignal(linked_parent, COMSIG_QDELETING) + linked_parent = null + /mob/living/simple_animal/hostile/hivebot/get_bullet_impact_effect_type(var/def_zone) return BULLET_IMPACT_METAL @@ -97,12 +113,10 @@ var/robot_gib_type = /obj/effect/decal/cleanable/blood/gibs/robot var/atom/turf_gibs = locate(robot_gib_type) in current_turf - if(turf_gibs) // we only want to spawn gibs here if there aren't any already - return - - var/list/gib_types = typesof(robot_gib_type) - var/selected_gib_type = pick(gib_types) - new selected_gib_type(current_turf) + if(!turf_gibs) // we only want to spawn gibs here if there aren't any already + var/list/gib_types = typesof(robot_gib_type) + var/selected_gib_type = pick(gib_types) + new selected_gib_type(current_turf) spark(current_turf, 1, GLOB.alldirs) @@ -155,16 +169,6 @@ mob_swap_flags = ~HEAVY mob_push_flags = 0 -/mob/living/simple_animal/hostile/hivebot/guardian/Initialize(mapload,mob/living/simple_animal/hostile/hivebot/hivebotbeacon) - .=..() - if(hivebotbeacon && linked_parent) - linked_parent.guard_amt++ - -/mob/living/simple_animal/hostile/hivebot/guardian/Destroy() - .=..() - if(linked_parent) - linked_parent.guard_amt-- - /mob/living/simple_animal/hostile/hivebot/guardian/think() . =..() if(stance != HOSTILE_STANCE_IDLE) diff --git a/code/modules/mob/living/simple_animal/hostile/hivebots/hivebot_beacon.dm b/code/modules/mob/living/simple_animal/hostile/hivebots/hivebot_beacon.dm index e78ac398dda..a6d411fc4a9 100644 --- a/code/modules/mob/living/simple_animal/hostile/hivebots/hivebot_beacon.dm +++ b/code/modules/mob/living/simple_animal/hostile/hivebots/hivebot_beacon.dm @@ -69,7 +69,7 @@ var/maximum_linked_and_alive_hivebots_to_playing_players_scaling_factor = 1 ///A list of `/mob/living/simple_animal/hostile` hivebots that are linked to this beacon - var/list/mob/living/simple_animal/hostile/hivebot/linked_bots = list() + var/list/mob/living/simple_animal/hostile/linked_bots = list() ///Amount of hivebots spawned and alive linked to this beacon, guardian type var/guard_amt = 0 @@ -128,8 +128,10 @@ /mob/living/simple_animal/hostile/hivebotbeacon/Destroy() //Remove the reference from all linked bots to us - for(var/mob/living/simple_animal/hostile/hivebot/latest_child in linked_bots) - latest_child.linked_parent = null + for(var/mob/living/simple_animal/hostile/retaliate/hivebotharvester/hbh in linked_bots) + hbh.unlink() + for(var/mob/living/simple_animal/hostile/hivebot/hb in linked_bots) + hb.unlink() linked_bots.Cut() //Smoke effect, we disappear in a smoke @@ -139,6 +141,48 @@ . = ..() +/mob/living/simple_animal/hostile/hivebotbeacon/proc/do_link(mob/living/simple_animal/hostile/add) + if(QDELETED(add) || (add in linked_bots)) + return + var/mob/living/simple_animal/hostile/hivebot/hb = astype(add) + if(!hb) + var/mob/living/simple_animal/hostile/retaliate/hivebotharvester/hbh = astype(add) + if(hbh) + if(hbh.linked_parent != src) + hbh.do_link(src) + harvester_amt++ + . = TRUE + else + if(hb.linked_parent != src) + hb.do_link(src) + if(istype(add, /mob/living/simple_animal/hostile/hivebot/guardian)) + guard_amt++ + . = TRUE + + if(.) + linked_bots += add + RegisterSignal(add, COMSIG_QDELETING, PROC_REF(unlink)) + + +/mob/living/simple_animal/hostile/hivebotbeacon/proc/unlink(mob/living/simple_animal/hostile/remove) + SIGNAL_HANDLER + if(!remove || !(remove in linked_bots)) + return + UnregisterSignal(remove, COMSIG_QDELETING) + linked_bots -= remove + var/mob/living/simple_animal/hostile/hivebot/hb = astype(remove) + if(hb) + if(hb.linked_parent == src) + hb.unlink() + if(istype(remove, /mob/living/simple_animal/hostile/hivebot/guardian)) + guard_amt-- + else + var/mob/living/simple_animal/hostile/retaliate/hivebotharvester/hbh = astype(remove) + if(hbh) + if(hbh.linked_parent == src) + hbh.unlink() + harvester_amt-- + /mob/living/simple_animal/hostile/hivebotbeacon/proc/generate_warp_destinations() destinations.Cut() diff --git a/code/modules/mob/living/simple_animal/hostile/hivebots/hivebot_harvester.dm b/code/modules/mob/living/simple_animal/hostile/hivebots/hivebot_harvester.dm index 188fc5001d0..03c039255ad 100644 --- a/code/modules/mob/living/simple_animal/hostile/hivebots/hivebot_harvester.dm +++ b/code/modules/mob/living/simple_animal/hostile/hivebots/hivebot_harvester.dm @@ -45,26 +45,42 @@ psi_pingable = FALSE sample_data = null -/mob/living/simple_animal/hostile/retaliate/hivebotharvester/Initialize(mapload,mob/living/simple_animal/hostile/hivebot/hivebotbeacon) - if(hivebotbeacon) - linked_parent = hivebotbeacon - linked_parent.harvester_amt ++ - .=..() +/mob/living/simple_animal/hostile/retaliate/hivebotharvester/Initialize(mapload,mob/living/simple_animal/hostile/hivebotbeacon/beacon) + do_link(beacon) + . = ..() set_light(3,2,LIGHT_COLOR_RED) if(!mapload) spark(get_turf(src), 3, GLOB.alldirs) +/mob/living/simple_animal/hostile/retaliate/hivebotharvester/proc/do_link(mob/living/simple_animal/hostile/hivebotbeacon/beacon) + if(QDELETED(beacon)) + return + + if(linked_parent) + if(linked_parent == beacon) + return + linked_parent.unlink(src) + + linked_parent = beacon + beacon.do_link(src) + RegisterSignal(linked_parent, COMSIG_QDELETING, PROC_REF(unlink)) + +/mob/living/simple_animal/hostile/retaliate/hivebotharvester/proc/unlink() + SIGNAL_HANDLER + if(!linked_parent) + return + linked_parent.unlink(src) + UnregisterSignal(linked_parent, COMSIG_QDELETING) + linked_parent = null + /mob/living/simple_animal/hostile/retaliate/hivebotharvester/death() ..(null,"teleports away!") - if(linked_parent) - linked_parent.harvester_amt -- spark(get_turf(src), 3, GLOB.alldirs) qdel(src) /mob/living/simple_animal/hostile/retaliate/hivebotharvester/Destroy() + unlink() . = ..() - if(linked_parent) - linked_parent.linked_bots -= src /mob/living/simple_animal/hostile/retaliate/hivebotharvester/Allow_Spacemove(var/check_drift = 0) return 1 diff --git a/html/changelogs/johnwildkins-hivebots.yml b/html/changelogs/johnwildkins-hivebots.yml new file mode 100644 index 00000000000..7ea48502985 --- /dev/null +++ b/html/changelogs/johnwildkins-hivebots.yml @@ -0,0 +1,13 @@ +# Your name. +author: JohnWildkins + +# Optional: Remove this file after generating master changelog. Useful for PR changelogs that won't get used again. +delete-after: True + +# Any changes you've made. See valid prefix list above. +# INDENT WITH TWO SPACES. NOT TABS. SPACES. +# SCREW THIS UP AND IT WON'T WORK. +# Also, this gets changed to [] after reading. Just remove the brackets when you add new shit. +# Please surround your changes in double quotes ("). It works without them, but if you use certain characters it screws up compiling. The quotes will not show up in the changelog. +changes: + - bugfix: "Fix hivebot hard delete."