Module:ProjectLister/Costs
From Terra Invicta Official Wiki
Documentation for this module may be created at Module:ProjectLister/Costs/doc
---
---Reads the Project data files and computes a table of costs
---Note: Currently does not handle Alt Prereqs!
--region Dependencies
local TechData = mw.loadData('Module:CSVReader/Tech')
local ProjectData = mw.loadData('Module:CSVReader/Project')
local ProjectPrereqs = mw.loadData('Module:ProjectLister/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(ProjectData) do
if not row['disable'] or row['disable'] ~= 'true' then
-- Initialize all costs to 0.
costTable[rowID] = {}
costTable[rowID]['energyTech'] = 0
costTable[rowID]['informationTech'] = 0
costTable[rowID]['lifeTech'] = 0
costTable[rowID]['materialTech'] = 0
costTable[rowID]['militaryTech'] = 0
costTable[rowID]['socialTech'] = 0
costTable[rowID]['spaceTech'] = 0
costTable[rowID]['energyProject'] = 0
costTable[rowID]['informationProject'] = 0
costTable[rowID]['lifeProject'] = 0
costTable[rowID]['materialProject'] = 0
costTable[rowID]['militaryProject'] = 0
costTable[rowID]['socialProject'] = 0
costTable[rowID]['spaceProject'] = 0
costTable[rowID]['xenologyProject'] = 0
costTable[rowID]['energyTotal'] = 0
costTable[rowID]['informationTotal'] = 0
costTable[rowID]['lifeTotal'] = 0
costTable[rowID]['materialTotal'] = 0
costTable[rowID]['militaryTotal'] = 0
costTable[rowID]['socialTotal'] = 0
costTable[rowID]['spaceTotal'] = 0
costTable[rowID]['xenologyTotal'] = 0
costTable[rowID]['totalTech'] = 0
costTable[rowID]['totalProject'] = 0
costTable[rowID]['total'] = 0
-- Add own cost
local cost = row['researchCost']
local category = ScienceCategories[row['techCategory']]
costTable[rowID][category .. 'Project'] = costTable[rowID][category .. 'Project'] + cost
costTable[rowID][category .. 'Total'] = costTable[rowID][category .. 'Total'] + cost
costTable[rowID]['totalProject'] = costTable[rowID]['totalProject'] + cost
costTable[rowID]['total'] = costTable[rowID]['total'] + cost
-- Add costs of each prereq
for prereq, _ in pairs(ProjectPrereqs[rowID]) do
if string.sub(prereq,1,7) == 'Project' then
cost = ProjectData[prereq]['researchCost']
category = ScienceCategories[ProjectData[prereq]['techCategory']]
costTable[rowID][category .. 'Project'] = costTable[rowID][category .. 'Project'] + cost
costTable[rowID][category .. 'Total'] = costTable[rowID][category .. 'Total'] + cost
costTable[rowID]['totalProject'] = costTable[rowID]['totalProject'] + cost
costTable[rowID]['total'] = costTable[rowID]['total'] + cost
else
cost = TechData[prereq]['researchCost']
category = ScienceCategories[TechData[prereq]['techCategory']]
costTable[rowID][category .. 'Tech'] = costTable[rowID][category .. 'Tech'] + cost
costTable[rowID][category .. 'Total'] = costTable[rowID][category .. 'Total'] + cost
costTable[rowID]['totalTech'] = costTable[rowID]['totalTech'] + cost
costTable[rowID]['total'] = costTable[rowID]['total'] + cost
end
end
end
end
return costTable
end
--endregion
--region Public methods
--endregion
return getCostTable()


