[B]baseVitalizeUpgrades = None
civSpecificVitalize = None[/B]
def initVitalizeCache():
'''
Initialize the vitalize cache.
Need to ensure that this function isn't called until the xml is loaded.
'''
global baseVitalizeUpgrades
global civSpecificVitalize
baseVitalizeUpgrades = dict( ( gc.getInfoTypeForString( start_terrain ), gc.getInfoTypeForString( end_terrain ) )
for start_terrain, end_terrain in [
('TERRAIN_SNOW', 'TERRAIN_TUNDRA'),
('TERRAIN_TUNDRA', 'TERRAIN_PLAINS'),
('TERRAIN_DESERT', 'TERRAIN_PLAINS'),
('TERRAIN_PLAINS', 'TERRAIN_GRASS'),
('TERRAIN_MARSH', 'TERRAIN_GRASS'),
('TERRAIN_OCEAN', 'TERRAIN_COAST'),
] )
civSpecificVitalize = dict()
civSpecificVitalize[gc.getInfoTypeForString('CIVILIZATION_ILLIANS')] = dict( ( gc.getInfoTypeForString( start_terrain ), gc.getInfoTypeForString( end_terrain ) )
for start_terrain, end_terrain in [
('TERRAIN_TUNDRA', 'TERRAIN_SNOW'),
('TERRAIN_DESERT', 'TERRAIN_SNOW'),
('TERRAIN_PLAINS', 'TERRAIN_SNOW'),
('TERRAIN_GRASS', 'TERRAIN_SNOW'),
('TERRAIN_MARSH', 'TERRAIN_SNOW'),
('TERRAIN_BURNING_SANDS', 'TERRAIN_SNOW'),
('TERRAIN_BROKEN_LANDS', 'TERRAIN_SNOW'),
('TERRAIN_FIELDS_OF_PERDITION', 'TERRAIN_SNOW'),
('TERRAIN_OCEAN', 'TERRAIN_COAST'),
] )
civSpecificVitalize[gc.getInfoTypeForString('CIVILIZATION_MAZATL')] = dict( baseVitalizeUpgrades )
civSpecificVitalize[gc.getInfoTypeForString('CIVILIZATION_MAZATL')].update( dict( ( gc.getInfoTypeForString( start_terrain ), gc.getInfoTypeForString( end_terrain ) )
for start_terrain, end_terrain in [
('TERRAIN_GRASS', 'TERRAIN_MARSH'),
('TERRAIN_MARSH', 'TERRAIN_MARSH'),
] ) )
civSpecificVitalize[gc.getInfoTypeForString('CIVILIZATION_CUALLI')] = dict (civSpecificVitalize[gc.getInfoTypeForString('CIVILIZATION_MAZATL')])
civSpecificVitalize[gc.getInfoTypeForString('CIVILIZATION_MALAKIM')] = dict( baseVitalizeUpgrades )
civSpecificVitalize[gc.getInfoTypeForString('CIVILIZATION_MALAKIM')].update( dict( ( gc.getInfoTypeForString( start_terrain ), gc.getInfoTypeForString( end_terrain ) )
for start_terrain, end_terrain in [
('TERRAIN_DESERT', 'TERRAIN_DESERT'),
] ) )
[I] # Delete upgrades to the same terrain, id est marsh to marsh
for key in baseVitalizeUpgrades.keys():
if key == baseVitalizeUpgrades[key]:
del baseVitalizeUpgrades[key]
for civUpgrades in civSpecificVitalize.values():
for key in civUpgrades.keys():
if key == civUpgrades[key]:
del civUpgrades[key][/I]
@spell
def reqVitalize(caster):
pPlot = caster.plot()
if pPlot.getOwner() != caster.getOwner():
return False
if pPlot.isWater():
return False
pPlayer = gc.getPlayer( caster.getOwner() )
[B] if baseVitalizeUpgrades is None:
initVitalizeCache()[/B]
vitalizeUpgrades = civSpecificVitalize.get( pPlayer.getCivilizationType(), baseVitalizeUpgrades )
if not pPlot.getTerrainType() in vitalizeUpgrades:
return False
return True
@spell
def spellVitalize(caster):
map = CvPythonExtensions.CyMap()
[B] if baseVitalizeUpgrades is None:
initVitalizeCache()[/B]
grass = gc.getInfoTypeForString( 'TERRAIN_GRASS' )
plains = gc.getInfoTypeForString( 'TERRAIN_PLAINS' )
desert = gc.getInfoTypeForString( 'TERRAIN_DESERT' )
floodPlains = gc.getInfoTypeForString('FEATURE_FLOOD_PLAINS')
pPlayer = gc.getPlayer( caster.getOwner() )
vitalizeUpgrades = civSpecificVitalize.get( pPlayer.getCivilizationType(), baseVitalizeUpgrades )
for x,y in plotsInRange( caster.getX(), caster.getY(), getSpellRange( caster )+1 ):
pPlot = map.plot(x,y)
if not pPlot.isNone() and pPlot.getOwner() == caster.getOwner():
terrain = pPlot.getTerrainType()
if terrain in vitalizeUpgrades:
pPlot.setTerrainType( vitalizeUpgrades[terrain], True, True )
# From here on terrain refers to what pPlot was before the upgrade
if terrain == desert and pPlot.getFeatureType() == floodPlains and terrain != pPlot.getTerrainType():
pPlot.setFeatureType(-1, -1)
if pPlot.getTerrainType() == grass and pPlot.isHills() and pPlot.isCity():
pPlot.setTerrainType( plains, True, True )