[MIRROR] bug fixes and code refactor for AI, malf or otherwise (#27499)

* bug fixes and code refactor for AI, malf or otherwise (#82590)

## About The Pull Request

I was trying to fix a bug with ejecting from mechs as malf AI and the
more I looked the worse it seemed to get? So I'm putting in this PR with
the intent to refactor AI code to not be a Byzantine nightmare of new
objects referencing each other incompletely or with buggy behavior.
Finished PR for #82579 because I didn't want to clutter the comments
with commits of me trying to fix shit with git restore and revert
## Why It's Good For The Game

Fixes #81877
Fixes #82524
Mech dominating now just works off (and integrates with) similar code
for APC shunting
The cores left behind by AIs shunting or controlling mechs now properly
reference the AI instead of only the other way around
Some of these refactors slightly change how malf works; I think most of
it was unintended behavior in the first place, let me know in review if
not
## Changelog

The code for AIs remoting out of their shell has been refactored.
🆑
fix: Mech domination now properly integrates with shunting.
fix: Combat upgraded AIs no longer get two buggy malf ability pickers if
they also become malfunctioning
refactor: Refactored most of the functionality around malf AI shunting,
mech control
/🆑

---------

Co-authored-by: MrMelbert <51863163+MrMelbert@ users.noreply.github.com>

* bug fixes and code refactor for AI, malf or otherwise

---------

Co-authored-by: Joshua Kidder <49173900+Metekillot@users.noreply.github.com>
Co-authored-by: MrMelbert <51863163+MrMelbert@ users.noreply.github.com>
This commit is contained in:
SkyratBot
2024-04-29 23:50:24 +01:00
committed by GitHub
co-authored by MrMelbert Joshua Kidder
parent 155d75ee38
commit c66bf3a16b
12 changed files with 113 additions and 66 deletions
+24 -2
View File
@@ -12,6 +12,8 @@
var/datum/ai_laws/laws
var/obj/item/circuitboard/aicore/circuit
var/obj/item/mmi/core_mmi
/// only used in cases of AIs piloting mechs or shunted malf AIs, possible later use cases
var/mob/living/silicon/ai/remote_ai = null
/obj/structure/ai_core/Initialize(mapload)
. = ..()
@@ -58,11 +60,20 @@
update_appearance()
/obj/structure/ai_core/Destroy()
if(istype(remote_ai))
remote_ai.break_core_link()
remote_ai = null
QDEL_NULL(circuit)
QDEL_NULL(core_mmi)
QDEL_NULL(laws)
return ..()
/obj/structure/ai_core/take_damage(damage_amount, damage_type, damage_flag, sound_effect, attack_dir, armour_penetration)
. = ..()
if(. > 0 && istype(remote_ai))
to_chat(remote_ai, span_danger("Your core is under attack!"))
/obj/structure/ai_core/deactivated
icon_state = "ai-empty"
anchored = TRUE
@@ -157,6 +168,8 @@
return ITEM_INTERACT_SUCCESS
/obj/structure/ai_core/attackby(obj/item/tool, mob/living/user, params)
if(remote_ai)
to_chat(remote_ai, span_danger("CORE TAMPERING DETECTED!"))
if(!anchored)
if(tool.tool_behaviour == TOOL_WELDER)
if(state != EMPTY_CORE)
@@ -295,8 +308,17 @@
if(tool.tool_behaviour == TOOL_CROWBAR && core_mmi)
tool.play_tool_sound(src)
balloon_alert(user, "removed [AI_CORE_BRAIN(core_mmi)]")
core_mmi.forceMove(loc)
return
if(remote_ai)
var/mob/living/silicon/ai/remoted_ai = remote_ai
remoted_ai.break_core_link()
if(!IS_MALF_AI(remoted_ai))
//don't pull back shunted malf AIs
remoted_ai.death(gibbed = TRUE, drop_mmi = FALSE)
///the drop_mmi param determines whether the MMI is dropped at their current location
///which in this case would be somewhere else, so we drop their MMI at the core instead
remoted_ai.make_mmi_drop_and_transfer(core_mmi, src)
core_mmi.forceMove(loc) //if they're malf, just drops a blank MMI, or if it's an incomplete shell
return //it drops the mmi that was put in before it was finished
if(GLASS_CORE)
if(tool.tool_behaviour == TOOL_CROWBAR)