I'd like something that would randomize city names when founded. The first city would always be the same (London, Washington, etc), but every other city would have a random name from the given list of city names. I find that I usually only have the first 6 or so cities, and I'd appreciate the variety. Thanks!
That would require DLL modification. Looks like it's handled in the function CvPlayer::getCivilizationCityName()
Modifying the DLL may be cleaner and more efficient, but it is not actually necessary.
It is possible to use python to rename a city as soon as it is founded.
It is even possible to use python to extract a list of city names from CIV4CivilizationInfos.xml and then randomly select a one of those names for a city.
As proof, I offer you this bit of code which I just now wrote and tested. It seems to work exactly as lugialord desires.
CvEventManager.py
Code:
def onCityBuilt(self, argsList):
'City Built'
city = argsList[0]
if not city.isCapital():
iCiv = city.getCivilizationType()
iPlayer = city.getOwner()
py = PyPlayer(iPlayer)
listCityNames = []
CivFile = open("Assets/XML/Civilizations/CIV4CivilizationInfos.xml")
bCiv = False
for line in CivFile.readlines():
if "<Type>" in line:
sCiv = line[line.find(">") +1 : line.find("</")]
if iCiv == gc.getInfoTypeForString(sCiv):
bCiv = True
else:
bCiv = False
elif bCiv:
if "<City>" in line:
txtKeyCity = line[line.find(">") +1 : line.find("</")]
sName = localText.getText(txtKeyCity, ())
for pyCity in py.getCityList():
if pyCity.GetCy().getName == sName:
break
else:
listCityNames.append(sName)
if len(listCityNames) > 0:
sName = listCityNames.pop(CyGame().getSorenRandNum(len(listCityNames), "Name city"))
city.setName(sName, False)
if (city.getOwner() == gc.getGame().getActivePlayer()):
self.__eventEditCityNameBegin(city, False)
CvUtil.pyPrint('City Built Event: %s' %(city.getName()))
The first version of this code which I tested required explicitly defining a list of city names for each civ in python, which was a bit of a hassle so I only actually got it working for 2 civs. That way is not very versatile and would require reprogramming for each mod.
I would not have known how to use python to read the files like that had I not come across something similar in the code of Platy World Builder, so Platyping deserves some of the credit.
Note: This code will probably not work well in modular mods where some civs (and thus their city lists) are defined in separate files.
It would also not work great in mods that write the city names directly in the CIV4CivilizationInfos.xml rather than using TXT_KEYs. I believe that would make it possible for some ciities to be given the name "-1."