1. We have added a Gift Upgrades feature that allows you to gift an account upgrade to another member, just in time for the holiday season. You can see the gift option when going to the Account Upgrades screen, or on any user profile screen.
    Dismiss Notice

[PYTHONCOMP] Random Unit Names

Discussion in 'Civ4 - Mod Components' started by TheLopez, Feb 27, 2006.

  1. TheLopez

    TheLopez Deity

    Joined:
    Jan 16, 2006
    Messages:
    2,525
    Location:
    Oregon
    First, welcome to the boards. Sure I could help you.

    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.

    There is no limit that I found. Its just an arbitrary number I picked.
     
  2. Rathelon

    Rathelon Prince

    Joined:
    Mar 10, 2006
    Messages:
    423
    Location:
    Portland, OR
    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.
     

    Attached Files:

  3. TheLopez

    TheLopez Deity

    Joined:
    Jan 16, 2006
    Messages:
    2,525
    Location:
    Oregon
    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
     
  4. Nexushyper

    Nexushyper Warlord

    Joined:
    Dec 3, 2002
    Messages:
    245
    Location:
    Colorado
    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)
     
  5. TheLopez

    TheLopez Deity

    Joined:
    Jan 16, 2006
    Messages:
    2,525
    Location:
    Oregon
    Sorry about that about that Nexus, your changes in the Unit Stats mod slipped my mind.
     
  6. Rathelon

    Rathelon Prince

    Joined:
    Mar 10, 2006
    Messages:
    423
    Location:
    Portland, OR
    Ok, great. I'll take a look at yours, Nexus.
     
  7. Nexushyper

    Nexushyper Warlord

    Joined:
    Dec 3, 2002
    Messages:
    245
    Location:
    Colorado
    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.
     
  8. Porges

    Porges Chieftain

    Joined:
    Mar 28, 2006
    Messages:
    50
    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.
     
  9. TheLopez

    TheLopez Deity

    Joined:
    Jan 16, 2006
    Messages:
    2,525
    Location:
    Oregon
    :goodjob: thats a great idea!
     
  10. Harada the Grea

    Harada the Grea Chieftain

    Joined:
    Jan 14, 2006
    Messages:
    52
    Location:
    england

    Hi sorry for what is probably stupid question. Where do I put this code for it to work, ie file name and extensions ets
     
  11. TheLopez

    TheLopez Deity

    Joined:
    Jan 16, 2006
    Messages:
    2,525
    Location:
    Oregon
    I just checked this mod and it is compatible with the v1.61 patch!!!
     
  12. Harada the Grea

    Harada the Grea Chieftain

    Joined:
    Jan 14, 2006
    Messages:
    52
    Location:
    england
    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
     
  13. TheLopez

    TheLopez Deity

    Joined:
    Jan 16, 2006
    Messages:
    2,525
    Location:
    Oregon
    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.
     
  14. Harada the Grea

    Harada the Grea Chieftain

    Joined:
    Jan 14, 2006
    Messages:
    52
    Location:
    england

    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:
     
  15. TheLopez

    TheLopez Deity

    Joined:
    Jan 16, 2006
    Messages:
    2,525
    Location:
    Oregon
    I think you should be able to add the file on its own.
     
  16. Harada the Grea

    Harada the Grea Chieftain

    Joined:
    Jan 14, 2006
    Messages:
    52
    Location:
    england
    :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:
     
  17. TheLopez

    TheLopez Deity

    Joined:
    Jan 16, 2006
    Messages:
    2,525
    Location:
    Oregon
    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.
     
  18. Barak

    Barak Emperor

    Joined:
    May 1, 2003
    Messages:
    1,513
    Location:
    Chicago
    Should this mod be placed in the C\...program files\...mods or the My Games\...\Custom Assets?

    Thanks
     
  19. TheLopez

    TheLopez Deity

    Joined:
    Jan 16, 2006
    Messages:
    2,525
    Location:
    Oregon
    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.
     
  20. Barak

    Barak Emperor

    Joined:
    May 1, 2003
    Messages:
    1,513
    Location:
    Chicago
    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
     

Share This Page