Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Harddel Fix Pack #42 + Better Live Reftracking Support #63877

Merged
merged 87 commits into from Jan 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
87 commits
Select commit Hold shift + click to select a range
bfab64a
Fixes robot customor sourced sign harddels
LemonInTheDark Dec 9, 2021
53d251a
Merge branch 'master' of https://github.com/tgstation/tgstation into …
LemonInTheDark Dec 9, 2021
0d4c999
Adds a define that enables live reference tracking, making testing le…
LemonInTheDark Dec 13, 2021
88a4c7c
Catches bad machine addition
LemonInTheDark Dec 13, 2021
b5b6556
I'm a dumbass, weakref properly
LemonInTheDark Dec 13, 2021
a297735
Minor improvement to ref tracking define errors
LemonInTheDark Dec 13, 2021
bdfaf05
Fixes aura healing alert harddels, why are you holding a ref you don'…
LemonInTheDark Dec 15, 2021
91dc0ee
Converts isproperdatum to a define, not sure why it wouldn't be one
LemonInTheDark Dec 15, 2021
015b053
Uses signals to prevent actions from hanging a ref to their target, I…
LemonInTheDark Dec 15, 2021
3d728c6
Fixes a borg screen object harddel, we never nulled this. Why? No idea
LemonInTheDark Dec 15, 2021
8e4e36f
Memories were passing atoms into extra_info, to be flattened into str…
LemonInTheDark Dec 15, 2021
b5a1c62
Fixes an uplink component harddel, this is why god invented weakrefs
LemonInTheDark Dec 15, 2021
5426600
Fixes the orbit menu hanging refs to deleted points of interest HHHHH…
LemonInTheDark Dec 15, 2021
2c07e75
Whoops, this needs to actually compile now that I think about it
LemonInTheDark Dec 15, 2021
9bfaadc
See above\
LemonInTheDark Dec 15, 2021
acbe87d
Oh. Shoulda thought about that one huh
LemonInTheDark Dec 15, 2021
7b20365
Remove can loop apperantly, let's just uh
LemonInTheDark Dec 15, 2021
3241bfa
Fixes mech actions holding a ref to their mech, makes removing them a…
LemonInTheDark Dec 16, 2021
cd85f54
Turns the recharging mech var into a weakref, fixing harddels. also c…
LemonInTheDark Dec 16, 2021
5f7a764
Fixes bluespace vendor sourced tank harddels
LemonInTheDark Dec 16, 2021
8f6385e
Weakref info button
LemonInTheDark Dec 16, 2021
ef41855
Fixes a plant gene harddel, pass by copy not by ref bud
LemonInTheDark Dec 23, 2021
61da2fb
Moves many ai behaviors over to weakrefs, with the goal of preventing…
LemonInTheDark Dec 23, 2021
1c9d57b
Converts a pictures human contents lists to weakrefs
LemonInTheDark Dec 23, 2021
6fcbca3
Suppose it should compile
LemonInTheDark Dec 23, 2021
a53d6d1
Cleans up surgery init a bit, fixes a mob/limb harddel, surgeries wer…
LemonInTheDark Dec 23, 2021
ec76c14
Fixes beartrap harddels. They were being removed, qdeling, losing the…
LemonInTheDark Dec 23, 2021
6ba95be
Small cleanups
LemonInTheDark Dec 23, 2021
50e05ff
Adds logging for attempting to give a mob a non string name. Hopefull…
LemonInTheDark Dec 23, 2021
95f0734
QDELETED is better here. I know something is causing the construct's …
LemonInTheDark Dec 23, 2021
94bd5c8
Oh come on
LemonInTheDark Dec 23, 2021
64fe415
Fixes an action that holds its parent hhhhhhhhh
LemonInTheDark Dec 23, 2021
1d35fc6
Ok so now the monitor itself is being held
LemonInTheDark Dec 23, 2021
edbb001
Jesus christ that's a lot of actions
LemonInTheDark Dec 23, 2021
ae73cbe
Fixes a manifest harddel, New -> Initialize, fixes a potential qdel i…
LemonInTheDark Dec 23, 2021
379de6e
Fixes cotten trying to merge with qdeleted things
LemonInTheDark Dec 23, 2021
c74b8fc
Sadkirby
LemonInTheDark Dec 23, 2021
137beb9
Ai var/Bot to weakrefs, jesus
LemonInTheDark Dec 23, 2021
109576c
Cleans up medigun/current_beam properly
LemonInTheDark Dec 23, 2021
ab6a349
Makes it compile
LemonInTheDark Dec 23, 2021
93f082f
Fixes a growth_queue harddelete, hardens the spacevine controller a b…
LemonInTheDark Dec 27, 2021
c863bf1
Merge branch 'master' of https://github.com/tgstation/tgstation into …
LemonInTheDark Dec 27, 2021
d9067e3
Fixes a regression with important_recursive_contents, got moved up in…
LemonInTheDark Dec 27, 2021
2b0abf9
Fixes a modular computer harddel, turns out a harddrive cam be remove…
LemonInTheDark Dec 27, 2021
61c052f
Cleans up modular computer programs a bit, fixing ref hangs, cleaning…
LemonInTheDark Dec 27, 2021
563d0d3
Cleans up kiosks, fixes a few harddels. Jesus fucking christ
LemonInTheDark Dec 27, 2021
95969a5
Converts the monkey enemies list to weakrefs
LemonInTheDark Dec 27, 2021
2a7e988
Converts monkey enemies to weakrefs
LemonInTheDark Dec 27, 2021
9a166c2
Wahhhh
LemonInTheDark Dec 27, 2021
f926452
wow your mom lets you compile AND run?
LemonInTheDark Dec 27, 2021
61419ac
Son I am fucking disappoint
LemonInTheDark Dec 27, 2021
d31d543
Fixes client cleanup related harddels. Basically we need a ref to the…
LemonInTheDark Dec 29, 2021
7cf91d4
Hopefully fixes a tackle component sourced harddel, we don't really o…
LemonInTheDark Jan 2, 2022
59cdc06
Removes a weird python like typebuilding pattern with a proper fullsc…
LemonInTheDark Jan 2, 2022
f4604a1
Kills the other two instances of /obj instanciation I can find, if we…
LemonInTheDark Jan 2, 2022
94f4410
Lightly firebombs expirementor code, fixing a pair of ian and runtime…
LemonInTheDark Jan 2, 2022
90ca856
Fixes an inserted_key harddel in vehicle code in 2 different ways. Is…
LemonInTheDark Jan 2, 2022
40f3ea2
Fixes a random manuel spawner harddel, it dels in init. Newing someth…
LemonInTheDark Jan 2, 2022
1288267
Fixes some stupid code that hangs refs in the conjure spell, alongsid…
LemonInTheDark Jan 2, 2022
a576808
Fixes assembly holders hanging refs to the assemblies inserted into t…
LemonInTheDark Jan 2, 2022
016af4d
Fixes flamethrower sourced harddels, QDEL_NULL instead of qdel you hh…
LemonInTheDark Jan 2, 2022
17e2e6f
Fixes onetankbomb sourced harddels, god these things are just horrible
LemonInTheDark Jan 2, 2022
d866e13
Makes the master var actually garbage collect, and marks it as deprec…
LemonInTheDark Jan 2, 2022
4a83991
Fixes some cartridge sourced bot harddels
LemonInTheDark Jan 2, 2022
8a10563
Makes the team_hud var a weakref. Not sure why it wasn't one before, …
LemonInTheDark Jan 2, 2022
032505b
Ok this is gonna be a big one
LemonInTheDark Jan 2, 2022
7155031
Merge branch 'master' of https://github.com/tgstation/tgstation into …
LemonInTheDark Jan 2, 2022
14efa67
Parently code needs to compile. Who knew
LemonInTheDark Jan 2, 2022
7530ed7
Merge branch 'master' of https://github.com/tgstation/tgstation into …
LemonInTheDark Jan 6, 2022
c478018
Fixes dna mutations being erroniously held even after their dna owner…
LemonInTheDark Jan 6, 2022
04f6887
Fixes ticket sourced human harddels. Come on man, come on
LemonInTheDark Jan 6, 2022
a664f31
Fixed pirate pad control sourced pad harddels
LemonInTheDark Jan 6, 2022
bcac6e9
Fixes a linked seat harddel
LemonInTheDark Jan 6, 2022
c0efb89
Wow it's as bad as I thought it'd be. Fixes paper wizard harddels
LemonInTheDark Jan 6, 2022
b6da07f
HHHHHHHH Hopefully fixes a new player harddel
LemonInTheDark Jan 6, 2022
623684d
Properly fixes customer harddels, forgot this was a weakref
LemonInTheDark Jan 6, 2022
95f3cf6
They don't want you to get better
LemonInTheDark Jan 6, 2022
8a819e2
Old me was a moron
LemonInTheDark Jan 6, 2022
3f7f12a
Always knew I could spell well
LemonInTheDark Jan 6, 2022
4e62847
Oh come on
LemonInTheDark Jan 6, 2022
c371f49
Sionara isproperdatum, parent_tyoe is my new best friend
LemonInTheDark Jan 6, 2022
ea169a4
Whoooops
LemonInTheDark Jan 6, 2022
bdbb64e
Merge branch 'master' of https://github.com/tgstation/tgstation into …
LemonInTheDark Jan 11, 2022
14e843d
Merge branch 'master' of https://github.com/tgstation/tgstation into …
LemonInTheDark Jan 12, 2022
e33555a
Merge branch 'here-we-go' of https://github.com/LemonInTheDark/tgstat…
LemonInTheDark Jan 12, 2022
f67eb49
Oh right, we need to compile
LemonInTheDark Jan 12, 2022
f63399b
FUCK
LemonInTheDark Jan 12, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions code/__DEFINES/is_helpers.dm
Expand Up @@ -7,6 +7,8 @@

