View Full Version : [BTS] CannotFoundCity


Davinci Fan
Jul 25, 2007, 08:36 PM
I'm working on some python code for cannotFoundCity in GameUtils, and I have some questions,

How do I check whether a player has a certain technology (I have the player ID)?

How do I iterate through the spaces 1 unit removed from the plot (like a small cross)?

Thanks,

Davinci Fan
Jul 26, 2007, 02:54 PM
Here's what I have so far. I haven't tested it, I just want peoples' thoughts. What the script is supposed to do:
If the plot is owned by [player], allow
If the plot is next to a plot owned by [player] and [player] has [tech] allow
If the unit attempting to found is [unit] allow - I can't figure this one out
Disallow


def cannotFoundCity(self,argsList):
iPlayer, iPlotX, iPlotY = argsList
iTech = gc.getInfoForString("TECH_LITERATURE")

if (map.Plot(iPlotX, iPlotY).getOwner() = iPlayer)
return False

if (GET_TEAM(getTeam()).isHasTech(iTech)) //is this correct?
{
for x in range(-1, 2):
for y in range(-1, 2):
if ((x == -1 or x == 1) and (y == -1 or y == 1)):
continue
pPlot = map.plot(iPlotX + x, iPlotY + y)
if (pPlot.getOwner() != iPlayer):
continue
else:
return False
continue
}
return True

Impaler[WrG]
Jul 26, 2007, 03:43 PM
if (GET_TEAM(GET_PLAYER(iPlayer).getTeam()).isHasTech (iTech))

should work for you

Davinci Fan
Jul 26, 2007, 05:35 PM
I am getting the error where the GUI doesn't show up, and I can't remember how to fix it. The only file in my mod is the modified GameUtils file, and all of the folder structure is correct.

Davinci Fan
Jul 26, 2007, 08:33 PM
This code for some reason is not working. Can someone explain to me why setting this to return true instead of false does nothing?

def cannotFoundCity(self,argsList):
iPlayer, iPlotX, iPlotY = argsList

return True

Zebra 9
Jul 26, 2007, 08:34 PM
if (map.Plot(iPlotX, iPlotY).getOwner() = iPlayer)
return FalseShould be if (CyMap().plot(iPlotX, iPlotY).getOwner() == iPlayer)
return False if (GET_TEAM(getTeam()).isHasTech(iTech))Should be if (gc.getTeam(gc.getPlayer(iPlayer).getTeam()).isHas Tech(iTech))pPlot = map.plot(iPlotX + x, iPlotY + y)Should bepPlot = CyMap().plot(iPlotX + x, iPlotY + y)

Davinci Fan
Jul 26, 2007, 09:34 PM
Thank you very much Zebra!

I still seem to be experiencing problems...

def cannotFoundCity(self,argsList):
iPlayer, iPlotX, iPlotY = argsList

iTech = gc.getInfoForString("TECH_LITERATURE")

if (iPlayer.getNumCities() = 0):
return False

if (CyMap().Plot(iPlotX, iPlotY).getOwner() = iPlayer):
return False

if (gc.getTeam(gc.getPlayer(iPlayer).getTeam()).isHas Tech(iTech)):
{
for x in range(-1, 2):
for y in range(-1, 2):
if ((x == -1 or x == 1) and (y == -1 or y == 1)):
continue
pPlot = CyMap().plot(iPlotX + x, iPlotY + y)
if (pPlot.getOwner() != iPlayer):
continue
else:
return False
continue
}

return True

The problem with the GUI is still there, and I am confused...

Zebra 9
Jul 27, 2007, 03:29 PM
Ok when you use code that compares 2 items like this:if item1 == items: you have to use 2 = signs not 1. Also Python uses curly braces ({ & }) for dictionaries not if statements. So your code can have all the curly braces removed. Now I just noticed that you are using iPlayer as a player instance (ie. you are calling methods defined in CyPlayer). iPlayer is actually a number. So what you need to do is get the player instance from the number using this code:gc.getPlayer(iPlayer)Als, python is case sensative. So CyMap().Plot is not the same as CyMap().plot. Using CyMap().Plot instead of CyMap().plot is an error. Now you also used gc.getInfoForString, this should be gc.getInfoTypeForString.

So in the end your code should look like: def cannotFoundCity(self,argsList):
iPlayer, iPlotX, iPlotY = argsList

iTech = gc.getInfoTypeForString("TECH_LITERATURE")

if (gc.getPlayer(iPlayer).getNumCities() == 0):
return False

if (CyMap().plot(iPlotX, iPlotY).getOwner() == iPlayer):
return False

if (gc.getTeam(gc.getPlayer(iPlayer).getTeam()).isHas Tech(iTech)):
for x in range(-1, 2):
for y in range(-1, 2):
if ((x == -1 or x == 1) and (y == -1 or y == 1)):
continue
pPlot = CyMap().plot(iPlotX + x, iPlotY + y)
if (pPlot.getOwner() != iPlayer):
continue
else:
return False
continue

return TrueThat should be syntacticly correct. :thumbsup:

Davinci Fan
Jul 28, 2007, 01:55 AM
Ok, so I've followed your code (to the letter - i.e. ctrl C&V), but the GUI problem is still showing up. I've set HidePythonExceptions to 0 and nothing is showing up. Am I doing something wrong?

Zebra 9
Jul 28, 2007, 01:00 PM
Upload your python folder.

Davinci Fan
Jul 29, 2007, 02:40 AM
I've found the solution: delete the 'continue' line; it is unnecessary and ends the function without returning a value.

Zebra 9
Jul 30, 2007, 08:54 AM
Ok, I can't beleive I missed that. It has an indentation error when it hits the continue. But don't worry as you found it's not needed.

Forbizzle
Mar 18, 2008, 10:04 PM
This code for some reason is not working. Can someone explain to me why setting this to return true instead of false does nothing?

def cannotFoundCity(self,argsList):
iPlayer, iPlotX, iPlotY = argsList

return True
Sorry to necro this thread, but I'm having the same problem. I wanted to test for sure that returning True would prevent building founding a city before working on my conditions, but it seems to ignore the result.

Seven05
Mar 19, 2008, 12:13 AM
Check PythonCallbackDefines.xml :)

If you have:

<Define>
<DefineName>USE_CANNOT_FOUND_CITY_CALLBACK</DefineName>
<iDefineIntVal>0</iDefineIntVal>
</Define>

Your python code isn't being run at all, change the zero to a 1 and you should be set.

Forbizzle
Mar 19, 2008, 07:42 PM
Check PythonCallbackDefines.xml :)

If you have:

<Define>
<DefineName>USE_CANNOT_FOUND_CITY_CALLBACK</DefineName>
<iDefineIntVal>0</iDefineIntVal>
</Define>

Your python code isn't being run at all, change the zero to a 1 and you should be set.

Thank you. I'm just starting to use this API, and that was the final cog that connected this whole machine together for me. :)