-
Notifications
You must be signed in to change notification settings - Fork 319
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
Rimilel
wants to merge
14
commits into
beyond-all-reason:master
Choose a base branch
from
Rimilel:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+228
−73
Open
Changes from 2 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
a02b902
Disallow upgrading of allied mexes and geo
dc61530
When unit sharing is disabled, restrict unit market to only selling t…
6c325ce
tax resource sharing: when using unit market, refund sharing tax to t…
8d84a20
refactor: changed name searching to matching a table of UnitDef ids
bdeb49a
refactor: roll mex and geo into same for-loop, return a boolean inste…
b61d952
Forgot a negation
7d43f2f
Added legion to list of t2 cons
b3d00a9
Replaced disable unit sharing with 3 finer options (In Progress). Jus…
fd5915c
Implement 3 finer options to disable_unit_sharing. Modoption features…
84ccb77
refactor: changed if to use elif
d1a7f56
Disallow builders from being set to movestate Roam, to prevent auto-a…
d6d2a7e
Only allow completed t2 cons to be put on sale while using Tax Resour…
b46f7c8
Use customparam unitgroup to identify econ buildings instead. energym…
8a7ba37
refactor: fixed misnamed function call, store modoption value, delete…
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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", | ||
} | ||
|
||
|
||
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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Where does this come from??? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh what the heck, that should be unitTypeAllowedToBeShared() |
||
end | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good.
There was a problem hiding this comment.
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