wire up ai idling to spatial grid (#30711)

* wire up ai idling to spatial grid

* lint

* Apply suggestions from code review

Co-authored-by: DGamerL <108773801+DGamerL@users.noreply.github.com>
Signed-off-by: warriorstar-orion <orion@snowfrost.garden>

* stupid loadbearing src

* some spatial grid cleanup

* make sure to remove controllers in the GLOB

* immediately set targets and state for hiveloord brood

* properly fail behaviors when movement targets are lost

* Apply suggestions from code review

Comment formatting

Co-authored-by: PollardTheDragon <144391971+PollardTheDragon@users.noreply.github.com>
Signed-off-by: Burzah <116982774+Burzah@users.noreply.github.com>

* Update code/datums/ai/ai_controller.dm

Co-authored-by: PollardTheDragon <144391971+PollardTheDragon@users.noreply.github.com>
Signed-off-by: Burzah <116982774+Burzah@users.noreply.github.com>

* Update code/datums/ai/ai_controller.dm

Co-authored-by: PollardTheDragon <144391971+PollardTheDragon@users.noreply.github.com>
Signed-off-by: Burzah <116982774+Burzah@users.noreply.github.com>

* Apply suggestions from code review

Comment formatting

Co-authored-by: PollardTheDragon <144391971+PollardTheDragon@users.noreply.github.com>
Signed-off-by: Burzah <116982774+Burzah@users.noreply.github.com>

* Update code/datums/ai/ai_controller.dm

Co-authored-by: PollardTheDragon <144391971+PollardTheDragon@users.noreply.github.com>
Signed-off-by: Burzah <116982774+Burzah@users.noreply.github.com>

---------

Signed-off-by: warriorstar-orion <orion@snowfrost.garden>
Signed-off-by: Burzah <116982774+Burzah@users.noreply.github.com>
Co-authored-by: DGamerL <108773801+DGamerL@users.noreply.github.com>
Co-authored-by: Burzah <116982774+Burzah@users.noreply.github.com>
Co-authored-by: PollardTheDragon <144391971+PollardTheDragon@users.noreply.github.com>
This commit is contained in:
warriorstar-orion
2025-12-09 18:46:38 -05:00
committed by GitHub
parent 9e87289bd8
commit be48d7598f
17 changed files with 351 additions and 127 deletions
@@ -44,8 +44,8 @@
ai_movement = /datum/ai_movement/jps // Not gonna get stuck on walls now, are ya?
idle_behavior = /datum/idle_behavior/idle_random_walk
planning_subtrees = list(
/datum/ai_planning_subtree/simple_find_target,
/datum/ai_planning_subtree/basic_melee_attack_subtree,
/datum/ai_planning_subtree/simple_find_target,
)
/// Same as hivelords, but go after corpses too
@@ -118,17 +118,21 @@
if(!target)
// Only summon if we have a hostile target
return
controller.queue_behavior(/datum/ai_behavior/summon_brood)
controller.queue_behavior(/datum/ai_behavior/summon_brood, target_key)
/datum/ai_behavior/summon_brood
action_cooldown = 3 SECONDS
behavior_flags = AI_BEHAVIOR_MOVE_AND_PERFORM
required_distance = 0
/datum/ai_behavior/summon_brood/perform(seconds_per_tick, datum/ai_controller/controller)
/datum/ai_behavior/summon_brood/perform(seconds_per_tick, datum/ai_controller/controller, target_key)
. = ..()
var/mob/living/basic/mining/hivelord/summoner = controller.pawn
var/mob/living/basic/mining/hivelordbrood/A = new summoner.brood_type(summoner.loc)
A.admin_spawned = summoner.admin_spawned
A.faction = summoner.faction.Copy()
var/mob/living/target = controller.blackboard[target_key]
if(istype(target) && istype(A.ai_controller))
A.ai_controller.set_ai_status(AI_STATUS_ON)
A.ai_controller.set_blackboard_key(target_key, target)
return AI_BEHAVIOR_DELAY | AI_BEHAVIOR_SUCCEEDED
+2 -2
View File
@@ -1084,7 +1084,7 @@
var/old_level_new_clients = (registered_z ? length(SSmobs.clients_by_zlevel[registered_z]) : null)
// No one is left after we're gone, shut off inactive ones
if(registered_z && old_level_new_clients == 0)
for(var/datum/ai_controller/controller as anything in SSai_controllers.ai_controllers_by_zlevel[registered_z])
for(var/datum/ai_controller/controller as anything in GLOB.ai_controllers_by_zlevel[registered_z])
controller.set_ai_status(AI_STATUS_OFF)
@@ -1097,7 +1097,7 @@
if(new_level_old_clients == 0) // No one was here before, wake up all the AIs.
// Basic mob AI
for(var/datum/ai_controller/controller as anything in SSai_controllers.ai_controllers_by_zlevel[new_z])
for(var/datum/ai_controller/controller as anything in GLOB.ai_controllers_by_zlevel[new_z])
// We don't set them directly on, for instances like AIs acting while dead and other cases that may exist in the future.
// This isn't a problem for AIs with a client since the client will prevent this from being called anyway.
controller.set_ai_status(controller.get_expected_ai_status())
@@ -49,11 +49,11 @@
"uid" = "[movement_target.UID()]",
"source" = "[controller.movement_target_source]",
)
if(LAZYLEN(controller.current_behaviors))
if(length(controller.current_behaviors))
for(var/datum/ai_behavior/behavior in controller.current_behaviors)
data["controller"]["current_behaviors"] += "[behavior.type]"
if(LAZYLEN(controller.planned_behaviors))
if(length(controller.planned_behaviors))
for(var/datum/ai_behavior/behavior in controller.planned_behaviors)
data["controller"]["planned_behaviors"] += "[behavior.type]"