This might be the best I can do on this issue. The biggest problem is trying to find units that are in the same strikegroup.
No need to read the following as I’m just rambling on about a better fix if gearbox was to add a few new functions.
Ramblings
If gearbox was to continue with Homeworld, and for some reason chose not to fix this bug, then (at least for me) 3 new functions and changes to 2 other functions would make this bug easily fixed with lua.
For the new functions, the most important is something to get the strikegroup of a unit.
SobGroup_FillStrikeGroup(<SobGroup-Out>,<SobGroup>)
Next, due to how strikegroups work, it would be best to know the group stance (“None”, “Batch”, “Shape” and “Subs”)
SobGroup_GetStanceGrouping(<SobGroup>)
With group stancing, sub formations are determined by there attack family and combat family. Currently, there is no way I know of determining a units combat family other then loading the units ship file. As such, adding a new filter tag “combatFamily” would be of use.
SobGroup_FilterInclude(<SobGroup-Out>,<SobGroup>,"combatFamily",<sAttackFamily>)
While the above determines what units are in a strikegroup as well as there current stance grouping, deciding who to attack with lua will replace any back-end code that does a much better job. To correct this, first it would be best to know what unit a ship is attacking.
SobGroup_GetPrimaryTargetIndex(<SobGroup>)
Lastly, there would need to be a way to set the primary target from a list of potential targets, this could be done using
SobGroup_Attack(<Player>, <SobGroup>, <SobGroup-ToAttack>, <PrimaryTargetIndex>)
If these function were added, the lua code to fix this bug would be
function FixTarget_Init()
if (Rule_Exists("FixTarget_Rule")~= 1) then
Rule_AddInterval("FixTarget_Rule", 0.25)
end
end
function FixTarget_Rule()
if (attackFamily == nil) then
dofilepath("Data:Scripts\\FamilyList.lua")
attackCount = getn(attackFamily)
end
SobGroup_CreateIfNotExist("Squadron")
SobGroup_CreateIfNotExist("StrikeGroup")
SobGroup_CreateIfNotExist("StrikeFamily")
SobGroup_CreateIfNotExist("Player_Ships")
for player = 0, Universe_PlayerCount()- 1 do
SobGroup_Copy("Player_Ships", "Player_Ships"..player)
while (SobGroup_Empty("Player_Ships")~= 1) do
SobGroup_FillShipsByIndexRange("Squadron", "Player_Ships", 0, 1)
SobGroup_FillSubstract("Player_Ships", "Player_Ships", "Squadron")
if (SobGroup_InStrikeGroup("Squadron")== 1) then
local groupStance = SobGroup_GetStanceGrouping("Squadron")
SobGroup_FillStrikeGroup("StrikeGroup", "Squadron")
SobGroup_FillSubstract("Player_Ships", "Player_Ships", "StrikeGroup")
if (groupStance == "None") then
-- fix everyone
FixTarget_Primary("StrikeGroup")
end
if (groupStance == "Shape") then
for int = 1, attackCount do
SobGroup_FilterInclude("StrikeFamily", "StrikeGroup", "combatFamily", attackFamily[int])
SobGroup_FillSubstract("StrikeGroup", "StrikeGroup", "StrikeFamily")
if (SobGroup_Count("StrikeFamily") > 0) then
FixTarget_Primary("StrikeFamily")
end
end
for int = 1, attackCount do
SobGroup_FilterInclude("StrikeFamily", "StrikeGroup", "attackFamily", attackFamily[int])
SobGroup_FillSubstract("StrikeGroup", "StrikeGroup", "StrikeFamily")
if (SobGroup_Count("StrikeFamily") > 0) then
FixTarget_SetPrimary("StrikeFamily")
end
end
end
if (groupStance == "Batch" or groupStance == "Subs") then
-- only fix squadrons
while (SobGroup_Empty("StrikeGroup")~= 1) do
SobGroup_FillShipsByIndexRange("StrikeFamily", "StrikeGroup", 0, 1)
SobGroup_FillSubstract("StrikeGroup", "StrikeGroup", "StrikeFamily")
if (SobGroup_Count("StrikeFamily") > 1) then
FixTarget_Primary("StrikeFamily")
end
end
end
end
end
end
end
function FixTarget_SetPrimary(player, sobGroup)
local player,primaryIndex = SobGroup_OwnedBy(sobGroup), SobGroup_GetPrimaryTargetIndex(sobGroup)
SobGroup_CreateIfNotExist("FixTarget_SetPrimary")
SobGroup_GetCommandTargets("FixTarget_SetPrimary", sobGroup, COMMAND_Attack)
SobGroup_Attack(player, sobGroup, "FixTarget_SetPrimary", primaryIndex)
end