event based incapicated and able_to_run (#86031)

## About The Pull Request
this is a revival of #82635 . i got permission from potato to reopen
this, he did almost all the work. i only just solved the conflicts and
fixed all the bugs that were preventing the original from being merged
(but it should be TMed first)

## Why It's Good For The Game
slightly improves the performance of basic mob AI

## Changelog
🆑
LemonInTheDark
refactor: able_to_run and incapacitated have been refactored to be event
based
/🆑

---------

Co-authored-by: LemonInTheDark <58055496+LemonInTheDark@users.noreply.github.com>
Co-authored-by: ZephyrTFA <matthew@tfaluc.com>
This commit is contained in:
Ben10Omintrix
2024-09-04 10:02:49 -04:00
committed by GitHub
co-authored by LemonInTheDark ZephyrTFA
parent 8fe62dac3d
commit 91baa94ac5
170 changed files with 446 additions and 307 deletions
+13 -7
View File
@@ -58,6 +58,7 @@ GLOBAL_LIST_INIT(command_strings, list(
///All initial access this bot started with.
var/list/initial_access = list()
///Bot-related mode flags on the Bot indicating how they will act. BOT_MODE_ON | BOT_MODE_AUTOPATROL | BOT_MODE_REMOTE_ENABLED | BOT_MODE_CAN_BE_SAPIENT | BOT_MODE_ROUNDSTART_POSSESSION
/// DO NOT MODIFY MANUALLY, USE set_bot_mode_flags. If you don't shit breaks BAD
var/bot_mode_flags = BOT_MODE_ON | BOT_MODE_REMOTE_ENABLED | BOT_MODE_CAN_BE_SAPIENT | BOT_MODE_ROUNDSTART_POSSESSION
///Bot-related cover flags on the Bot to deal with what has been done to their cover, including emagging. BOT_COVER_MAINTS_OPEN | BOT_COVER_LOCKED | BOT_COVER_EMAGGED | BOT_COVER_HACKED
var/bot_access_flags = BOT_COVER_LOCKED
@@ -151,6 +152,11 @@ GLOBAL_LIST_INIT(command_strings, list(
ai_controller.set_blackboard_key(BB_RADIO_CHANNEL, radio_channel)
update_appearance()
/mob/living/basic/bot/proc/set_mode_flags(mode_flags)
SHOULD_CALL_PARENT(TRUE)
bot_mode_flags = mode_flags
SEND_SIGNAL(src, COMSIG_BOT_MODE_FLAGS_SET, mode_flags)
/mob/living/basic/bot/proc/get_mode()
if(client) //Player bots do not have modes, thus the override. Also an easy way for PDA users/AI to know when a bot is a player.
return span_bold("[paicard ? "pAI Controlled" : "Autonomous"]")
@@ -181,7 +187,7 @@ GLOBAL_LIST_INIT(command_strings, list(
/mob/living/basic/bot/proc/turn_on()
if(stat == DEAD)
return FALSE
bot_mode_flags |= BOT_MODE_ON
set_mode_flags(bot_mode_flags | BOT_MODE_ON)
remove_traits(list(TRAIT_INCAPACITATED, TRAIT_IMMOBILIZED, TRAIT_HANDS_BLOCKED), POWER_LACK_TRAIT)
set_light_on(bot_mode_flags & BOT_MODE_ON ? TRUE : FALSE)
update_appearance()
@@ -190,7 +196,7 @@ GLOBAL_LIST_INIT(command_strings, list(
return TRUE
/mob/living/basic/bot/proc/turn_off()
bot_mode_flags &= ~BOT_MODE_ON
set_mode_flags(bot_mode_flags & ~BOT_MODE_ON)
add_traits(on_toggle_traits, POWER_LACK_TRAIT)
set_light_on(bot_mode_flags & BOT_MODE_ON ? TRUE : FALSE)
bot_reset() //Resets an AI's call, should it exist.
@@ -308,7 +314,7 @@ GLOBAL_LIST_INIT(command_strings, list(
return FALSE
bot_access_flags |= BOT_COVER_EMAGGED
bot_access_flags |= BOT_COVER_LOCKED
bot_mode_flags &= ~BOT_MODE_REMOTE_ENABLED //Manually emagging the bot also locks the AI from controlling it.
set_mode_flags(bot_mode_flags & ~BOT_MODE_REMOTE_ENABLED) //Manually emagging the bot also locks the AI from controlling it.
bot_reset()
turn_on() //The bot automatically turns on when emagged, unless recently hit with EMP.
to_chat(src, span_userdanger("(#$*#$^^( OVERRIDE DETECTED"))
@@ -553,9 +559,9 @@ GLOBAL_LIST_INIT(command_strings, list(
switch(command)
if("patroloff")
bot_reset() //HOLD IT!! //OBJECTION!!
bot_mode_flags &= ~BOT_MODE_AUTOPATROL
set_mode_flags(bot_mode_flags & ~BOT_MODE_AUTOPATROL)
if("patrolon")
bot_mode_flags |= BOT_MODE_AUTOPATROL
set_mode_flags(bot_mode_flags | BOT_MODE_AUTOPATROL)
if("summon")
summon_bot(user, user_access = user_access)
if("ejectpai")
@@ -607,10 +613,10 @@ GLOBAL_LIST_INIT(command_strings, list(
if("maintenance")
bot_access_flags ^= BOT_COVER_MAINTS_OPEN
if("patrol")
bot_mode_flags ^= BOT_MODE_AUTOPATROL
set_mode_flags(bot_mode_flags ^ BOT_MODE_AUTOPATROL)
bot_reset()
if("airplane")
bot_mode_flags ^= BOT_MODE_REMOTE_ENABLED
set_mode_flags(bot_mode_flags ^ BOT_MODE_REMOTE_ENABLED)
if("hack")
if(!HAS_SILICON_ACCESS(the_user))
return