Module:ClaimLister/Full
From Terra Invicta Official Wiki
Documentation for this module may be created at Module:ClaimLister/Full/doc
---
---Reads the Claim data files and computes a table of Nations to
----all nations they can unify with by any means necessary
----But without future tech social or PRA
--region Dependencies
local ClaimData = mw.loadData('Module:CSVReader/Claim')
local RegionData = mw.loadData('Module:CSVReader/Region')
--endregion
--region Private constants
--endregion
--region Private member variables
local FullTable = {{},{}}
--endregion
--region Private methods
function getFullTable()
-- First get the direct claims
for rowID, row in pairs(ClaimData[1]) do
if not FullTable[1][rowID] then
FullTable[1][rowID] = {} -- Nations
FullTable[2][rowID] = {} -- Regions
end
for _, regionID in ipairs(row) do
if RegionData[regionID] then -- Check that region actually exists.
FullTable[2][rowID][regionID] = true
for _, nationID in ipairs(ClaimData[5][regionID]) do
-- Ban Protectorate Authority nation
if rowID ~= nationID and nationID ~= 'PRA' and nationID ~= '2070_PRA' and nationID ~= '2026_PRA' then
FullTable[1][rowID][nationID] = true
end
end
end
end
end
-- Dynamic Programming
local changed = true
local maxIterations = 10 -- Safety limit to prevent infinite loops
local iteration = 0
while changed and iteration < maxIterations do
changed = false
iteration = iteration + 1
for rowID, row in pairs(FullTable[1]) do
local toAdd = {{},{}}
for nationID, _ in pairs(row) do
for subregionID, _ in pairs(FullTable[2][nationID]) do
toAdd[2][subregionID] = true
end
for subnationID, _ in pairs(FullTable[1][nationID]) do
toAdd[1][subnationID] = true
end
end
for subnationID, _ in pairs(toAdd[1]) do
if not FullTable[1][rowID][subnationID] and rowID ~= subnationID then
changed = true
FullTable[1][rowID][subnationID] = true
end
end
for subregionID, _ in pairs(toAdd[2]) do
if not FullTable[2][rowID][subregionID] then
changed = true
FullTable[2][rowID][subregionID] = true
end
end
end
end
return FullTable
end
--endregion
--region Public methods
--endregion
return getFullTable()