#define isatom(A) (isloc(A))

#define isdatum(thing) (istype(thing, /datum))

LemonInTheDark marked this conversation as resolved.
Show resolved Hide resolved
#define isweakref(D) (istype(D, /datum/weakref))

//Turfs
Expand Down
11 changes: 9 additions & 2 deletions code/__HELPERS/_logging.dm
Expand Up @@ -57,9 +57,16 @@ GLOBAL_LIST_INIT(testing_global_profiler, list("_PROFILE_NAME" = "Global"))
SEND_TEXT(world.log, text)
#endif

#ifdef REFERENCE_TRACKING
#if defined(REFERENCE_DOING_IT_LIVE)
#define log_reftracker(msg) log_harddel("## REF SEARCH [msg]")

/proc/log_harddel(text)
WRITE_LOG(GLOB.harddel_log, text)

#elif defined(REFERENCE_TRACKING) // Doing it locally
#define log_reftracker(msg) log_world("## REF SEARCH [msg]")
#else

#else //Not tracking at all
#define log_reftracker(msg)
#endif

Expand Down
2 changes: 1 addition & 1 deletion code/__HELPERS/memory_helpers.dm
Expand Up @@ -16,7 +16,7 @@
* Adds a memory to a mob's mind if conditions are met, called wherever the memory takes place (memory for catching on fire in mob's fire code, for example)
* Argument:
* * memory_type: defined string in memory_defines.dm, shows the memories.json file which story parts to use (and generally what type it is)
* * extra_info: the contents of the story. You're gonna want at least the protagonist for who is the main character in the story
* * extra_info: the contents of the story. You're gonna want at least the protagonist for who is the main character in the story (Any non basic type will be converted to a string on insertion)
* * story_value: the quality of the memory, make easy or roundstart memories have a low value so they don't flood persistence
* * memory_flags: special specifications for skipping parts of the memory like moods for stories where showing moods doesn't make sense
* Returns the datum memory created, null otherwise.
Expand Down
10 changes: 10 additions & 0 deletions code/_compile_options.dm
Expand Up @@ -39,6 +39,16 @@
#define TRACK_MAX_SHARE //Allows max share tracking, for use in the atmos debugging ui
#endif //ifdef TESTING

