FAForever / fa

Lua code for FAF
221 stars 228 forks source link

Fix units not rebuilding on army transfer #6106

Closed lL1l1 closed 2 months ago

lL1l1 commented 2 months ago

Description of the proposed changes

Fixes units not being rebuilt after being transferred.

Testing done on the proposed changes

Spawn a bunch of RAS presets, start building a T4 unit. Then run this console command to transfer the unbuilt T4 to yourself:

SimLua 
local tu = import('/lua/SimUtils.lua').TransferUnfinishedUnitsAfterDeath
local b = ArmyBrains[GetFocusArmy()]
local units = b:GetListOfUnits(categories.EXPERIMENTAL)
ForkThread(tu, units, {b:GetArmyIndex()})

It should return to you at the same HP/progress you partially built it at.

Additional context

Caused by a change to Unit:GetBuildRate (lua, not engine function) in #5932 unrelated to the reclaim costs. Instead of returning 0.0001 for 0 buildrate, it returned 0 which did not allow the rebuilder unit (zxa0001) to build.

This means that an alternative fix is to give the rebuilder 1 buildrate, and fixing this: https://github.com/FAForever/fa/commit/efdfc5e5a1ee68d45246df075fa864f6fdf558bd in a different way (we at least divide by buildrate in GetReclaimCosts and GiveNukeSiloBlocks).

Checklist

Garanas commented 2 months ago

Great find!

edit: also a very interesting approach to testing it. How did you come up with that?