Civ Specific Great People Name

platyping

Sleeping Dragon
Joined
Oct 22, 2010
Messages
4,626
Location
Emerald Dreams
Unique Names

Feature 1:
Great People born will get different names based on the civilization of the player.
Example:
A Great General born in China may be Liu Bei, Guan Yu or Zhang Fei, but a Great General born elsewhere will never be one of those.

There are just 3 parts:
1) UnitInfos.xml
Remove all default unique names.

2) CvEventManager
Just one part under onGreatPersonBorn.
Leave it alone.

2) Text files
Some examples there.
Code:
<TEXT>
	<Tag>TXT_GREECE_SCIENTIST_0</Tag>
	<English>Harry0</English>
</TEXT>
<TEXT>
	<Tag>TXT_GREECE_SCIENTIST_1</Tag>
	<English>Harry1</English>
</TEXT>
<TEXT>
	<Tag>TXT_GREECE_SCIENTIST_2</Tag>
	<English>Harry2</English>
</TEXT>
<TEXT>
	<Tag>TXT_GREECE_ARTIST_0</Tag>
	<English>Potter</English>
</TEXT>
	<TEXT>
	<Tag>TXT_GREECE_GREAT_SPY_0</Tag>
	<English>Ron</English>
</TEXT>
<TEXT>
	<Tag>TXT_GREECE_MERCHANT_0</Tag>
	<English>Hermoine</English>
</TEXT>
<TEXT>
	<Tag>TXT_GREECE_PROPHET_0</Tag>
	<English>Tom</English>
</TEXT>
<TEXT>
	<Tag>TXT_GREECE_ENGINEER_0</Tag>
	<English>Riddler</English>
</TEXT>

So the first Scientist born in Greece will be Harry0.
The next Scientist born in Greece will be Harry1.
If the next Great Person is enginner, then it will be Riddler instead.
If the next Great Person is enginner again, since there is no further entry for enginner, it will simply be Great Enginner just like default BTS.

The only issue is that the yellow global message will simply display as Great Enginner born in XXX(XXX) without the unique name.
Currently, it will just follow the numbers so the first Scientist in Greece will always be Harry0 and not Harry1.
May look into randomisation when bored again.

Feature 2:
Cities built with different names according to Leader rather than Civ.
Alexander can have a different name list compared to Pericles.
Uses Greece city name list instead when Alexander list runs out.
 
Well done! :goodjob:

One week without a single comment, what a shame! :sad:

At first, I was thinking that I was not really interested but then I thought that this could be used for any other unit...

Quote:
"2) CvEventManager
Just one part under onGreatPersonBorn.
Leave it alone."

That I could not do! :D

So that is what I did on onUnitBuilt:

Spoiler :
PHP:
	def onUnitBuilt(self, argsList):
		'Unit Completed'
		city = argsList[0]
		unit = argsList[1]
		player = PyPlayer(city.getOwner())
		
## platyping Civ Specific Names Start ##
		iUnitType = unit.getUnitType()
		iPlayer = city.getOwner()
		sUnitType = gc.getUnitInfo(iUnitType).getType()[4:] +"_"
		sCivilization = gc.getCivilizationInfo(gc.getPlayer(iPlayer).getCivilizationType()).getType()[13:]
		sName = CyTranslator().getText("TXT_" + sCivilization + sUnitType + str(CyStatistics().getPlayerNumUnitsBuilt(iPlayer, iUnitType)),())
		if sName.find("TXT_") == -1:
			unit.setName(sName)
## platyping Civ Specific Names End ##
Like that it works for every unit! Is it too much taxing? The alternative is to add a Unique Unit for each Civ you want to have a list. Not very good neither.

Two questions:
1) what if we want more than ten units with unique names? I'm referring to the TEXT ending with _x.
2) once the text list is over, we can't revert to the list in UnitInfos, can we?

Quote: "May look into randomisation when bored again."

Personally, I'm not interested. I have de-randomised the standard way through a fix in the dll.

But I like it when you get bored! :D
 
1) There is no limit
2) By right it will, but I remove all the default ones.
Because the global message displayed will still display the default name even though the unit name has changed.
 
1) good to know.

2) I don't think so because I tested it with 1 name in the Musketman UnitInfos and another one in the text file. First came the one in the text file (correct) but the second one was without a name.
 
Actually a more useful application is to use it for cities.
Since various leaders of a nation have capitals at different places, you can use this to assign different city names to different leaders.

I didn't see the point of using it for normal units, because there are various ways to create a unit without building it.
Drafting is an example.
 
1) good to know.

2) I don't think so because I tested it with 1 name in the Musketman UnitInfos and another one in the text file. First came the one in the text file (correct) but the second one was without a name.

What actually happens is that when a unit is built, the system picks a random unused unique name and assign to the unit.
The python then rename the unit to follow the list.
As such, the first unit took the unique name but was renamed to the one in the list.
The second one therefore has no name since there isn't any unused unique name nor one in the list.

The problem I mentioned is for great people since there is a yellow global message.
That one will still display the unique name and not the list name
 
