Questions: Removing Ice

Barathor

Emperor
Joined
May 7, 2011
Messages
1,202
This is from my post on the 2K forums:
http://forums.2kgames.com/showthread.php?114581-Question-Removing-Ice
-----------------------------------------------------------------------------------

Code:
[COLOR="blue"]function[/COLOR] FeatureGenerator:[b]AddIceAtPlot[/b](plot, iX, iY, lat)
	[COLOR="blue"]if[/COLOR](plot:CanHaveFeature(self.featureIce) [COLOR="green"]and plot:IsAdjacentToLand() == false[/COLOR]) [COLOR="blue"]then[/COLOR]
		[COLOR="blue"]if[/COLOR] Map.IsWrapX() [COLOR="blue"]and[/COLOR] (iY == 0 [COLOR="blue"]or[/COLOR] iY == self.iGridH - 1) [COLOR="blue"]then[/COLOR]
			plot:SetFeatureType(self.featureIce, -1)

		[COLOR="blue"]else[/COLOR]
			local rand = Map.Rand(100, "Add Ice Lua")/100.0;

			[COLOR="blue"]if[/COLOR](rand < 8 * (lat - [COLOR="red"][B]0.875[/B][/COLOR])) [COLOR="blue"]then[/COLOR]  
				plot:SetFeatureType(self.featureIce, -1);
			[COLOR="blue"]elseif[/COLOR](rand < 4 * (lat - [COLOR="red"][B]0.75[/B][/COLOR]))[COLOR="blue"] then[/COLOR]
				plot:SetFeatureType(self.featureIce, -1);  
			[COLOR="blue"]end
		end
	end
end
[/COLOR]

So, I added the code shown in green as the original example showed it and it works well. Most of it looks great! The only problem now is that bits of land sometimes form near the very top/bottom edge or land masses are close to those edges. When that happens you get a "hole" in the ice and there's now water tiles at the very edge of the map. Also, one could settle in these odd areas near the edge of the map (mostly concerned with the AI doing that or city-states spawning there) and you'd have half your cultural borders shrouded under the clouds. It would just be awkward.

Is there any way to prevent land plots from forming so close to the top/bottom edges? This didn't seem to occur with the default maps. Which LUA file would I have to edit to prevent land plots from forming? For example, coding it so that anything above a latitude of 0.90 is prevented. AssignStartingPlots.lua or MapGenerator.lua?

Also, I still could use some help in how this function exactly "functions". :D

This is what I think happens (with my very limited knowledge of programming) without counting the new code I added:
-----------------------------------------------------------------------------------
1. The first "if" checks whether or not the Y coordinate equals 0 (southern edge) or the map height (norther edge) and if it does it sets it to ice.

2. If it doesn't, it then generates a random number (not sure what (100, "add ice lua")/100.0 equals, but I'm guessing it'll at least be a positive number). It then goes thru the next "if" statements using the plot's lat (0.0 equator to 1.0 polar) and subtracts the given numbers from it.

So basically, if a lat is lower than 0.875 and 0.75 (closer to the equator) it'll generate a negative number which will always make the "if" statements false since a positive number will never be less than it. I think the reason there's two checks is to make the ice edges more random instead of a straighter edge.

Also, another observation of mine is that with the first "if" statement, if the lat=1 then 1.0 - 0.875 equals 0.125... then 8 x 0.125 = 1. The second one, if the lat=1 then 1.0 - 0.75 equals 0.25... then 4 x 0.25 = 1. So, in these cases, both statements would check if rand < 1. So now the 8 and 4 kinda make sense to me. I just wish I knew what (100, "add Ice Lua")/100.0 equals. Is it a positive number that's always less than or equal to 1?
-----------------------------------------------------------------------------------

I don't know... am I close? :p Anyway, given that explanation of the function, THEN...

Would it be better to add "and plot:IsAdjacentToLand() == false" to both of the latter "if" statements instead? That way, the default top and bottom edge of ice will always generate and will be unaffected by land tiles and you won't have a hole punched thru the ice.

Code:
[COLOR="blue"]function[/COLOR] FeatureGenerator:[b]AddIceAtPlot[/b](plot, iX, iY, lat)
	[COLOR="blue"]if[/COLOR](plot:CanHaveFeature(self.featureIce)) [COLOR="blue"]then[/COLOR]
		[COLOR="blue"]if[/COLOR] Map.IsWrapX() [COLOR="blue"]and[/COLOR] (iY == 0 [COLOR="blue"]or[/COLOR] iY == self.iGridH - 1) [COLOR="blue"]then[/COLOR]
			plot:SetFeatureType(self.featureIce, -1)

		[COLOR="blue"]else[/COLOR]
			local rand = Map.Rand(100, "Add Ice Lua")/100.0;

			[COLOR="blue"]if[/COLOR](rand < 8 * (lat - [COLOR="maroon"][B]0.875[/B][/COLOR]) [COLOR="green"]and plot:IsAdjacentToLand() == false[/COLOR]) [COLOR="blue"]then[/COLOR]  
				plot:SetFeatureType(self.featureIce, -1);
			[COLOR="blue"]elseif[/COLOR](rand < 4 * (lat - [COLOR="red"][B]0.75[/B][/COLOR]) [COLOR="green"]and plot:IsAdjacentToLand() == false[/COLOR])[COLOR="blue"] then[/COLOR]
				plot:SetFeatureType(self.featureIce, -1);  
			[COLOR="blue"]end
		end
	end
end
[/COLOR]

Or should I just add the line of code to only one of the "if" statements so that there's almost 2 layers of ice always genereated near the top/bottom edges? I'm not sure which one generates more ice; I'm guessing it's maybe the second one since a lower lat number can generate a positive number more often, plus it's only multiplied by 4 instead of 8... again, I don't know.
 
Back
Top Bottom