diff --git a/loc/US/strings_db.lua b/loc/US/strings_db.lua index 8f78dae33e..21883d0d11 100644 --- a/loc/US/strings_db.lua +++ b/loc/US/strings_db.lua @@ -7735,6 +7735,8 @@ lobui_0792="Manual unit sharing are allowed" lobui_0793="Yes except builders" lobui_0794="No manual sharing of builder/factory" lobui_0795="No manual sharing of units" +lobui_0796="Partial Share" +lobui_0797="Your buildings and engineers will be transferred to your highest rated ally when you die. Your other units will be destroyed when you die, except those captured by the enemy." aisettings_0001="AIx Cheat Multiplier" aisettings_0002="Set the cheat multiplier for the cheating AIs." diff --git a/lua/SimUtils.lua b/lua/SimUtils.lua index a227c968bc..64fd7abd53 100644 --- a/lua/SimUtils.lua +++ b/lua/SimUtils.lua @@ -15,15 +15,25 @@ local buildersCategory = categories.ALLUNITS - categories.CONSTRUCTION - categor local sharedUnits = {} ---@param owner number -function KillSharedUnits(owner) +-- categoriesToKill is an optional input (it defaults to all categories) +function KillSharedUnits(owner, categoriesToKill) local sharedUnitOwner = sharedUnits[owner] if sharedUnitOwner and not table.empty(sharedUnitOwner) then for _, unit in sharedUnitOwner do if not unit.Dead and unit.oldowner == owner then - unit:Kill() + if categoriesToKill then + if ContainsCategory(unit, categoriesToKill) then + table.remove(sharedUnits[owner], unit) + unit:Kill() + end + else + unit:Kill() + end end end - sharedUnits[owner] = {} + if not categoriesToKill then + sharedUnits[owner] = {} + end end end diff --git a/lua/aibrain.lua b/lua/aibrain.lua index 7726618cca..0f1a856289 100644 --- a/lua/aibrain.lua +++ b/lua/aibrain.lua @@ -918,19 +918,25 @@ AIBrain = Class(moho.aibrain_methods) { end -- Transfer our units to other brains. Wait in between stops transfer of the same units to multiple armies. - local function TransferUnitsToBrain(brains) + -- Optional Categories input (defaults to all units except wall and command) + local function TransferUnitsToBrain(brains, categoriesToTransfer) if not table.empty(brains) then + local units if shareOption == 'FullShare' then local indexes = {} for _, brain in brains do table.insert(indexes, brain.index) end - local units = self:GetListOfUnits(categories.ALLUNITS - categories.WALL - categories.COMMAND, false) + units = self:GetListOfUnits(categories.ALLUNITS - categories.WALL - categories.COMMAND, false) TransferUnfinishedUnitsAfterDeath(units, indexes) end for k, brain in brains do - local units = self:GetListOfUnits(categories.ALLUNITS - categories.WALL - categories.COMMAND, false) + if categoriesToTransfer then + units = self:GetListOfUnits(categoriesToTransfer, false) + else + units = self:GetListOfUnits(categories.ALLUNITS - categories.WALL - categories.COMMAND, false) + end if units and not table.empty(units) then local givenUnitCount = table.getn(TransferUnitsOwnership(units, brain.index)) @@ -946,7 +952,8 @@ AIBrain = Class(moho.aibrain_methods) { end -- Sort the destiniation brains (armies/players) by rating (and if rating does not exist (such as with regular AI's), by score, after players with positive rating) - local function TransferUnitsToHighestBrain(brains) + -- optional category input (default of everything but walls and command) + local function TransferUnitsToHighestBrain(brains, categoriesToTransfer) if not table.empty(brains) then local ratings = ScenarioInfo.Options.Ratings for i, brain in brains do @@ -959,7 +966,7 @@ AIBrain = Class(moho.aibrain_methods) { end -- sort brains by rating table.sort(brains, function(a, b) return a.rating > b.rating end) - TransferUnitsToBrain(brains) + TransferUnitsToBrain(brains, categoriesToTransfer) end end @@ -1041,7 +1048,12 @@ AIBrain = Class(moho.aibrain_methods) { KillSharedUnits(self:GetArmyIndex()) -- Kill things I gave away ReturnBorrowedUnits() -- Give back things I was given by others elseif shareOption == 'FullShare' then - TransferUnitsToHighestBrain(BrainCategories.Allies) -- Transfer things to allies, highest score first + TransferUnitsToHighestBrain(BrainCategories.Allies) -- Transfer things to allies, highest rating first + TransferOwnershipOfBorrowedUnits(BrainCategories.Allies) -- Give stuff away permanently + elseif shareOption == 'PartialShare' then + KillSharedUnits(self:GetArmyIndex(), categories.ALLUNITS - categories.STRUCTURE - categories.ENGINEER) -- Kill some things I gave away + ReturnBorrowedUnits() -- Give back things I was given by others + TransferUnitsToHighestBrain(BrainCategories.Allies, categories.STRUCTURE + categories.ENGINEER) -- Transfer some things to allies, highest rating first TransferOwnershipOfBorrowedUnits(BrainCategories.Allies) -- Give stuff away permanently else GetBackUnits(BrainCategories.Allies) -- Get back units I gave away diff --git a/lua/ui/game/score.lua b/lua/ui/game/score.lua index e1bb368acb..2e904d7a72 100644 --- a/lua/ui/game/score.lua +++ b/lua/ui/game/score.lua @@ -249,6 +249,7 @@ end local ShareNameLookup = { } ShareNameLookup["FullShare"] = "lobui_0742" ShareNameLookup["ShareUntilDeath"] = "lobui_0744" +ShareNameLookup["PartialShare"] = "lobui_0796" ShareNameLookup["TransferToKiller"] = "lobui_0762" ShareNameLookup["Defectors"] = "lobui_0766" ShareNameLookup["CivilianDeserter"] = "lobui_0764" @@ -256,6 +257,7 @@ ShareNameLookup["CivilianDeserter"] = "lobui_0764" local ShareDescriptionLookup = { } ShareDescriptionLookup["FullShare"] = "lobui_0743" ShareDescriptionLookup["ShareUntilDeath"] = "lobui_0745" +ShareDescriptionLookup["PartialShare"] = "lobui_0797" ShareDescriptionLookup["TransferToKiller"] = "lobui_0763" ShareDescriptionLookup["Defectors"] = "lobui_0767" ShareDescriptionLookup["CivilianDeserter"] = "lobui_0765" diff --git a/lua/ui/lobby/lobbyOptions.lua b/lua/ui/lobby/lobbyOptions.lua index ef8b763831..e521e50bb1 100644 --- a/lua/ui/lobby/lobbyOptions.lua +++ b/lua/ui/lobby/lobbyOptions.lua @@ -29,7 +29,7 @@ ---@field RevealCivilians 'No' | 'Yes' ---@field RandomMap 'Off' | 'Official' | 'All' ---@field Score 'no' | 'yes' ----@field Share 'FullShare' | 'ShareUntilDeath' | 'TransferToKiller' | 'Defectors' | 'CivilianDeserter' +---@field Share 'FullShare' | 'ShareUntilDeath' | 'PartialShare' | 'TransferToKiller' | 'Defectors' | 'CivilianDeserter' ---@field ShareUnitCap 'none' | 'allies' | 'all' ---@field Timeouts '0' | '3'| '-1' ---@field UnitCap '125' | '250' | '375' | '500' | '625' | '750' | '875' | '1000' | '1250' | '1500' @@ -205,6 +205,11 @@ globalOpts = { help = "All units you have built this game will be destroyed when you die, except those captured by the enemy.", key = 'ShareUntilDeath', }, + { + text = "Partial Share", + help = "Your buildings and engineers will be transferred to your highest rated ally when you die. Your other units will be destroyed when you die, except those captured by the enemy.", + key = 'PartialShare', + }, { text = "Traitors", help = "Your units will be transferred to the control of your killer.",