About converting it to regular units-I am having some issues.
I inserted isenchine's code in the correct location, and renamed the text files thusly:
Spoiler :

<TEXT>
<Tag>TXT_GREECE_WARRIOR_0</Tag>
<English>Warrior 1</English>
</TEXT>
<TEXT>
<Tag>TXT_GREECE_WARRIOR_1</Tag>
<English>Warrior 2</English>
</TEXT>

However, the names did not appear in-game. Can anyone tell me what I'm doing wrong here?
 
It depends on what you tested.
As I mentioned, onUnitBuilt is triggered only when the unit is built literally.
It will not trigger when unit is created under other situations such as drafting.
Thus, if your test is simply start a game, stare at the settler and warrior, neither of them will have the new name since neither of them was built.

Since I am bored, I did you a favour:

New Version
Comes with 3 Features

1) Great People Born comes with different names based on Civ
Chinese Great People Born will have different names compared to Greek ones.

2) Units Created have numbers attached to them.
Applied to all situations including building, drafting, capturing, world builder etc
Only exception is upgrading, unit retains name.
First Warrior will be Warrior 1

3) Cities Built with different names based on Leaders.
Alexander can have a different name list compared to Pericles.
If the list runs out, it will just go to default database and use the default ones for Greece.

These 3 features are all in the same python file.
Just delete/ comment whichever part you do not want to use.
The python callback is only for the 2nd feature, so you can deactivate it if not needed.
Moved to Database
 
2) Units Created have numbers attached to them.
Applied to all situations including building, drafting, capturing, world builder etc
Only exception is upgrading, unit retains name.
First Warrior will be Warrior 1

Well, thanks, but that was just an example. I would like to have the names, not just numbers. And yes, I did build a unit.
 
It will be easier if you zip up your modified version and attached here for me to test and see why.
 
Attach your CvEventManager then.
Sometimes there are mistakes even when copy and paste.
 
If I understand it correctly, when you use onUnitCreated (with the Callback), you don't need to use onUnitBuilt, right?

PS: for info, I also just need names and up to a limited number but thanks anyway. If you remember, I asked some time ago how to assign a promotion to a unit with a unique name and I got it working with your help. I don't want "other" units to get that promotion.
 
If you have both oUB and oUC activated:

Whatever is built is definitely created, whatever is created may not be built.
Those that are built will activate both codes.
Those that are created but not built will activate just oUC codes.

If you are using python to change the names of units just to assign particular promotions, you might as well just use python to assign the particular promotions without changing the names by simply checking certain conditions.
 
In other words, you mean Yes! :lol: If I want the code to be activated regardless of the unit being built or created, it's enough to put the code on onUnitCreated. Putting it again on onUnitBuilt is redundant in that case. The only drawback is the callback, right?

I want some units to have a certain name therefore they are elligible for a specific promotion. It's a way to distribute names of Generals and Explorers. Your Python allows me now to distribute the names even if there is no Unique Unit. :goodjob:
 
Yeah, so long as you are happy :D
Although I will not use the codes you copied and paste from GP portion.
Because the CyStatistics().getPlayerNumUnitsBuilt(XXX) only count those that you built.
You will end up with units with similar unique names.
For instance, First Rifleman built is Peter.
Now I draft a new Rifleman.
oUC is activated so a name is given to the new one.
However, CyStatistics().getPlayerNumUnitsBuilt(XXX) has not increased since you have not built a new Rifleman.
Thus, the drafted Rifleman will be Peter as well...
 
Then tant pis! I don't use oUC!

Good that I asked ;).
 
Just modify from the new version I posted.
Uses a different way, shouldn't be an issue to modify for you.
 
Code:
	def onUnitCreated(self, argsList):
		'Unit Completed'
		unit = argsList[0]
		player = PyPlayer(unit.getOwner())
## platyping Civ Specific Names Start ## 
        iUnitType = unit.getUnitType() 
        iPlayer = city.getOwner() 
        sUnitType = gc.getUnitInfo(iUnitType).getType()[4:] +"_" 
        sCivilization = gc.getCivilizationInfo(gc.getPlayer(iPlayer).getCivilizationType()).getType()[13:] 
        sName = CyTranslator().getText("TXT_" + sCivilization + sUnitType + str(CyStatistics().getPlayerNumUnitsBuilt(iPlayer, iUnitType)),()) 
        if sName.find("TXT_") == -1: 
            unit.setName(sName) 
## platyping Civ Specific Names End ## 		
		if (not self.__LOG_UNITBUILD):
			return

First thing I feel is indentation may be wrong.
Didn't bother to test since you are using "Spaces" rather than "Tabs".

2nd thing, city is not defined in onUnitCreated.
Isenchine defined it under onUnitBuilt.
Use unit instead, or look at what I did...

3rd thing, if you are using onUnitCreated, make sure you activate python callback.

Lastly, activate python exceptions.
Since the city is obviously wrong, python exceptions will have told you it is wrong if enabled.
 
Back
Top Bottom