[MIRROR] [no gbp] fixes ai controller runtime (#26278)

* [no gbp] fixes ai controller runtime (#81134)

## About The Pull Request
fixes the flaky error that would happen in cleanbot controllers. i
discovered thru the profiler that a proc i was using to stop tracking
unreachable targets and caching them to a blacklist in selectbehavior
had a bit of a high real time cost, so if the mob got deleted midway
through for any reason would cause a runtime error. ive moved this proc
off selectbehavior and im instead letting the move loop cache this
target into the blacklist if it reaches the max pathing attempts
## Why It's Good For The Game
fixes a runtime that sometimes happens in ai controllers

## Changelog
🆑
fix: fixes a runtime that sometimes happens in ai controllers
/🆑

* [no gbp] fixes ai controller runtime

---------

Co-authored-by: Ben10Omintrix <138636438+Ben10Omintrix@users.noreply.github.com>
This commit is contained in:
SkyratBot
2024-01-29 02:34:58 +01:00
committed by GitHub
co-authored by Ben10Omintrix
parent 5922f34a2a
commit 7f252e6e94
7 changed files with 79 additions and 49 deletions
@@ -7,7 +7,7 @@
/datum/ai_planning_subtree/find_and_hunt_target/patients_in_crit,
/datum/ai_planning_subtree/treat_wounded_target,
/datum/ai_planning_subtree/salute_authority,
/datum/ai_planning_subtree/find_patrol_beacon,
/datum/ai_planning_subtree/find_patrol_beacon/medbot,
)
ai_movement = /datum/ai_movement/jps/bot/medbot
reset_keys = list(
@@ -19,6 +19,8 @@
ai_traits = PAUSE_DURING_DO_AFTER
/datum/ai_movement/jps/bot/medbot
maximum_length = BOT_PATIENT_PATH_LIMIT
max_pathing_attempts = 20
// only AI isnt allowed to move when this flag is set, sentient players can
/datum/ai_movement/jps/bot/medbot/allowed_to_move(datum/move_loop/source)
@@ -28,6 +30,9 @@
return FALSE
return ..()
/datum/ai_movement/jps/bot/medbot/travel_to_beacon
maximum_length = AI_BOT_PATH_LENGTH
/datum/ai_planning_subtree/treat_wounded_target
@@ -37,9 +42,8 @@
controller.clear_blackboard_key(BB_PATIENT_TARGET)
return
var/is_stationary = bot_pawn.medical_mode_flags & MEDBOT_STATIONARY_MODE
var/reach_distance = (is_stationary) ? 1 : BOT_PATIENT_PATH_LIMIT
if(controller.reachable_key(BB_PATIENT_TARGET, distance = reach_distance, bypass_add_to_blacklist = is_stationary))
controller.queue_behavior(/datum/ai_behavior/tend_to_patient, BB_PATIENT_TARGET, bot_pawn.heal_threshold, bot_pawn.damage_type_healer, bot_pawn.bot_access_flags)
if(controller.blackboard_key_exists(BB_PATIENT_TARGET))
controller.queue_behavior(/datum/ai_behavior/tend_to_patient, BB_PATIENT_TARGET, bot_pawn.heal_threshold, bot_pawn.damage_type_healer, bot_pawn.bot_access_flags, is_stationary)
return SUBTREE_RETURN_FINISH_PLANNING
controller.queue_behavior(/datum/ai_behavior/find_suitable_patient, BB_PATIENT_TARGET, bot_pawn.heal_threshold, bot_pawn.damage_type_healer, bot_pawn.medical_mode_flags, bot_pawn.bot_access_flags)
@@ -56,15 +60,15 @@
if(LAZYACCESS(ignore_keys, REF(treatable_target)) || treatable_target.stat == DEAD)
continue
if((access_flags & BOT_COVER_EMAGGED) && treatable_target.stat == CONSCIOUS)
controller.set_blackboard_key(BB_PATIENT_TARGET, treatable_target)
controller.set_if_can_reach(BB_PATIENT_TARGET, treatable_target, distance =BOT_PATIENT_PATH_LIMIT, bypass_add_to_blacklist = (search_range == 1))
break
if((heal_type == HEAL_ALL_DAMAGE))
if(treatable_target.get_total_damage() > threshold)
controller.set_blackboard_key(BB_PATIENT_TARGET, treatable_target)
controller.set_if_can_reach(BB_PATIENT_TARGET, treatable_target, distance = BOT_PATIENT_PATH_LIMIT, bypass_add_to_blacklist = (search_range == 1))
break
continue
if(treatable_target.get_current_damage_of_type(damagetype = heal_type) > threshold)
controller.set_blackboard_key(BB_PATIENT_TARGET, treatable_target)
controller.set_if_can_reach(BB_PATIENT_TARGET, treatable_target, distance = BOT_PATIENT_PATH_LIMIT, bypass_add_to_blacklist = (search_range == 1))
break
finish_action(controller, controller.blackboard_key_exists(BB_PATIENT_TARGET))
@@ -86,14 +90,14 @@
return FALSE
set_movement_target(controller, target)
/datum/ai_behavior/tend_to_patient/perform(seconds_per_tick, datum/ai_controller/basic_controller/bot/controller, target_key, threshold, damage_type_healer, access_flags)
/datum/ai_behavior/tend_to_patient/perform(seconds_per_tick, datum/ai_controller/basic_controller/bot/controller, target_key, threshold, damage_type_healer, access_flags, is_stationary)
. = ..()
var/mob/living/carbon/human/patient = controller.blackboard[target_key]
if(QDELETED(patient) || patient.stat == DEAD)
finish_action(controller, FALSE, target_key)
finish_action(controller, FALSE, target_key, is_stationary)
return
if(check_if_healed(patient, threshold, damage_type_healer, access_flags))
finish_action(controller, TRUE, target_key, healed_target = TRUE)
finish_action(controller, TRUE, target_key, is_stationary, healed_target = TRUE)
return
var/mob/living/basic/bot/bot_pawn = controller.pawn
@@ -101,16 +105,23 @@
var/datum/action/cooldown/bot_announcement/announcement = controller.blackboard[BB_ANNOUNCE_ABILITY]
announcement?.announce(pick(controller.blackboard[BB_NEAR_DEATH_SPEECH]))
bot_pawn.melee_attack(patient)
finish_action(controller, TRUE, target_key)
finish_action(controller, TRUE, target_key, is_stationary)
// only clear the target if they get healed
/datum/ai_behavior/tend_to_patient/finish_action(datum/ai_controller/controller, succeeded, target_key, healed_target = FALSE)
/datum/ai_behavior/tend_to_patient/finish_action(datum/ai_controller/controller, succeeded, target_key, is_stationary, healed_target = FALSE)
. = ..()
if(!succeeded)
return
var/atom/target = controller.blackboard[target_key]
if(!succeeded)
if(!isnull(target) && !is_stationary)
controller.set_blackboard_key_assoc_lazylist(BB_TEMPORARY_IGNORE_LIST, REF(target), TRUE)
controller.clear_blackboard_key(target_key)
return
if(QDELETED(target) || !healed_target)
return
var/datum/action/cooldown/bot_announcement/announcement = controller.blackboard[BB_ANNOUNCE_ABILITY]
announcement?.announce(pick(controller.blackboard[BB_AFTERHEAL_SPEECH]))
controller.clear_blackboard_key(target_key)
@@ -208,4 +219,11 @@
. = ..()
controller.clear_blackboard_key(target_key)
/datum/ai_planning_subtree/find_patrol_beacon/medbot
///travel towards beacon behavior
travel_behavior = /datum/ai_behavior/travel_towards/beacon/medbot
/datum/ai_behavior/travel_towards/beacon/medbot
new_movement_type = /datum/ai_movement/jps/bot/medbot/travel_to_beacon
#undef BOT_PATIENT_PATH_LIMIT