Python question

RogerBacon

King
Joined
Nov 16, 2003
Messages
649
The following code gives an error "AttributeError: 'CyMap' object has no attribute 'getPlot'" on the line: pPlot = gc.getMap().getPlot(iX, iY) .
Now, I KNOW that CyMap objects DO have attribute of getPlotso I don't know why this isn't working. Any ideas?

Roger Bacon

Code:
		for i in range(3):
			for ii in range(3):
				iX = i-1 + plotX
				iY = ii-1 + plotY
				if (gc.getMap().isPlot(iX, iY)): # Make sure this plot is on the map.
					pPlot = gc.getMap().getPlot(iX, iY) 
					plotCulture = pPlot.getCulture(gc.getGame().getActivePlayer())
					pPlot.setCulture(gc.getGame().getActivePlayer(), plotCulture+amount)
					#pPlot.setCulture(gc.getGame().getActivePlayer(), plotCulture+amount)
 
Here is the code I use:

Code:
def spellEarthquake(caster):
	doCast(caster)
	iX = caster.getX()
	iY = caster.getY()
	pPlayer = gc.getPlayer(caster.getOwner())
	eTeam = pPlayer.getTeam()
	for iiX in range(iX-1, iX+2, 1):
		for iiY in range(iY-1, iY+2, 1):
			pPlot = CyMap().plot(iiX,iiY)
			if (pPlot.isCity() or pPlot.getImprovementType() != -1):
				startWar(pPlot.getOwner(), caster.getOwner())
			if pPlot.isCity():
				pCity = pPlot.getPlotCity()
				for i in range(gc.getNumBuildingInfos()):
					iRnd = CyGame().getSorenRandNum(100, "Bob")
					if (gc.getBuildingInfo(i).getConquestProbability() != 100 and iRnd <= 25):
							pCity.setHasRealBuilding(i, False)
			iRnd = CyGame().getSorenRandNum(100, "Bob")
			if iRnd <= 25:
				pPlot.setImprovementType(-1)

Note I use CyMap() instead of gc.getMap()
 
Kael, you never check for map wrapping? what happens if you get a negative value for y?
 
getPlot() is a myth - no actual function with that name.

I use CyMap().plot(x,y) all the time. Pretty certain it works.

EDIT: I seem to remember somebody saying that it did y wrapping automatically if it was out of bounds. Could be wrong though.
 
TheLopez said:
Kael, you never check for map wrapping? what happens if you get a negative value for y?

I don't know. I ran Meshabber (he uses a similiar function every turn) at the edge of the map and the game didn't seem to have any problem with it.
 
The Great Apple said:
getPlot() is a myth - no actual function with that name.

I use CyMap().plot(x,y) all the time. Pretty certain it works.

EDIT: I seem to remember somebody saying that it did y wrapping automatically if it was out of bounds. Could be wrong though.

Well, I changed it to:
Code:
		for i in range(3):
			for ii in range(3):
				iX = i-1 + plotX
				iY = ii-1 + plotY
				if (gc.getMap().isPlot(iX, iY)): # Make sure this plot is on the map.
					pPlot = CyMap().Plot(iX, iY) 
					plotCulture = pPlot.getCulture(gc.getGame().getActivePlayer())

and it still doesn't work.
AttributeError: 'CyMap' object has no attribute 'Plot'

Am I not including a necessary file? Here are my includes:
import CvUtil
from CvPythonExtensions import *
from PyHelpers import *
 
Nevermind, 12monkeys nailed it.
 
RogerBacon said:
Well, I changed it to:
Code:
		for i in range(3):
			for ii in range(3):
				iX = i-1 + plotX
				iY = ii-1 + plotY
				if (gc.getMap().isPlot(iX, iY)): # Make sure this plot is on the map.
					pPlot = CyMap().Plot(iX, iY) 
					plotCulture = pPlot.getCulture(gc.getGame().getActivePlayer())

and it still doesn't work.
AttributeError: 'CyMap' object has no attribute 'Plot'

Am I not including a necessary file? Here are my includes:
import CvUtil
from CvPythonExtensions import *
from PyHelpers import *


the problem is the uppercase "P". Try "CyMap().plot()" instead of "CyMap().Plot()".
Python is case sensitive!!!!
 
12monkeys said:
the problem is the uppercase "P". Try "CyMap().plot()" instead of "CyMap().Plot()".
Python is case sensitive!!!!

Ok, that seems to have done it. Thanks. It's amazing how often you can look at something and yet not notice it.

The next line gave me an error right after I changed that one:
pPlot.setCulture(gc.getGame().getActivePlayer(), plotCulture+amount)

TypeError: this constructor takes no arguments

On a hunch I added a zero as a third parameter and not it works. All of the on-line APIs I know of have this parameter as taking only two parameters but if you don't give it a third it doesn't work.

CyPlot's funciton:
VOID changeCulture(PlayerType eIndex, INT iChange)
void (int /*PlayerTypes*/ eIndex, int iChange)

There is another member function of CyCity:
VOID changeCulture(PlayerType eIndex, INT iChange, BOOL bPlots)

It seems to be using this one. Anyway, it works now if I use the three parameter one.

Thanks all,
Roger Bacon
 
The Great Apple said:
EDIT: I seem to remember somebody saying that it did y wrapping automatically if it was out of bounds. Could be wrong though.

You are. A negative value as argument for plot() (or a positive one that is too greater than the map size) will return an invalid plot object, which basically doesn't do or contan anything. In Kael's code, the isCity() checks on it will fail and setImprovementType() will not do anything at all. If you check the coordinates of an invalid tile, you'll always get (-1, -1).

For Kael's code, that isn't a real problem, but it does mean that if an earthquake takes place near the map edge, it won't have affect all tiles it's supposed to affect (unless the map has no wrap in either direction of course).
 
RogerBacon said:
All of the on-line APIs I know of have this parameter as taking only two parameters but if you don't give it a third it doesn't work.

All online APIs are out of date, or at least all the ones I know. When the new patch is released my API (at civilization4.net) will be updated immediately (it's already done, just waiting for the patch to go public...)

FWIW you're indeed right about CyPlot().changeCulture, in the new patch at least it has a third BOOL bUpdate argument. Apparently that's in v1.52 as well then.
 
Locutus said:
FWIW you're indeed right about CyPlot().changeCulture, in the new patch at least it has a third BOOL bUpdate argument. Apparently that's in v1.52 as well then.

Can you tell us what the third argument is for? I'm kind of leery of just throwing a zero in there without knowing what it does.

Roger Bacon
 
RogerBacon said:
Can you tell us what the third argument is for? I'm kind of leery of just throwing a zero in there without knowing what it does.

Roger Bacon
bUpdate... hmmm. Maybe if it's true it will recalcualte who owns the plot or something?
 
Back
Top Bottom