Skip to content

T2 Constructor Sharing Mode#4447

Closed
keithharvey wants to merge 2 commits into
beyond-all-reason:masterfrom
keithharvey:t2_sharing
Closed

T2 Constructor Sharing Mode#4447
keithharvey wants to merge 2 commits into
beyond-all-reason:masterfrom
keithharvey:t2_sharing

Conversation

@keithharvey

@keithharvey keithharvey commented Mar 3, 2025

Copy link
Copy Markdown
Collaborator

Closes #4416

LLM Usage

A bit on this one. Gemini iirc. This was one of my first times using LLMs for coding and it ended up being mostly by hand because it honestly wasn't super helpful.

Refactor: T2 Constructor Sharing and Fix Take Command

This PR refactors unit sharing logic, introduces the requested "T2 Constructor Sharing Only" mode, and fixes related bugs with the /take command and Unit Market interactions.

Problem Description & Motivation

  • Implement t2cons Sharing Mode: Provide the community-requested middle ground sharing option (Disabled Unit Sharing Except T2 #4416) between fully enabled and fully disabled, reflecting the common meta of sharing T2 constructors in team games.
  • Fix /take Command Bug: Resolve the issue where restricted sharing modes (disabled or t2cons) incorrectly blocked the /take command, preventing players from taking control of inactive allied teams.
  • Decouple Unit Market: Address feedback from previous reviews that unit sharing logic was improperly intertwined with Unit Market functionality. The goal is to allow the Unit Market to operate independently.

Implementation Approach & Changes

Unit Sharing Mode (luarules/gadgets/game_unit_sharing_mode.lua):
* Renamed game_disable_unit_sharing.lua to game_unit_sharing_mode.lua for clarity and naming convention.
* Converted the "Disable Unit Sharing" checkbox into a unit_sharing_mode dropdown option with keys: enabled (default), t2cons, combat, combat_t2cons, disabled. (Renamed t2cons_only to t2cons for brevity).
* Refactored AllowUnitTransfer to correctly check the selected mode for standard player-to-player transfers.
* Unit Market Decoupling: Implemented a flag (marketTransferInProgress). game_unit_market.lua sets this flag before transfer; game_unit_sharing_mode.lua checks and clears it, bypassing sharing rules for market transactions.
* /take Command Fix: Added a workaround function (CheckTakeCondition) that bypasses sharing rules if the sender is allied and has no active human players, mirroring the engine's apparent condition for /take. This was necessary as /take doesn't set capture=true or provide another detectable flag. (Includes a TODO and suggestion for a future engine flag improvement).
* Preserved the capture=true check to allow engine-managed transfers.

Testing Results

  • Verified unit_sharing_mode options:
    • enabled: Allows all standard transfers.
    • t2cons: Allows standard transfer of T2 constructors (e.g., armack), blocks T1 constructors, factories, combat units.
    • disabled: Blocks all standard transfers.
  • Verified bypasses work correctly when sharing is restricted (disabled or t2cons):
    • Unit Market purchases/sales succeed.
    • /take <TeamID> command successfully transfers all units from inactive allied teams.
    • Engine-managed transfers (capture=true) succeed.

Release Notes

  • The disable_unit_sharing checkbox mod option has been replaced by the unit_sharing_mode dropdown list option.
    • Old !bset modoption disable_unit_sharing 1 is now !bset modoption unit_sharing_mode disabled.
    • Old !bset modoption disable_unit_sharing 0 is now !bset modoption unit_sharing_mode enabled.
    • The new option is !bset modoption unit_sharing_mode t2cons.
  • This should probably be published with the new Metal Send Threshold feature, since this enables standard transfers of t2 cons/payment mechanisms, while still allowing taxes to be in place, which is pretty important for this feature.

Before

Image

After

image
(ignore the overlap in the screenshot I fixed that at some point)

@keithharvey

Copy link
Copy Markdown
Collaborator Author

@WatchTheFort cleaned this up and it's now ready for you to review

Comment thread modoptions.lua Outdated
Comment thread modoptions.lua Outdated
Comment thread luarules/gadgets/game_disable_unit_sharing.lua Outdated
Comment thread luarules/gadgets/game_disable_unit_sharing.lua Outdated
Comment thread luarules/gadgets/game_disable_unit_sharing.lua Outdated
@keithharvey keithharvey marked this pull request as draft April 16, 2025 08:49
Comment thread luarules/gadgets/unit_sharing_mode.lua Outdated
Comment thread luarules/gadgets/game_tax_resource_sharing.lua Outdated
@keithharvey keithharvey marked this pull request as ready for review April 16, 2025 18:29
@keithharvey

Copy link
Copy Markdown
Collaborator Author

Thank you @badosu for all of your help!

Comment thread modoptions.lua
Comment thread luarules/gadgets/game_unit_sharing_mode.lua Outdated
Comment thread luarules/gadgets/game_unit_sharing_mode.lua Outdated
Comment thread luarules/gadgets/game_unit_sharing_mode.lua Outdated
Comment thread luarules/gadgets/game_unit_sharing_mode.lua Outdated
@badosu

badosu commented Apr 16, 2025

Copy link
Copy Markdown
Contributor

Overall LGTM, some small things to address, up to the author but in general looks solid!

Comment thread modoptions.lua Outdated
Comment thread luarules/gadgets/game_unit_sharing_mode.lua Outdated
@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
@keithharvey keithharvey force-pushed the t2_sharing branch 2 times, most recently from a678d95 to f964adc Compare April 25, 2025 23:42
@keithharvey

keithharvey commented Aug 18, 2025

Copy link
Copy Markdown
Collaborator Author

Moving into widgets necessitated a common set of helper functions, which is all good.

At minimum the "Share Unit" button should be removed from the commands panel when no t2 cons are selected

This is hard. Like why won't it redraw? I tried to make it dynamic then I tried to separate commands, neither redrew on selection. Not sure whatsup with that but Imma give up and work on something else.

and there should be an echo explaining the blocking of sharing

This one is done
image

@thehobojoe feel free to integrate this into another PR or merge this one. I think maybe we change the PR target of this and metal_send_threshold and emp to a new branch you create tonight (combined_mod_options?) that we can then rebase on top of with some of this other chobby/organizational work. I rebased this one too and I think both are ready to roll.

Comment thread luarules/gadgets/game_unit_sharing_mode.lua Outdated
Comment thread luarules/gadgets/game_unit_sharing_mode.lua Outdated
Comment thread luarules/gadgets/game_unit_sharing_mode.lua Outdated
Comment thread luarules/gadgets/game_unit_sharing_mode.lua Outdated
@thehobojoe

Copy link
Copy Markdown
Contributor

This is hard. Like why won't it redraw? I tried to make it dynamic then I tried to separate commands, neither redrew on selection. Not sure whatsup with that but Imma give up and work on something else.

Redraw already happens on every selection change. You can see how to accomplish this here

@keithharvey

keithharvey commented Aug 23, 2025

Copy link
Copy Markdown
Collaborator Author

This is hard. Like why won't it redraw? I tried to make it dynamic then I tried to separate commands, neither redrew on selection. Not sure whatsup with that but Imma give up and work on something else.

Redraw already happens on every selection change. You can see how to accomplish this here

Interestingly I was already doing that, let me test this again.

edit: On testing, the branch linked also always shows the transfer button I was attempting to fix. I thought we were talking about this button in advanced player list:
image

@keithharvey

Copy link
Copy Markdown
Collaborator Author

Ok that's done, the share button in adv playerlist now shows a greyed out transfer button [with a tooltip I failed to screen grab that reads "Attempted to transfer 1 unshareable units. Share mode is T2 constructors only"

image

@keithharvey keithharvey force-pushed the t2_sharing branch 2 times, most recently from 49a7f32 to f60bdfc Compare August 23, 2025 23:15
Comment thread luaui/Widgets/gui_advplayerslist.lua Outdated
Comment thread luarules/gadgets/game_unit_market.lua Outdated
@keithharvey

keithharvey commented Oct 16, 2025

Copy link
Copy Markdown
Collaborator Author

This commit was lost to time and very valuable: f60bdfc#diff-40c052408aba0b8d61ccb4d5dbd6743bc00d82a1dc532342290f5c0587c7f8c8

Putting this here so I don't have to rummage again, accidentally force pushed this branch to an old as hell version at some point, and am probably going to just put this feature on top of metal_send_threshold, since they are all up in gui_advplayerslist business in the same places.

@keithharvey keithharvey marked this pull request as draft October 17, 2025 18:49
@keithharvey keithharvey force-pushed the t2_sharing branch 2 times, most recently from ad27b79 to 2d2a2f6 Compare October 20, 2025 07:17
@keithharvey keithharvey marked this pull request as ready for review October 20, 2025 07:19
@keithharvey

Copy link
Copy Markdown
Collaborator Author

This branch is now at the exact same place as player send threshold, since they share a lot of common code and I think these go together if they go. I can close this one or keep it open for the description.

- 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.
@keithharvey

keithharvey commented Oct 20, 2025

Copy link
Copy Markdown
Collaborator Author

Closing this in favor of player_send_threshold or possibly some different PR. Really both of these PRs together are the "split mod option" approach to team sharing and should be a unified PR.

I'm tired of maintaining it in isolation/it's REALLY hard to keep these two branches separated in gui_advplayerlist, though I did try at the commit level.

This was referenced Oct 20, 2025
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.

Disabled Unit Sharing Except T2

9 participants