/// If this is uncommented, we set up the ref tracker to be used in a live environment
/// And to log events to [log_dir]/harddels.log
//#define REFERENCE_DOING_IT_LIVE
#ifdef REFERENCE_DOING_IT_LIVE
// compile the backend
#define REFERENCE_TRACKING
// actually look for refs
#define GC_FAILURE_HARD_LOOKUP
#endif // REFERENCE_DOING_IT_LIVE

//#define UNIT_TESTS //If this is uncommented, we do a single run though of the game setup and tear down process with unit tests in between

#ifndef PRELOAD_RSC //set to:
Expand Down
4 changes: 4 additions & 0 deletions code/_globalvars/logging.dm
Expand Up @@ -89,3 +89,7 @@ GLOBAL_PROTECT(picture_logging_id)
GLOBAL_VAR(picture_logging_prefix)
GLOBAL_PROTECT(picture_logging_prefix)
/////
#ifdef REFERENCE_DOING_IT_LIVE
GLOBAL_LIST_EMPTY(harddel_log)
GLOBAL_PROTECT(harddel_log)
#endif
8 changes: 8 additions & 0 deletions code/_onclick/hud/fullscreen.dm
Expand Up @@ -150,6 +150,14 @@
icon_state = "flash"
alpha = 80

/atom/movable/screen/fullscreen/bluespace_sparkle
icon = 'icons/effects/effects.dmi'
screen_loc = "WEST,SOUTH to EAST,NORTH"
icon_state = "shieldsparkles"
layer = FLASH_LAYER
mouse_opacity = MOUSE_OPACITY_TRANSPARENT
show_when_dead = TRUE

