changing a plot type with python

omegaflames

Warlord
Joined
Sep 21, 2012
Messages
181
I'm doing a bit of modding of the ffh2 mod and I'm having trouble getting a plot change to happen. What I'm trying to do is if a plot has a TERRAIN_PEAK (PLOT_PEAK?) then I want to have a unit be able to change it to TERRAIN_SNOW and TERRAIN_HILL (PLOT_HILLS?). I can get the code to recognize the plot is a peak (or at least I'm 99.9% sure it's recognizing the plot is a peak) but it wont change the peak into the snow/hill. I'm sure some part of this is probably written wrong as I've tweaked this code 10-15 times now trying to get it work. The full code is:
Code:
def reqScorch(caster):
	pPlot = caster.plot()
	pPlayer = gc.getPlayer(caster.getOwner())
	if (pPlot.getTerrainType() == gc.getInfoTypeForString('TERRAIN_PLAINS') or pPlot.getTerrainType() == gc.getInfoTypeForString('TERRAIN_FIELDS_OF_PERDITION')):
		if pPlayer.isHuman() == False:
			if caster.getOwner() == pPlot.getOwner():
				return False
		return True
	if (pPlot.getTerrainType() == gc.getInfoTypeForString('TERRAIN_GRASS') or pPlot.getTerrainType() == gc.getInfoTypeForString('TERRAIN_BROKEN_LANDS')):
		if pPlayer.isHuman() == False:
			if caster.getOwner() == pPlot.getOwner():
				return False
		return True
[COLOR="Red"]	if (pPlot.getPlotType() == 0 and pPlot.getFeatureType() != gc.getInfoTypeForString('FEATURE_VOLCANO')):
		if pPlayer.isHuman() == False:
			if caster.getOwner() == pPlot.getOwner():
				return False
		return True[/COLOR]
	if pPlot.getTerrainType() == gc.getInfoTypeForString('TERRAIN_TUNDRA'):
		if pPlayer.isHuman() == False:
			if caster.getOwner() == pPlot.getOwner():
				return False
		return True
	if pPlot.getTerrainType() == gc.getInfoTypeForString('TERRAIN_MARSH'):
		if pPlayer.isHuman() == False:
			if caster.getOwner() == pPlot.getOwner():
				return False
		return True
	if pPlot.getTerrainType() == gc.getInfoTypeForString('TERRAIN_SNOW'):
		if pPlayer.isHuman() == False:
			if caster.getOwner() != pPlot.getOwner():
				return False
			if pPlayer.getCivilizationType() == gc.getInfoTypeForString('CIVILIZATION_DOVIELLO'):
				return False
			if pPlayer.getCivilizationType() == gc.getInfoTypeForString('CIVILIZATION_ILLIANS'):
				return False
		return True	
	return False

def spellScorch(caster):
	pPlot = caster.plot()
	if pPlot.getTerrainType() == gc.getInfoTypeForString('TERRAIN_PLAINS'):
		pPlot.setTerrainType(gc.getInfoTypeForString('TERRAIN_DESERT'),True,True)
	if pPlot.getTerrainType() == gc.getInfoTypeForString('TERRAIN_GRASS'):
		pPlot.setTerrainType(gc.getInfoTypeForString('TERRAIN_PLAINS'),True,True)
	if pPlot.getTerrainType() == gc.getInfoTypeForString('TERRAIN_BROKEN_LANDS'):
		pPlot.setTerrainType(gc.getInfoTypeForString('TERRAIN_FIELDS_OF_PERDITION'),True,True)
[COLOR="Red"]	if pPlot.getPlotType() == 0:
		pPlot.setTerrainType(gc.getInfoTypeForString('TERRAIN_SNOW'),True,True)
		pPlot.setPlotType(1,True,True)[/COLOR]
	if pPlot.getTerrainType() == gc.getInfoTypeForString('TERRAIN_FIELDS_OF_PERDITION'):
		pPlot.setTerrainType(gc.getInfoTypeForString('TERRAIN_BURNING_SANDS'),True,True)
	if pPlot.getTerrainType() == gc.getInfoTypeForString('TERRAIN_SNOW'):
		pPlot.setTerrainType(gc.getInfoTypeForString('TERRAIN_TUNDRA'),True,True)
	if pPlot.getTerrainType() == gc.getInfoTypeForString('TERRAIN_TUNDRA'):
		pPlot.setTerrainType(gc.getInfoTypeForString('TERRAIN_PLAINS'),True,True)
	if pPlot.getTerrainType() == gc.getInfoTypeForString('TERRAIN_MARSH'):
		pPlot.setTerrainType(gc.getInfoTypeForString('TERRAIN_GRASS'),True,True)
	if pPlot.isOwned():
		cf.startWar(caster.getOwner(), pPlot.getOwner(), WarPlanTypes.WARPLAN_TOTAL)
 
So what are the results...

Looking at the codes, even if it works, it will never turn it to snow.
1) If it is peak, change it to snow
2) If it is snow, change it to tundra
3) If it is tundra, change it to plains

