How to use the "can build" function

liwy

Chieftain
Joined
Nov 15, 2009
Messages
63
Location
Brussels
I wanted to make a civic specific improvement. A pasture that doesn't require ressources for semi-nomadic developpement.

It worked, except that it overwrote the xml, as a consequence I could put it anywhere, even on desert or cities and on itself (I fear that the AI might build it on itself infinitely)... not really the goal. I tried to put limit it's use: to limit it to the plains and grass tiles.

Code:
	def canBuild(self,argsList):
		iX, iY, iBuild, iPlayer = argsList
		eCivic = argsList[1]
		pPlayer = gc.getPlayer(iPlayer)
		pPlot = CyMap().plot(iX, iY)
		iterrain=pPlot.getTerrainType()
		iPasture_nomad = CvUtil.findInfoTypeNum(gc.getBuildInfo,gc.getNumBuildInfos(),'BUILD_PASTURE_NOMAD')
		
		if iBuild == gc.getInfoTypeForString('BUILD_PASTURE_NOMAD'):
			if (pPlot.isCity or pPlot.getImprovementType()==gc.getInfoTypeForString('IMPROVEMENT_PASTURE_NOMAD')):
				return False
			elif (iterrain==gc.getInfoTypeForString('TERRAIN_DESERT') or iterrain==gc.getInfoTypeForString('TERRAIN_TOUNDRA') or iterrain==gc.getInfoTypeForString('TERRAIN_ICE')):
				return False
			elif pPlayer.getCivics(gc.getInfoTypeForString('CIVICOPTION_LABOR')) == gc.getInfoTypeForString('CIVIC_PASTORALISME'):
				return	True
		return -1	# Returning -1 means ignore; 0 means Build cannot be performed; 1 or greater means it can
 
You need to set the can build entry in the PythonCallbackDefines.XML file to 1
Code:
  <Define>
    <DefineName>USE_CAN_BUILD_CALLBACK</DefineName>
    <iDefineIntVal>[B]1[/B]</iDefineIntVal>
  </Define>

You can limit the terrains in the improvement XML by using the TerrainMakesValids tag on the improvement but you need to list all valid terrains
Code:
			<TerrainMakesValids>
				<TerrainMakesValid>
					<TerrainType>TERRAIN_GRASS</TerrainType>
					<bMakesValid>1</bMakesValid>
				</TerrainMakesValid>
			</TerrainMakesValids>
 
Back
Top Bottom