Module:RegionLister
From Terra Invicta Official Wiki
Documentation for this module may be created at Module:RegionLister/doc
---
---Reads the Region data files and presents them in readable formats, with additional calculated statistics.
---
---@module RegionLister
local RegionLister = {}
--region Dependencies
local IconModule = require('Module:Icon')
local MapRegionData = mw.loadData('Module:CSVReader/MapRegion')
local RegionData = mw.loadData('Module:CSVReader/Region')
local RegionNameBuilder = require('Module:RegionLister/NameBuilder')
--endregion
--region Private constants
local ssub = string.sub
--endregion
--region Private member variables
--none
--endregion
--region Private methods
--endregion
--region Public methods
function RegionLister.ListPresentRegions()
return RegionLister.ListRegions('2022')
end
function RegionLister.List2026Regions()
return RegionLister.ListRegions('2026')
end
function RegionLister.ListFutureRegions()
return RegionLister.ListRegions('2070')
end
---@param campaignYear The start year of the campaign to show regions for. Defaults to 2022 if not specified.
---@return table
function RegionLister.ListRegions(campaignYear)
if not campaignYear then
campaignYear = '2022'
end
local frame = mw.getCurrentFrame()
local returnString = '{| class="wikitable sortable mw-collapsible" style="text-align: center;'
returnString = returnString .. '\n|-'
returnString = returnString .. '\n! rowspan=2|Region'
returnString = returnString .. '\n! rowspan=2|Could Be' .. frame:extensionTag( 'ref', 'Whether the region can be improved into a Mining or Oil Region. See [[Regions#Improving_Regions]] for details.' )
returnString = returnString .. '\n! rowspan=2|Area (km²)' .. frame:extensionTag( 'ref', 'Regions smaller than 150000km² are considered small for the purposes of [[Terrestrial_Warfare#Army_Movement|army movement]].' )
returnString = returnString .. '\n! colspan=3|Population' .. IconModule.Icon({args={'pop'}})
returnString = returnString .. '\n! colspan=2|Annual Boost' .. IconModule.Icon({args={'boost'}})
returnString = returnString .. '\n! rowspan=2|' .. IconModule.Icon({args={'mc'}})
returnString = returnString .. '\n! rowspan=2|Naval Access'
returnString = returnString .. '\n|-'
returnString = returnString .. '\n! Initial (in Millions)'
returnString = returnString .. '\n! [[Population#Population_Growth|Growth Modifier]]'
returnString = returnString .. '\n! [[Population#Population_Growth|Latitude Modifier]]'
returnString = returnString .. '\n! Initial'
returnString = returnString .. '\n! Gain Per Priority Completion'
returnString = returnString .. '\n|-'
for rowID, row in pairs(RegionData) do
if ((string.sub(rowID,1,4) == campaignYear) or (campaignYear == '2022' and string.sub(rowID,1,2) ~= '20')) then
returnString = returnString .. '\n| ' .. RegionNameBuilder.buildName({args={rowID}})
local mapRegionID = row['mapRegionName']
returnString = returnString .. '\n| '
if row['oilCapable'] == 'true' then
returnString = returnString .. IconModule.Icon({args={'oil region'}})
end
if row['mineCapable'] == 'true' then
returnString = returnString .. IconModule.Icon({args={'resource region'}})
end
returnString = returnString .. '\n| '
if tonumber(MapRegionData[mapRegionID]['area_km2']) < 150000 then
returnString = returnString .. 'style="color:red;" | '
end
returnString = returnString .. MapRegionData[mapRegionID]['area_km2']
returnString = returnString .. '\n| ' .. row['population_Millions']
returnString = returnString .. '\n| '
if tonumber(row['annualPopGrowthModifier']) < 0 then
returnString = returnString .. 'style="color:red;" | '
end
returnString = returnString .. row['annualPopGrowthModifier']
returnString = returnString .. '\n| '
local latitudeGrowth = -0.115739931206548 * math.abs(tonumber(MapRegionData[mapRegionID]['latitude'])) ^ 0.5
latitudeGrowth = math.floor(latitudeGrowth * 1000 + 0.5) / 1000
returnString = returnString .. tostring(latitudeGrowth)
returnString = returnString .. '\n| ' .. row['boostPerYear_tons']
returnString = returnString .. '\n| ' .. tostring(0.4 - math.abs(tonumber(MapRegionData[mapRegionID]['boostLatitude']))/250)
returnString = returnString .. '\n| ' .. row['missionControl']
returnString = returnString .. '\n| '
if row['worldOcean'] == 'Yes' then
returnString = returnString .. 'style="color:green;" | '
elseif row['worldOcean'] == 'Seasonal' then
returnString = returnString .. 'style="color:orange;" | '
else
returnString = returnString .. 'style="color:red;" | '
end
returnString = returnString .. row['worldOcean']
returnString = returnString .. '\n|-'
end
end
returnString = returnString .. '\n|}'
return returnString
end
--endregion
return RegionLister


