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

Conversation

Rimilel
Copy link
Contributor

@Rimilel Rimilel commented Dec 11, 2024

Work done

Buying t2 cons:

  • When using tax resource sharing, only allow buying t2 cons via unit market. Being able to buy other units would allow converting metal into instant econ or units from a teammate's lab and would defeat the purpose of this mod.
  • Refund the resource sharing tax to the seller when using Unit Market. This is to preserve the familiar t2 sharing gameflow, and not discourage techers from selling to their teammates.

Allied Construction:

  • Prevent upgrading allied mexes and geos. Necessary since upgrading allied mexes is economy boosting. The player should buy the t2 con through the unit market.
  • Prevent builders from being set to roam and auto-assisting allied construction

Unit Sharing

  • Finer controls for Disable Unit Sharing. Using Tax Resource Sharing no longer disables all unit sharing, instead it only disables Econ and Lab Sharing by default.

Typical Usage

spring_xA0nzBs9kt

Test steps (partial)

  • Should not be able to upgrade allied mex or geo.
  • Should be able to upgrade own mex and geo
  • Should not be able to upgrade allied t2 mex to t2 combat mex
  • Should not be able to upgrade allied t2 geo to different kind of t2 geo

When Unit Market enabled together with Disable Unit Sharing or Tax Resource Sharing

  • Should be able to buy t2 cons, but not other unit types
  • Seller should receive full metal value of con

....

Issues

I'm getting frequent luaui crashes when using Unit Market (Build Menu and Buy signs ($) goes invisible until /luaui reload) in single player.

Discord thread: https://discord.com/channels/549281623154229250/1253060706039890000

@robertthepie
Copy link
Contributor

Only allow buying t2 cons via unit market.

This seems counter intuitive

luarules/gadgets/game_disable_assist_ally.lua Outdated Show resolved Hide resolved
Comment on lines 80 to 82
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

luarules/gadgets/game_disable_assist_ally.lua Outdated Show resolved Hide resolved
luarules/gadgets/game_disable_assist_ally.lua Outdated Show resolved Hide resolved
Comment on lines 152 to 158
local t2cons = {"armack", "armacv", "armaca", "armacsub", "corack", "coracv", "coraca", "coracsub"}
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

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".

luarules/gadgets/game_unit_market.lua Outdated Show resolved Hide resolved
@Rimilel
Copy link
Contributor Author

Rimilel commented Dec 13, 2024

Added finer options for disable unit sharing, modoption features complete fd5915c

Disable unit sharing test

No econ or production sharing:
spring_TQRx6fKGMC
No econ or lab sharing, nor combat units or tactical buildings (only scouts and transports are shareable)
spring_Bk4VnF44t1

The unit market usage could be improved -- prevent non-valid units (non t2 cons) from being put on sale to reduce clutter/confusion.

Comment on lines 36 to 40
-- 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

@Rimilel Rimilel changed the title Resource Sharing Tax Mod: only allow buying t2 cons via unit market, prevent allied mex upgrade. Resource Sharing Tax Mod: only allow buying t2 cons via unit market, prevent allied mex upgrade, ... Dec 13, 2024
@Rimilel Rimilel changed the title Resource Sharing Tax Mod: only allow buying t2 cons via unit market, prevent allied mex upgrade, ... Resource Sharing Tax Mod: Prevent upgrading allied mex/geos. No longer disables sharing completely, and can buy t2 con through Unit Market Dec 13, 2024
@Rimilel Rimilel marked this pull request as draft December 14, 2024 09:45
Rimilel added 2 commits December 14, 2024 04:43
…ce Sharing. Do place unit on sale checks properly, and clean up related UnitMarket code
@Rimilel Rimilel marked this pull request as ready for review December 14, 2024 16:54
…ake was not failproof anyways as winds/tidal/solar did not have that
@Rimilel Rimilel requested a review from robertthepie December 16, 2024 16:38
Copy link
Contributor

@robertthepie robertthepie left a comment

Choose a reason for hiding this comment

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

I'm personally not a fan of the t2 cons limit, and this is starting to feel like spaghetti 🍝

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()

luarules/gadgets/game_unit_market.lua Outdated Show resolved Hide resolved
luarules/gadgets/game_unit_market.lua Outdated Show resolved Hide resolved
Comment on lines +103 to +109
local t2conNames = {"armack", "armacv", "armaca", "armacsub", "corack", "coracv", "coraca", "coracsub", "legack", "legacv", "legaca", "legacsub"}
local isT2Con = {}
for _, name in ipairs(t2conNames) do
if UnitDefNames[name] then
isT2Con[UnitDefNames[name].id] = true
end
end
Copy link
Contributor

Choose a reason for hiding this comment

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

set t2conNames to nil after it has been used

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.

Is this by convention or for something like garbage collection?

Copy link
Contributor

Choose a reason for hiding this comment

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

it doesn't take a lot of memory, but it frees it up i believe

Copy link
Collaborator

@sprunk sprunk Dec 21, 2024

Choose a reason for hiding this comment

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

Not really. The var isn't used anywhere else afterwards so the Lua interpreter knows on its own to free the memory. I think the reason some wupgets do this is cargo cult.

@Rimilel
Copy link
Contributor Author

Rimilel commented Dec 21, 2024

re: t2 cons

I can't allow shareable units to be buyable through the marketplace, otherwise a player can share a unit, then buy it back repeatedly to give resources to someone tax free.
For non-shareable units (ie. economy units), it still ends up being a "boost" if you purchase economy for the metal cost, because you saved the build power and E cost. This includes T1 cons.
spring_PkADsbzQ1o

In terms of being intuitive for the end user, T2 cons on sale conveniently popup, and the player can buy it from there.

spaghetti

I've tried to make it as clear as possible what it's doing, though the tiredness might have gotten to me. Appreciate the help.
IMO the ruleset has to close many loopholes, so it's necessarily complicated.

@Rimilel Rimilel changed the title Resource Sharing Tax Mod: Prevent upgrading allied mex/geos. No longer disables sharing completely, and can buy t2 con through Unit Market Resource Sharing Tax Mod: Prevent upgrading allied mex/geos. No longer disables unit sharing completely, and can buy t2 con through Unit Market Dec 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants