Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resource Sharing Tax Mod: Prevent upgrading allied mex/geos. No longer disables unit sharing completely, and can buy t2 con through Unit Market #4010

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 63 additions & 7 deletions luarules/gadgets/game_disable_unit_sharing.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,77 @@ if not gadgetHandler:IsSyncedCode() then
return false
end

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
local tax_resource_sharing_enabled = Spring.GetModOptions().tax_resource_sharing_amount ~= nil and Spring.GetModOptions().tax_resource_sharing_amount > 0
local disable_share_econ_and_lab = Spring.GetModOptions().disable_unit_sharing_economy_and_production or tax_resource_sharing_enabled
local disable_share_combat_units = Spring.GetModOptions().disable_unit_sharing_combat_units
local disable_share_all = Spring.GetModOptions().disable_unit_sharing_all

if not disable_share_econ_and_lab and not disable_share_combat_units and not disable_share_all then
return false
end


function gadget:AllowUnitTransfer(unitID, unitDefID, fromTeamID, toTeamID, capture)

-- create a table of all mex and geo unitDefIDs
local isEconOrLab = {}
local isCombatUnitOrTacticalBuilding = {}


-- List storages manually (some units or buildings may provide e or m storage but they are not primarily econ)
local storageNames = {
"armestor", "corestor", "legestor", "armuwes", "coruwes", "leguwes", "armuwadves", "coruwadves", "leguwadves",
"armmstor", "cormstor", "legmstor", "armuwms", "coruwms", "leguwms", "armuwadvms", "coruwadvms", "leguwadvms",
}
Copy link
Collaborator

@sprunk sprunk Dec 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

perhaps a "dedicated storage" customparam? or some sort of "if stores more than it costs" heuristic

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A customparam like "dedicatedEnergyStorage : true" is fine? Might be a useful classification for other gadgets too. A heuristic seems hackey and harder to read.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good.

Copy link
Contributor Author

@Rimilel Rimilel Dec 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

implemented it then realized unitgroup "metal" and "energy" already exist.
Changed to use customparam unitgroup. b46f7c8



for unitDefID, unitDef in pairs(UnitDefs) do
-- Mark econ units
if unitDef.isBuilding and (unitDef.energyMake or unitDef.extractsMetal > 0) > 0 then
isEconOrLab[unitDefID] = true
elseif unitDef.canResurrect then
isEconOrLab[unitDefID] = true
elseif unitDef.customParams.energyconv_capacity then
isEconOrLab[unitDefID] = true
elseif table.contains(storageNames, unitDef.name) then
isEconOrLab[unitDefID] = true

-- Mark labs and mobile production
elseif unitDef.isFactory or unitDef.isBuilder then
isEconOrLab[unitDefID] = true
end

-- Mark combat units and tactical buildings
if unitDef.isBuilding and not isEconOrLab[unitDefID] then
isCombatUnitOrTacticalBuilding[unitDefID] = true
elseif #unitDef.weapons > 0 then
isCombatUnitOrTacticalBuilding[unitDefID] = true
end
end





-- Returns whether the unit is allowed to be shared according to the unit sharing restrictions.
local function unitTypeAllowedToBeShared(unitDefID)
if disable_share_all then return false end
if disable_share_econ_and_lab and isEconOrLab[unitDefID] then return false end
if disable_share_combat_units and isCombatUnitOrTacticalBuilding[unitDefID] then return false end
return true
end
GG.disable_unit_sharing_unitTypeAllowedToBeShared = unitTypeAllowedToBeShared

if Spring.GetModOptions().unit_market then
-- let unit market handle unit sharing so that buying units will still work.
return false
end


function gadget:AllowUnitTransfer(unitID, unitDefID, fromTeamID, toTeamID, capture)
if(capture) then
return true
end
return false
return allowedToBeShared(unitDefID)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where does this come from???

Copy link
Contributor Author

@Rimilel Rimilel Dec 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh what the heck, that should be unitTypeAllowedToBeShared()

end


Expand Down
24 changes: 16 additions & 8 deletions luarules/gadgets/game_unit_market.lua
Original file line number Diff line number Diff line change
Expand Up @@ -157,13 +157,17 @@ for _, name in ipairs(t2conNames) do
end
end


