@@ -310,9 +310,18 @@ function AssignStartingPlots:__SetStartMajor(plots)
sortedPlots ={};
+ if plots == nil then
+ return;
+ end
+
local iSize = #plots;
local iContinentIndex = 1;
-
+
+ -- Nothing there? Just exit, returing nil
+ if iSize == 0 then
+ return;
+ end
+
for i, plot in ipairs(plots) do
row = {};
row.Plot = plot;
@@ -339,6 +348,8 @@ function AssignStartingPlots:__SetStartMajor(plots)
end
local bValid = false;
+ local pFallback:table = Map.GetPlotByIndex(sortedPlots[1].Plot);
+ local iFallBackScore = 0;
while bValid == false and iSize >= iContinentIndex do
bValid = true;
local NWMajor = 0;
@@ -349,26 +360,48 @@ function AssignStartingPlots:__SetStartMajor(plots)
-- Checks to see if the plot is impassable
if(pTempPlot:IsImpassable() == true) then
bValid = false;
+ else
+ local iFallBackScoreTemp = 0;
+ if (iFallBackScore <= iFallBackScoreTemp) then
+ pFallback = pTempPlot;
+ iFallBackScore = iFallBackScoreTemp;
+ end
end
-- Checks to see if the plot is water
if(pTempPlot:IsWater() == true) then
bValid = false;
+ else
+ local iFallBackScoreTemp = 1;
+ if (iFallBackScore <= iFallBackScoreTemp and bValid == true) then
+ pFallback = pTempPlot;
+ iFallBackScore = iFallBackScoreTemp;
+ end
end
-
- -- Checks to see if there are resources
- if(pTempPlot:GetResourceCount() > 0) then
- local bValidResource = self:__BonusResource(pTempPlot);
- if(bValidResource == false) then
- bValid = false;
- end
- end
+
+ -- Checks to see if there are any major civs in the given distance
+ local bMajorCivCheck = self:__MajorCivBuffer(pTempPlot);
+ if(bMajorCivCheck == false) then
+ bValid = false;
+ else
+ local iFallBackScoreTemp = 2;
+ if (iFallBackScore <= iFallBackScoreTemp and bValid == true) then
+ pFallback = pTempPlot;
+ iFallBackScore = iFallBackScoreTemp;
+ end
+ end
-- Checks to see if there are luxuries
if (math.ceil(self.iDefaultNumberMajor * 1.25) + self.iDefaultNumberMinor > self.iNumMinorCivs + self.iNumMajorCivs) then
local bLuxuryCheck = self:__LuxuryBuffer(pTempPlot);
if(bLuxuryCheck == false) then
bValid = false;
+ else
+ local iFallBackScoreTemp = 3;
+ if (iFallBackScore <= iFallBackScoreTemp and bValid == true) then
+ pFallback = pTempPlot;
+ iFallBackScore = iFallBackScoreTemp;
+ end
end
end
@@ -383,23 +416,49 @@ function AssignStartingPlots:__SetStartMajor(plots)
local bWaterCheck = self:__GetWaterCheck(pTempPlot);
if(bWaterCheck == false) then
bValid = false;
+ else
+ local iFallBackScoreTemp = 4;
+ if (iFallBackScore <= iFallBackScoreTemp and bValid == true) then
+ pFallback = pTempPlot;
+ iFallBackScore = iFallBackScoreTemp;
+ end
end
local bValidAdjacentCheck = self:__GetValidAdjacent(pTempPlot, 0);
if(bValidAdjacentCheck == false) then
bValid = false;
+ else
+ local iFallBackScoreTemp = 5;
+ if (iFallBackScore <= iFallBackScoreTemp and bValid == true) then
+ pFallback = pTempPlot;
+ iFallBackScore = iFallBackScoreTemp;
+ end
end
-- Checks to see if there are natural wonders in the given distance
local bNaturalWonderCheck = self:__NaturalWonderBuffer(pTempPlot, false);
if(bNaturalWonderCheck == false) then
bValid = false;
+ else
+ local iFallBackScoreTemp = 6;
+ if (iFallBackScore <= iFallBackScoreTemp and bValid == true) then
+ pFallback = pTempPlot;
+ iFallBackScore = iFallBackScoreTemp;
+ end
end
-
- -- Checks to see if there are any major civs in the given distance
- local bMajorCivCheck = self:__MajorCivBuffer(pTempPlot);
- if(bMajorCivCheck == false) then
- bValid = false;
+
+ -- Checks to see if there are resources
+ if(pTempPlot:GetResourceCount() > 0) then
+ local bValidResource = self:__BonusResource(pTempPlot);
+ if(bValidResource == false) then
+ bValid = false;
+ end
+ else
+ local iFallBackScoreTemp = 7;
+ if (iFallBackScore <= iFallBackScoreTemp and bValid == true) then
+ pFallback = pTempPlot;
+ iFallBackScore = iFallBackScoreTemp;
+ end
end
-- Checks to see if there is an Oasis
@@ -416,7 +475,7 @@ function AssignStartingPlots:__SetStartMajor(plots)
end
end
- return nil;
+ return pFallback;
end
------------------------------------------------------------------------------
@@ -429,8 +488,18 @@ function AssignStartingPlots:__SetStartMinor(plots)
-- minimum food
sortedPlots ={};
-
+
+ if plots == nil then
+ return;
+ end
+
local iSize = #plots;
+
+ -- Nothing there? Just exit, returing nil
+ if iSize == 0 then
+ return;
+ end
+
local iContinentIndex = 1;
for i, plot in ipairs(plots) do
@@ -443,6 +512,8 @@ function AssignStartingPlots:__SetStartMinor(plots)
table.sort (sortedPlots, function(a, b) return a.Fertility > b.Fertility; end);
local bValid = false;
+ local pFallback:table = Map.GetPlotByIndex(sortedPlots[1].Plot);
+ local iFallBackScore = 0;
while bValid == false and iSize >= iContinentIndex do
bValid = true;
local NWMinor = 2;
@@ -453,36 +524,72 @@ function AssignStartingPlots:__SetStartMinor(plots)
-- Checks to see if the plot is impassable
if(pTempPlot:IsImpassable() == true) then
bValid = false;
+ else
+ local iFallBackScoreTemp = 0;
+ if (iFallBackScore <= iFallBackScoreTemp) then
+ pFallback = pTempPlot;
+ iFallBackScore = iFallBackScoreTemp;
+ end
end
-- Checks to see if the plot is water
if(pTempPlot:IsWater() == true) then
bValid = false;
- end
-
- -- Checks to see if there are resources
- if(pTempPlot:GetResourceCount() > 0) then
- local bValidResource = self:__BonusResource(pTempPlot);
- if(bValidResource == false) then
- bValid = false;
+ else
+ local iFallBackScoreTemp = 1;
+ if (iFallBackScore <= iFallBackScoreTemp and bValid == true) then
+ pFallback = pTempPlot;
+ iFallBackScore = iFallBackScoreTemp;
end
end
+
+ -- Checks to see if there are any minor civs in the given distance
+ local bMinorCivCheck = self:__MinorCivBuffer(pTempPlot, 1);
+ if(bMinorCivCheck == false) then
+ bValid = false;
+ else
+ local iFallBackScoreTemp = 2;
+ if (iFallBackScore <= iFallBackScoreTemp and bValid == true) then
+ pFallback = pTempPlot;
+ iFallBackScore = iFallBackScoreTemp;
+ end
+ end
local bValidAdjacentCheck = self:__GetValidAdjacent(pTempPlot, 2);
if(bValidAdjacentCheck == false) then
bValid = false;
+ else
+ local iFallBackScoreTemp = 3;
+ if (iFallBackScore <= iFallBackScoreTemp and bValid == true) then
+ pFallback = pTempPlot;
+ iFallBackScore = iFallBackScoreTemp;
+ end
end
-- Checks to see if there are natural wonders in the given distance
local bNaturalWonderCheck = self:__NaturalWonderBuffer(pTempPlot, true);
if(bNaturalWonderCheck == false) then
bValid = false;
+ else
+ local iFallBackScoreTemp = 4;
+ if (iFallBackScore <= iFallBackScoreTemp and bValid == true) then
+ pFallback = pTempPlot;
+ iFallBackScore = iFallBackScoreTemp;
+ end
end
- -- Checks to see if there are any minor civs in the given distance
- local bMinorCivCheck = self:__MinorCivBuffer(pTempPlot, 1);
- if(bMinorCivCheck == false) then
- bValid = false;
+ -- Checks to see if there are resources
+ if(pTempPlot:GetResourceCount() > 0) then
+ local bValidResource = self:__BonusResource(pTempPlot);
+ if(bValidResource == false) then
+ bValid = false;
+ end
+ else
+ local iFallBackScoreTemp = 5;
+ if (iFallBackScore <= iFallBackScoreTemp and bValid == true) then
+ pFallback = pTempPlot;
+ iFallBackScore = iFallBackScoreTemp;
+ end
end
-- Checks to see if there is an Oasis
@@ -498,7 +605,7 @@ function AssignStartingPlots:__SetStartMinor(plots)
end
end
- return nil;
+ return pFallback;
end