function AssignStartingPlots:AddStrategicBalanceResources(region_number)
-- This function adds the required Strategic Resources to start plots, for
-- games that have selected to enable Strategic Resource Balance.
local iW, iH = Map.GetGridSize();
local start_point_data = self.startingPlots[region_number];
local x = start_point_data[1];
local y = start_point_data[2];
local plot = Map.GetPlot(x, y);
local plotIndex = y * iW + x + 1;
local wrapX = Map:IsWrapX();
local wrapY = Map:IsWrapY();
local odd = self.firstRingYIsOdd;
local even = self.firstRingYIsEven;
local nextX, nextY, plot_adjustments;
local iron_list, horse_list, oil_list = {}, {}, {};
local iron_fallback, horse_fallback, oil_fallback = {}, {}, {};
local radius = 3;
--print("- Adding Strategic Balance Resources for start location in Region#", region_number);
for ripple_radius = 1, radius do
local ripple_value = radius - ripple_radius + 1;
local currentX = x - ripple_radius;
local currentY = y;
for direction_index = 1, 6 do
for plot_to_handle = 1, ripple_radius do
if currentY / 2 > math.floor(currentY / 2) then
plot_adjustments = odd[direction_index];
else
plot_adjustments = even[direction_index];
end
nextX = currentX + plot_adjustments[1];
nextY = currentY + plot_adjustments[2];
if wrapX == false and (nextX < 0 or nextX >= iW) then
-- X is out of bounds.
elseif wrapY == false and (nextY < 0 or nextY >= iH) then
-- Y is out of bounds.
else
local realX = nextX;
local realY = nextY;
if wrapX then
realX = realX % iW;
end
if wrapY then
realY = realY % iH;
end
-- We've arrived at the correct x and y for the current plot.
local plot = Map.GetPlot(realX, realY);
local plotType = plot:GetPlotType()
local terrainType = plot:GetTerrainType()
local featureType = plot:GetFeatureType()
local plotIndex = realY * iW + realX + 1;
-- Check this plot for resource placement eligibility.
if plotType == PlotTypes.PLOT_HILLS then
if ripple_radius < 3 then
table.insert(iron_list, plotIndex)
else
table.insert(iron_fallback, plotIndex)
end
if terrainType ~= TerrainTypes.TERRAIN_SNOW and featureType == FeatureTypes.NO_FEATURE then
table.insert(horse_fallback, plotIndex)
end
elseif plotType == PlotTypes.PLOT_LAND then
if featureType == FeatureTypes.NO_FEATURE then
if terrainType == TerrainTypes.TERRAIN_TUNDRA or terrainType == TerrainTypes.TERRAIN_DESERT then
if ripple_radius < 3 then
table.insert(oil_list, plotIndex)
else
table.insert(oil_fallback, plotIndex)
end
table.insert(iron_fallback, plotIndex)
table.insert(horse_fallback, plotIndex)
elseif terrainType == TerrainTypes.TERRAIN_PLAINS or terrainType == TerrainTypes.TERRAIN_GRASS then
if ripple_radius < 3 then
table.insert(horse_list, plotIndex)
else
table.insert(horse_fallback, plotIndex)
end
table.insert(iron_fallback, plotIndex)
table.insert(oil_fallback, plotIndex)
elseif terrainType == TerrainTypes.TERRAIN_SNOW then
if ripple_radius < 3 then
table.insert(oil_list, plotIndex)
else
table.insert(oil_fallback, plotIndex)
end
end
elseif featureType == FeatureTypes.FEATURE_MARSH then
if ripple_radius < 3 then
table.insert(oil_list, plotIndex)
else
table.insert(oil_fallback, plotIndex)
end
table.insert(iron_fallback, plotIndex)
elseif featureType == FeatureTypes.FEATURE_FLOOD_PLAINS then
table.insert(horse_fallback, plotIndex)
table.insert(oil_fallback, plotIndex)
elseif featureType == FeatureTypes.FEATURE_JUNGLE or featureType == FeatureTypes.FEATURE_FOREST then
table.insert(iron_fallback, plotIndex)
table.insert(oil_fallback, plotIndex)
end
end
currentX, currentY = nextX, nextY;
end
end
end
end
local uran_amt, horse_amt, oil_amt, iron_amt, coal_amt, alum_amt = self:GetMajorStrategicResourceQuantityValues()
local shuf_list;
local placed_iron, placed_horse, placed_oil = false, false, false;
if table.maxn(iron_list) > 0 then
shuf_list = GetShuffledCopyOfTable(iron_list)
iNumLeftToPlace = self:PlaceSpecificNumberOfResources(self.iron_ID, iron_amt, 1, 1, -1, 0, 0, shuf_list);
if iNumLeftToPlace == 0 then
placed_iron = true;
end
end
if table.maxn(horse_list) > 0 then
shuf_list = GetShuffledCopyOfTable(horse_list)
iNumLeftToPlace = self:PlaceSpecificNumberOfResources(self.horse_ID, horse_amt, 1, 1, -1, 0, 0, shuf_list);
if iNumLeftToPlace == 0 then
placed_horse = true;
end
end
if table.maxn(oil_list) > 0 then
shuf_list = GetShuffledCopyOfTable(oil_list)
iNumLeftToPlace = self:PlaceSpecificNumberOfResources(self.oil_ID, oil_amt, 1, 1, -1, 0, 0, shuf_list);
if iNumLeftToPlace == 0 then
placed_oil = true;
end
end
if placed_iron == false and table.maxn(iron_fallback) > 0 then
shuf_list = GetShuffledCopyOfTable(iron_fallback)
iNumLeftToPlace = self:PlaceSpecificNumberOfResources(self.iron_ID, iron_amt, 1, 1, -1, 0, 0, shuf_list);
end
if placed_horse == false and table.maxn(horse_fallback) > 0 then
shuf_list = GetShuffledCopyOfTable(horse_fallback)
iNumLeftToPlace = self:PlaceSpecificNumberOfResources(self.horse_ID, horse_amt, 1, 1, -1, 0, 0, shuf_list);
end
if placed_oil == false and table.maxn(oil_fallback) > 0 then
shuf_list = GetShuffledCopyOfTable(oil_fallback)
iNumLeftToPlace = self:PlaceSpecificNumberOfResources(self.oil_ID, oil_amt, 1, 1, -1, 0, 0, shuf_list);
end
end