16,254
edits
(Added p.GetWorshipTable) |
((Partially) update for v1.1.2, requires a far more thorough rework following Township changes) |
||
Line 1: | Line 1: | ||
local Shared = require('Module:Shared') | local Shared = require('Module:Shared') | ||
local Icons = require('Module:Icons') | local Icons = require('Module:Icons') | ||
local GameData = require('Module:GameData') | local GameData = require('Module:Sandbox/GameData') | ||
local Constants = require('Module:Constants') | local Constants = require('Module:Constants') | ||
Line 388: | Line 388: | ||
for _, biomeid in ipairs(building.biomes) do | for _, biomeid in ipairs(building.biomes) do | ||
local biomename = GameData.getEntityByID(Township.biomes, biomeid).name | local biomename = GameData.getEntityByID(Township.biomes, biomeid).name | ||
table.insert(ret, '<br>'..Icons.Icon({biomename, type='biome', notext=true, nolink=true})..' <span>'..biomename..'</span>') | |||
end | end | ||
Line 416: | Line 405: | ||
-- Gets a string displaying the base production of a building, or nil if no production | -- Gets a string displaying the base production of a building, or nil if no production | ||
function p._GetBuildingBaseProduction(building) | function p._GetBuildingBaseProduction(building) | ||
local production = Shared.clone(building.provides.resources) | -- TODO Fix always using first biome | ||
local production = Shared.clone(building.provides[1].resources) | |||
if #production == 0 then | if #production == 0 then | ||
Line 426: | Line 416: | ||
local retProduction = {} | local retProduction = {} | ||
local job = p._GetJobFromResource(resource.id) | local job = p._GetJobFromResource(resource.id) | ||
local workers = GameData.getEntityByID(building.provides.workers, job).quantity | -- TODO Fix always using first biome | ||
local workers = GameData.getEntityByID(building.provides[1].workers, job).quantity | |||
-- Sourced from township.js -> Township.computeTownResourceGain() | -- Sourced from township.js -> Township.computeTownResourceGain() | ||
local production = resource.quantity*100*(Township.tickLength/10) | local production = resource.quantity*100*(Township.tickLength/10) | ||
Line 457: | Line 448: | ||
} | } | ||
for key, stat in pairs(stats) do | for key, stat in pairs(stats) do | ||
if building.provides[key] ~= nil and building.provides[key] ~= 0 then | -- TODO Fix always using first biome | ||
local quantity = building.provides[key] | if building.provides[1][key] ~= nil and building.provides[1][key] ~= 0 then | ||
local quantity = building.provides[1][key] | |||
if quantity < 0 then | if quantity < 0 then | ||
quantity = '<span style="color:red">'..quantity..'</span>' | quantity = '<span style="color:red">'..quantity..'</span>' | ||
Line 497: | Line 489: | ||
local join = _join ~= nil and _join or ', ' | local join = _join ~= nil and _join or ', ' | ||
local cost = {} | local cost = {} | ||
for _, resource in ipairs(building.cost) do | -- TODO Cost can vary by biome, properly handle this rather than | ||
-- always taking costs for the first biome | |||
for _, resource in ipairs(building.cost[1].cost) do | |||
local resource_data = p._GetResourceByID(resource.id) | local resource_data = p._GetResourceByID(resource.id) | ||
table.insert(cost, Icons.Icon({resource_data.name, type='resource', notext=true})..' '..resource.quantity) | table.insert(cost, Icons.Icon({resource_data.name, type='resource', notext=true})..' '..resource.quantity) | ||
Line 511: | Line 505: | ||
-- Gets text for only the biomes that have a modifier for a building | -- Gets text for only the biomes that have a modifier for a building | ||
function p._GetBiomeModifiers(building) | function p._GetBiomeModifiers(building) | ||
-- TODO Concept of biome modifiers doesn't exist anymore | |||
return '' | |||
--[==[ | |||
local biomeRet = {} | local biomeRet = {} | ||
for _, biome in ipairs(building.biomeModifiers) do | for _, biome in ipairs(building.biomeModifiers) do | ||
Line 522: | Line 519: | ||
end | end | ||
return table.concat(biomeRet, '<br>') | return table.concat(biomeRet, '<br>') | ||
--]==] | |||
end | end | ||
Line 607: | Line 605: | ||
end | end | ||
local FREE_LAND = Township.sectionSize | -- TODO Fix | ||
local FREE_LAND = Township.sectionSize or 0 | |||
-- Gets the cost of the current price of land | -- Gets the cost of the current price of land | ||
-- Taken from township.js -> Township.getNextSectionCost | -- Taken from township.js -> Township.getNextSectionCost | ||
Line 642: | Line 641: | ||
-- Returns a table showing the land cost of a town | -- Returns a table showing the land cost of a town | ||
function p.GetLandCostTable() | function p.GetLandCostTable() | ||
-- TODO Fix | |||
return '' | |||
--[[=[ | |||
local ret = {} | local ret = {} | ||
table.insert(ret, '\r\n{| class="wikitable"') | table.insert(ret, '\r\n{| class="wikitable"') | ||
Line 650: | Line 652: | ||
table.insert(ret, '\r\n|}') | table.insert(ret, '\r\n|}') | ||
return table.concat(ret) | return table.concat(ret) | ||
--]=]] | |||
end | end | ||
Line 657: | Line 660: | ||
-- Setup the table | -- Setup the table | ||
local ret = {} | local ret = {} | ||
table.insert(ret, ' | table.insert(ret, '{| class="wikitable sortable" style="text-align:center"') | ||
table.insert(ret, ' | table.insert(ret, '\n!Building') | ||
-- Make a biomeModifiers table that will keep track of the bonus of each building | -- Make a biomeModifiers table that will keep track of the bonus of each building | ||
-- At the same time, make the output table header | -- At the same time, make the output table header | ||
local | local biomesMaster = {} | ||
for _, biome in ipairs(Township.biomes) do | for _, biome in ipairs(Township.biomes) do | ||
table.insert(ret, ' | table.insert(ret, '\n!'..Icons.Icon({biome.name, type='biome', notext=true, nolink=true})..'<br>'..biome.name) | ||
biomesMaster[biome.id] = false | |||
end | end | ||
Line 675: | Line 678: | ||
if downgrade == nil then | if downgrade == nil then | ||
-- Let's populate the biome habitability data | -- Let's populate the biome habitability data | ||
local | local buildingBiomes = Shared.clone(biomesMaster) | ||
-- Set all valid biomes to 0 | -- Set all valid biomes to 0 | ||
for _, biomeid in ipairs(building.biomes) do | for _, biomeid in ipairs(building.biomes) do | ||
buildingBiomes[biomeid] = true | |||
end | end | ||
-- Let's build the row | -- Let's build the row | ||
table.insert(ret, ' | table.insert(ret, '\n|-') | ||
table.insert(ret, ' | table.insert(ret, '\n!data-sort-value="'..building.name..'" style="text-align:left"|'..Icons.Icon({building.name, type='building'})) | ||
for _, biome in ipairs(Township.biomes) do | for _, biome in ipairs(Township.biomes) do | ||
if buildingBiomes[biome.id] then | |||
-- Buildable | |||
table.insert(ret, '\n|class="table-positive"|✓') | |||
else | else | ||
-- Invalid biome | -- Invalid biome | ||
table.insert(ret, ' | table.insert(ret, '\n|style="border:0px"|') | ||
end | end | ||
end | end | ||
end | end | ||
end | end | ||
table.insert(ret, ' | table.insert(ret, '\n|}') | ||
return table.concat(ret) | return table.concat(ret) | ||
end | end | ||
Line 825: | Line 770: | ||
function p.GetTaskTable(frame) | function p.GetTaskTable(frame) | ||
local category = frame.args ~= nil and frame.args[1] or frame | local category = frame.args ~= nil and frame.args[1] or frame | ||
local | local categoryData = GameData.getEntityByID(Township.taskCategories, category) | ||
if categoryData == nil then | |||
return Shared.printError('Invalid task category specified: ' .. (tostring(category) or 'nil')) | |||
end | |||
local categoryname = categoryData.name | |||
local taskcount = 0 | local taskcount = 0 | ||
Line 957: | Line 906: | ||
table.insert(ret, GetCheckpointCell(0)) | table.insert(ret, GetCheckpointCell(0)) | ||
for _, worship in ipairs(Township.worships) do | for _, worship in ipairs(Township.worships) do | ||
if worship.isHidden == false then | if worship.isHidden == false then | ||
table.insert(ret, '\r\n|'..Constants.getModifiersText(worship.modifiers)) | table.insert(ret, '\r\n|'..Constants.getModifiersText(worship.modifiers)) |