This project is abandoned but will probably be replaced by another some time in the future. Thanks goes out to all that contributed to it however.
Spoiler :
No, this is not about adding entries to the City Name Manager - thats another thread altogether. What I'm proposing to do is cut out some 3000 lines of Python code from the current CityNameManger.py file by replacing that code with "data structures".
This will have several benefits. First and foremost it will also enable non-programmers to easily edit the city name entries. Another benefit is that manually changing the default city name no longer disables the dynamic name changes when the city is acquired by another Civ. This because the new set of code will lookup the actual map tile and not all the known city name aliases. Furthermore, we can have default city names for map tiles that are available for all Civs, even the minor ones who don't have City Name Maps. (This is also helpful for modders and scenario makers.)
Hopefully the code will run faster, also, but I have no proof to support such claims at this point.
So, I've made a Python script that will convert all the city name changing code into the new setup. This is an example of the tile designated as the Roman starting location:
So once I run my script on the whole map, tile by tile, city name map by city name map, this is what the computer generated entries could look like. Before I go into the specifics of what it contains, I thought I'd show you what lines of code this single line would replace:
Now I have to convince you that the above line is more easy to read and edit...
So, the whole line is enclosed in a pair of parenthesis - this makes it a data structure. The first piece of data inside this data structure (known as a "tuple") is this:
The first value is the X coordinate for Rome, and the second value is the Y coordinate. The enclosing parenthesis is just what I said before - it makes this data entry a data structure (tuple) in it-self. But we could skip those and just go with two integer values:
What do you think? Which would be easier in the long run?
Ok, moving on:
The next piece of data is called a string as it consist of a set of characters - enclosed in a pair of quotations. (Double quotations work just the same.) This would be the default city name for the city located on the tile. So unless some other name is specified for a given Civ, this default name will be used instead.
On to the main attraction:
This is one single data structure called a "dictionary" as indicated by the curly brackets at each end. This particular dictionary holds 5 entries, each consisting of a pair of values divided by a colon. The first value - the "key" - is a constant variable corresponding to a indexed Civ. The second value in each pair is the city name alias for that Civ, expressed as a string (note the quotations).
Personally I think this new setup is much more clear and also easier to edit. Especially as it involves no actual programming - so you don't have to worry about indentation or logical expressions. The best part is of course that any change or addition you make don't have to be reflected on multiple places in order to work!
Now, what does the community at large think about such a setup? Have I failed to take something into account? (Like what if the city isn't built on the specified map tile?) Is there additional functionality that could be built into an "enhanced" City Name Manager? Could the actual city name entries be formatted in some other fashion?
This will have several benefits. First and foremost it will also enable non-programmers to easily edit the city name entries. Another benefit is that manually changing the default city name no longer disables the dynamic name changes when the city is acquired by another Civ. This because the new set of code will lookup the actual map tile and not all the known city name aliases. Furthermore, we can have default city names for map tiles that are available for all Civs, even the minor ones who don't have City Name Maps. (This is also helpful for modders and scenario makers.)
Hopefully the code will run faster, also, but I have no proof to support such claims at this point.
So, I've made a Python script that will convert all the city name changing code into the new setup. This is an example of the tile designated as the Roman starting location:
Code:
( [COLOR="Sienna"](60, 44)[/COLOR], [COLOR="DarkGreen"]'Roma'[/COLOR], [COLOR="DarkSlateBlue"]{iChina:'Daqin', iArabia:'Rumiya', iFrance:'Rome', iGermany:'Rom', iNetherlands:'Rome'}[/COLOR] )
Spoiler :
Code:
elif (sName == 'Rome' or sName == 'Rom' or sName == 'Rumiya' or sName == 'Roma'):
city.setName('Daqin', False)
elif (sName == 'Rome' or sName == 'Rom' or sName == 'Roma' or sName == 'Daqin'):
city.setName('Rumiya', False)
elif (sName == 'Rome' or sName == 'Rom' or sName == 'Rumiya' or sName == 'Daqin'):
city.setName('Roma', False)
elif (sName == 'Roma' or sName == 'Rom' or sName == 'Rumiya' or sName == 'Daqin'):
city.setName('Rome', False)
elif (sName == 'Roma' or sName == 'Rome' or sName == 'Rumiya' or sName == 'Daqin'):
city.setName('Rom', False)
elif (sName == 'Roma' or sName == 'Rom' or sName == 'Rumiya' or sName == 'Daqin'):
city.setName('Rome', False)
elif (sName == 'Rome' or sName == 'Rom' or sName == 'Rumiya' or sName == 'Daqin'):
city.setName('Roma', False)
elif (sName == 'Rome' or sName == 'Rom' or sName == 'Rumiya' or sName == 'Daqin'):
city.setName('Roma', False)
So, the whole line is enclosed in a pair of parenthesis - this makes it a data structure. The first piece of data inside this data structure (known as a "tuple") is this:
Code:
(60, 44)
Spoiler :
Code:
( [COLOR="Sienna"]60[/COLOR], [COLOR="Sienna"]44[/COLOR], [COLOR="DarkGreen"]'Roma'[/COLOR], [COLOR="DarkSlateBlue"]{iChina:'Daqin', iArabia:'Rumiya', iFrance:'Rome', iGermany:'Rom', iNetherlands:'Rome'}[/COLOR] )
Ok, moving on:
Code:
'Roma'
On to the main attraction:
Code:
{iChina:'Daqin', iArabia:'Rumiya', iFrance:'Rome', iGermany:'Rom', iNetherlands:'Rome'}
Personally I think this new setup is much more clear and also easier to edit. Especially as it involves no actual programming - so you don't have to worry about indentation or logical expressions. The best part is of course that any change or addition you make don't have to be reflected on multiple places in order to work!
Now, what does the community at large think about such a setup? Have I failed to take something into account? (Like what if the city isn't built on the specified map tile?) Is there additional functionality that could be built into an "enhanced" City Name Manager? Could the actual city name entries be formatted in some other fashion?