local tax_resource_sharing_enabled = Spring.GetModOptions().tax_resource_sharing_amount ~= nil and Spring.GetModOptions().tax_resource_sharing_amount > 0
local disable_share_econ_and_lab = Spring.GetModOptions().disable_unit_sharing_economy_and_production or tax_resource_sharing_enabled
local disable_share_combat_units = Spring.GetModOptions().disable_unit_sharing_combat_units
local disable_share_all = Spring.GetModOptions().disable_unit_sharing_all

-- Override unit sharing block from other modoptions
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 disable_unit_sharing_enabled = (
Spring.GetModOptions().disable_unit_sharing_economy_and_production
or Spring.GetModOptions().disable_unit_sharing_combat_units
or Spring.GetModOptions().disable_unit_sharing_all
or (Spring.GetModOptions().tax_resource_sharing_amount or 0) ~= 0)
local saleWhitelist = {}

local function tryToBuyUnit(unitID, msgFromTeamID)
Expand Down Expand Up @@ -196,7 +200,7 @@ local function tryToBuyUnit(unitID, msgFromTeamID)

if (current < price) then return end

if disable_unit_sharing then
if disable_unit_sharing_enabled then
saleWhitelist[unitID] = true
end

Expand All @@ -214,7 +218,7 @@ local function tryToBuyUnit(unitID, msgFromTeamID)
UnitSoldBroadcast(unitID, price, old_ownerTeamID, msgFromTeamID)
end

if disable_unit_sharing then
if disable_unit_sharing_enabled then
function gadget:AllowUnitTransfer(unitID, unitDefID, fromTeamID, toTeamID, capture)
if(capture) then
return true
Expand All @@ -223,7 +227,11 @@ if disable_unit_sharing then
saleWhitelist[unitID] = nil
return true
end
return false
if(GG.disable_unit_sharing_unitTypeAllowedToBeShared) then
return GG.disable_unit_sharing_unitTypeAllowedToBeShared(unitDefID)
else
return true
end
end
end

Expand Down
63 changes: 39 additions & 24 deletions modoptions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ local options = {
step = 1,
},

{
{
key = "sub_header",
section = "options_main",
type = "separator",
Expand All @@ -244,52 +244,67 @@ local options = {
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",
"Set to [0] to turn off. Recommend: [0.4]. (Ranges: 0 - 0.99)\n"..
"Enable [Unit Market] to allow buying t2 cons\n"..
"*Disables: Reclaiming of Allied Units, [Economy and Lab Sharing] and [Assisting Ally Construction] to prevent loopholes\n",
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,
lock = {"disable_unit_sharing_economy_and_production","disable_assist_ally_construction"},
unlock = {"disable_unit_sharing_economy_and_production_forced","disable_assist_ally_construction_forced"},
},

{
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",
{
key = "disable_unit_sharing_economy_and_production",
name = "Disable Economy and Lab Sharing",
desc = "Disable sharing of economy and labs (including mobile engineers)",
type = "bool",
section = "options_main",
def = false,
},
{
key = "disable_assist_ally_construction_forced",
--name = "\255\252\191\76".."Disable Assist Ally Construction [Forced ON]",
name = "\255\252\191\76".."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".."[■] [■]",
key = "disable_unit_sharing_economy_and_production_forced",
--name = "\255\252\191\76".."Disable Unit Sharing [Forced ON]",
name = "\255\252\191\76".."Disable Economy and Lab Sharing [■]",
type = "subheader",
section = "options_main",
column = 1.505,
font = 4,
},
{
key = "disable_unit_sharing_combat_units",
name = "Disable Combat Unit Sharing",
desc = "Disable sharing combat units and tactical structures (e.g static defense, jammers, LRPC's)",
type = "bool",
section = "options_main",
def = false,
},
{
key = "disable_unit_sharing_all",
name = "Disable All Unit Sharing",
desc = "Disable all unit sharing (including scouts and transports)",
type = "bool",
section = "options_main",
def = false,
},

{
key = "unit_market",
name = "Unit Market",
Expand Down