Conclusion is that it will be turned into plains even if it works...
Also, isPeak() is much simpler :D
 
results are that it stays as a peak thou I do think it's at least changing to a snow tile under peak as a snow tile right beside it has it's graphic change like there are 2 snow tiles beside each other after the spell is cast. When my caster is standing on a peak plot the button lights up letting me cast the scorch spell but it won't remove the peak or change the peak into a hill.

If I do get it to work and it starts going from peak to plains then I think using elif instead of if would stop it but being my current problem is getting rid of the peak I'll fix that bridge if it happens.
 
There are two possibly relevant functions on CyPlot, so you could try one or both of:
pPlot.setFlagDirty(True) - should set the flag that tells the game engine the plot has changed
pPlot.updateVisibility() - the modiki says this "refreshes all of the plots"

And Platyping is right - your changes should cascade through and change plots multiple times. Try it on a snow plot, so there is no peak in the way, and it should end up as a plains plot via snow->tundra->plains.

Also, that last check would appear to want to make a player go to war with himself when he changes a plot he owns.
 
my new code is:
Code:
def reqScorch(caster):
	pPlot = caster.plot()
	pPlayer = gc.getPlayer(caster.getOwner())
	if pPlot.getTerrainType() == gc.getInfoTypeForString('TERRAIN_PLAINS'):
		return True
	if pPlot.getTerrainType() == gc.getInfoTypeForString('TERRAIN_FIELDS_OF_PERDITION'):
		return True
	if pPlot.getTerrainType() == gc.getInfoTypeForString('TERRAIN_GRASS'):
		return True
	if pPlot.getTerrainType() == gc.getInfoTypeForString('TERRAIN_BROKEN_LANDS'):
		return True
	if (pPlot.getPlotType() == 0 and pPlot.getFeatureType() != gc.getInfoTypeForString('FEATURE_VOLCANO')):
		return True
	if pPlot.getTerrainType() == gc.getInfoTypeForString('TERRAIN_TUNDRA'):
		return True
	if pPlot.getTerrainType() == gc.getInfoTypeForString('TERRAIN_MARSH'):
		return True
	if pPlot.getTerrainType() == gc.getInfoTypeForString('TERRAIN_SNOW'):
		if pPlayer.getCivilizationType() == gc.getInfoTypeForString('CIVILIZATION_ILLIANS'):
			if pPlayer.isHuman() == False:
				if caster.getOwner() == pPlot.getOwner():
					return False
		return True	
	return False

def spellScorch(caster):
	pPlot = caster.plot()
	if pPlot.getTerrainType() == gc.getInfoTypeForString('TERRAIN_FIELDS_OF_PERDITION'):
		pPlot.setTerrainType(gc.getInfoTypeForString('TERRAIN_BURNING_SANDS'),True,True)
	if pPlot.getTerrainType() == gc.getInfoTypeForString('TERRAIN_BROKEN_LANDS'):
		pPlot.setTerrainType(gc.getInfoTypeForString('TERRAIN_FIELDS_OF_PERDITION'),True,True)
	if pPlot.getTerrainType() == gc.getInfoTypeForString('TERRAIN_PLAINS'):
		pPlot.setTerrainType(gc.getInfoTypeForString('TERRAIN_DESERT'),True,True)
	if pPlot.getTerrainType() == gc.getInfoTypeForString('TERRAIN_GRASS'):
		pPlot.setTerrainType(gc.getInfoTypeForString('TERRAIN_PLAINS'),True,True)
	if pPlot.getTerrainType() == gc.getInfoTypeForString('TERRAIN_MARSH'):
		pPlot.setTerrainType(gc.getInfoTypeForString('TERRAIN_GRASS'),True,True)
	if pPlot.getTerrainType() == gc.getInfoTypeForString('TERRAIN_TUNDRA'):
		pPlot.setTerrainType(gc.getInfoTypeForString('TERRAIN_PLAINS'),True,True)
	if pPlot.getTerrainType() == gc.getInfoTypeForString('TERRAIN_SNOW'):
		pPlot.setTerrainType(gc.getInfoTypeForString('TERRAIN_TUNDRA'),True,True)
	if pPlot.getPlotType() == 0:
		pPlot.setTerrainType(gc.getInfoTypeForString('TERRAIN_SNOW'),True,True)
		pPlot.setPlotType(1,True,True)
	if pPlot.isOwned():
		if caster.getOwner() != pPlot.getOwner():
			cf.startWar(caster.getOwner(), pPlot.getOwner(), WarPlanTypes.WARPLAN_TOTAL)
	pPlot.setFlagDirty(True)
	pPlot.updateVisibilty()
when my caster was standing on a peak the python allowed me to cast it but once again the peak stayed on the map, I even allowed a turn to happen just incase that would make a difference but it didn't.
 
so i finally figured it out. The correct code to change a plot into a hill is
Code:
pPlot.setPlotType(PlotTypes.PLOT_HILLS,True,True)
 
Back
Top Bottom