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 3 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
59 changes: 59 additions & 0 deletions luarules/gadgets/game_disable_assist_ally.lua
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,65 @@ local function isComplete(u)
end



-- table of all mex unitDefIDs
local isMex = {}
for unitDefID, unitDef in pairs(UnitDefs) do
if unitDef.extractsMetal > 0 then
isMex[unitDefID] = true
end
end

local function existsNonOwnedMex(myTeam, x, y, z)
local units = Spring.GetUnitsInCylinder(x, z, 10)
for k, unitID in ipairs(units) do
if isMex[Spring.GetUnitDefID(unitID)] then
if Spring.GetUnitTeam(unitID) ~= myTeam then
return unitID
end
end
end
return false
end

-- table of all geo unitDefIDs
local isGeo = {}
for unitDefID, unitDef in pairs(UnitDefs) do
if unitDef.customParams.geothermal then
isGeo[unitDefID] = true
end
end
Rimilel marked this conversation as resolved.
Show resolved Hide resolved


local function existsNonOwnedGeo(myTeam, x, y, z)
local units = Spring.GetUnitsInCylinder(x, z, 10)
for k, unitID in ipairs(units) do
if isGeo[Spring.GetUnitDefID(unitID)] then
if Spring.GetUnitTeam(unitID) ~= myTeam then
return unitID
end
end
end
return false
end

function gadget:AllowUnitCreation(unitDefID, builderID, builderTeam, x, y, z)
-- Disallow upgrading allied mexes
if isMex[unitDefID] then
if existsNonOwnedMex(builderTeam, x, y, z) then
return false
end
Copy link
Contributor

Choose a reason for hiding this comment

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

You're not using the unitID it returns, you could instead have it return a bool and return that instead.
instead of returning false or running the is geo check before returning true.

Copy link
Contributor Author

@Rimilel Rimilel Dec 11, 2024

Choose a reason for hiding this comment

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

change made bdeb49a

end
-- Disallow upgrading allied geos
if isGeo[unitDefID] then
Rimilel marked this conversation as resolved.
Show resolved Hide resolved
if existsNonOwnedGeo(builderTeam, x, y, z) then
return false
Rimilel marked this conversation as resolved.
Show resolved Hide resolved
end
end
return true
end


function gadget:AllowCommand(unitID, unitDefID, unitTeam, cmdID, cmdParams, cmdOptions, cmdTag, synced)

-- Disallow guard commands onto labs, units that have buildOptions or can assist
Expand Down
24 changes: 24 additions & 0 deletions luarules/gadgets/game_unit_market.lua
Original file line number Diff line number Diff line change
Expand Up @@ -149,19 +149,37 @@ local function offerUnitForSale(unitID, sale_price, msgFromTeamID)
end
end

local t2cons = {"armack", "armacv", "armaca", "armacsub", "corack", "coracv", "coraca", "coracsub"}
Rimilel marked this conversation as resolved.
Show resolved Hide resolved
function contains(table, value)
for _, v in pairs(table) do
if v == value then return true end
end
return false
end
Copy link
Contributor

Choose a reason for hiding this comment

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

Create a table of unitDefIDs instead, keyed using the id returns true. rather than getting the unit name and going through the entire table.

Copy link
Collaborator

Choose a reason for hiding this comment

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

agree with @robertthepie, also note table.contains already exists and this is basically reimplementing it.

Copy link
Contributor Author

@Rimilel Rimilel Dec 11, 2024

Choose a reason for hiding this comment

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

ohh it's defined in the project. I'm not the most familiar with lua, couldn't believe that such a basic function didn't exist already. thanks for the heads up sautron.

changes made 8d84a20


-- 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 saleWhitelist = {}

local function tryToBuyUnit(unitID, msgFromTeamID)

if not unitID or unitsForSale[unitID] == nil or unitsForSale[unitID] == 0 then return end
local unitDefID = spGetUnitDefID(unitID)
if not unitDefID then return end
local unitDef = UnitDefs[unitDefID]
if not unitDef then return end


-- Only allow selling t2 cons when unit sharing is disabled
Copy link
Contributor

Choose a reason for hiding this comment

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

Limiting it to only selling t2 seems counterintuitive?

Copy link
Contributor Author

@Rimilel Rimilel Dec 11, 2024

Choose a reason for hiding this comment

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

I'm using the unit market to implement an exception -- Since that is the game flow players are used to. In general, buying 'anything' is a form of boosting, since you save the E cost, BP, and time. Allowing buy/sell of t1 cons lets you build safe eco anywhere, and you can easily "let" allies cap mexes arbitrarily at the start of the game. For example a front player could buy 2 cons from the backline, use them to cap the backliner secondary mexes and make winds, effectively boosting themselves.

By default tax unit sharing will only disable sharing of economy/labs. You are free to share combat units or other units freely.

Copy link
Contributor Author

@Rimilel Rimilel Dec 11, 2024

Choose a reason for hiding this comment

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

For context, this is a competitive modoption for a small subset of players. The ruleset has to cover everything to achieve the desired effect (also a similiar ruleset hasn't been tested before). I'm open to ideas to make the option selection more explanatory.
For ruleset changes maybe it would be better to discuss in https://discord.com/channels/549281623154229250/1253060706039890000

Tax Resource Sharing can be explained as: "You can't share eco/production, can't assist allied labs/blueprints, and resource sharing is taxed. You can buy/sell t2 at normal price via unit Market".


--Spring.Echo("unitDefID", unitDefID, UnitDefs[unitDefID].name)
if(disable_unit_sharing) then
if not contains(t2cons, UnitDefs[unitDefID].name) then return end
end

local old_ownerTeamID = spGetUnitTeam(unitID)
local _, _, _, isAiTeam = spGetTeamInfo(old_ownerTeamID)
if not spAreTeamsAllied(old_ownerTeamID, msgFromTeamID) then return end
Expand All @@ -184,6 +202,12 @@ local function tryToBuyUnit(unitID, msgFromTeamID)
TransferUnit(unitID, msgFromTeamID)
if msgFromTeamID ~= old_ownerTeamID and price > 0 then -- don't send resources to yourself
ShareTeamResource(msgFromTeamID, old_ownerTeamID, "metal", price)
-- if tax resource sharing is on, refund tax to the seller
if(Spring.GetModOptions().tax_resource_sharing_amount>0) then
local taxRate = Spring.GetModOptions().tax_resource_sharing_amount
Rimilel marked this conversation as resolved.
Show resolved Hide resolved
local taxAmount = price * taxRate
Spring.AddTeamResource(old_ownerTeamID, "metal", taxAmount)
end
end
setNotForSale(unitID)
UnitSoldBroadcast(unitID, price, old_ownerTeamID, msgFromTeamID)
Expand Down