From 4053aa490d7a16c90991832fb492a5f92c532622 Mon Sep 17 00:00:00 2001 From: Bradd Szonye Date: Fri, 10 Nov 2017 02:51:26 -0800 Subject: [PATCH 1/4] Fix polar starts and bad terrain --- assignstartingplots.lua | 102 ++++++++++++++++++++++++++++++---------- 1 file changed, 76 insertions(+), 26 deletions(-) diff --git a/assignstartingplots.lua b/assignstartingplots.lua index 413b341..7ae785b 100644 --- a/assignstartingplots.lua +++ b/assignstartingplots.lua @@ -296,7 +296,10 @@ function AssignStartingPlots:__InitStartingData() end -- XXX: debug - --RevealAll(0); + -- Test seed: -348648294 / -348648293 (standard) + -- Test seed: -355184160 / -355184159 (huge) + --RevealAll(0); -- explore all + --RevealAll(1); -- reveal all end ------------------------------------------------------------------------------ @@ -422,9 +425,10 @@ function AssignStartingPlots:__SetStartMajor(plots) end local bValidAdjacentCheck = self:__GetValidAdjacent(pTempPlot, 0); - if(bValidAdjacentCheck == false) then + if(bValidAdjacentCheck ~= 0) then bValid = false; - score = score - 1; + score = score - bValidAdjacentCheck; + print(string.format("major GetValidAdjacent: %d:%d (%d-%d)", pTempPlot:GetX(), pTempPlot:GetY(), bValidAdjacentCheck, crunch)); end -- Checks to see if there are natural wonders in the given distance @@ -454,7 +458,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 @@ -462,7 +466,7 @@ function AssignStartingPlots:__SetStartMajor(plots) if iScore - iCrunch < score - crunch then iCrunch = crunch; iScore = score; - --print(string.format("maybe: %d:%d (%d-%d)", pTempPlot:GetX(), pTempPlot:GetY(), iScore, iCrunch)); + print(string.format("maybe: %d:%d (%d-%d)", pTempPlot:GetX(), pTempPlot:GetY(), iScore, iCrunch)); pFallback = pTempPlot; end end @@ -470,9 +474,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)", pTempPlot:GetX(), pTempPlot:GetY(), iScore, iCrunch)); else - print(string.format("major failed")); + print(string.format("MAJOR FAILED")); end return pFallback; end @@ -546,9 +550,10 @@ function AssignStartingPlots:__SetStartMinor(plots) end local bValidAdjacentCheck = self:__GetValidAdjacent(pTempPlot, 2); - if(bValidAdjacentCheck == false) then + if(bValidAdjacentCheck ~= 0) then bValid = false; - score = score - 1; + score = score - bValidAdjacentCheck; + print(string.format("minor GetValidAdjacent: %d:%d (%d-%d)", pTempPlot:GetX(), pTempPlot:GetY(), bValidAdjacentCheck, crunch)); end -- Checks to see if there are natural wonders in the given distance @@ -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 @@ -585,16 +590,16 @@ function AssignStartingPlots:__SetStartMinor(plots) if iScore - iCrunch < score - crunch then iCrunch = crunch; iScore = score; - --print(string.format("maybe: %d:%d (%d-%d)", pTempPlot:GetX(), pTempPlot:GetY(), iScore, iCrunch)); + print(string.format("maybe: %d:%d (%d-%d)", pTempPlot:GetX(), pTempPlot:GetY(), iScore, iCrunch)); pFallback = pTempPlot; end end if pFallback then self:__TryToRemoveBonusResource(pTempPlot); - print(string.format("minor fallback: (%d-%d)", iScore, iCrunch)); + print(string.format("MINOR: %d:%d (%d-%d)", pTempPlot:GetX(), pTempPlot:GetY(), iScore, iCrunch)); else - print(string.format("minor failed")); + print(string.format("MINOR FAILED")); end return pFallback; end @@ -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 @@ -687,26 +699,64 @@ 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 + + local awful = 0; + local badness = impassable + water + desert + snow; + if minor == 0 and badness > 3 then + awful = 1; + end + + if nil then + local stuck = 0; + if self.waterMap == false then + local ok = 1 + minor - balancedStart; + stuck = math.max(0, impassable - ok) + math.max(0, water - ok); + else + local okI = 1 + minor * 2 - balancedStart; + local okW = 3 + minor; + stuck = math.max(0, impassable - okI) + math.max(0, water - okW); + end + if impassable + water > 5 then + stuck = stuck + 1 + end + + local waste = 0; + if minor == 0 then + local okD = 2 - balancedStart; + local okS = 1 - balancedStart; + waste = math.max(0, desert - okD) + math.max(0, snow - okS); + else + waste = math.max(0, snow - 2); + end + end + + local penalty = polar + stuck + waste; -- + awful; + if polar ~= 0 or (penalty == 0 and awful ~= 0) then + print(string.format("penalty %d (badness %d imp %d water %d desert %d snow %d polar %d stuck %d waste %d)", penalty, badness, impassable, water, desert, snow, polar, stuck, waste)); end + return penalty; end ------------------------------------------------------------------------------ From 0c4a0b07c7d86854988f36ef19094486b82f26b5 Mon Sep 17 00:00:00 2001 From: Bradd Szonye Date: Tue, 14 Nov 2017 02:43:47 -0800 Subject: [PATCH 2/4] Extra debugging & cleanup --- assignstartingplots.lua | 40 ++++++++++++---------------------------- 1 file changed, 12 insertions(+), 28 deletions(-) diff --git a/assignstartingplots.lua b/assignstartingplots.lua index 7ae785b..f281003 100644 --- a/assignstartingplots.lua +++ b/assignstartingplots.lua @@ -296,8 +296,10 @@ function AssignStartingPlots:__InitStartingData() end -- XXX: debug - -- Test seed: -348648294 / -348648293 (standard) - -- Test seed: -355184160 / -355184159 (huge) + -- 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 @@ -474,7 +476,7 @@ function AssignStartingPlots:__SetStartMajor(plots) if pFallback then self:__TryToRemoveBonusResource(pTempPlot); self:__AddBonusFoodProduction(pTempPlot); - print(string.format("MAJOR: %d:%d (%d-%d)", pTempPlot:GetX(), pTempPlot:GetY(), iScore, iCrunch)); + print(string.format("MAJOR: %d:%d (%d-%d)", pFallback:GetX(), pFallback:GetY(), iScore, iCrunch)); else print(string.format("MAJOR FAILED")); end @@ -597,7 +599,7 @@ function AssignStartingPlots:__SetStartMinor(plots) if pFallback then self:__TryToRemoveBonusResource(pTempPlot); - print(string.format("MINOR: %d:%d (%d-%d)", pTempPlot:GetX(), pTempPlot:GetY(), iScore, iCrunch)); + print(string.format("MINOR: %d:%d (%d-%d)", pFallback:GetX(), pFallback:GetY(), iScore, iCrunch)); else print(string.format("MINOR FAILED")); end @@ -700,6 +702,11 @@ function AssignStartingPlots:__GetValidAdjacent(plot, minor) balancedStart = 1; end + -- 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 stuck = 0; if((impassable >= 2 + minor - balancedStart or (self.landMap == true and impassable >= 2 + minor)) and self.waterMap == false) then stuck = 1; @@ -722,36 +729,13 @@ function AssignStartingPlots:__GetValidAdjacent(plot, minor) waste = 1; end + -- TODO: handle special situations like all mountains & all snow local awful = 0; local badness = impassable + water + desert + snow; if minor == 0 and badness > 3 then awful = 1; end - if nil then - local stuck = 0; - if self.waterMap == false then - local ok = 1 + minor - balancedStart; - stuck = math.max(0, impassable - ok) + math.max(0, water - ok); - else - local okI = 1 + minor * 2 - balancedStart; - local okW = 3 + minor; - stuck = math.max(0, impassable - okI) + math.max(0, water - okW); - end - if impassable + water > 5 then - stuck = stuck + 1 - end - - local waste = 0; - if minor == 0 then - local okD = 2 - balancedStart; - local okS = 1 - balancedStart; - waste = math.max(0, desert - okD) + math.max(0, snow - okS); - else - waste = math.max(0, snow - 2); - end - end - local penalty = polar + stuck + waste; -- + awful; if polar ~= 0 or (penalty == 0 and awful ~= 0) then print(string.format("penalty %d (badness %d imp %d water %d desert %d snow %d polar %d stuck %d waste %d)", penalty, badness, impassable, water, desert, snow, polar, stuck, waste)); From 7ad49146d8c0dd151d44fa78d7ad5296144d3c57 Mon Sep 17 00:00:00 2001 From: Bradd Szonye Date: Tue, 14 Nov 2017 23:07:48 -0800 Subject: [PATCH 3/4] More debugging & style cleanup --- assignstartingplots.lua | 36 ++++++++++++------------------------ 1 file changed, 12 insertions(+), 24 deletions(-) diff --git a/assignstartingplots.lua b/assignstartingplots.lua index f281003..81ae540 100644 --- a/assignstartingplots.lua +++ b/assignstartingplots.lua @@ -426,11 +426,10 @@ function AssignStartingPlots:__SetStartMajor(plots) score = score - 2; end - local bValidAdjacentCheck = self:__GetValidAdjacent(pTempPlot, 0); - if(bValidAdjacentCheck ~= 0) then + local iValidAdjacentCheck = self:__GetValidAdjacent(pTempPlot, 0); + if(iValidAdjacentCheck ~= 0) then bValid = false; - score = score - bValidAdjacentCheck; - print(string.format("major GetValidAdjacent: %d:%d (%d-%d)", pTempPlot:GetX(), pTempPlot:GetY(), bValidAdjacentCheck, crunch)); + score = score - iValidAdjacentCheck; end -- Checks to see if there are natural wonders in the given distance @@ -468,7 +467,7 @@ function AssignStartingPlots:__SetStartMajor(plots) if iScore - iCrunch < score - crunch then iCrunch = crunch; iScore = score; - print(string.format("maybe: %d:%d (%d-%d)", pTempPlot:GetX(), pTempPlot:GetY(), iScore, iCrunch)); + --print(string.format("maybe: %d:%d (%d-%d)", pTempPlot:GetX(), pTempPlot:GetY(), iScore, iCrunch)); pFallback = pTempPlot; end end @@ -551,11 +550,10 @@ function AssignStartingPlots:__SetStartMinor(plots) bValid = false; end - local bValidAdjacentCheck = self:__GetValidAdjacent(pTempPlot, 2); - if(bValidAdjacentCheck ~= 0) then + local iValidAdjacentCheck = self:__GetValidAdjacent(pTempPlot, 2); + if(iValidAdjacentCheck ~= 0) then bValid = false; - score = score - bValidAdjacentCheck; - print(string.format("minor GetValidAdjacent: %d:%d (%d-%d)", pTempPlot:GetX(), pTempPlot:GetY(), bValidAdjacentCheck, crunch)); + score = score - iValidAdjacentCheck; end -- Checks to see if there are natural wonders in the given distance @@ -592,7 +590,7 @@ function AssignStartingPlots:__SetStartMinor(plots) if iScore - iCrunch < score - crunch then iCrunch = crunch; iScore = score; - print(string.format("maybe: %d:%d (%d-%d)", pTempPlot:GetX(), pTempPlot:GetY(), iScore, iCrunch)); + --print(string.format("maybe: %d:%d (%d-%d)", pTempPlot:GetX(), pTempPlot:GetY(), iScore, iCrunch)); pFallback = pTempPlot; end end @@ -702,11 +700,6 @@ function AssignStartingPlots:__GetValidAdjacent(plot, minor) balancedStart = 1; end - -- 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 stuck = 0; if((impassable >= 2 + minor - balancedStart or (self.landMap == true and impassable >= 2 + minor)) and self.waterMap == false) then stuck = 1; @@ -730,16 +723,11 @@ function AssignStartingPlots:__GetValidAdjacent(plot, minor) end -- TODO: handle special situations like all mountains & all snow - local awful = 0; - local badness = impassable + water + desert + snow; - if minor == 0 and badness > 3 then - awful = 1; - end - - local penalty = polar + stuck + waste; -- + awful; - if polar ~= 0 or (penalty == 0 and awful ~= 0) then - print(string.format("penalty %d (badness %d imp %d water %d desert %d snow %d polar %d stuck %d waste %d)", penalty, badness, impassable, water, desert, snow, polar, stuck, waste)); + -- 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 From 6d6d67e23e3a7d6330c2d79f775b13daaf62d96e Mon Sep 17 00:00:00 2001 From: Bradd Szonye Date: Tue, 14 Nov 2017 23:08:53 -0800 Subject: [PATCH 4/4] Version 0.9.2 --- capslock.modinfo | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/capslock.modinfo b/capslock.modinfo index 092cfcc..3faf218 100644 --- a/capslock.modinfo +++ b/capslock.modinfo @@ -1,5 +1,5 @@ - + Caps Lock Starting plot improvements