Skip to content

Commit 2250848

Browse files
clean and de-nest training candidates
1 parent e274598 commit 2250848

1 file changed

Lines changed: 28 additions & 20 deletions

File tree

autotraining.lua

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -104,29 +104,37 @@ function getTrainingCandidates()
104104
local citizen = dfhack.units.getCitizens(true)
105105
ignore_count = 0
106106
for _, unit in ipairs(citizen) do
107-
if dfhack.units.isAdult(unit) then
108-
local noblePos = dfhack.units.getNoblePositions(unit)
109-
local isIgnNoble = false
110-
if ( not state.ignored[unit.id] ) then
111-
if noblePos ~=nil then
112-
for _, position in ipairs(noblePos) do
113-
if state.ignored_nobles[position.position.code] then
114-
isIgnNoble = true
115-
break
116-
end
117-
end
118-
end
119-
if not isIgnNoble then
120-
table.insert(ret, unit)
121-
else
122-
dfhack.military.removeFromSquad(unit)
123-
ignore_count = ignore_count +1
124-
end
125-
else
126-
dfhack.military.removeFromSquad(unit)
107+
if state.ignored[unit.id] then
108+
ignore_count = ignore_count +1
109+
goto next_unit
110+
end
111+
if not dfhack.units.isAdult(unit) then
112+
ignore_count = ignore_count +1
113+
goto next_unit
114+
end
115+
local need = getTrainingNeed(unit)
116+
if ( need ~= nil ) then
117+
if ( need.focus_level >= state.threshold ) then
127118
ignore_count = ignore_count +1
119+
goto next_unit
120+
end
121+
end
122+
local noblePos = dfhack.units.getNoblePositions(unit)
123+
local isIgnNoble = false
124+
if noblePos ~=nil then
125+
for _, position in ipairs(noblePos) do
126+
if state.ignored_nobles[position.position.code] then
127+
isIgnNoble = true
128+
break
129+
end
128130
end
129131
end
132+
if isIgnNoble then
133+
ignore_count = ignore_count +1
134+
goto next_unit
135+
end
136+
table.insert(ret, unit)
137+
::next_unit::
130138
end
131139
return ret
132140
end

0 commit comments

Comments
 (0)