Module:DriveLister
From Terra Invicta Official Wiki
Documentation for this module may be created at Module:DriveLister/doc
---
---Reads the Drive data files and presents them in readable formats, with additional calculated statistics.
---
---@module DriveLister
local DriveLister = {}
--region Dependencies
local RestrictionChecker = require('Module:RestrictionChecker')
local IconModule = require('Module:Icon')
local TVModule = require('Module:TV')
local DriveData = mw.loadData('Module:CSVReader/Drive')
local DriveNames = mw.loadData('Module:ENReader/Drive')
local PowerPlantNames = mw.loadData('Module:ENReader/PowerPlant')
local ProjectNameBuilder = require('Module:ProjectLister/NameBuilder')
local ProjectCosts = mw.loadData('Module:ProjectLister/Costs')
--endregion
--region Private constants
local floor = math.floor
local ssub = string.sub
local slen = string.len
--endregion
--region Private member variables
--none
--endregion
--region Private methods
--endregion
--region Public methods
function DriveLister.ListRestrictedDrives(frame)
return DriveLister.ListDrives(true, frame.args)
end
function DriveLister.ListDetailedDrives()
return DriveLister.ListDrives(true)
end
function DriveLister.ListBasicDrives()
return DriveLister.ListDrives(false)
end
---@param detailed boolean whether to show the detailed or basic version.
---@return wiki table of Drives
function DriveLister.ListDrives(detailed, restrictionsTable)
local returnString = '{| class="wikitable sortable mw-collapsible" style="text-align: center;"'
returnString = returnString .. '\n|-'
returnString = returnString .. '\n! Drive'
if detailed then
returnString = returnString .. '\n! Required Project'
returnString = returnString .. '\n! Total ' .. TVModule.TV({args={'research', '', 'true'}}) .. ' Cost'
end
returnString = returnString .. '\n! Thrust<br>(N)'
returnString = returnString .. '\n! Combat Thrust<br>Multiplier'
returnString = returnString .. '\n! EV<br>(kps)'
returnString = returnString .. '\n! Efficiency'
returnString = returnString .. '\n! Required Power Plant'
returnString = returnString .. '\n! Propellent<br>(per tank)'
if detailed then
returnString = returnString .. '\n! Supplies Power'
end
returnString = returnString .. '\n! Special'
returnString = returnString .. '\n|-'
for rowID, row in pairs(DriveData) do
if ((not row['disable']) or row['disable'] ~= 'true') and row['thrusters'] == '1' and RestrictionChecker.AllPass(restrictionsTable, row) then
local dName = DriveNames['TIDriveTemplate.displayName.' .. rowID] or 'Error: Missing Display Name for ' .. rowID
local dlen = slen(dName)
local onlyOneThruster = false
if ssub(dName,-2) == 'x1' then
dName = ssub(dName,1,dlen - 2)
else
onlyOneThruster = true
end
returnString = returnString .. '\n| ' .. dName
if detailed then
returnString = returnString .. '\n| ' .. ProjectNameBuilder.buildName({args={row['requiredProjectName']}})
returnString = returnString .. '\n| ' .. TVModule.TV({args={'research', ProjectCosts[row['requiredProjectName']]['total'], 'true'}})
end
returnString = returnString .. '\n| ' .. row['thrust_N']
returnString = returnString .. '\n| ' .. row['thrustCap']
returnString = returnString .. '\n| ' .. row['EV_kps']
returnString = returnString .. '\n| ' .. row['efficiency']
returnString = returnString .. '\n| ' .. "[[" .. PowerPlantNames['TIPowerPlantTemplate.PowerPlantRequirement.' .. row['requiredPowerPlant']] .. " Power Plant|" .. PowerPlantNames['TIPowerPlantTemplate.PowerPlantRequirement.' .. row['requiredPowerPlant']] .. "]]"
returnString = returnString .. '\n| ' .. DriveNames['TIDriveTemplate.' .. row['propellant']] .. '<br>'
local waterCost = (tonumber(row['perTankPropellantMaterials/water']) or 0) * 10
local volatileCost = (tonumber(row['perTankPropellantMaterials/volatiles']) or 0) * 10
local metalCost = (tonumber(row['perTankPropellantMaterials/metals']) or 0) * 10
local nobleCost = (tonumber(row['perTankPropellantMaterials/nobleMetals']) or 0) * 10
local fissileCost = (tonumber(row['perTankPropellantMaterials/fissiles']) or 0) * 10
local antimatterCost = (tonumber(row['perTankPropellantMaterials/antimatter']) or 0) * 10
local exoticCost = (tonumber(row['perTankPropellantMaterials/exotics']) or 0) * 10
if waterCost ~= 0 then
returnString = returnString .. TVModule.TV({args={'water', waterCost, 'true'}}) .. ' '
end
if volatileCost ~= 0 then
returnString = returnString .. TVModule.TV({args={'volatiles', volatileCost, 'true'}}) .. ' '
end
if metalCost ~= 0 then
returnString = returnString .. TVModule.TV({args={'metals', metalCost, 'true'}}) .. ' '
end
if nobleCost ~= 0 then
returnString = returnString .. TVModule.TV({args={'nobles', nobleCost, 'true'}}) .. ' '
end
if fissileCost ~= 0 then
returnString = returnString .. TVModule.TV({args={'fissiles', fissileCost, 'true'}}) .. ' '
end
if antimatterCost ~= 0 then
returnString = returnString .. TVModule.TV({args={'antimatter', antimatterCost, 'true'}}) .. ' '
end
if exoticCost ~= 0 then
returnString = returnString .. TVModule.TV({args={'exotics', exoticCost, 'true'}}) .. ' '
end
if detailed then
returnString = returnString .. '\n| ' .. (DriveNames['TIDriveTemplate.PowerGenerationType.' .. (row['powerGen'] or 'Never')] or 'Never')
end
returnString = returnString .. '\n| style="text-align: left;" | '
if DriveNames['TIDriveTemplate.' .. row['propellant']] == 'Anything' then
returnString = returnString .. '\n* Can use [[Spaceships#Remass_Scoop|Remass Scoop]]'
elseif DriveNames['TIDriveTemplate.' .. row['propellant']] == 'Hydrogen' and waterCost + volatileCost >= 10 then
returnString = returnString .. '\n* Can use [[Spaceships#Remass_Scoop|Remass Scoop]]'
elseif DriveNames['TIDriveTemplate.' .. row['propellant']] == 'Hydrogen' and waterCost + volatileCost + fissileCost >= 10 and row['helium3Fuel'] == 'true' then
returnString = returnString .. '\n* Can use [[Spaceships#Remass_Scoop|Remass Scoop]] with [[Spaceships#Propellant|He3]]'
end
if row['helium3Fuel'] == 'true' then
returnString = returnString .. '\n* Uses [[Spaceships#Propellant|He3]]'
end
if row['cooling'] == 'Open' then
returnString = returnString .. '\n* Open-Cycle'
elseif row['cooling'] == 'Calc' and tonumber(row['thrust_N']) / tonumber(row['thrusters']) / tonumber(row['EV_kps']) > 3000 then
returnString = returnString .. '\n* Open-Cycle'
elseif row['driveClassification'] == 'Fission_Pulse' or row['driveClassification'] == 'Fusion_Pulse' then
returnString = returnString .. '\n* Open-Cycle'
end
if row['freeISRU'] == 'true' then
returnString = returnString .. '\n* Free [[Spaceships#ISRU|ISRU]]'
end
if onlyOneThruster then
returnString = returnString .. '\n* Only x1 Thruster'
end
returnString = returnString .. '\n|-'
end
end
returnString = returnString .. '\n|}'
return returnString
end
--endregion
return DriveLister


