[PYTHONCOMP] Random Unit Names

Rathelon said:
I'm new to these forums, but I've done some modding in the past for Freelancer so I'd like to give it a shot. If you dont mind, I'd like to use your script and just alter the lists it generates from, but I have a question that perhaps you could help me with.
First, welcome to the boards. Sure I could help you.

Rathelon said:
I would prefer it only named certain units upon creation, i.e. combat units only - not settlers, workers, scouts, explorers, and spies. Would that entail altering your script, and if so, maybe you could tell me which part to look at?
Well the code just provides the names for the units. The place you would need to look is the CvEventManager.py file, the onUnitCreated method. Basically you would need to build a filter to only name units with the characteristics you are looking for.

Rathelon said:
Also, I noticed in your script that you only generate the middle name if the first and last are less than 14. Is there a limit to the number of characters in the name, and if so, what is the limit?
There is no limit that I found. Its just an arbitrary number I picked.
 
Ok, here's a quick modification of Lopez's generator that does military unit designations in a rather generic way. You'll still need to have downloaded his, and then just swap this file into the MyDoc/MyGames...CustomAssets/Python folder in place of the file with the same name.

It still names the missionaries, settlers, workers, etc, but I am going to see if I can figure out how to make one that is a little better so I can include more specific unit designations (like Infantry, Armor, Fleet, etc.), as well as naming the non-combat units with a civ-specific typical surname (first and last).

I did test this though, and it's pretty cool. Adds some flavor to the units.
 

Attachments

  • MilitaryUnits.zip
    1.6 KB · Views: 308
Very cool Rathelon. Thanks. When I get a chance I will take a look at it and see about folding it into my code :D
 
Actually I have already done something like this.

If you go to the Unit Statistics mod thread and download it, you will find my code based on your code, TheLopez. It names Ground units, Sea units, and AIr units. Examples: 5thArmy 6thCorp 1stDiv 3rdFleet 2ndGroup 4thSquad.

It can go up to 5000th of each portion of the name. And there are many options on how it works. (Such as the examples above or 5thA 6thC 1stD)
 
Sorry about that about that Nexus, your changes in the Unit Stats mod slipped my mind.
 
There might be a small bug in my code. I know I made a fix to it but I haven't had time to upload a new version. Hopefully tonight I can get a new version of my Mod uploaded. (In my sig). And it will have the bug free version.

One note with my code: There is nothing that distiguishes air units from say workers, thus I have to count out the unitClassType of all units in my mod and determine which number goes with land, sea, air. unittype will return say combat_melee, combat_Naval, etc. But air units return combat_none like workers, so you see why I have to count out the units in the xml file. DOes that make sense?

It is the delima of trying to custom name air units.
 
Here's one that works with SimCutie's event manager:
Code:
#import utility functions
from CvPythonExtensions import *
import pickle			

def getCityNumber(city):
	cityDict = pickle.loads( city.getScriptData() )
	cityDict['unitNumber'] = cityDict['unitNumber'] + 1
	city.setScriptData( pickle.dumps(cityDict) )
	return cityDict['unitNumber']

def onUnitBuilt(argsList):
	city = argsList[0]

	unit = argsList[1]

	unit.setName(findOrdinal(getCityNumber(city)) + " " + unit.getName() + " of " + city.getName())
	return 0
	
def onCityBuilt(argsList):
	city = argsList[0]
	cityDict = {'unitNumber':0}
	city.setScriptData( pickle.dumps(cityDict) )
	return 0
	
def findOrdinal(num):
    t = 'th st nd rd th th th th th th'.split()
    if num % 100 in (11, 12, 13): #special case
        return '%dth' % num
    return str(num) + t[num % 10]

def EventHandlerRegister(eventManager,unused = None):
	return {'unitBuilt-':onUnitBuilt,'cityBuilt-':onCityBuilt}

Sets the names like "1st Worker of Moscow", "2nd Warrior of Moscow". The number is dependant upon all units built in the city.
 
:goodjob: thats a great idea!
 
Porges said:
Here's one that works with SimCutie's event manager:
Code:
#import utility functions
from CvPythonExtensions import *
import pickle			

def getCityNumber(city):
	cityDict = pickle.loads( city.getScriptData() )
	cityDict['unitNumber'] = cityDict['unitNumber'] + 1
	city.setScriptData( pickle.dumps(cityDict) )
	return cityDict['unitNumber']

def onUnitBuilt(argsList):
	city = argsList[0]

	unit = argsList[1]

	unit.setName(findOrdinal(getCityNumber(city)) + " " + unit.getName() + " of " + city.getName())
	return 0
	
def onCityBuilt(argsList):
	city = argsList[0]
	cityDict = {'unitNumber':0}
	city.setScriptData( pickle.dumps(cityDict) )
	return 0
	
def findOrdinal(num):
    t = 'th st nd rd th th th th th th'.split()
    if num % 100 in (11, 12, 13): #special case
        return '%dth' % num
    return str(num) + t[num % 10]

def EventHandlerRegister(eventManager,unused = None):
	return {'unitBuilt-':onUnitBuilt,'cityBuilt-':onCityBuilt}

Sets the names like "1st Worker of Moscow", "2nd Warrior of Moscow". The number is dependant upon all units built in the city.


Hi sorry for what is probably stupid question. Where do I put this code for it to work, ie file name and extensions ets
 
I just checked this mod and it is compatible with the v1.61 patch!!!
 
what do you mean Drop the file in customassets file, just put the file in or do you add it to the files already there, complete novice at adding mods just getting the hang of adding units
 
Well it depends on the current contents of your custom assests folder. You might need to merge different files to get it to work correctly with the files in your folder.
 
TheLopez said:
Well it depends on the current contents of your custom assests folder. You might need to merge different files to get it to work correctly with the files in your folder.


the only thing that might be in that file is the regiments mod as I always download it, do i add this file to them or just add the file on its own. BTW thanks for the help :goodjob:
 
I think you should be able to add the file on its own.
 
TheLopez said:
I think you should be able to add the file on its own.

:goodjob:
going to download this and add it to the game. Cheers for the help. Without people like you the game wou;ld get stale quick but all your mods constantly change the game and keep me enthralled for just 1 more turn :lol:
 
Alright guys, I've added random name generation support for all of the original civilizations included in the original game. If someone wants to add other names they will have to do it themselves :p.
 
Should this mod be placed in the C\...program files\...mods or the My Games\...\Custom Assets?

Thanks
 
Only if you want *all* of your units, including great people, to be renamed. The appropriate use for this mod would be to take the RandomUnitNames.py file and incorporate it into a mod in whatever way you see fit.
 
TheLopez said:
Only if you want *all* of your units, including great people, to be renamed. The appropriate use for this mod would be to take the RandomUnitNames.py file and incorporate it into a mod in whatever way you see fit.

Considering that I have little knowledge of python, how would I include the mod in a game to have my Roman units have roman names and English units English names? I tried the new version and in the three tests I conducted each civ (England, Rome, Egypt) appeard to have Celtic/Norse names.

Thanks in advance
 
Top Bottom