OrionVeteran
Deity
I have a very elegant Python function which returns a numerical rating for a plot. The "for" commands use Python data iteration tables to evauate and rate the plot. It works perfectly in Python. However, I need to make a call to this function from SDK. I'd prefer to avoid making a Python call from the SDK. Instead, I'd like to convert the Python function to SDK, where it can process very fast. Problem is that I don't know how to convert the Python data iteration over to SDK and need an example of how to do it. Here is the Python function that I need to convert:
Any help would be greatly appreciated.
Code:
[SPOILER]
dTerrainData = {
"TERRAIN_HILL": 3,
"TERRAIN_GRASS": 3,
"TERRAIN_PLAINS": 3,
"TERRAIN_DESERT": 2,
"TERRAIN_TUNDRA": 2,
"TERRAIN_COAST": 4,
"TERRAIN_SNOW": 1,
"TERRAIN_OCEAN": 1
}
dFeatureData = {
"FEATURE_FOREST": 3,
"FEATURE_JUNGLE": 2,
"FEATURE_OASIS": 3,
"FEATURE_FLOOD_PLAINS": 2,
"FEATURE_FALLOUT": 1
}
dImprovementData = {
"IMPROVEMENT_FARM": 4,
"IMPROVEMENT_MINE": 4,
"IMPROVEMENT_ROAD": 2,
"IMPROVEMENT_RAILROAD": 3,
"IMPROVEMENT_GOODY_HUT": 3,
"IMPROVEMENT_FISHING_BOATS": 4,
"IMPROVEMENT_WHALING_BOATS": 3,
"IMPROVEMENT_WELL": 4,
"IMPROVEMENT_OFFSHORE_PLATFORM": 4,
}
def getPlotRating(pPlot):
# Orion's Minewarefare Mod
# Purpose: Rate the plot
# Returns a numerical rating for the plot
iPlotRating = 0
ePlotType = pPlot.getPlotType()
eTerrainType = pPlot.getTerrainType()
eFeatureType = pPlot.getFeatureType()
eImprovementType = pPlot.getImprovementType()
# Terrain
for szTerrainType, iTerrainValue in dTerrainData.iteritems():
iTerrainType = gc.getInfoTypeForString(str(szTerrainType))
if iTerrainType == eTerrainType:
iPlotRating += iTerrainValue
# Features
for szFeatureType, iFeatureValue in dFeatureData.iteritems():
iFeatureType = gc.getInfoTypeForString(str(szFeatureType))
if iFeatureType == eFeatureType:
iPlotRating += iFeatureValue
# Improvements
for szImprovementType, iImprovementValue in dImprovementData.iteritems():
iImprovementType = gc.getInfoTypeForString(str(szImprovementType))
if iImprovementType == eImprovementType:
iPlotRating += iImprovementValue
# Food
for iFoodYield in range(1, 7):
if pPlot.getYield(YieldTypes.YIELD_FOOD) == iFoodYield:
iPlotRating += iFoodYield
break
# Production
for iProductionYield in range(1, 7):
if pPlot.getYield(YieldTypes.YIELD_PRODUCTION) == iProductionYield:
iPlotRating += iProductionYield
break
# COMMERCE
for iCommerceYield in range(1, 7):
if pPlot.getYield(YieldTypes.YIELD_PRODUCTION) == iCommerceYield:
iPlotRating += iCommerceYield
break
if hasBonusOnPlot(pPlot):
iPlotRating += 4
if pPlot.isFreshWater():
iPlotRating += 2
return iPlotRating
[/SPOILER]
Any help would be greatly appreciated.