### Historical City Names Manager, by Baldyr and J_mie6
from Helpers import *
from eNums import *
# constants
lDirectionTypes = list()
for eDirection in xrange(DirectionTypes.NUM_DIRECTION_TYPES):
lDirectionTypes.append(DirectionTypes(eDirection))
# main functions
def nameCity(pCity):
"""
Handles incoming calls from CvEventManager.onCityBuilt().
Firstly checks if the city plot is a special case by calling renameCity(). If so, the function exits.
Secondly checks the city name dictionary by calling getSite().
If a valid historical site is found the value is used as the city name, by calling setName().
"""
if renameCity(pCity.getOwner(), pCity): return
tCoords = getSite(pCity)
if tCoords:
setName(pCity, cityNameDict[tCoords])
def renameCity(ePlayer, pCity):
"""
Called from CvEventManager.onCityAcquiredAndKept().
Checks plots by coordinates and city ownership; sets the name accordingly.
"""
tCoords = getCoords(pCity)
name = ""
if tCoords == (46, 27):
if ePlayer == CivPlayer.playerID("Byzantium"):
name = "Constantinople"
elif ePlayer == CivPlayer.playerID("Rome"):
name = "Byzantion"
elif tCoords == (71, 15):
if ePlayer == CivPlayer.playerID("Egypt"):
name = "Damascus"
elif ePlayer == CivPlayer.playerID("Rome"):
name = "Damasci"
if name:
setName(pCity, name)
return True
def isInvalidSite(ePlayer, tCoords):
"""
Called from CvGameUtils.cannotFoundCity().
Returns False if the city plot or any adjacent plot is found in the city name dictionary.
Also always returns False if the call concerns the human player.
Returns True by default if no conditions are met.
"""
if ( instance(ePlayer) == human()
or isHistoric(tCoords)
or isHistoric(checkAdjacent(tCoords)) ):
return False
return True
# helper functions
def setName(pCity, name):
"""
Changes the city name.
"""
pCity.setName(name, False)
def getSite(pCity):
"""
Returns a tuple containing map coordinates if a match is found in the city name dictionary.
Firstly checks the city plot, secondly all adjacent plots, and finally all plots within city's radius.
"""
tCoords = getCoords(pCity)
if isHistoric(tCoords):
return tCoords
else:
tAlternateSite = checkAdjacent(tCoords)
if tAlternateSite:
return tAlternateSite
else:
tAlternateSite = checkBFC(pCity)
if tAlternateSite:
return tAlternateSite
def isHistoric(tCoords):
"""
Returns True if the plot coordinate tuple is a valid key in the city name dictonary. Else returns False.
"""
return cityNameDict.has_key(tCoords)
def checkAdjacent(tCoords):
"""
Returns the map coordinates of the first found historical city site on an adjacent tile.
"""
for eDirection in lDirectionTypes:
tAlternateSite = getCoords(plotDirection(tCoords[0], tCoords[1], eDirection))
if isHistoric(tAlternateSite):
return tAlternateSite
def checkBFC(pCity):
"""
Returns the map coordinates of the first found historical city site within the city's radius.
"""
for iIndex in xrange(19):
tAlternateSite = getCoords(pCity.getCityIndexPlot(iIndex))
if isHistoric(tAlternateSite):
return tAlternateSite
# data
cityNameDict = {
(...)
def onCityBuilt(self, argsList):
'City Built'
city = argsList[0]
Powers.gaul(city, city.getOwner())
[COLOR="Red"] Cities.nameCity(city)[/COLOR]
[COLOR="Red"]##[/COLOR] if (city.getOwner() == gc.getGame().getActivePlayer()):
[COLOR="Red"]##[/COLOR] self.__eventEditCityNameBegin(city, False)
CvUtil.pyPrint('City Built Event: %s' %(city.getName()))
def onCityAcquiredAndKept(self, argsList):
'City Acquired and Kept'
iOwner,pCity = argsList
[COLOR="Red"] Cities.renameCity(*argsList)[/COLOR]
def initiateCustomPython():
if gc.getGame().isFinalInitialized():
global Powers, Rebellion, Custom, CC[COLOR="Red"], Cities[/COLOR]
import Powers, Rebellion, CustomFeatures as Custom, CatapultConstruction as CC[COLOR="Red"], HistoricalCities as Cities[/COLOR]
if not Rebellion.getGlobalScriptDict():
Rebellion.setup()
CC.load()
from CvGameUtils import CvGameUtils
CvGameUtils.powers = Powers
CvGameUtils.custom = Custom
[COLOR="Red"] CvGameUtils.cities = Cities[/COLOR]
Custom.gameTurn()
def cannotFoundCity(self,argsList):
iPlayer, iPlotX, iPlotY = argsList
return [COLOR="Red"]self.cities.isInvalidSite(iPlayer, (iPlotX, iPlotY))[/COLOR]
<Define>
<DefineName>USE_CANNOT_FOUND_CITY_CALLBACK</DefineName>
<iDefineIntVal>[COLOR="Red"]1[/COLOR]</iDefineIntVal>
</Define>
## if (city.getOwner() == gc.getGame().getActivePlayer()):
## self.__eventEditCityNameBegin(city, False)
def checkAdjacent(tCoords):
"""
Returns the map coordinates of the first found historical city site on an adjacent tile.
"""
for eDirection in lDirectionTypes:
[COLOR="Red"] pPlot = plotDirection(tCoords[0], tCoords[1], eDirection)
if pPlot.isNone(): continue
tAlternateSite = getCoords(pPlot)[/COLOR]
if isHistoric(tAlternateSite):
return tAlternateSite
I have no recollection of this, but if you need help with it please explain. If you have the design all done (coordinates and specifics on the players concerned), then it would be easy enough to fix it for you.Well I did ask you to do player restriction but you must have overlooked it!
Oh, there is bound to be some issue with it, eventually. I did test things and made sure everything loaded alright and that there were no exceptions in-game, but nothing more.Congratulations on your error free code! (kind of unnerving, makes me think something really wrong will happen soon)