How to make a list in python of the 20 plots of a city radius??

Maniac

Apolyton Sage
Joined
Nov 27, 2004
Messages
5,596
Location
Gent, Belgium
What's the easiest way to make a list including only the 20 tiles of the city radius? Currently I use variations of the following, which includes four plots I don't want included:

Code:
pPlot = pCity.plot()
...
iX = pPlot.getX()
iY = pPlot.getY()
...
listcitycircle24 = []
for iiX in range(iX-2, iX+3, 1):
	for iiY in range(iY-2, iY+3, 1):
		pPlot2 = CyMap().plot(iiX,iiY)
		if (pPlot2.blahblahblah and pPlot2.isCity() == False):
			listcitycircle24.append(pPlot2)
 
i use to do like this :

Code:
pPlot = pCity.plot()

#if pPlot.isNone(): do something

areaPlot = pPlot.getArea()

iX = pPlot.getX()
iY = pPlot.getY()

listcitycircle24 = []
playerStartCross = [(-1,-1),(-1,0),(-1,1),(0,-1),(0,1),(1,-1),(1,0),(1,1),(-2,-1),(-2,0),(-2,1),(2,-1),(2,0),(2,1),(-1,2),(0,2),(1,2),(-1,-2),(0,-2),(1,-2)]

for dX,dY in playerStartCross :
        pTempPlot = CyMap().plot(iX+dX,iY+dY)
        if pTempPlot.isNone(): continue
        #if pTempPlot.isImpassable(): continue
        #if pTempPlot.getArea()!=areaPlot: continue
        listcitycircle24.append(pTempPlot)

Tcho !
 
Keep in mind when you loop in that way you could have a plot (or city) which is on the edge of the world, which means it'll grab an invalid plot (there's no such thing as plot [-1, 12], for example).

Jon
 
CyMap().plot() do the wrap itself ( [-1,12] will become [iW-1,12]) . I check "If pTempPlot.isNone()" in case you're at the border of the map with no wrap to not store a None plot .

Tcho !
 
Thanks. :) Also interesting new info regarding the map wraps.

Btw, do you know what's the reason for the last "1" in range(iX-2, iX+3, 1) in my old method? I just copied that method from someone else, without fully understanding it, it strikes me now. :mischief:
 
the 1 have no use , it is used by default in a range .

Tcho !

Edit : this is the increment between two values
 
1 is the step. But 1 is the default so you don't need to specify it.
 
Top Bottom