/atom/movable/screen/fullscreen/color_vision/green
color = "#00ff00"

Expand Down
3 changes: 3 additions & 0 deletions code/controllers/subsystem/air.dm
Expand Up @@ -632,6 +632,9 @@ GLOBAL_LIST_EMPTY(colored_images)
/datum/controller/subsystem/air/proc/start_processing_machine(obj/machinery/machine)
if(machine.atmos_processing)
return
if(QDELETED(machine))
stack_trace("We tried to add a garbage collecting machine to SSair. Don't")
return
machine.atmos_processing = TRUE
atmos_machinery += machine

Expand Down
2 changes: 1 addition & 1 deletion code/controllers/subsystem/garbage.dm
Expand Up @@ -372,7 +372,7 @@ SUBSYSTEM_DEF(garbage)
#ifdef REFERENCE_TRACKING
if (QDEL_HINT_FINDREFERENCE) //qdel will, if REFERENCE_TRACKING is enabled, display all references to this object, then queue the object for deletion.
SSgarbage.Queue(D)
D.find_references()
D.find_references() //This breaks ci. Consider it insurance against somehow pring reftracking on accident
if (QDEL_HINT_IFFAIL_FINDREFERENCE) //qdel will, if REFERENCE_TRACKING is enabled and the object fails to collect, display all references to this object.
SSgarbage.Queue(D)
SSgarbage.reference_find_on_fail["\ref[D]"] = TRUE
Expand Down
3 changes: 2 additions & 1 deletion code/controllers/subsystem/parallax.dm
Expand Up @@ -40,7 +40,8 @@ SUBSYSTEM_DEF(parallax)
if(!istype(movable_eye))
continue

for (movable_eye; isloc(movable_eye.loc) && !isturf(movable_eye.loc); movable_eye = movable_eye.loc);
while(isloc(movable_eye.loc) && !isturf(movable_eye.loc))
movable_eye = movable_eye.loc
//get the last movable holding the mobs eye

if(movable_eye == processing_client.movingmob)
Expand Down
21 changes: 14 additions & 7 deletions code/datums/action.dm
Expand Up @@ -33,7 +33,8 @@

/datum/action/proc/link_to(Target)
target = Target
RegisterSignal(Target, COMSIG_ATOM_UPDATED_ICON, .proc/OnUpdatedIcon)
RegisterSignal(target, COMSIG_ATOM_UPDATED_ICON, .proc/OnUpdatedIcon)
RegisterSignal(target, COMSIG_PARENT_QDELETING, .proc/clear_ref, override = TRUE)

/datum/action/Destroy()
if(owner)
Expand All @@ -49,7 +50,7 @@
return
Remove(owner)
owner = M
RegisterSignal(owner, COMSIG_PARENT_QDELETING, .proc/owner_deleted)
RegisterSignal(owner, COMSIG_PARENT_QDELETING, .proc/clear_ref, override = TRUE)

//button id generation
var/counter = 0
Expand All @@ -75,9 +76,12 @@
else
Remove(owner)

