572
edits
(_GetBuildingBenefits: Added worship support) |
(Add GetBuildingBiomeTable) |
||
Line 80: | Line 80: | ||
-- Get a sorted list of all the resources | -- Get a sorted list of all the resources | ||
local resources = GameData.sortByOrderTable(Township.resources, Township.resourceDisplayOrder[1].ids) | local resources = GameData.sortByOrderTable(Township.resources, Township.resourceDisplayOrder[1].ids) | ||
-- TODO Fix when the GameData is updated | |||
-- local resources = GameData.sortByOrderTable(Township.resources, Township.resourceDisplayOrder) | |||
resources = Shared.clone(resources) | resources = Shared.clone(resources) | ||
return resources | return resources | ||
end | |||
-- Returns a sorted list of all Township buildings | |||
function p._SortedBuildings() | |||
return Township.buildings | |||
-- TODO Fix when the GameData is updated. Currently doesn't actually sort | |||
-- return GameData.sortByOrderTable(Township.buildings, Township.buildingDisplayOrder) | |||
end | end | ||
Line 662: | Line 671: | ||
for i=FREE_LAND,Township.maxTownSize,FREE_LAND do | for i=FREE_LAND,Township.maxTownSize,FREE_LAND do | ||
table.insert(ret, '\r\n|-\r\n|'..i..'\r\n|'..Icons.GP(p._GetLandCost(i))..'\r\n|'..Icons.GP(p._GetCumulativeLandCost(i))) | table.insert(ret, '\r\n|-\r\n|'..i..'\r\n|'..Icons.GP(p._GetLandCost(i))..'\r\n|'..Icons.GP(p._GetCumulativeLandCost(i))) | ||
end | |||
table.insert(ret, '\r\n|}') | |||
return table.concat(ret) | |||
end | |||
-- Generates a table showing which buildings can be built in which biomes | |||
-- Skips upgraded buildings | |||
function p.GetBuildingBiomeTable() | |||
-- Setup the table | |||
local ret = {} | |||
table.insert(ret, '\r\n{| class="wikitable sortable" style="text-align:center"') | |||
table.insert(ret, '\r\n!Building') | |||
-- Make a biomeModifiers table that will keep track of the bonus of each building | |||
-- At the same time, make the output table header | |||
local biomeModifiersMaster = {} | |||
for _, biome in ipairs(Township.biomes) do | |||
table.insert(ret, '\r\n!'..biome.name) | |||
biomeModifiersMaster[biome.id] = false | |||
end | |||
for _, _building in ipairs(p._SortedBuildings()) do | |||
-- Fix melvorF:Statues | |||
local building = p._GetBuildingByID(_building.id) | |||
-- Skip upgraded buildings | |||
local downgrade = p._GetBuildingDowngrade(building) | |||
if downgrade == nil then | |||
-- Let's populate the biome habitability data | |||
local biomeModifiers = Shared.clone(biomeModifiersMaster) | |||
-- Set all valid biomes to 0 | |||
for _, biomeid in ipairs(building.biomes) do | |||
biomeModifiers[biomeid] = 0 | |||
end | |||
-- Then add the biome modifier values | |||
for _, biomeModifier in ipairs(building.biomeModifiers) do | |||
biomeModifiers[biomeModifier.biomeID] = biomeModifier.value | |||
end | |||
-- Let's build the row | |||
table.insert(ret, '\r\n|-') | |||
table.insert(ret, '\r\n!data-sort-value="'..building.name..'" style="text-align:left"|'..Icons.Icon({building.name, type='building'})) | |||
for _, biome in ipairs(Township.biomes) do | |||
local modifier = biomeModifiers[biome.id] | |||
if modifier then | |||
if modifier == 0 then | |||
-- Buildable but no bonuses | |||
table.insert(ret, '\r\n|class="table-na"|+0%') | |||
else | |||
-- Bonus or penalty | |||
local class = modifier < 0 and 'table-negative' or 'table-positive' | |||
local modifier_value = Shared.numStrWithSign(modifier) | |||
table.insert(ret, '\r\n|class="'..class..'"|<b>'..modifier_value..'%</b>') | |||
end | |||
else | |||
-- Invalid biome | |||
table.insert(ret, '\r\n|style="border:0px"|') | |||
end | |||
end | |||
end | |||
end | end | ||
table.insert(ret, '\r\n|}') | table.insert(ret, '\r\n|}') |
edits