View Full Version : [PYTHON] Ocean/Sea/Coast


Molybdeus
Jul 19, 2007, 12:50 PM
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.)

Sto
Jul 19, 2007, 01:23 PM
Most of scripts use CvMapGeneratorUtil.TerrainGenerator :

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 !

Sto
Jul 19, 2007, 01:46 PM
here the 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 !

Sto
Jul 19, 2007, 02:06 PM
i've forgotten a test because i've tested the code with terrain coast .insert this test in order to not replace coast tiles :


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



TCho !

Molybdeus
Jul 19, 2007, 02:35 PM
You, dear Sir (ma'am?) are a genius. Merci.

Sto
Jul 19, 2007, 06:03 PM
no ma'am -> loved and married . :lol: Just fan of this cartoon

Tcho !