/datum/action/proc/owner_deleted(datum/source)
/datum/action/proc/clear_ref(datum/ref)
SIGNAL_HANDLER
Remove(owner)
if(ref == owner)
Remove(owner)
if(ref == target)
qdel(src)

/datum/action/proc/Remove(mob/M)
for(var/datum/weakref/reference as anything in sharers)
Expand All @@ -93,10 +97,13 @@
M.update_action_buttons()
if(owner)
UnregisterSignal(owner, COMSIG_PARENT_QDELETING)
if(target == owner)
RegisterSignal(target, COMSIG_PARENT_QDELETING, .proc/clear_ref)
owner = null
button.moved = FALSE //so the button appears in its normal position when given to another owner.
button.locked = FALSE
button.id = null
if(button)
button.moved = FALSE //so the button appears in its normal position when given to another owner.
button.locked = FALSE
button.id = null

/datum/action/proc/Trigger()
if(!IsAvailable())
Expand Down
17 changes: 10 additions & 7 deletions code/datums/ai/_item_behaviors.dm
Expand Up @@ -22,16 +22,16 @@
///Max attemps to make
var/max_attempts = 3


/datum/ai_behavior/item_move_close_and_attack/setup(datum/ai_controller/controller, target_key, throw_count_key)
. = ..()
controller.current_movement_target = controller.blackboard[target_key]

var/datum/weakref/target_ref = controller.blackboard[target_key]
controller.current_movement_target = target_ref?.resolve()

/datum/ai_behavior/item_move_close_and_attack/perform(delta_time, datum/ai_controller/controller, target_key, throw_count_key)
. = ..()
var/obj/item/item_pawn = controller.pawn
var/atom/throw_target = controller.blackboard[target_key]
var/datum/weakref/target_ref = controller.blackboard[target_key]
var/atom/throw_target = target_ref?.resolve()

item_pawn.visible_message(span_warning("[item_pawn] hurls towards [throw_target]!"))
item_pawn.throw_at(throw_target, rand(4,5), 9)
Expand All @@ -48,12 +48,15 @@
controller.blackboard -= target_key
controller.blackboard[throw_count_key] = 0

/datum/ai_behavior/item_move_close_and_attack/haunted
/datum/ai_behavior/item_move_close_and_attack/ghostly
attack_sound = 'sound/items/haunted/ghostitemattack.ogg'
max_attempts = 4

/datum/ai_behavior/item_move_close_and_attack/haunted/finish_action(datum/ai_controller/controller, succeeded, target_key, throw_count_key)
var/atom/throw_target = controller.blackboard[target_key]
/datum/ai_behavior/item_move_close_and_attack/ghostly/haunted

/datum/ai_behavior/item_move_close_and_attack/ghostly/haunted/finish_action(datum/ai_controller/controller, succeeded, target_key, throw_count_key)
var/datum/weakref/target_ref = controller.blackboard[target_key]
var/atom/throw_target = target_ref?.resolve()
var/list/hauntee_list = controller.blackboard[BB_TO_HAUNT_LIST]
hauntee_list[throw_target]--
return ..()
10 changes: 4 additions & 6 deletions code/datums/ai/cursed/cursed_behaviors.dm
@@ -1,10 +1,8 @@
/datum/ai_behavior/item_move_close_and_attack/ghostly/cursed

/datum/ai_behavior/item_move_close_and_attack/cursed
attack_sound = 'sound/items/haunted/ghostitemattack.ogg'
max_attempts = 4

/datum/ai_behavior/item_move_close_and_attack/cursed/reset_blackboard(datum/ai_controller/controller, succeeded, target_key, throw_count_key)
var/atom/throw_target = controller.blackboard[target_key]
/datum/ai_behavior/item_move_close_and_attack/ghostly/cursed/reset_blackboard(datum/ai_controller/controller, succeeded, target_key, throw_count_key)
var/datum/weakref/target_ref = controller.blackboard[target_key]
var/atom/throw_target = target_ref?.resolve()
//dropping our target from the blackboard if they are no longer a valid target after the attack behavior
if(get_dist(throw_target, controller.pawn) > CURSED_VIEW_RANGE)
controller.blackboard[target_key] = null
5 changes: 3 additions & 2 deletions code/datums/ai/cursed/cursed_subtrees.dm
Expand Up @@ -2,7 +2,8 @@
var/obj/item/item_pawn = controller.pawn

