View Full Version : How to make a list in python of the 20 plots of a city radius??


Maniac
Sep 01, 2007, 08:53 PM
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:

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)

Sto
Sep 02, 2007, 04:07 AM
i use to do like this :

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 !

Jon Shafer
Sep 02, 2007, 08:44 AM
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

Sto
Sep 02, 2007, 09:52 AM
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 !

Maniac
Sep 02, 2007, 02:44 PM
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:

Sto
Sep 02, 2007, 02:47 PM
the 1 have no use , it is used by default in a range .

Tcho !

Edit : this is the increment between two values

snarko
Sep 02, 2007, 02:48 PM
1 is the step. But 1 is the default so you don't need to specify it.

Maniac
Sep 02, 2007, 02:50 PM
Thanks again!