diff --git a/luarules/gadgets/game_disable_assist_ally.lua b/luarules/gadgets/game_disable_assist_ally.lua index 4b517dbde0..a3bd88a89f 100644 --- a/luarules/gadgets/game_disable_assist_ally.lua +++ b/luarules/gadgets/game_disable_assist_ally.lua @@ -16,7 +16,9 @@ end if not gadgetHandler:IsSyncedCode() then return false end -if not Spring.GetModOptions().disable_assist_ally_construction then +if not (Spring.GetModOptions().disable_assist_ally_construction + -- tax force enables this + or (Spring.GetModOptions().tax_resource_sharing_amount or 0) ~= 0) then return false end diff --git a/luarules/gadgets/game_disable_unit_sharing.lua b/luarules/gadgets/game_disable_unit_sharing.lua index f8e22e47e3..0b0bd82154 100644 --- a/luarules/gadgets/game_disable_unit_sharing.lua +++ b/luarules/gadgets/game_disable_unit_sharing.lua @@ -16,7 +16,12 @@ end if not gadgetHandler:IsSyncedCode() then return false end -if not Spring.GetModOptions().disable_unit_sharing then + +if not (Spring.GetModOptions().disable_unit_sharing + -- tax force enables this + or (Spring.GetModOptions().tax_resource_sharing_amount or 0) ~= 0) + -- unit market handles the restriction instead if enabled so that selling still works + or Spring.GetModOptions().unit_market then return false end diff --git a/luarules/gadgets/game_tax_resource_sharing.lua b/luarules/gadgets/game_tax_resource_sharing.lua index 280764606e..8eb35a4d54 100644 --- a/luarules/gadgets/game_tax_resource_sharing.lua +++ b/luarules/gadgets/game_tax_resource_sharing.lua @@ -16,7 +16,7 @@ end if not gadgetHandler:IsSyncedCode() then return false end -if not Spring.GetModOptions().tax_resource_sharing_and_prevent_some_reclaim_loopholes then +if Spring.GetModOptions().tax_resource_sharing_amount == 0 then return false end @@ -25,6 +25,8 @@ local spGetTeamUnitCount = Spring.GetTeamUnitCount local gameMaxUnits = math.min(Spring.GetModOptions().maxunits, math.floor(32000 / #Spring.GetTeamList())) +local sharingTax = Spring.GetModOptions().tax_resource_sharing_amount + ---------------------------------------------------------------- -- Callins ---------------------------------------------------------------- @@ -52,11 +54,10 @@ function gadget:AllowResourceTransfer(senderTeamId, receiverTeamId, resourceType -- rShare is the share slider setting, don't exceed their share slider max when sharing local maxShare = rStor * rShare - rCur - local sharingTax = Spring.GetModOptions().tax_resource_sharing_amount local taxedAmount = math.min((1-sharingTax)*amount, maxShare) local totalAmount = taxedAmount / (1-sharingTax) - local transferTax = totalAmount * sharingTax - + local transferTax = totalAmount * sharingTax + Spring.SetTeamResource(receiverTeamId, resourceName, rCur+taxedAmount) local sCur, _, _, _, _, _ = Spring.GetTeamResources(senderTeamId, resourceName) Spring.SetTeamResource(senderTeamId, resourceName, sCur-totalAmount) @@ -74,10 +75,8 @@ function gadget:AllowUnitTransfer(unitID, unitDefID, oldTeam, newTeam, capture) end - --- Disallow reclaiming allied units for metal function gadget:AllowCommand(unitID, unitDefID, unitTeam, cmdID, cmdParams, cmdOptions, cmdTag, synced) - + -- Disallow reclaiming allied units for metal if (cmdID == CMD.RECLAIM and #cmdParams >= 1) then local targetID = cmdParams[1] local targetTeam @@ -88,20 +87,15 @@ function gadget:AllowCommand(unitID, unitDefID, unitTeam, cmdID, cmdParams, cmdO if unitTeam ~= targetTeam and Spring.AreTeamsAllied(unitTeam, targetTeam) then return false end - end - return true -end - --- Also block guarding allied units that can reclaim -function gadget:AllowCommand(unitID, unitDefID, unitTeam, cmdID, cmdParams, cmdOptions, cmdTag, synced) - if (cmdID == CMD.GUARD) then + -- Also block guarding allied units that can reclaim + elseif (cmdID == CMD.GUARD) then local targetID = cmdParams[1] local targetTeam = Spring.GetUnitTeam(targetID) local targetUnitDef = UnitDefs[Spring.GetUnitDefID(targetID)] if (unitTeam ~= Spring.GetUnitTeam(targetID)) and Spring.AreTeamsAllied(unitTeam, targetTeam) then -- Labs are considered able to reclaim. In practice you will always use this modoption with "disable_assist_ally_construction", so disallowing guard labs here is fine - if targetUnitDef.canReclaim then + if targetUnitDef.canReclaim then return false end end diff --git a/luarules/gadgets/game_unit_market.lua b/luarules/gadgets/game_unit_market.lua index 7ade43533a..7e8312f330 100644 --- a/luarules/gadgets/game_unit_market.lua +++ b/luarules/gadgets/game_unit_market.lua @@ -149,6 +149,12 @@ local function offerUnitForSale(unitID, sale_price, msgFromTeamID) end end +local disable_unit_sharing = ( + Spring.GetModOptions().disable_unit_sharing + or (Spring.GetModOptions().tax_resource_sharing_amount or 0) ~= 0) +and Spring.GetModOptions().unit_market +local saleWhitelist = {} + local function tryToBuyUnit(unitID, msgFromTeamID) if not unitID or unitsForSale[unitID] == nil or unitsForSale[unitID] == 0 then return end local unitDefID = spGetUnitDefID(unitID) @@ -171,6 +177,10 @@ local function tryToBuyUnit(unitID, msgFromTeamID) if (current < price) then return end + if disable_unit_sharing then + saleWhitelist[unitID] = true + end + TransferUnit(unitID, msgFromTeamID) if msgFromTeamID ~= old_ownerTeamID and price > 0 then -- don't send resources to yourself ShareTeamResource(msgFromTeamID, old_ownerTeamID, "metal", price) @@ -179,6 +189,19 @@ local function tryToBuyUnit(unitID, msgFromTeamID) UnitSoldBroadcast(unitID, price, old_ownerTeamID, msgFromTeamID) end +if disable_unit_sharing then + function gadget:AllowUnitTransfer(unitID, unitDefID, fromTeamID, toTeamID, capture) + if(capture) then + return true + end + if saleWhitelist[unitID] then + saleWhitelist[unitID] = nil + return true + end + return false + end +end + -- this takes control and makes all cons stop using metal, we remove all limits on a) shutdown b) storage getting full c) widget crash - should be safe enough local function SetTeamSavingMetal(teamID, status) local old_status = TeamIsSaving[teamID] diff --git a/modoptions.lua b/modoptions.lua index db9491d4f1..48df28f7c9 100644 --- a/modoptions.lua +++ b/modoptions.lua @@ -161,15 +161,6 @@ local options = { }, }, - { - key = "unit_market", - name = "Unit Market", - desc = "Allow players to trade units. (Select unit, press 'For Sale' in order window or say /sell_unit in chat to mark the unit for sale. Double-click to buy from allies. T2cons show up in shop window!)", - type = "bool", - def = false, - section = "options_main", - }, - { key = "transportenemy", name = "Enemy Transporting", @@ -184,7 +175,6 @@ local options = { } }, - { key = "teamffa_start_boxes_shuffle", name = "Shuffle TeamFFA Start Boxes", @@ -234,6 +224,78 @@ local options = { step = 1, }, + { + key = "sub_header", + section = "options_main", + type = "separator", + }, + { + key = "sub_header", + name = "-- Sharing and Taxes", + section = "options_main", + type = "subheader", + def = true, + }, + { + key = "tax_resource_sharing_amount", + name = "Resource Sharing Tax", + desc = "Taxes resource sharing".."\255\128\128\128".." and overflow (engine TODO:)\n".. + "Set to [0] to turn off. Recommened: [0.4]. (Ranges: 0 - 0.99)\n".. + "*Disables: Reclaiming of Allied Units, [Unit Sharing] and [Assisting Ally Construction] to prevent loopholes", + type = "number", + def = 0, + min = 0, + max = 0.99, + step = 0.01, + section = "options_main", + column = 1, + lock = {"disable_unit_sharing","disable_assist_ally_construction"}, + unlock = {"disable_unit_sharing_forced","disable_assist_ally_construction_forced"}, + }, + { + key = "disable_unit_sharing", + name = "Disable Unit Sharing", + desc = "Disable sharing units and structures to allies", + type = "bool", + section = "options_main", + def = false, + }, + { + key = "disable_assist_ally_construction", + name = "Disable Assist Ally Construction", + desc = "Disables assisting allied blueprints and labs.", + type = "bool", + section = "options_main", + def = false, + column = 1.76, + }, + { key = "tax_padding", name = "", type = "subheader", section = "options_main", column = -3, }, + { + key = "disable_unit_sharing_forced", + --name = "\255\252\191\76".."Disable Unit Sharing [Forced ON]", + name = "\255\252\191\76".."Disable Unit Sharing Disable Assist Ally Construction", + type = "subheader", + section = "options_main", + }, + { + key = "disable_assist_ally_construction_forced", + --name = "\255\252\191\76".."Disable Assist Ally Construction [Forced ON]", + name = "\255\252\191\76".."[■] [■]", + type = "subheader", + section = "options_main", + column = 1.505, + font = 4, + }, + { + key = "unit_market", + name = "Unit Market", + desc = "Allow players to trade units. (Select unit, press 'For Sale' in order window or say /sell_unit in chat to mark the unit for sale. Double-click to buy from allies. T2cons show up in shop window!)", + type = "bool", + def = false, + section = "options_main", + }, + + { key = "sub_header", section = "options_main", @@ -378,42 +440,7 @@ local options = { def = false, column = 1.66, }, - - { - key ="disable_unit_sharing", - name ="Disable Unit Sharing", - desc ="Disable sharing units and structures to allies", - type ="bool", - section ="restrictions", - def = false, - }, - { - key ="disable_assist_ally_construction", - name ="Disable Assist Ally Construction", - desc ="Disables assisting an allied blueprint or lab.", - type ="bool", - section ="restrictions", - def = false, - }, - { - key ="tax_resource_sharing_and_prevent_some_reclaim_loopholes", - name ="Tax Resource Sharing", - desc ="Taxes resource sharing and overflow (engine TODO), and disables reclaiming allied units for metal. If using, should also select 'Disable Unit Sharing' and 'Disable Assist Ally Construction'", - type = "bool", - section ="restrictions", - def = false, - }, - { - key = "tax_resource_sharing_amount", - name = "Resource Sharing Tax Amount", - desc = "(Range: 0 - 0.99). What portion of shared resources (including overflow) will consumed as transfer tax.", - type = "number", - def = 0.4, - min = 0, - max = 0.99, - step = 0.01, - section= "restrictions", - }, + --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------