Fixes removing AIs from mechs (#55986)

Basically the old code attempted to use locate(AI), but the AI in this case is a ref that is supposed to be provided by the card. Since the card is initially empty when removing AIs from the mech, it couldn't find the null in the occupants list and thus failed with a report that there was no AI in the mech.

Now it checks all occupants and makes a list of any AIs it finds, then gives the user the option to pick an AI (though since we don't have any multi-pilot mechs yet the most you can get is one AI, and input with one option just auto-chooses).
This commit is contained in:
zxaber
2021-01-11 01:37:48 -08:00
committed by GitHub
parent 041732939f
commit 93b2aa0820
+13 -2
View File
@@ -812,10 +812,21 @@
if(!construction_state) //Mech must be in maint mode to allow carding.
to_chat(user, "<span class='warning'>[name] must have maintenance protocols active in order to allow a transfer.</span>")
return
if(!locate(AI) in occupants) //Mech does not have an AI for a pilot
var/list/ai_pilots = list()
for(var/mob/living/silicon/ai/aipilot in occupants)
ai_pilots += aipilot
if(!ai_pilots.len) //Mech does not have an AI for a pilot
to_chat(user, "<span class='warning'>No AI detected in the [name] onboard computer.</span>")
return
for(var/mob/living/silicon/ai in occupants)
if(ai_pilots.len > 1) //Input box for multiple AIs, but if there's only one we'll default to them.
AI = input(user,"Which AI do you wish to card?", "AI Selection") as null|anything in sortList(ai_pilots)
else
AI = ai_pilots[1]
if(!AI)
return
if(!(AI in occupants) || !user.Adjacent(src))
return //User sat on the selection window and things changed.
AI.ai_restore_power()//So the AI initially has power.
AI.control_disabled = TRUE
AI.radio_enabled = FALSE