-- Print percentages of each tile type
local iW, iH = Map.GetGridSize();
local plotTotals = {}
local terrainTotals = {}
local featureTotals = {}
local freshwaterTotal = 0
local landPlots = 0
local totalPlots = 0
for x=0, iW-1 do
for y=0, iH-1 do
plot = Map.GetPlot(x, y)
local plotType = plot:GetPlotType()
local terrainType = plot:GetTerrainType()
local featureType = plot:GetFeatureType()
plotTotals[plot:GetPlotType()] = (plotTotals[plot:GetPlotType()] or 0) + 1
featureTotals[featureType] = (featureTotals[featureType] or 0) + 1
freshwaterTotal = freshwaterTotal + (plot:IsFreshWater() and 1 or 0)
if plotType == PlotTypes.PLOT_HILLS or plotType == PlotTypes.PLOT_MOUNTAINS then
-- skip terrain, add only to plot
elseif terrainType == TerrainTypes.TERRAIN_DESERT and featureType == FeatureTypes.FEATURE_FLOOD_PLAINS then
-- skip terrain, add only to feature
else
terrainTotals[terrainType] = (terrainTotals[plot:GetTerrainType()] or 0) + 1
end
totalPlots = totalPlots + 1
if plotType ~= PlotTypes.PLOT_OCEAN then
landPlots = landPlots + 1
end
end
end
print("-");
print("--- Table of Final Results, Tile Distribution ---");
print("-");
print("- PLOTS -");
print(string.format("- %3s%% - %-s", math.floor(100 * ((plotTotals[PlotTypes.PLOT_HILLS] or 0) + (plotTotals[PlotTypes.PLOT_LAND] or 0)) / totalPlots), "LAND" ))
print(string.format("- %3s%% - %-s", math.floor(100 * (terrainTotals[TerrainTypes.TERRAIN_COAST] or 0) / totalPlots), "COAST" ))
print(string.format("- %3s%% - %-s", math.floor(100 * (terrainTotals[TerrainTypes.TERRAIN_OCEAN] or 0) / totalPlots), "OCEAN" ))
print("-");
print("- LAND TERRAIN -");
print(string.format("- %3s%% - %-s", math.floor(100 * freshwaterTotal / landPlots), "Freshwater"))
print(string.format("- %3s%% - %-s", math.floor(100 * (featureTotals[FeatureTypes.FEATURE_FLOOD_PLAINS] or 0) / landPlots), "FLOOD_PLAINS" ))
for terrainInfo in GameInfo.Terrains("Type IN ('TERRAIN_GRASS', 'TERRAIN_PLAINS', 'TERRAIN_DESERT', 'TERRAIN_TUNDRA', 'TERRAIN_SNOW')") do
print(string.format("- %3s%% - %-s", math.floor(100 * (terrainTotals[terrainInfo.ID] or 0) / landPlots), string.gsub(terrainInfo.Type, "TERRAIN_", "") ))
end
print(string.format("- %3s%% - %-s", math.floor(100 * (plotTotals[PlotTypes.PLOT_HILLS] or 0) / totalPlots), "HILLS" ))
print(string.format("- %3s%% - %-s", math.floor(100 * (plotTotals[PlotTypes.PLOT_MOUNTAIN] or 0) / totalPlots), "MOUNTAIN" ))
print("-");
print("- FEATURES -");
for featureInfo in GameInfo.Features("Type IN ('FEATURE_JUNGLE', 'FEATURE_FOREST', 'FEATURE_MARSH', 'FEATURE_ATOLL', 'FEATURE_OASIS')") do
if featureTotals[featureInfo.ID] and featureTotals[featureInfo.ID] > 2 then
print(string.format( "- %3s%% - %-s", math.floor(100 * (featureTotals[featureInfo.ID] or 0) / landPlots), string.gsub(featureInfo.Type, "FEATURE_", "") ))
end
end