I finally found out how to control tribal villages amount and position. Here is the code below that has to be added to /publicMaps/continents.py, for example. You notice I have to check if the terrain is valid by myself, if anyone know how to use the canPlaceGoodyAt() function it would be great. The code is basic and need further improvement to get a good result, but it shows everything needed to get it working.
Code:
def addGoodies():
gc = CyGlobalContext()
map = CyMap()
dice = gc.getGame().getMapRand()
iW = map.getGridWidth()
iH = map.getGridHeight()
idGoodie=gc.getInfoTypeForString("IMPROVEMENT_GOODY_HUT")
idOcean=gc.getInfoTypeForString("TERRAIN_OCEAN")
idCoast=gc.getInfoTypeForString("TERRAIN_COAST")
iNumPlots=iW*iH
iNumGoodies=iNumPlots/100
for x in range(iNumGoodies):
validPos=0
while validPos==0:
posX=dice.get(iW, "Continents.py - addGoodies")
posY=dice.get(iH, "Continents.py - addGoodies")
plotTerrainType=map.plot(posX,posY).getTerrainType()
if not map.plot(posX,posY).isPeak() and plotTerrainType!=idOcean and plotTerrainType!=idCoast:
map.plot(posX,posY).setImprovementType(idGoodie)
validPos=1
return None