

### 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>
I'm confident that you can clear up any exceptions and whatnot on your own.
I documented the code for you, after all. 
## 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



however,
, because the city has the same name anyway!) the Damascus/Damasci link works perfectly!
everywhere gave me a name
well not everywhere)
it gives the message that happens when a rebel civ becomes the reborn civ
(probs as I resurrected it
) but that won't happen in game I think...
?
), also I was thinking about the dire situation of the ERE last night and how it basically required the human to be the roman civ... So... I am going to attempt 2 new events, the first only occurs if Rome is under AI control, They will get an army outside of byzantium and 2 turns before the ERE flip if rome doesn't control it then it gets fliped to them (The idea is they take the city and some surrounding cities) and then the second happens regardless (provided the ERE has less than x amount of cities) where the ere flips everything within a box (small, probably northern greece and some of the eastern surroundings) maybee 3 turns after they spawn with a message saying a number of cities have joined the cause of the mighty Eastern Roman empire! So... These 2 events secure the life of the ERE if Rome is the AI or if the player fails to make a big enough empire in the east 
)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)




why did you have to there?
(Well unless you think differently?) I guess will work on this tommorrow! What are your thoughts on why the Byzantium -> constaninople code doesn't work? I checked the coords for it and they are all fine... I'm stumped, I guess tommorrow I will make a debug for that part
It's not like it has any excuse! The damasci code works fine (a question about that, if egypt founds Damasci will it be named the eygptian variant? I guess not as it is on the CityAcquiredAndKept callback Should be easy to hard code that in somewhere though!)