Skip to content

Player Resource Send Threshold#4804

Closed
keithharvey wants to merge 8 commits into
beyond-all-reason:masterfrom
keithharvey:metal_send_threshold
Closed

Player Resource Send Threshold#4804
keithharvey wants to merge 8 commits into
beyond-all-reason:masterfrom
keithharvey:metal_send_threshold

Conversation

@keithharvey

@keithharvey keithharvey commented Apr 16, 2025

Copy link
Copy Markdown
Collaborator

Player Resource Send Threshold

Introduces a new configurable threshold for resource sharing tax, for both energy and metal.

  • creates a per-team policy cache using SetTeamRulesParam
  • this lets the UI ask for bounds for metal/energy transfers to teammates
  • this result is used to drive the UI in gui_advplayerslist directly
  • deprecates the AllowResourceTransfer hook in prevent_excessive_share. game_tax_resource_sharing is now the only handler and it just transfers within bounds defined by the policy, if that is possible.

Note: This is a complete rewrite of the tax system mostly to accommodate the new requirements without exploding gui_advplayerslist, but a side effect of this is that it simplifies the UI considerably.

Demo Video

How does it work?

Right away and then every N frames: game_tax_resource_sharing.lua will build and cache a tax policy for each team pair <-> resource type (energy and metal). It uses a single function for both resource type calculations and follows that pattern of functional reuse between synced and unsynced to ensure all resource transfer follows the same rules and is driven by the same contract: the policy result.

---@class ResourcePolicyResult : PolicyResult
---@field canShare boolean
---@field amountSendable number
---@field amountReceivable number
---@field taxedPortion number
---@field untaxedPortion number
---@field taxRate number
---@field resourceType ResourceType
---@field remainingTaxFreeAllowance number
---@field resourceShareThreshold number
---@field cumulativeSent number

This policy result is then serialized and thrown into a cache:

local hypothetical_resource_policy_result = "remainingTaxFreeAllowance:400:resourceShareThreshold:400:canShare:1:untaxedPortion:400:taxedPortion:0:taxRate:0.5:resourceType:energy:cumulativeSent:0:amountSendable:400:amountReceivable:0"
local baseKey = string.format("policy_cache_%d_%s_", receiverId, resourceType)
Spring.SetTeamRulesParam(senderId, baseKey, serialized)

This gives you a serialized policy result that the UI can quickly grab if it needs to know the bounds of a particular transfer. This also gives you a shared type to use across synced and unsynced functions.

Testing Results

  • Verified threshold logic:
    • Metal/Energy sent below the sender’s cumulative threshold is tax-free.
    • Metal/Energy sent after the sender exceeds their cumulative threshold is taxed correctly based on tax_resource_sharing_amount.
  • Confirmed UI preview and slider cap behavior:
    • Metal/Energy upper bound stable and intuitive.
    • Label fits for two-number display and remains adjacent to the slider.
    • Echo message includes threshold context only when configured.

LLM usage disclosure

None. I tried LLM for this, it was hard. Ended up validating it with unit tests and then backporting this raw implementation by hand.

@keithharvey keithharvey force-pushed the metal_send_threshold branch from 682bb95 to 5c98db0 Compare April 16, 2025 20:16
@WatchTheFort WatchTheFort added the Awaiting GDT Approval Awaiting approval from the Game Design Team (game mechanics, balance only) label Apr 17, 2025
@keithharvey keithharvey mentioned this pull request Apr 17, 2025
8 tasks
Comment thread luarules/gadgets/game_tax_resource_sharing.lua Outdated
Comment thread luarules/gadgets/game_tax_resource_sharing.lua
@WatchTheFort WatchTheFort changed the title Feat: Add Player Metal Send Threshold Feature: Add Player Metal Send Threshold Apr 24, 2025
Comment thread luarules/gadgets/game_tax_resource_sharing.lua
@keithharvey keithharvey force-pushed the metal_send_threshold branch 2 times, most recently from 37f45be to d9e4064 Compare April 25, 2025 23:46
@keithharvey

Copy link
Copy Markdown
Collaborator Author

Rebased

@WilliamPas

Copy link
Copy Markdown
Collaborator

Rejected by the GDT: This is counter to our desired game design, we want to address co-op issues via balance rather than arbitrary restrictions.

@WilliamPas WilliamPas closed this Jun 15, 2025
@PtaQQ PtaQQ reopened this Aug 10, 2025
@PtaQQ

PtaQQ commented Aug 10, 2025

Copy link
Copy Markdown
Collaborator

Reopened after the new decision by the GDT. Awaiting code review.

