Module:TechLister/Costs
From Terra Invicta Official Wiki
Documentation for this module may be created at Module:TechLister/Costs/doc
---
---Reads the Tech data files and computes a table of costs
--region Dependencies
local TechData = mw.loadData('Module:CSVReader/Tech')
local TechPrereqs = mw.loadData('Module:TechLister/Prereqs')
--endregion
--region Private constants
local ScienceCategories = {
Energy = 'energy',
InformationScience='information',
LifeScience='life',
Materials='material',
MilitaryScience='military',
SocialScience='social',
SpaceScience='space',
Xenology='xenology'
}
--endregion
--region Private member variables
local costTable = {}
--endregion
--region Private methods
function getCostTable()
for rowID, row in pairs(TechData) do
-- Initialize all costs to 0.
costTable[rowID] = {}
costTable[rowID]['energy'] = 0
costTable[rowID]['information'] = 0
costTable[rowID]['life'] = 0
costTable[rowID]['material'] = 0
costTable[rowID]['military'] = 0
costTable[rowID]['social'] = 0
costTable[rowID]['space'] = 0
costTable[rowID]['total'] = 0
-- Add own cost
local cost = row['researchCost']
local category = ScienceCategories[row['techCategory']]
costTable[rowID][category] = costTable[rowID][category] + cost
costTable[rowID]['total'] = costTable[rowID]['total'] + cost
-- Add costs of each prereq
for prereq, _ in pairs(TechPrereqs[rowID]) do
cost = TechData[prereq]['researchCost']
category = ScienceCategories[TechData[prereq]['techCategory']]
costTable[rowID][category] = costTable[rowID][category] + cost
costTable[rowID]['total'] = costTable[rowID]['total'] + cost
end
end
return costTable
end
--endregion
--region Public methods
--endregion
return getCostTable()


