Hot to get latitude for an individual plot?

draco963

Prince
Joined
Jan 26, 2007
Messages
451
Location
Earth
I'm working through a terraforming mod that I found, and am trying to find a way to have the game assign the correct Forest graphic depending on the latitude of the plot being modified.

Here's the exisitng code from CvEventManager that takes care of replacing the improvement that just got "built" with the Forest feature:
Code:
		if(iImprovement==gc.getInfoTypeForString('IMPROVEMENT_FOREST')):
			pPlot = CyMap().plot(iX, iY)
			CyInterface().addMessage(CyGame().getActivePlayer(),True,25,'A tree nursery has matured into a Forest!','AS2D_DISCOVERBONUS',1,'Art/Interface/Buttons/TerrainFeatures/Forest.dds',ColorTypes(8),iX,iY,True,True)
			pPlot.setFeatureType(gc.getInfoTypeForString('FEATURE_FOREST'), 0)
			pPlot.setImprovementType(-1)

Unfortunately, as written, the above code can't accommodate for the fact that game uses different graphics at different latitudes. So, how could I get the latitude of the plot being modified? The logic to apply the different graphics I've already got worked out, but I need a way to quantify what the actual latitude is...

Thanks in advance!
 
Didn't know about the API, thanks. Looking at it though, there aren't any examples of usage. So, would this work?

Code:
		if(iImprovement==gc.getInfoTypeForString('IMPROVEMENT_FOREST')):
			pPlot = CyMap().plot(iX, iY)
			CyInterface().addMessage(CyGame().getActivePlayer(),True,25,'A tree nursery has matured into a Forest!','AS2D_DISCOVERBONUS',1,'Art/Interface/Buttons/TerrainFeatures/Forest.dds',ColorTypes(8),iX,iY,True,True)
			if abs(pPlot.getLatitude(iX, iY) < 28
				pPlot.setFeatureType(gc.getInfoTypeForString('FEATURE_FOREST'), 0)
			elseif abs(pPlot.getLatitude(iX, iY) < 55
				pPlot.setFeatureType(gc.getInfoTypeForString('FEATURE_FOREST'), 1)
			else
				pPlot.setFeatureType(gc.getInfoTypeForString('FEATURE_FOREST'), 2)
			pPlot.setImprovementType(-1)

Just to be clear, the intention of the above is to get the latitude of the plot being changed, and then, if the latitude is less than 28°, assign the deciduous forest graphic. If the latitude is between 28° and 54.99°, use the coniferous forest graphic. And of course, at 55° and up, use the snowy forest graphic. I've used abs so that I don't have to set up two separate arguments for the north and south hemispheres.

Thanks!
 
Yup, that's correct. You are missing colons (:) at the end of your if and else lines, but the rest looks fine.
 
I don't think getLatitude() has any arguments. The plot object already knows what plot it is, and what its own X and Y coordinates are, so you shouldn't need to specify them.
 
So, it should be this?
Code:
		if(iImprovement==gc.getInfoTypeForString('IMPROVEMENT_FOREST')):
			pPlot = CyMap().plot(iX, iY)
			CyInterface().addMessage(CyGame().getActivePlayer(),True,25,'A tree nursery has matured into a Forest!','AS2D_DISCOVERBONUS',1,'Art/Interface/Buttons/TerrainFeatures/Forest.dds',ColorTypes(8),iX,iY,True,True)
			if abs(pPlot.getLatitude) < 28:
				pPlot.setFeatureType(gc.getInfoTypeForString('FEATURE_FOREST'), 0)
			elseif abs(pPlot.getLatitude) < 55:
				pPlot.setFeatureType(gc.getInfoTypeForString('FEATURE_FOREST'), 1)
			else:
				pPlot.setFeatureType(gc.getInfoTypeForString('FEATURE_FOREST'), 2)
			pPlot.setImprovementType(-1)
 
While getlatitude has no arguments, you still need to have the "()" after it so that Python knows it is a function instead of just a variable (which doesn't exist).

Example:
Code:
if abs(pPlot.getLatitude()) < 28:
 
Even when you aren't passing any arguments to a function call you must still use parentheses:

Code:
if abs(pPlot.getLatitude[B][COLOR="Red"]()[/COLOR][/B]) < 28:
 
Well, it did anyways once I realized that "elseif" in Python is spelt elif!

You know you've been spending too much time writing PHP code when elseif starts looking okay. :cry:
 
Yeah, three days of doc-writing while trying to rest and get over a nasty cold. Probably not the best choice of "rest" activity.
 
I tried to use getLatitude() and discovered that it only returns positive numbers from 0 (equator) to 90 (both poles). Is there any way to identify whether I'm in the Northern or Southern hemisphere?
 
You could probably do it a dirty way where you find where latitude is 0 and see whether its above or below that to see north or south
 
I tried to use getLatitude() and discovered that it only returns positive numbers from 0 (equator) to 90 (both poles). Is there any way to identify whether I'm in the Northern or Southern hemisphere?

I ended up using CyMap.getGridHeight() and then checking to see if the Y value for the current plot is less than half the GridHeight. If so, it's in the south, otherwise its north of the equator.
 
Back
Top Bottom