Skip to content

Commit

Permalink
Fix unintended case allowing multiple AI spawns shiftstart (tgstation…
Browse files Browse the repository at this point in the history
  • Loading branch information
Timberpoes authored May 20, 2021
1 parent f3bcf89 commit b15c08b
Showing 1 changed file with 10 additions and 13 deletions.
23 changes: 10 additions & 13 deletions code/controllers/subsystem/job.dm
Original file line number Diff line number Diff line change
Expand Up @@ -259,23 +259,20 @@ SUBSYSTEM_DEF(job)
var/mob/dead/new_player/candidate = pick(candidates)
AssignRole(candidate, command_position)

/datum/controller/subsystem/job/proc/FillAIPosition()
var/ai_selected = FALSE
var/datum/job/job = GetJob("AI")
if(!job)
return FALSE
for(var/i = job.total_positions, i > 0, i--)
/// Attempts to fill out all available AI positions.
/datum/controller/subsystem/job/proc/fill_ai_positions()
var/datum/job/ai_job = GetJob("AI")
if(!ai_job)
return
// In byond for(in to) loops, the iteration is inclusive so we need to stop at ai_job.total_positions - 1
for(var/i in ai_job.current_positions to ai_job.total_positions - 1)
for(var/level in level_order)
var/list/candidates = list()
candidates = FindOccupationCandidates(job, level)
candidates = FindOccupationCandidates(ai_job, level)
if(candidates.len)
var/mob/dead/new_player/candidate = pick(candidates)
if(AssignRole(candidate, "AI"))
ai_selected++
break
if(ai_selected)
return TRUE
return FALSE


/** Proc DivideOccupations
Expand Down Expand Up @@ -341,9 +338,9 @@ SUBSYSTEM_DEF(job)
FillHeadPosition()
JobDebug("DO, Head Check end")

//Check for an AI
// Fill out any remaining AI positions.
JobDebug("DO, Running AI Check")
FillAIPosition()
fill_ai_positions()
JobDebug("DO, AI Check end")

//Other jobs are now checked
Expand Down

0 comments on commit b15c08b

Please sign in to comment.