mirror of
https://github.com/Bubberstation/Bubberstation.git
synced 2025-12-20 06:32:56 +00:00
* Experiment with replacing weakrefs in AI blackboard with deleting signals, ideally making it easier to work with and harder to cause hard deletes (#74791) ## About The Pull Request Replaces weakref usage in AI blackboards with deleting signals All blackboard var setting must go through setters rather than directly ## Why It's Good For The Game This both makes it a ton easier to develop AI for, and also makes it harder for hard deletes to sneak in, as has been seen with recent 515 prs showing hard deletes in AI blackboards (To quantify "making it easier to develop AI", I found multiple bugs in existing AI code due to the usage of weakrefs.) I'm looking for `@ Jacquerel` `@ tralezab` 's opinions on the matter, also maybe `@ LemonInTheDark` if they're interested ## Changelog 🆑 Melbert refactor: Mob ai refactored once again /🆑 * Experiment with replacing weakrefs in AI blackboard with deleting signals, ideally making it easier to work with and harder to cause hard deletes --------- Co-authored-by: MrMelbert <51863163+MrMelbert@users.noreply.github.com>
65 lines
2.8 KiB
Plaintext
65 lines
2.8 KiB
Plaintext
/**
|
|
* Generic Instrument Subtree, For your pawn playing instruments
|
|
*
|
|
* Requires at least a living mob that can hold items.
|
|
*
|
|
* relevant blackboards:
|
|
* * BB_SONG_INSTRUMENT - set by this subtree, is the song datum the pawn plays music from.
|
|
* * 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, seconds_per_tick)
|
|
var/obj/item/instrument/song_player = controller.blackboard[BB_SONG_INSTRUMENT]
|
|
|
|
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/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)
|
|
controller.queue_behavior(/datum/ai_behavior/setup_instrument, BB_SONG_INSTRUMENT, BB_SONG_LINES)
|
|
|
|
if(!song_player.song.playing) //we may stop playing if we weren't playing before, were setting up dk theme, or ran out of repeats (also causing setup behavior)
|
|
controller.queue_behavior(/datum/ai_behavior/play_instrument, BB_SONG_INSTRUMENT)
|
|
|
|
/**
|
|
* Generic Resist Subtree, resist if it makes sense to!
|
|
*
|
|
* Requires nothing beyond a living pawn, makes sense on a good amount of mobs since anything can get buckled.
|
|
*
|
|
* relevant blackboards:
|
|
* * None!
|
|
*/
|
|
/datum/ai_planning_subtree/generic_resist/SelectBehaviors(datum/ai_controller/controller, seconds_per_tick)
|
|
var/mob/living/living_pawn = controller.pawn
|
|
|
|
if(SHOULD_RESIST(living_pawn) && SPT_PROB(RESIST_SUBTREE_PROB, seconds_per_tick))
|
|
controller.queue_behavior(/datum/ai_behavior/resist) //BRO IM ON FUCKING FIRE BRO
|
|
return SUBTREE_RETURN_FINISH_PLANNING //IM NOT DOING ANYTHING ELSE BUT EXTINGUISH MYSELF, GOOD GOD HAVE MERCY.
|
|
|
|
/**
|
|
* Generic Hunger Subtree,
|
|
*
|
|
* Requires at least a living mob that can hold items.
|
|
*
|
|
* relevant blackboards:
|
|
* * BB_NEXT_HUNGRY - set by this subtree, is when the controller is next hungry
|
|
*/
|
|
/datum/ai_planning_subtree/generic_hunger/SelectBehaviors(datum/ai_controller/controller, seconds_per_tick)
|
|
var/next_eat = controller.blackboard[BB_NEXT_HUNGRY]
|
|
if(!next_eat)
|
|
//inits the blackboard timer
|
|
next_eat = world.time + rand(0, 30 SECONDS)
|
|
controller.set_blackboard_key(BB_NEXT_HUNGRY, next_eat)
|
|
|
|
if(world.time < next_eat)
|
|
return
|
|
|
|
if(!controller.blackboard[BB_FOOD_TARGET])
|
|
controller.queue_behavior(/datum/ai_behavior/find_and_set/edible, BB_FOOD_TARGET, /obj/item, 2)
|
|
return
|
|
|
|
controller.queue_behavior(/datum/ai_behavior/drop_item)
|
|
controller.queue_behavior(/datum/ai_behavior/consume, BB_FOOD_TARGET, BB_NEXT_HUNGRY)
|
|
return SUBTREE_RETURN_FINISH_PLANNING
|