//make sure we have a target
var/mob/living/carbon/curse_target = controller.blackboard[BB_CURSE_TARGET]
var/datum/weakref/target_ref = controller.blackboard[BB_CURSE_TARGET]
var/mob/living/carbon/curse_target = target_ref?.resolve()
if(!curse_target)
controller.queue_behavior(/datum/ai_behavior/find_and_set, BB_CURSE_TARGET, /mob/living/carbon, CURSED_VIEW_RANGE)
return
Expand All @@ -11,4 +12,4 @@
controller.blackboard[BB_CURSE_TARGET] = null
return
controller.current_movement_target = curse_target
controller.queue_behavior(/datum/ai_behavior/item_move_close_and_attack/cursed)
controller.queue_behavior(/datum/ai_behavior/item_move_close_and_attack/ghostly/cursed)
30 changes: 19 additions & 11 deletions code/datums/ai/generic/generic_behaviors.dm
Expand Up @@ -79,20 +79,22 @@
pawn.activate_hand(pawn.get_active_hand())
finish_action(controller, TRUE)

/// Use the currently held item, or unarmed, on an object in the world
/// Use the currently held item, or unarmed, on a weakref to an object in the world
/datum/ai_behavior/use_on_object
required_distance = 1
behavior_flags = AI_BEHAVIOR_REQUIRE_MOVEMENT

/datum/ai_behavior/use_on_object/setup(datum/ai_controller/controller, target_key)
. = ..()
controller.current_movement_target = controller.blackboard[target_key]
var/datum/weakref/target_ref = controller.blackboard[target_key]
controller.current_movement_target = target_ref?.resolve()

/datum/ai_behavior/use_on_object/perform(delta_time, datum/ai_controller/controller, target_key)
. = ..()
var/mob/living/pawn = controller.pawn
var/obj/item/held_item = pawn.get_item_by_slot(pawn.get_active_hand())
var/atom/target = controller.blackboard[BB_MONKEY_CURRENT_PRESS_TARGET]
var/datum/weakref/target_ref = controller.blackboard[target_key]
var/atom/target = target_ref?.resolve()

if(!target || !pawn.CanReach(target))
finish_action(controller, FALSE)
Expand All @@ -113,13 +115,15 @@

/datum/ai_behavior/give/setup(datum/ai_controller/controller, target_key)
. = ..()
controller.current_movement_target = controller.blackboard[target_key]
var/datum/weakref/target_ref = controller.blackboard[target_key]
controller.current_movement_target = target_ref?.resolve()

/datum/ai_behavior/give/perform(delta_time, datum/ai_controller/controller, target_key)
. = ..()
var/mob/living/pawn = controller.pawn
var/obj/item/held_item = pawn.get_item_by_slot(pawn.get_active_hand())
var/atom/target = controller.blackboard[target_key]
var/datum/weakref/target_ref = controller.blackboard[target_key]
var/atom/target = target_ref?.resolve()

if(!target || !pawn.CanReach(target) || !isliving(target))
finish_action(controller, FALSE)
Expand Down Expand Up @@ -151,12 +155,14 @@

/datum/ai_behavior/consume/setup(datum/ai_controller/controller, target_key)
. = ..()
controller.current_movement_target = controller.blackboard[target_key]
var/datum/weakref/target_ref = controller.blackboard[target_key]
controller.current_movement_target = target_ref?.resolve()

/datum/ai_behavior/consume/perform(delta_time, datum/ai_controller/controller, target_key, hunger_timer_key)
. = ..()
var/mob/living/living_pawn = controller.pawn
var/obj/item/target = controller.blackboard[target_key]
var/datum/weakref/target_ref = controller.blackboard[target_key]
var/obj/item/target = target_ref.resolve()

if(!(target in living_pawn.held_items))
if(!living_pawn.put_in_hand_check(target))
Expand Down Expand Up @@ -187,7 +193,7 @@
. = ..()
var/find_this_thing = search_tactic(controller, locate_path, search_range)
if(find_this_thing)
controller.blackboard[set_key] = find_this_thing
controller.blackboard[set_key] = WEAKREF(find_this_thing)
finish_action(controller, TRUE)
else
finish_action(controller, FALSE)
Expand Down Expand Up @@ -341,7 +347,8 @@
/datum/ai_behavior/setup_instrument/perform(delta_time, datum/ai_controller/controller, song_instrument_key, song_lines_key)
. = ..()

