diff --git a/code/game/gamemodes/game_mode.dm b/code/game/gamemodes/game_mode.dm
index 997926885ec..14dd7e1e3d0 100644
--- a/code/game/gamemodes/game_mode.dm
+++ b/code/game/gamemodes/game_mode.dm
@@ -591,6 +591,7 @@ proc/get_nt_opposed()
if(BE_TRAITOR) roletext="traitor"
if(BE_OPERATIVE) roletext="operative"
if(BE_WIZARD) roletext="wizard"
+ if(BE_MALF) roletext="malf AI"
if(BE_REV) roletext="revolutionary"
if(BE_CULTIST) roletext="cultist"
if(BE_NINJA) roletext="ninja"
diff --git a/code/game/gamemodes/gameticker.dm b/code/game/gamemodes/gameticker.dm
index ea2cfe38c62..c1288516e19 100644
--- a/code/game/gamemodes/gameticker.dm
+++ b/code/game/gamemodes/gameticker.dm
@@ -350,7 +350,7 @@ var/global/datum/controller/gameticker/ticker
proc/create_characters()
for(var/mob/new_player/player in player_list)
if(player.ready && player.mind)
- if(player.mind.assigned_role=="AI")
+ if(player.mind.assigned_role == "AI" || player.mind.special_role == "malfunctioning AI")
player.close_spawn_windows()
player.AIize()
else if(!player.mind.assigned_role)
diff --git a/code/game/gamemodes/malfunction/malfunction.dm b/code/game/gamemodes/malfunction/malfunction.dm
index 4684d94410d..fdca56bd5cc 100644
--- a/code/game/gamemodes/malfunction/malfunction.dm
+++ b/code/game/gamemodes/malfunction/malfunction.dm
@@ -20,6 +20,7 @@
var/station_captured = 0
var/to_nuke_or_not_to_nuke = 0
var/apcs = 0 //Adding dis to track how many APCs the AI hacks. --NeoFite
+ var/list/datum/mind/antag_candidates = list() // List of possible starting antags goes here
/datum/game_mode/malfunction/announce()
@@ -27,15 +28,36 @@
The AI on the satellite has malfunctioned and must be destroyed.
The AI satellite is deep in space and can only be accessed with the use of a teleporter! You have [AI_win_timeleft/60] minutes to disable it."}
+/datum/game_mode/malfunction/get_players_for_role(var/role = BE_MALF)
+ var/roletext = get_roletext(role)
+
+ var/datum/job/ai/DummyAIjob = new
+ for(var/mob/new_player/player in player_list)
+ if(player.client && player.ready)
+ if(player.client.prefs.be_special & BE_MALF)
+ if(!jobban_isbanned(player, "Syndicate") && !jobban_isbanned(player, "AI") && !jobban_isbanned(player, roletext) && DummyAIjob.player_old_enough(player.client))
+ if(player_old_enough_antag(player.client,role))
+ antag_candidates += player.mind
+ antag_candidates = shuffle(antag_candidates)
+ return antag_candidates
/datum/game_mode/malfunction/pre_setup()
- for(var/mob/new_player/player in player_list)
- if(player.mind && player.mind.assigned_role == "AI" && (player.client.prefs.be_special & BE_MALF))
- malf_ai+=player.mind
- if(malf_ai.len)
- return 1
- return 0
+ get_players_for_role(BE_MALF)
+ var/datum/mind/chosen_ai
+ if(!antag_candidates.len)
+ return 0
+ for(var/i = required_enemies, i > 0, i--)
+ chosen_ai=pick(antag_candidates)
+ malf_ai += chosen_ai
+ antag_candidates -= malf_ai
+ if (malf_ai.len < required_enemies)
+ return 0
+ for(var/datum/mind/ai_mind in malf_ai)
+ ai_mind.assigned_role = "MODE"
+ ai_mind.special_role = "malfunctioning AI"//So they actually have a special role/N
+ log_game("[ai_mind.key] (ckey) has been selected as a malf AI")
+ return 1
/datum/game_mode/malfunction/post_setup()
for(var/datum/mind/AI_mind in malf_ai)
diff --git a/code/game/jobs/job_controller.dm b/code/game/jobs/job_controller.dm
index 48e4dc6937a..0d43e6628e2 100644
--- a/code/game/jobs/job_controller.dm
+++ b/code/game/jobs/job_controller.dm
@@ -226,26 +226,22 @@ var/global/datum/controller/occupations/job_master
if(!job) return 0
if((job.title == "AI") && (config) && (!config.allow_ai)) return 0
+ if(ticker.mode.name == "AI malfunction") // malf. AIs are pre-selected before jobs
+ for (var/datum/mind/mAI in ticker.mode.malf_ai)
+ AssignRole(mAI.current, "AI")
+ ai_selected++
+ if(ai_selected) return 1
+ return 0
+
for(var/i = job.total_positions, i > 0, i--)
for(var/level = 1 to 3)
var/list/candidates = list()
- if(ticker.mode.name == "AI malfunction")//Make sure they want to malf if its malf
- candidates = FindOccupationCandidates(job, level, BE_MALF)
- else
- candidates = FindOccupationCandidates(job, level)
+ candidates = FindOccupationCandidates(job, level)
if(candidates.len)
var/mob/new_player/candidate = pick(candidates)
if(AssignRole(candidate, "AI"))
ai_selected++
break
- //Malf NEEDS an AI so force one if we didn't get a player who wanted it
- if((ticker.mode.name == "AI malfunction")&&(!ai_selected))
- unassigned = shuffle(unassigned)
- for(var/mob/new_player/player in unassigned)
- if(jobban_isbanned(player, "AI")) continue
- if(AssignRole(player, "AI"))
- ai_selected++
- break
if(ai_selected) return 1
return 0
diff --git a/code/modules/admin/topic.dm b/code/modules/admin/topic.dm
index d2b3dada0e2..a1eaae00273 100644
--- a/code/modules/admin/topic.dm
+++ b/code/modules/admin/topic.dm
@@ -668,12 +668,11 @@
jobs += "