@PtaQQ PtaQQ added Approved Approved for implementation by the Game Design Team and removed Awaiting GDT Approval Awaiting approval from the Game Design Team (game mechanics, balance only) labels Aug 10, 2025
@keithharvey keithharvey force-pushed the metal_send_threshold branch from d9e4064 to 92b8326 Compare August 10, 2025 17:37
@keithharvey

Copy link
Copy Markdown
Collaborator Author

Rebased

@drivver44

Copy link
Copy Markdown
Contributor

blocked until @thehobojoe does a review

@thehobojoe thehobojoe left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This PR is fine, but it needs a way to communicate to the player what is happening with their metal, and when taxes are going to kick in and how much it will cost them.

This could be as simple as an echo to the team, but I would prefer some indication during sharing that communicates the threshold and the taxes before they send resources.

@keithharvey keithharvey force-pushed the metal_send_threshold branch 2 times, most recently from 309652d to 907e333 Compare August 18, 2025 22:49
@keithharvey

keithharvey commented Aug 18, 2025

Copy link
Copy Markdown
Collaborator Author

Great suggestions. Updated the description with the requested changes. Was able to get this one completely right. Squashed it.

@keithharvey keithharvey force-pushed the metal_send_threshold branch 2 times, most recently from 127a099 to 0eb420c Compare August 19, 2025 23:45
Comment thread luarules/gadgets/game_tax_resource_sharing.lua Outdated
Comment thread common/luaUtilities/team_transfer/resource_share_tax.lua Outdated
@keithharvey keithharvey changed the title Feature(Sharing): clean mod options only Sharing Mod Options Only Oct 20, 2025
@keithharvey keithharvey changed the title Sharing Mod Options Only Sharing Mod Options Oct 20, 2025
@keithharvey keithharvey force-pushed the metal_send_threshold branch 9 times, most recently from 427f162 to 74e0d85 Compare October 21, 2025 02:36
keithharvey and others added 6 commits October 21, 2025 18:35
- Add modoption `player_metal_send_threshold` to defer metal tax until a sender’s cumulative sent metal exceeds the threshold; energy unchanged (taxed only by `tax_resource_sharing_amount`).
- Track cumulative sent metal per sender and expose via team rules params: `metal_share_cumulative_sent`, `metal_share_threshold`, `resource_share_tax_rate`.
- UI (AdvPlayersList): while dragging the share slider
  - Energy shows received/sent preview.
  - Metal shows amount_to_send/max_allowance and caps the slider by min(my metal, receiver free, remaining allowance).
  - Right-justified label with auto-sized grey background to fit two-number display.
  - Echo on send uses i18n: “Sent Xm[/Ym allowed by the player send threshold]” (optional bracket when threshold > 0).
- Refactor: add `common/luaUtilities/resource_share_tax.lua` and use it from both gadget and UI to keep the math in one place.
- Safety: clamps against receiver max share, handles 100% tax case, guards against negatives. Default threshold is 0 (immediate tax if base rate > 0). No changes to unit-sharing logic.
- i18n: add `ui.playersList.chat.sentMetal` and `ui.playersList.chat.sentMetalThreshold` (en). translation keys try to match the policy keys.
Refactor unit sharing mode into the policy cache/policyResult format and simplify gui_advplayerslist.

ded line units
Ported out of taxes to make it explicit.
all credit to hobo on this one I just tied in my unit_sharing_mode

Co-authored-by: thehobojoe <the.hobo.joe@gmail.com>
I needed some way to turn sharing off completely and tax=1 didn't seem intuitive (or desirable since semantically following the logic of tax = 1 the sender would lose everything and the receiver would get nothing).
It is a bit kludgey but it is isolated and works surprisingly well until we get engine hooks.

Co-authored-by: Fx-Doo <hedibertille93@gmail.com>
@keithharvey keithharvey force-pushed the metal_send_threshold branch 2 times, most recently from 64a93b0 to e01c720 Compare October 22, 2025 01:11
Had to add an api_extensions because gui_advplayerlist (especially draw) is hitting its local variable limit. Split it off into its own file in teamtransfer since it's api_extensions for that thing
This reverts commit 8d6917d.
@keithharvey keithharvey changed the title Sharing Mod Options Metal Send Threshold Oct 24, 2025
@keithharvey keithharvey changed the title Metal Send Threshold Player Resource Send Threshold Oct 24, 2025
@keithharvey keithharvey mentioned this pull request Oct 24, 2025
@keithharvey

Copy link
Copy Markdown
Collaborator Author

Closed this because I am consolidating further into #5704 which presents a complete UX and functional solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Approved Approved for implementation by the Game Design Team

Projects

None yet

Development

Successfully merging this pull request may close these issues.