[PYTHON] Ocean/Sea/Coast

Molybdeus

Prince
Joined
Jul 30, 2006
Messages
528
I am trying to implement a third water terrain type -"sea"- that I want to place in between coast and ocean. Because I don't know what map script the user will employ, I want to have the game replace all ocean tiles adjacent to coast tiles with sea tiles when the game loads.

How do I go through each ocean tile and check to see if it is adjacent to a coast tile?

How do I change an ocean tile into a sea tile? (I've added the terrain type in the relevant XML file, I just need to know how change it in python.)
 
Most of scripts use CvMapGeneratorUtil.TerrainGenerator :

Code:
	def generateTerrainAtPlot(self,iX,iY):
		lat = self.getLatitudeAtPlot(iX,iY)

		if (self.map.plot(iX, iY).isWater()):
			return self.map.plot(iX, iY).getTerrainType()

However , there is 2 problems ( and may be 3 ) :

_ the terrain type for water is directly took in the SDK . there is also some normalize stuff at the end of the script that can cause problems .

_ all the map scripts doesn't use this function . ( all the scenario by the way are not changed )

_ it seems that there is an action with SeeFromLevel and getSeeThroughLevel for the choice of the terrain for water , not sure this is an easy way to try to change that in the SDK . Lot of functions are involved .

The best way is to change the terrain type at the beginning of the game i think .

Edit : sorry , i misunderstood , wait 5min to get the code



Tcho !
 
here the code :

Code:
                map = CyMap()

                for iX in range(map.getGridWidth()):
                        for iY in range(map.getGridHeight()):

                                pLoopPlot = map.plot(iX,iY)
                                if not pLoopPlot.isWater() : continue

                                bNearCoastal = False
                                for (dX,dY) in [(-1,-1),(-1,0),(-1,1),(0,-1),(0,1),(1,-1),(1,0),(1,1)]:
                                        if map.plot(iX+dX,iY+dY).getTerrainType() == gc.getInfoTypeForString('TERRAIN_COAST'):
                                                bNearCoastal = True
                                                break

                                if bNearCoastal : pLoopPlot.setTerrainType( gc.getInfoTypeForString('TERRAIN_SEA'), True, True )

Tcho !
 
i've forgotten a test because i've tested the code with terrain coast .insert this test in order to not replace coast tiles :


Code:
                                if not pLoopPlot.isWater() : continue
                                if pLoopPlot.getTerrainType() == gc.getInfoTypeForString('TERRAIN_COAST'): continue

TCho !
 
no ma'am -> loved and married . :lol: Just fan of this cartoon

Tcho !
 
Back
Top Bottom