Module:Sandbox/GauTest/Township: Difference between revisions

no edit summary
No edit summary
No edit summary
Line 667: Line 667:
end
end


-- Generates a table showing which buildings can be built in which biomes
-- Skips upgraded buildings
function p.GetBuildingBiomeTable()
function p.GetBuildingBiomeTable()
-- Setup the table
local ret = {}
local ret = {}
table.insert(ret, '\r\n{| class="wikitable"')
table.insert(ret, '\r\n{| class="wikitable"')
table.insert(ret, '\r\n!Building')
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
for _, biome in ipairs(Township.biomes) do
table.insert(ret, '\r\n!'..biome.name)
table.insert(ret, '\r\n!'..biome.name)
biomeModifiersMaster[biome.id] = false
end
for _, building in ipairs(Township.buildings) do
-- 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
table.insert(ret, '\r\n!'..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|style="background-color:grey;"|0')
else
-- Bonus or penalty
local color = modifier < 0 and 'red' or 'green'
local modifier_value = Shared.numStrWithSign(modifier)
table.insert(ret, '\r\n|style="background-color:'..color..'"|<b>'..modifier_value'</b>')
end
else
-- Invalid biome
table.insert(ret, '\r\n|')
end
end
end
end
end
table.insert(ret, '\r\n|}')
table.insert(ret, '\r\n|}')
572

edits