@@ -89,7 +89,7 @@ dfhack.onStateChange[GLOBAL_KEY] = function(sc)
8989 -- retrieve state saved in game. merge with default state so config
9090 -- saved from previous versions can pick up newer defaults.
9191 load_state ()
92- if ( state .enabled ) then
92+ if state .enabled then
9393 start ()
9494 end
9595 persist_state ()
101101-- ######
102102function getTrainingCandidates ()
103103 local ret = {}
104- local citizen = dfhack .units .getCitizens (true )
105104 ignore_count = 0
106- for _ , unit in ipairs (citizen ) do
105+ for _ , unit in ipairs (dfhack . units . getCitizens ( true ) ) do
107106 if state .ignored [unit .id ] then
108107 ignore_count = ignore_count + 1
109108 goto next_unit
@@ -171,21 +170,21 @@ function checkSquads()
171170 for _ , squad in ipairs (getTrainingSquads ()) do
172171 if squad .entity_id == df .global .plotinfo .group_id then
173172 local leader = squad .positions [0 ].occupant
174- if ( leader ~= - 1 ) then
173+ if leader ~= - 1 then
175174 table.insert (squads ,squad )
176175 end
177176 end
178177 end
179178
180- if ( # squads == 0 ) then
179+ if # squads == 0 then
181180 return nil
182181 end
183182
184183 return squads
185184end
186185
187186function addTraining (unit ,good_squads )
188- if ( unit .military .squad_id ~= - 1 ) then
187+ if unit .military .squad_id ~= - 1 then
189188 for _ , squad in ipairs (good_squads ) do
190189 if unit .military .squad_id == squad .id then
191190 return true
@@ -195,7 +194,7 @@ function addTraining(unit,good_squads)
195194 end
196195 for _ , squad in ipairs (good_squads ) do
197196 for i = 1 ,9 ,1 do
198- if ( squad .positions [i ].occupant == - 1 ) then
197+ if squad .positions [i ].occupant == - 1 then
199198 return dfhack .military .addToSquad (unit .id ,squad .id ,i )
200199 end
201200 end
@@ -205,7 +204,7 @@ function addTraining(unit,good_squads)
205204end
206205
207206function removeAll ()
208- if ( state .training_squads == nil ) then return end
207+ if state .training_squads == nil then return end
209208 for _ , squad in ipairs (getTrainingSquads ()) do
210209 for i = 1 ,9 ,1 do
211210 local hf = df .historical_figure .find (squad .positions [i ].occupant )
@@ -221,44 +220,35 @@ function check()
221220 local squads = checkSquads ()
222221 local intraining_count = 0
223222 local inque_count = 0
224- if ( squads == nil ) then return end
223+ if squads == nil then return end
225224 for _ ,squad in ipairs (squads ) do
226225 for i = 1 ,9 ,1 do
227- if ( squad .positions [i ].occupant ~= - 1 ) then
226+ if squad .positions [i ].occupant ~= - 1 then
228227 local hf = df .historical_figure .find (squad .positions [i ].occupant )
229228 if hf ~= nil then
230229 local unit = df .unit .find (hf .unit_id )
231230 local training_need = getTrainingNeed (unit )
232- if ( training_need ~= nil ) then
233- if ( training_need .focus_level >= state .threshold ) then
234- dfhack .military .removeFromSquad (unit )
235- end
231+ if not training_need or training_need .focus_level >= state .threshold then
232+ dfhack .military .removeFromSquad (unit )
236233 end
237234 end
238235 end
239236 end
240237 end
241238 for _ , unit in ipairs (getTrainingCandidates ()) do
242- local training_need = getTrainingNeed (unit )
243- if ( training_need ~= nil ) then
244- if ( training_need .focus_level < state .threshold ) then
245- local added = addTraining (unit , squads )
246- if added then
247- intraining_count = intraining_count + 1
248- else
249- inque_count = inque_count + 1
250- end
251- else
252- dfhack .military .removeFromSquad (unit )
253- end
239+ local added = addTraining (unit , squads )
240+ if added then
241+ intraining_count = intraining_count + 1
242+ else
243+ inque_count = inque_count + 1
254244 end
255245 end
256246
257247 dfhack .println (GLOBAL_KEY .. " | IGNORED: " .. ignore_count .. " TRAINING: " .. intraining_count .. " QUEUE: " .. inque_count )
258248end
259249
260250function start ()
261- if ( args .t ) then
251+ if args .t then
262252 state .threshold = 0 - tonumber (args .t )
263253 end
264254 repeatUtil .scheduleEvery (GLOBAL_KEY , 1 , ' days' , check )
@@ -281,7 +271,7 @@ if dfhack_flags.module then
281271 return
282272end
283273
284- if ( state .enabled ) then
274+ if state .enabled then
285275 start ()
286276else
287277 stop ()
0 commit comments