Skip to content

Commit

Permalink
Fix infinite loop in map script (#10419)
Browse files Browse the repository at this point in the history
  • Loading branch information
axatin authored Nov 2, 2023
1 parent 74cb1b9 commit 247900f
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions (2) Vox Populi/Core Files/Overrides/AssignStartingPlots.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11165,48 +11165,60 @@ function AssignStartingPlots:PlaceStrategicAndBonusResources()

-- Check for low or missing Strategic resources
uran_amt, horse_amt, oil_amt, iron_amt, coal_amt, alum_amt = self:GetSmallStrategicResourceQuantityValues();
while self.amounts_of_resources_placed[self.iron_ID + 1] < 4 * self.iNumCivs do
iLoop = 0;
while self.amounts_of_resources_placed[self.iron_ID + 1] < 4 * self.iNumCivs and iLoop < 999 do
print("Map has very low iron, adding another.");
local resources_to_place = { {self.iron_ID, iron_amt, 20, 1, 2} };
self:ProcessResourceList(99999, ImpactLayers.LAYER_IRON, self.desert_flat_no_feature, resources_to_place); -- 99999 means one per that many tiles: a single instance.
self:ProcessResourceList(99999, ImpactLayers.LAYER_IRON, self.hills_forest_list, resources_to_place);
self:ProcessResourceList(99999, ImpactLayers.LAYER_IRON, self.hills_open_list, resources_to_place);
self:ProcessResourceList(99999, ImpactLayers.LAYER_IRON, self.forest_flat_that_are_not_tundra, resources_to_place);
self:ProcessResourceList(99999, ImpactLayers.LAYER_IRON, self.tundra_flat_forest, resources_to_place);
iLoop = iLoop + 1;
end
while self.amounts_of_resources_placed[self.horse_ID + 1] < 4 * self.iNumCivs do
iLoop = 0;
while self.amounts_of_resources_placed[self.horse_ID + 1] < 4 * self.iNumCivs and iLoop < 999 do
print("Map has very low horse, adding another.");
local resources_to_place = { {self.horse_ID, horse_amt, 25, 1, 2} };
self:ProcessResourceList(99999, ImpactLayers.LAYER_HORSE, self.grass_flat_no_feature, resources_to_place);
self:ProcessResourceList(99999, ImpactLayers.LAYER_HORSE, self.plains_flat_no_feature, resources_to_place);
self:ProcessResourceList(99999, ImpactLayers.LAYER_HORSE, self.desert_wheat_list, resources_to_place);
self:ProcessResourceList(99999, ImpactLayers.LAYER_HORSE, self.tundra_flat_no_feature, resources_to_place);
iLoop = iLoop + 1;
end
while self.amounts_of_resources_placed[self.coal_ID + 1] < 4 * self.iNumCivs do
iLoop = 0;
while self.amounts_of_resources_placed[self.coal_ID + 1] < 4 * self.iNumCivs and iLoop < 999 do
print("Map has very low coal, adding another.");
local resources_to_place = { {self.coal_ID, coal_amt, 33, 1, 2} };
self:ProcessResourceList(99999, ImpactLayers.LAYER_COAL, self.hills_open_no_tundra_no_desert, resources_to_place);
self:ProcessResourceList(99999, ImpactLayers.LAYER_COAL, self.grass_flat_no_feature, resources_to_place);
self:ProcessResourceList(99999, ImpactLayers.LAYER_COAL, self.plains_flat_no_feature, resources_to_place);
iLoop = iLoop + 1;
end
while self.amounts_of_resources_placed[self.oil_ID + 1] < 4 * self.iNumCivs do
iLoop = 0;
while self.amounts_of_resources_placed[self.oil_ID + 1] < 4 * self.iNumCivs and iLoop < 999 do
print("Map has very low oil, adding another.");
local resources_to_place = { {self.oil_ID, oil_amt, 33, 1, 2} };
self:ProcessResourceList(99999, ImpactLayers.LAYER_OIL, self.desert_flat_no_feature, resources_to_place);
self:ProcessResourceList(99999, ImpactLayers.LAYER_OIL, self.tundra_flat_no_feature, resources_to_place);
self:ProcessResourceList(99999, ImpactLayers.LAYER_OIL, self.jungle_flat_list, resources_to_place);
iLoop = iLoop + 1;
end
while self.amounts_of_resources_placed[self.aluminum_ID + 1] < 5 * self.iNumCivs do
iLoop = 0;
while self.amounts_of_resources_placed[self.aluminum_ID + 1] < 5 * self.iNumCivs and iLoop < 999 do
print("Map has very low aluminum, adding another.");
local resources_to_place = { {self.aluminum_ID, alum_amt, 33, 1, 2} };
self:ProcessResourceList(99999, ImpactLayers.LAYER_ALUMINUM, self.hills_open_no_grass, resources_to_place);
self:ProcessResourceList(99999, ImpactLayers.LAYER_ALUMINUM, self.flat_open_no_grass_no_plains, resources_to_place);
self:ProcessResourceList(99999, ImpactLayers.LAYER_ALUMINUM, self.plains_flat_no_feature, resources_to_place);
iLoop = iLoop + 1;
end
while self.amounts_of_resources_placed[self.uranium_ID + 1] < 2 * self.iNumCivs do
iLoop = 0;
while self.amounts_of_resources_placed[self.uranium_ID + 1] < 2 * self.iNumCivs and iLoop < 999 do
print("Map has very low uranium, adding another.");
local resources_to_place = { {self.uranium_ID, uran_amt, 100, 2, 4} };
self:ProcessResourceList(99999, ImpactLayers.LAYER_URANIUM, self.land_hills_list, resources_to_place);
iLoop = iLoop + 1;
end

self:PlaceBonusResources();
Expand Down

0 comments on commit 247900f

Please sign in to comment.