@@ -43,6 +43,7 @@ local GetGameSeconds = Spring.GetGameSeconds
4343local GetSelectedUnits = Spring .GetSelectedUnits
4444local GetUnitTeam = Spring .GetUnitTeam
4545local GetTeamResources = Spring .GetTeamResources
46+ local spGetFeaturesInCylinder = Spring .GetFeaturesInCylinder
4647
4748---- ----------------------------------------------------------------------------
4849---- ----------------------------------------------------------------------------
@@ -303,40 +304,20 @@ function widget:Update(deltaTime)
303304 nanoTurrets [unitID ].damaged = false
304305 end
305306
306- local cmdID , _ , _ , cmdParam = Spring .GetUnitCurrentCommand (unitID )
307+ local prevCommand , _ , _ , prevUnit = Spring .GetUnitCurrentCommand (unitID ) -- CMDID, _,_, Commandparam
307308 local cQueueCount = GetUnitCommandCount (unitID )
308-
309+
309310 local commandMe = false
310-
311- local prevCommand = nil
312- local prevUnit = nil
313-
311+
314312 if (cQueueCount == 0 ) then
315313 commandMe = true
316314 nanoTurrets [unitID ].auto = false
315+ elseif (prevCommand == CMD .PATROL ) and (cQueueCount <= 4 ) then
316+ commandMe = true
317+ nanoTurrets [unitID ].auto = false
317318 else
318- if (cmdID == CMD .PATROL ) and (cQueueCount <= 4 ) then
319- commandMe = true
320- nanoTurrets [unitID ].auto = false
321- end
322-
323- if nanoTurrets [unitID ].auto then
324- if (cmdID == CMD .RECLAIM ) then
325- prevCommand = CMD .RECLAIM
326- prevUnit = cmdParam
327- if prevUnit < Game .maxUnits then
328- local targetDefID = GetUnitDefID (prevUnit )
329- if (targetDefID ~= nil ) and UnitDefs [targetDefID ].canMove then
330- local uX , _ , uZ = GetUnitPosition (prevUnit )
331- if (getDistance (unitDefs .posX , unitDefs .posZ , uX , uZ ) > unitDefs .buildDistanceSqr ) then
332- commandMe = true
333- end
334- end
335- end
336- end
337- if (cmdID == CMD .REPAIR ) then
338- prevCommand = CMD .REPAIR
339- prevUnit = cmdParam
319+ if (prevCommand == CMD .RECLAIM ) then
320+ if prevUnit < Game .maxUnits then
340321 local targetDefID = GetUnitDefID (prevUnit )
341322 if (targetDefID ~= nil ) and UnitDefs [targetDefID ].canMove then
342323 local uX , _ , uZ = GetUnitPosition (prevUnit )
@@ -345,11 +326,20 @@ function widget:Update(deltaTime)
345326 end
346327 end
347328 end
348-
349- if ((unitDefs .timeCounter + UPDATE_TICK ) < GetGameSeconds ()) then
350- commandMe = true
329+ end
330+ if (prevCommand == CMD .REPAIR ) then
331+ local targetDefID = GetUnitDefID (prevUnit )
332+ if (targetDefID ~= nil ) and UnitDefs [targetDefID ].canMove then
333+ local uX , _ , uZ = GetUnitPosition (prevUnit )
334+ if (getDistance (unitDefs .posX , unitDefs .posZ , uX , uZ ) > unitDefs .buildDistanceSqr ) then
335+ commandMe = true
336+ end
351337 end
352338 end
339+
340+ if ((unitDefs .timeCounter + UPDATE_TICK ) < GetGameSeconds ()) then
341+ commandMe = true
342+ end
353343 end
354344
355345 if (commandMe ) then
@@ -358,16 +348,13 @@ function widget:Update(deltaTime)
358348 local ordered = false
359349
360350 local nearUnits = GetUnitsInCylinder (unitDefs .posX ,unitDefs .posZ ,unitDefs .buildDistance )
361- local nearFeatures = Spring .GetFeaturesInRectangle (
362- unitDefs .posX - (unitDefs .buildDistance + 75 ), unitDefs .posZ - (unitDefs .buildDistance + 75 ),
363- unitDefs .posX + (unitDefs .buildDistance + 75 ), unitDefs .posZ + (unitDefs .buildDistance + 75 )
364- )
351+ local nearFeatures = spGetFeaturesInCylinder (unitDefs .posX , unitDefs .posZ , unitDefs .buildDistance )
365352
366353 if (nearUnits ~= nil ) and (nearFeatures ~= nil ) then
367354
368355 for _ ,nearUnitID in pairs (nearUnits ) do
369356 if nanoTurrets [nearUnitID ] and nanoTurrets [nearUnitID ].damaged and (unitID ~= nearUnitID ) then
370- if (prevCommand ~= CMD .REPAIR ) or ( prevUnit ~= bestUnit ) then
357+ if (prevCommand ~= CMD .REPAIR ) then
371358 orderQueue [unitID ] = {1 , CMD .REPAIR , nearUnitID }
372359 end
373360 ordered = true
@@ -381,9 +368,9 @@ function widget:Update(deltaTime)
381368 local nextUnit = nil
382369 for _ ,nearUnitID in pairs (nearUnits ) do
383370 if (teamUnits [nearUnitID ] and teamUnits [nearUnitID ].damaged ) then
384- if ( nextUnit == nil ) then nextUnit = nearUnitID end
385- if (# UnitDefs [GetUnitDefID (nearUnitID )].weapons > 0 ) then
386- if (teamUnits [nearUnitID ].rHealth < bestStat ) then
371+ nextUnit = nextUnit or nearUnitID
372+ if (# UnitDefs [GetUnitDefID (nearUnitID )].weapons > 0 ) then
373+ if (teamUnits [nearUnitID ].rHealth < bestStat ) then
387374 bestUnit = nearUnitID
388375 bestStat = teamUnits [nearUnitID ].rHealth
389376 end
@@ -469,8 +456,8 @@ function widget:Update(deltaTime)
469456 end
470457
471458 if (nanoTurrets [unitID ].auto ) and (not ordered ) and (cQueueCount > 0 ) and
472- ((cmdID == CMD .REPAIR ) or (cmdID == CMD .RECLAIM )) then
473- orderQueue [unitID ] = {0 , cmdID , cmdParam }
459+ ((prevCommand == CMD .REPAIR ) or (prevCommand == CMD .RECLAIM )) then
460+ orderQueue [unitID ] = {0 , prevCommand , prevUnit }
474461 elseif ordered then
475462 nanoTurrets [unitID ].auto = true
476463 end
0 commit comments