Skip to content

Commit

Permalink
Merge pull request #12 from bszonye/arctic-fix
Browse files Browse the repository at this point in the history
Fix polar starts and bad terrain
  • Loading branch information
bszonye authored Nov 15, 2017
2 parents 5a31e48 + 6d6d67e commit ab348e8
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 27 deletions.
74 changes: 48 additions & 26 deletions assignstartingplots.lua
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,12 @@ function AssignStartingPlots:__InitStartingData()
end

-- XXX: debug
--RevealAll(0);
-- Test seed: -348648293 (standard)
-- Test seed: -355184159 (standard or huge)
-- Test seed: 1911259460 (standard, new age, crowded)
-- Test seed: -975958907 (standard, pangaea, new age, crowded)
--RevealAll(0); -- explore all
--RevealAll(1); -- reveal all
end

------------------------------------------------------------------------------
Expand Down Expand Up @@ -421,10 +426,10 @@ function AssignStartingPlots:__SetStartMajor(plots)
score = score - 2;
end

local bValidAdjacentCheck = self:__GetValidAdjacent(pTempPlot, 0);
if(bValidAdjacentCheck == false) then
local iValidAdjacentCheck = self:__GetValidAdjacent(pTempPlot, 0);
if(iValidAdjacentCheck ~= 0) then
bValid = false;
score = score - 1;
score = score - iValidAdjacentCheck;
end

-- Checks to see if there are natural wonders in the given distance
Expand Down Expand Up @@ -454,7 +459,7 @@ function AssignStartingPlots:__SetStartMajor(plots)
if bValid == true then
self:__TryToRemoveBonusResource(pTempPlot);
self:__AddBonusFoodProduction(pTempPlot);
print(string.format("major ok: %d:%d", pTempPlot:GetX(), pTempPlot:GetY()));
print(string.format("major: %d:%d", pTempPlot:GetX(), pTempPlot:GetY()));
return pTempPlot;
end

Expand All @@ -470,9 +475,9 @@ function AssignStartingPlots:__SetStartMajor(plots)
if pFallback then
self:__TryToRemoveBonusResource(pTempPlot);
self:__AddBonusFoodProduction(pTempPlot);
print(string.format("major fallback: (%d-%d)", iScore, iCrunch));
print(string.format("MAJOR: %d:%d (%d-%d)", pFallback:GetX(), pFallback:GetY(), iScore, iCrunch));
else
print(string.format("major failed"));
print(string.format("MAJOR FAILED"));
end
return pFallback;
end
Expand Down Expand Up @@ -545,10 +550,10 @@ function AssignStartingPlots:__SetStartMinor(plots)
bValid = false;
end

local bValidAdjacentCheck = self:__GetValidAdjacent(pTempPlot, 2);
if(bValidAdjacentCheck == false) then
local iValidAdjacentCheck = self:__GetValidAdjacent(pTempPlot, 2);
if(iValidAdjacentCheck ~= 0) then
bValid = false;
score = score - 1;
score = score - iValidAdjacentCheck;
end

-- Checks to see if there are natural wonders in the given distance
Expand Down Expand Up @@ -577,7 +582,7 @@ function AssignStartingPlots:__SetStartMinor(plots)
-- If the plots passes all the checks then the plot equals the temp plot
if(bValid == true) then
self:__TryToRemoveBonusResource(pTempPlot);
print(string.format("minor ok: %d:%d", pTempPlot:GetX(), pTempPlot:GetY()));
print(string.format("minor: %d:%d", pTempPlot:GetX(), pTempPlot:GetY()));
return pTempPlot;
end

Expand All @@ -592,9 +597,9 @@ function AssignStartingPlots:__SetStartMinor(plots)

if pFallback then
self:__TryToRemoveBonusResource(pTempPlot);
print(string.format("minor fallback: (%d-%d)", iScore, iCrunch));
print(string.format("MINOR: %d:%d (%d-%d)", pFallback:GetX(), pFallback:GetY(), iScore, iCrunch));
else
print(string.format("minor failed"));
print(string.format("MINOR FAILED"));
end
return pFallback;
end
Expand Down Expand Up @@ -642,8 +647,15 @@ function AssignStartingPlots:__GetValidAdjacent(plot, minor)
min = math.ceil(gridHeight * self.uiStartMinY / 100);
end

-- This biases the map away from the south pole, maybe an off-by-one error?
-- It matches the way the map scripts put snow on the map, however.
local polar = 0;
if(plot:GetY() <= min or plot:GetY() > gridHeight - max) then
return false;
-- distance out of bounds
local south = math.max(0, min - plot:GetY() + 1);
local north = math.max(0, plot:GetY() - (gridHeight - max));
-- penalty for being out of bounds
polar = 1 + south + north; -- minimum 2
end

for direction = 0, DirectionTypes.NUM_DIRECTION_TYPES - 1, 1 do
Expand Down Expand Up @@ -687,26 +699,36 @@ function AssignStartingPlots:__GetValidAdjacent(plot, minor)
if(self.uiStartConfig == 1 and minor == 0) then
balancedStart = 1;
end


local stuck = 0;
if((impassable >= 2 + minor - balancedStart or (self.landMap == true and impassable >= 2 + minor)) and self.waterMap == false) then
return false;
stuck = 1;
elseif(self.waterMap == true and impassable >= 2 + minor * 2 - balancedStart) then
return false;
stuck = 1;
elseif(water + impassable >= 4 + minor - balancedStart and self.waterMap == false) then
return false;
stuck = 1;
elseif(water >= 3 + minor - balancedStart) then
return false;
stuck = 1;
elseif(water >= 4 + minor and self.waterMap == true) then
return false;
elseif(minor == 0 and desert > 2 - balancedStart) then
return false;
stuck = 1;
end

local waste = 0;
if(minor == 0 and desert > 2 - balancedStart) then
waste = 1;
elseif(minor == 0 and snow > 1 - balancedStart) then
return false;
waste = 1;
elseif(minor > 0 and snow > 2) then
return false;
else
return true;
waste = 1;
end

-- TODO: handle special situations like all mountains & all snow
-- XXX: debug
if plot:IsImpassable() ~= true and impassable + water >= 6 then
print(string.format("STUCK: %d:%d impassable %d water %d", plot:GetX(), plot:GetY(), impassable, water));
end
local penalty = polar + stuck + waste;
return penalty;
end

------------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion capslock.modinfo
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<Mod id="475e175c-0e19-4918-8771-3b849b261ac2" version="0.9.1">
<Mod id="475e175c-0e19-4918-8771-3b849b261ac2" version="0.9.2">
<Properties>
<Name>Caps Lock</Name>
<Description>Starting plot improvements</Description>
Expand Down

0 comments on commit ab348e8

Please sign in to comment.