var/obj/item/instrument/song_instrument = controller.blackboard[song_instrument_key]
var/datum/weakref/instrument_ref = controller.blackboard[song_instrument_key]
var/obj/item/instrument/song_instrument = instrument_ref.resolve()
var/datum/song/song = song_instrument.song
var/song_lines = controller.blackboard[song_lines_key]

Expand All @@ -357,7 +364,8 @@
/datum/ai_behavior/play_instrument/perform(delta_time, datum/ai_controller/controller, song_instrument_key)
. = ..()

var/obj/item/instrument/song_instrument = controller.blackboard[song_instrument_key]
var/datum/weakref/instrument_ref = controller.blackboard[song_instrument_key]
var/obj/item/instrument/song_instrument = instrument_ref.resolve()
var/datum/song/song = song_instrument.song

song.start_playing(controller.pawn)
Expand All @@ -377,5 +385,5 @@
possible_targets += thing
if(!possible_targets.len)
finish_action(controller, FALSE)
controller.blackboard[target_key] = pick(possible_targets)
controller.blackboard[target_key] = WEAKREF(pick(possible_targets))
finish_action(controller, TRUE)
10 changes: 6 additions & 4 deletions code/datums/ai/generic/generic_subtrees.dm
Expand Up @@ -8,12 +8,13 @@
* * BB_SONG_LINES - not set by this subtree, is the song loaded into the song datum.
*/
/datum/ai_planning_subtree/generic_play_instrument/SelectBehaviors(datum/ai_controller/controller, delta_time)
if(!controller.blackboard[BB_SONG_INSTRUMENT])
var/datum/weakref/player_ref = controller.blackboard[BB_SONG_INSTRUMENT]
var/obj/item/instrument/song_player = player_ref?.resolve()

if(!song_player)
controller.queue_behavior(/datum/ai_behavior/find_and_set/in_hands, BB_SONG_INSTRUMENT, /obj/item/instrument)
return //we can't play a song since we do not have an instrument

var/obj/item/instrument/song_player = controller.blackboard[BB_SONG_INSTRUMENT]

var/list/parsed_song_lines = splittext(controller.blackboard[BB_SONG_LINES], "\n")
popleft(parsed_song_lines) //remove BPM as it is parsed out
if(!compare_list(song_player.song.lines, parsed_song_lines) || !song_player.song.repeat)
Expand Down Expand Up @@ -53,7 +54,8 @@
if(world.time < controller.blackboard[BB_NEXT_HUNGRY])
return

if(!controller.blackboard[BB_FOOD_TARGET])
var/datum/weakref/food_ref = controller.blackboard[BB_FOOD_TARGET]
if(!food_ref?.resolve())
controller.queue_behavior(/datum/ai_behavior/find_and_set/edible, BB_FOOD_TARGET, /obj/item, 2)
return

Expand Down
8 changes: 4 additions & 4 deletions code/datums/ai/hauntium/hauntium_subtrees.dm
Expand Up @@ -13,11 +13,11 @@

var/list/to_haunt_list = controller.blackboard[BB_TO_HAUNT_LIST]

for(var/i in to_haunt_list)
if(to_haunt_list[i] <= 0)
for(var/mob/living/potential_target as anything in to_haunt_list)
if(to_haunt_list[potential_target] <= 0)
to_haunt_list -= potential_target
continue
var/mob/living/potential_target = i
if(get_dist(potential_target, item_pawn) <= 7)
controller.blackboard[BB_HAUNT_TARGET] = potential_target
controller.queue_behavior(/datum/ai_behavior/item_move_close_and_attack/haunted, BB_HAUNT_TARGET, BB_HAUNTED_THROW_ATTEMPT_COUNT)
controller.queue_behavior(/datum/ai_behavior/item_move_close_and_attack/ghostly/haunted, BB_HAUNT_TARGET, BB_HAUNTED_THROW_ATTEMPT_COUNT)
return SUBTREE_RETURN_FINISH_PLANNING