mirror of
https://github.com/Bubberstation/Bubberstation.git
synced 2026-01-06 15:02:29 +00:00
## About The Pull Request In some cases, you need to perform behaviors that can occur ontop of different behaviors. E.g. "I need to continiously spit out foam while moving to a point". If these behaviors are put separetely, it is difficult to determine that the behavior for spitting out foam needs to end. And in the current code, aslong as it has not ended, the plan will never end. So once the AI reaches the point it would stand still at the end and spit out foam unendingly. To work around this I've made it so behaviors can be set to allow planning while they run if they have the AI_BEHAVIOR_CAN_PLAN_DURING_EXECUTION flag. If all remaining behaviors on a controller have this flag, a new plan is made. If this plan is the exact same as the plan that was currently being performed, nothing happens. But if the plan is different, the current one is ended and the new plan is executed. This means situations like this are handled gracefully now. This will be required for basic bots. ## Why It's Good For The Game More graceful handling of "continous" behaviors! :) ## Changelog 🆑 Capybara Holly refactor: Allows datum AI to create new plans while a plan is still executing /🆑 Co-authored-by: Capybara <Capybara@CapybaraMailingServices.com>
35 lines
1.4 KiB
Plaintext
35 lines
1.4 KiB
Plaintext
/// The subsystem used to tick [/datum/ai_controllers] instances. Handling the re-checking of plans.
|
|
SUBSYSTEM_DEF(ai_controllers)
|
|
name = "AI Controller Ticker"
|
|
flags = SS_POST_FIRE_TIMING|SS_BACKGROUND
|
|
priority = FIRE_PRIORITY_NPC
|
|
runlevels = RUNLEVEL_GAME | RUNLEVEL_POSTGAME
|
|
init_order = INIT_ORDER_AI_CONTROLLERS
|
|
wait = 0.5 SECONDS //Plan every half second if required, not great not terrible.
|
|
|
|
///List of all ai_subtree singletons, key is the typepath while assigned value is a newly created instance of the typepath. See setup_subtrees()
|
|
var/list/ai_subtrees = list()
|
|
///List of all ai controllers currently running
|
|
var/list/active_ai_controllers = list()
|
|
|
|
/datum/controller/subsystem/ai_controllers/Initialize()
|
|
setup_subtrees()
|
|
return SS_INIT_SUCCESS
|
|
|
|
/datum/controller/subsystem/ai_controllers/proc/setup_subtrees()
|
|
ai_subtrees = list()
|
|
for(var/subtree_type in subtypesof(/datum/ai_planning_subtree))
|
|
var/datum/ai_planning_subtree/subtree = new subtree_type
|
|
ai_subtrees[subtree_type] = subtree
|
|
|
|
/datum/controller/subsystem/ai_controllers/fire(resumed)
|
|
for(var/datum/ai_controller/ai_controller as anything in active_ai_controllers)
|
|
if(!COOLDOWN_FINISHED(ai_controller, failed_planning_cooldown))
|
|
continue
|
|
|
|
if(!ai_controller.able_to_plan())
|
|
continue
|
|
ai_controller.SelectBehaviors(wait * 0.1)
|
|
if(!LAZYLEN(ai_controller.current_behaviors)) //Still no plan
|
|
COOLDOWN_START(ai_controller, failed_planning_cooldown, AI_FAILED_PLANNING_COOLDOWN)
|