View Full Version : [PYTHONCOMP] Random Unit Names
TheLopez Feb 27, 2006, 07:42 PM Random Unit Names Mod
By: TheLopez
Last Updated 06/09/06
Version: v0.5.2
Patch Compatibility: v1.52, 1.61
MP Compatible: ?
Download Mod v0.5.2 (http://www.aracnet.com/~opus/Civiv/RandomUnitNamesv0.5.2.zip)
Description:
This mod will give any unit created in the game a unique name. The current
version of this mod can generate over well to many names to count. There are
two ways to use this mod. The first is to just call the getRandomName method
which will return just that, a random name. The second and new way to use this
mod is to use the getRandomCivilizationName passing in the civilization type ID
number. This mod should NOT be used as a stand-alone mod. You should just use
the RandomNameUtils.py file instead. The other files are just used to show
how the RandomNameUtils.py can be used.
Installation Instructions:
1) Unzip this into the "civ4_install_folder\Mods\" folder.
2) Open the CivilizationIV.ini configuration file
3) Change the Mod line to read: Mod = Mods\Random Unit Names
4) Load the game.
5) Then play as normal.
-----Version Information-----
-----v0.5.x------
- Tweaked the Japan names so they don't always produce really long names
- 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.
-----v0.4------
- Forked off the mercenaries mod random name generation code
- Stripped the mercenary specific code from the mod
-----===Credits & Thanks===-----
- Exavier
[TAB]Composite Mod - readme.txt format
Crayton Feb 27, 2006, 09:11 PM Wow, these look very Celtic :). I'm looking forward to the diversification for each civilization. I'd help, but the internet abounds in resources. Great job getting this to work. I especially enjoy the first AND last name components. I doubt it taxes the system much at all with the giant list of names, but I'm sure each civilizations' lists will be rich with half as much. Congrats.
spincrus Feb 28, 2006, 08:51 AM I won't download this mod component, as I'm waiting for the mercenary mod to be released :D
Come on already, I'm getting veeery veeery impatient! :bounce:
TheLopez Feb 28, 2006, 08:54 AM Spincrus,
It is getting very, very close ... would you like to see some new screen shots of the pre-release version?
spincrus Feb 28, 2006, 11:13 AM :bounce: Yes yes yes yes yes! :clap:
CurtSibling Mar 03, 2006, 09:03 AM Please do! Screenies!
:D
WaxonWaxov Mar 03, 2006, 09:42 AM Personally, I would like a mod that numbers units by type,
For example, the first archer you build would be named "1st Militia"
Militia would be city defense units.
Infantry would be walking attack units (Swordsman, etc)
Cavalry would be mounted units.
etc etc.
So the idea is early in the game you create a Horse Archer which gets named "5th Cavalry"
Eventually, that unit could upgrade into a gunship, but would have the historical name "5th Cavalry"
Just like the Scottish Black Watch used to use muskets, now they use Armoured Personnel Carriers.
Hey Lopez, give me insight as to how you did this one and maybe I'll do my idea myself.
TheLopez Mar 03, 2006, 09:56 AM Personally, I would like a mod that numbers units by type,
For example, the first archer you build would be named "1st Militia"
Militia would be city defense units.
Infantry would be walking attack units (Swordsman, etc)
Cavalry would be mounted units.
etc etc.
So the idea is early in the game you create a Horse Archer which gets named "5th Cavalry"
Eventually, that unit could upgrade into a gunship, but would have the historical name "5th Cavalry"
Just like the Scottish Black Watch used to use muskets, now they use Armoured Personnel Carriers.
Hmmm..... well that is a very interesting idea. When I put out the random unit names mod I just ripped out the code from my Merc. Mod and made it available since someone had requested it. I am planning to extend it by making the random names a bit more specific depending on the civilization for the unit. Though I could introduce an option to do the type of naming that you are asking for as well. Let me mull this over and I'll see what I can do after I release my Merc. mod.
Hey Lopez, give me insight as to how you did this one and maybe I'll do my idea myself.
Well, you can download the mod and see for yourself how I did it.
WaxonWaxov Mar 03, 2006, 10:01 AM The unique units for Each Civ should retain their type in the name.
Navy Seals would be "Seal Team One", etc.
Also, Ships should get names, like in the original mod here, but they should be civ specific. Like HMS, USS, etc.
I did look at the mod and it seems pretty straight forward, but I'm python stupid.
SK138 Mar 03, 2006, 11:11 AM What if you named the ships after city names for the civ?
Barak Mar 03, 2006, 11:30 AM This may sound like a ignorant question, but does this mod work separately or is it integrated into the regular Civ game. Meaning would I play it as a mod, or just when I start a regular game. If regular, does it work with other mods?
TheLopez Mar 03, 2006, 12:45 PM @Barak - It can work when starting a regular game if you drop the files into the customassets folder.
@SK138 - Hmmm.... that is an interesting idea, maybe after some of the great people that have joined your civ as well?
WaxonWaxov Mar 03, 2006, 01:02 PM ......maybe after some of the great people that have joined your civ as well?
Isn't that completely random? I don't think a record is kept somewhere....
The Great Apple Mar 03, 2006, 01:47 PM Isn't that completely random? I don't think a record is kept somewhere....It's done linearly through the ones listed in the xml file. Whenever a great leader is born it would trigger something in python, and backtracking you will be able to work out which civ has which great person....
Or you could just grab the name when the trigger happened.
In other words - a record could be made!
SK138 Mar 03, 2006, 02:26 PM I think I might try to do WaxonWaxov's idea with 1st Calvary or 3rd Infantry and stuff like that but I need some help. I was looking at your code for the RandomNames and I understand most of it but how do I find what unit was actually completed. Once I have that, how do I make the names count up, like 1st Calvary, 2nd Calvary, ..., Nth Calvary?
TheLopez Mar 03, 2006, 02:34 PM Isn't that completely random? I don't think a record is kept somewhere....
Well I ripped out the code that actually saves the names. The person who originally asked for the mod didn't require that the names be saved like in the Mercenaries Mod.
WaxonWaxov Mar 03, 2006, 03:12 PM Explorers/Scouts should have names like Christopher Columbus, Ponce DeLeon, etc.
Rathelon Mar 29, 2006, 02:12 AM This is a really good mod, but being a former military man myself, I also would love to see this adapted to give the units military designations.
Using your 'first', 'middle', and 'last' name format would work. The fist name could be a numeral designation, the middle name would be the unit type (infantry, cavalry, armor, etc), and the last name would be variable depending on the unit type as well (division, regiment, battalion, brigade, squadron, airwing, fleet, team, etc).
Perhaps even to make it simpler, (so you wouldnt have to have a script to recognize the unit type being created) the 'middle' name could just be left as a long list of random names (perhaps civ-specific). So you would end up generating things like 7th Yoritomi Regiment (Japan), 29th Sun Yi Division (China), 512th Strecken Brigade (Germany), etc.
TheLopez Mar 29, 2006, 04:54 AM This is a really good mod, but being a former military man myself, I also would love to see this adapted to give the units military designations.
Using your 'first', 'middle', and 'last' name format would work. The fist name could be a numeral designation, the middle name would be the unit type (infantry, cavalry, armor, etc), and the last name would be variable depending on the unit type as well (division, regiment, battalion, brigade, squadron, airwing, fleet, team, etc).
Perhaps even to make it simpler, (so you wouldnt have to have a script to recognize the unit type being created) the 'middle' name could just be left as a long list of random names (perhaps civ-specific). So you would end up generating things like 7th Yoritomi Regiment (Japan), 29th Sun Yi Division (China), 512th Strecken Brigade (Germany), etc.
All very good ideas, I am planning to update this mod after I complete my current mod: Sniper mod.
Thanks for all the great ideas.
Rathelon Mar 29, 2006, 01:42 PM 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.
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?
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?
TheLopez Mar 29, 2006, 02:36 PM 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.
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.
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.
Rathelon Mar 29, 2006, 06:03 PM 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.
TheLopez Mar 29, 2006, 06:09 PM 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
Nexushyper Mar 29, 2006, 07:48 PM 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)
TheLopez Mar 29, 2006, 08:06 PM Sorry about that about that Nexus, your changes in the Unit Stats mod slipped my mind.
Rathelon Mar 29, 2006, 08:31 PM Ok, great. I'll take a look at yours, Nexus.
Nexushyper Mar 30, 2006, 08:55 AM 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.
Porges Mar 31, 2006, 04:59 PM Here's one that works with SimCutie's event manager:
#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.
TheLopez Mar 31, 2006, 05:13 PM :goodjob: thats a great idea!
Harada the Grea Apr 01, 2006, 02:34 AM Here's one that works with SimCutie's event manager:
#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
TheLopez Apr 14, 2006, 05:57 AM I just checked this mod and it is compatible with the v1.61 patch!!!
Harada the Grea Apr 19, 2006, 08:41 AM 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
TheLopez Apr 19, 2006, 08:47 AM 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.
Harada the Grea Apr 19, 2006, 09:40 AM 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:
TheLopez Apr 19, 2006, 10:11 AM I think you should be able to add the file on its own.
Harada the Grea Apr 19, 2006, 12:07 PM 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:
TheLopez Apr 21, 2006, 11:57 PM 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.
Barak Apr 28, 2006, 06:08 AM Should this mod be placed in the C\...program files\...mods or the My Games\...\Custom Assets?
Thanks
TheLopez Apr 28, 2006, 06:23 AM 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.
Barak Apr 28, 2006, 07:08 AM 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
ruff_hi May 02, 2006, 09:45 PM TheLopez - your random unit name by civilization requires a civ type parameter. I've been trying to figure out how to pass it the civ type and I cannot work it out. I tried these ...
civtype = gc.getPlayer(unit.getOwner()).getCivilizationType( )
civtype = unit.getOwner().getCivilizationType()
... but they caused errors. Suggestions?
TheLopez May 02, 2006, 09:59 PM This code works for me:
objOwner = gc.getPlayer(unit.getOwner())
iCivilizationType = objOwner.getCivilizationType()
unit.setName(RandomNameUtils.getRandomCivilization Name(iCivilizationType))
ruff_hi May 02, 2006, 10:22 PM Ok, that works - thx. I thought that I did try a combination that looked like that. Is there a problem with something like this ...
iCivilizationType = gc.getPlayer(unit.getOwner()).getCivilizationType( )
... apart from being slightly long and confusing?
Do you have a code snip if I want to restrict it to only renaming the human players units?
TheLopez May 02, 2006, 10:44 PM objOwner = gc.getPlayer(unit.getOwner())
if(objOwner.isHuman()):
iCivilizationType = objOwner.getCivilizationType()
unit.setName(RandomNameUtils.getRandomCivilization Name(iCivilizationType))
Barak May 03, 2006, 08:45 AM Is there a further update for those of us without python skill?
When I loaded 0.5.1 i still got all celtic looking names.
Thanks
Padmewan May 03, 2006, 08:58 AM This is asking a lot, I think, but there are random-string generators out there for password generation that produce "pronouncable" words. Any chance that could be hooked into this so that the names are entirely random and don't require you to keep adding more names to each civ? Admittedy, they would lose some flavor, but maybe you'd keep more hair.
TheLopez May 03, 2006, 09:17 AM @Barak - as stated in the description this mod is not to be used as a stand-alone mod, it is to be integrated into other mods. The current reference implementation is still using the original random names
@Padmewan - I am using a pseudo random name generator for some of the civilizations, for some I had to use actual names since I couldn't fine the lexicon algorithms to do the actual random name generation.
Barak May 04, 2006, 06:17 AM @TheLopez - Gotcha, I was able to impliment the mod, and it worked great, I just thought we were up to level 2 (civ spacific random generations).
I will await the next version. Keep up the great work!
TheLopez May 04, 2006, 06:25 AM Barak, civ specific random naming is already implemented in the current version. All you need to do is change the line in the CvCustomEventManager.py file from:
unit.setName(RandomNameUtils.getRandomName())
to
iOwner = gc.getPlayer(unit.getOwner())
iCivilizationType = iOwner.getCivilizationType()
unit.setName(RandomNameUtils.getRandomCivilization Name(iCivilizationType))
zulu9812 Jun 05, 2006, 12:30 PM This is probably a horrendously basic question to ask, but how do I go about adding this to other mods? I've got the hang on editing XML files, but python files are doing my nut in. What I did was use 'import RandomNameUtils' to the CustomEventManager.py of the main mod, put the 'RandomNameUtils.py' file in the main python folder of the root directory. The part where I think I went wrong was with 'CVEventInterface.py' in the EntryPoints folder. All I did was copy from <RUN START> to <RUN END> and paste that into the CVEventInterface.py of the main mod. I started up the mod, built the furst unit - but no random name.
TheLopez Jun 05, 2006, 12:33 PM Can you please post a copy of your event manager class so I can see what you did in it?
zulu9812 Jun 05, 2006, 12:41 PM do you mean this?
TheLopez Jun 05, 2006, 12:50 PM do you mean this?
Yep, your onUnitCreated method should be like this:
def onUnitCreated(self, argsList):
'Unit Completed'
unit = argsList[0]
player = PyPlayer(unit.getOwner())
SevoTraits.checkNewUnit(argsList[0],false)
self.parent.onUnitCreated(self, argsList)
iOwner = gc.getPlayer(unit.getOwner())
iCivilizationType = iOwner.getCivilizationType()
unit.setName(RandomNameUtils.getRandomCivilization Name(iCivilizationType))
zulu9812 Jun 05, 2006, 12:53 PM Brilliant, thanks - I'll give it a whirl.
zulu9812 Jun 05, 2006, 03:37 PM Actually, I'm still just getting the regular unit names. I've uploaded all the files that I modified for this purpose, I'd appreciate it if you could please take a look.
http://www.civfanatics.net/uploads11/Assets.zip
The Great Apple Jun 05, 2006, 03:43 PM It's the indentation. Python treats white space as syntax.
Instead of
self.parent.onUnitCreated(self, argsList)
iOwner = gc.getPlayer(unit.getOwner())
iCivilizationType = iOwner.getCivilizationType()
unit.setName(RandomNameUtils.getRandomCivilization Name(iCivilizationType))
you need:
self.parent.onUnitCreated(self, argsList)
iOwner = gc.getPlayer(unit.getOwner())
iCivilizationType = iOwner.getCivilizationType()
unit.setName(RandomNameUtils.getRandomCivilization Name(iCivilizationType))
That should work.
zulu9812 Jun 05, 2006, 03:53 PM Lol, I'd forgotten about that - cheers.
Man, are all programming languages as sensitive as that?
TheLopez Jun 05, 2006, 03:55 PM Lol, I'd forgotten about that - cheers.
Man, are all programming languages as sensitive as that?
Nope, only some as silly as python.
zulu9812 Jun 05, 2006, 05:54 PM Incidentally, it still doesn't work. I noticed that my custom event manager was missing something from the RUN event manager (the UnitBuilt was more extensive) so I added that in, but it made no difference. In case it helps, here is the updated folder.
http://www.civfanatics.net/uploads11/Assets2.zip
I did consider that it was because the SevoMod had civilizations that your mod wouldn't cater for, but I tested this with Germany, France and the Celts and still no joy.
TheLopez Jun 05, 2006, 06:05 PM Incidentally, it still doesn't work. I noticed that my custom event manager was missing something from the RUN event manager (the UnitBuilt was more extensive) so I added that in, but it made no difference. In case it helps, here is the updated folder.
http://www.civfanatics.net/uploads11/Assets2.zip
I did consider that it was because the SevoMod had civilizations that your mod wouldn't counter for, but I tested this with Germany, France and the Celts and still no joy.
Your onUnitCreated method in your CvSevoEventManager file is still not correct. Here is what the CvSevoEventManager file should look like:
#
# SevoMod (by Sevo, duh!)
# CvSevoEventManager
#
from CvPythonExtensions import *
import CvUtil
import CvEventManager
import sys
import PyHelpers
import CvCameraControls
import SevoMod
import RandomNameUtils
gc = CyGlobalContext()
cd = SevoMod.CulturalDecay()
rf = SevoMod.RealFort()
tc = SevoMod.TechConquest()
Forest = SevoMod.NewForest()
ancient = SevoMod.AncientTemple()
SevoTraits = SevoMod.SevoTraits()
jungleBurn = SevoMod.JungleBurner()
realSlavery = SevoMod.RealSlavery()
CMI = CvEventManager.CvScreensInterface.CvMainInterface
PyPlayer = PyHelpers.PyPlayer
# globals
################################################## #
class CvSevoEventManager(CvEventManager.CvEventManager):
def __init__(self):
# initialize base class
self.parent = CvEventManager.CvEventManager
self.parent.__init__(self)
def onUnitCreated(self, argsList):
'Unit Completed'
unit = argsList[0]
player = PyPlayer(unit.getOwner())
SevoTraits.checkNewUnit(argsList[0],false)
self.parent.onUnitCreated(self, argsList)
iOwner = gc.getPlayer(unit.getOwner())
iCivilizationType = iOwner.getCivilizationType()
unit.setName(RandomNameUtils.getRandomCivilization Name(iCivilizationType))
def onBeginGameTurn(self, argsList):
iGameTurn = argsList[0]
# I am intentionally NOT going to parent onBeginGameTurn
# The CvTopCivs popup screen is generating errors b/c of a random num generator prob.
# That is the only other function called, so screw it.
#self.parent.onBeginGameTurn(self, argsList)
def onUnitMove(self, argsList):
rf.onUnitMove(argsList)
SevoTraits.onUnitMove(argsList)
self.parent.onUnitMove(self, argsList)
def onLoadGame(self, argsList):
self.parent.onLoadGame(self, argsList)
# Gotta reload all the __init__ variables in the system!
SevoTraits.__init__()
def onGameStart(self, argsList):
CMI.CvMainInterface.pOldPlot = 0
self.parent.onGameStart(self, argsList)
def onTechAcquired(self, argsList):
rf.onTechAcquired(argsList)
#tw.onTechAcquired(argsList)
self.parent.onTechAcquired(self, argsList)
def onCityGrowth(self, argsList):
SevoTraits.checkCityForTrait(argsList[0])
self.parent.onCityGrowth(self,argsList)
def onCityAcquired(self, argsList):
tc.onCityAcquired(argsList)
SevoTraits.checkCityForTrait(argsList[2])
self.parent.onCityAcquired(self, argsList)
def onCityBuilt(self, argsList):
if (gc.getGame().getElapsedGameTurns() < 11) :
jungleBurn.onCityBuilt(argsList)
self.parent.onCityBuilt(self, argsList)
def onEndGameTurn(self, argsList):
cd.onEndGameTurn(argsList)
Forest.updateAllPlots()
self.parent.onEndGameTurn(self, argsList)
def onBeginPlayerTurn(self, argsList):
self.parent.onBeginPlayerTurn(self, argsList)
def onEndPlayerTurn(self, argsList):
iGameTurn, iPlayer = argsList
realSlavery.onEndPlayerTurn(argsList)
self.parent.onEndPlayerTurn
def onImprovementBuilt(self, argsList):
rf.onImprovementBuilt(argsList)
#nf.onImprovementBuilt(argsList)
ancient.onImprovementBuilt(argsList)
self.parent.onImprovementBuilt(self, argsList)
def onUnitBuilt(self, argsList):
SevoTraits.checkNewUnit(argsList[1],true)
self.parent.onUnitBuilt(self, argsList)
iOwner = gc.getPlayer(unit.getOwner())
iCivilizationType = iOwner.getCivilizationType()
unit.setName(RandomNameUtils.getRandomCivilization Name(iCivilizationType))
def onUnitPromoted(self,argsList):
self.parent.onUnitPromoted(self, argsList)
def onCombatResult(self, argsList):
realSlavery.onCombatResult(argsList)
self.parent.onCombatResult(self, argsList)
zulu9812 Jun 06, 2006, 03:44 AM Mmm, it's still not working. I copied everything from inside that spoiler tag and pasted it into a new text file and from there to my event manager file, writing over everything. I also used a comparison tool to check that the .txt file matched the .py file (which it did).
The Great Apple Jun 06, 2006, 04:22 AM From the zip you uploaded it would seem that you have 2 event managers, one in Assets/Python, and one in the mod root directory. The one is Assets/Python is the one being run, and it doesn't seem to have been updated with the indentation fix.
zulu9812 Jun 06, 2006, 07:23 AM From the zip you uploaded it would seem that you have 2 event managers, one in Assets/Python, and one in the mod root directory. The one is Assets/Python is the one being run, and it doesn't seem to have been updated with the indentation fix.
Cheers for the help. That's an outdated zip. This is the python folder that I'm working with, but I'm still not getting random names.
http://www.civfanatics.net/uploads11/python.zip
The Great Apple Jun 06, 2006, 07:40 AM Gotcha.
Okies - I think it is because you've put the code into onUnitBuilt as well as onUnitCreated, but the on in onUnitBuilt won't work, because 'unit' isn't defined - this is throwing an error so it doesn't even get to onUnitCreated. You should be able to get away with deleting the bold bits (but only in the onUnitBuilt method - not onUnitCreated)
def onUnitBuilt(self, argsList):
SevoTraits.checkNewUnit(argsList[1],true)
self.parent.onUnitBuilt(self, argsList)
iOwner = gc.getPlayer(unit.getOwner())
iCivilizationType = iOwner.getCivilizationType()
unit.setName(RandomNameUtils.getRandomCivilization Name(iCivilizationType))
TheLopez Jun 06, 2006, 07:52 AM Gotcha.
Okies - I think it is because you've put the code into onUnitBuilt as well as onUnitCreated, but the on in onUnitBuilt won't work, because 'unit' isn't defined - this is throwing an error so it doesn't even get to onUnitCreated. You should be able to get away with deleting the bold bits (but only in the onUnitBuilt method - not onUnitCreated)
def onUnitBuilt(self, argsList):
SevoTraits.checkNewUnit(argsList[1],true)
self.parent.onUnitBuilt(self, argsList)
iOwner = gc.getPlayer(unit.getOwner())
iCivilizationType = iOwner.getCivilizationType()
unit.setName(RandomNameUtils.getRandomCivilization Name(iCivilizationType))
Actually, it should be in both methods. onUnitBuilt be:
def onUnitBuilt(self, argsList):
SevoTraits.checkNewUnit(argsList[1],true)
self.parent.onUnitBuilt(self, argsList)
city = argsList[0]
unit = argsList[1]
iOwner = gc.getPlayer(unit.getOwner())
iCivilizationType = iOwner.getCivilizationType()
unit.setName(RandomNameUtils.getRandomCivilization Name(iCivilizationType))
zulu9812 Jun 06, 2006, 07:55 AM So, what's stopping the mod from working is that I'm missing the part in bold?
def onUnitBuilt(self, argsList):
SevoTraits.checkNewUnit(argsList[1],true)
self.parent.onUnitBuilt(self, argsList)
city = argsList[0]
unit = argsList[1]
iOwner = gc.getPlayer(unit.getOwner())
iCivilizationType = iOwner.getCivilizationType()
unit.setName(RandomNameUtils.getRandomCivilization Name(iCivilizationType))
TheLopez Jun 06, 2006, 08:26 AM So, what's stopping the mod from working is that I'm missing the part in bold?
def onUnitBuilt(self, argsList):
SevoTraits.checkNewUnit(argsList[1],true)
self.parent.onUnitBuilt(self, argsList)
city = argsList[0]
unit = argsList[1]
iOwner = gc.getPlayer(unit.getOwner())
iCivilizationType = iOwner.getCivilizationType()
unit.setName(RandomNameUtils.getRandomCivilization Name(iCivilizationType))
sounds like it.
The Great Apple Jun 06, 2006, 08:59 AM onUnitCreated and onUnitBuilt are two different events which often get triggered together, although not always. At the moment you have the code in both, where it only ever need be in one - onUnitCreated if you want it for all your units (starting units & units not built), and onUnitBuilt for only built units. I'm not certain onUnitCreated doesn't trigger when you upgrade a unit though.
zulu9812 Jun 06, 2006, 10:58 AM Goddamitt!
Still not working! Here is the event manager that I am using (including the fix that TheLopez just suggested), although I can't help but think that the problem might lie elsewhere,
The Great Apple Jun 06, 2006, 11:07 AM Right. I have no idea now. Time for plan B!
These ini switches in the main ini file should enable python error popups (change old values to new), which should hopefully say what is going wrong when the naming doesn't work:
HidePythonExceptions = 0
ShowPythonDebugMsgs = 1
LoggingEnabled = 1
MessageLog = 1
After failing to do the naming a popup should come up, the contents of which should be written to My Docs/My Games/Civ 4/Logs/PythonErr.log. If you post that log up then it should be faily easy to see what is going wrong.
If you don't get a popup, then something more fundamental is wrong (the code isn't being called, or for some reason is being cut). I'm pretty sure you'll get a popup...
TheLopez Jun 06, 2006, 11:39 AM Goddamitt!
Still not working! Here is the event manager that I am using (including the fix that TheLopez just suggested), although I can't help but think that the problem might lie elsewhere,
zulu9812, What version of the SevoMod are you using?
zulu9812 Jun 06, 2006, 11:43 AM I am using 2.9z
TheLopez Jun 06, 2006, 11:55 AM I am using 2.9z
Ah, there's the problem, whenever I run Sevo Mod 2.9z with the debug messages turned on I get an error message myself that says:
AttributeError: RealSlavery instance has no attribute 'playerSlaves'
you might want to comment out all RealSlavery related items in the event manager and see if that resolves it.
zulu9812 Jun 06, 2006, 04:13 PM These ini switches in the main ini file should enable python error popups (change old values to new), which should hopefully say what is going wrong when the naming doesn't work
I wasn't sure which INI file you meant, so I entered them into the mod's ini file (in the mod root directory) and the game's ini file (in the Civ4 directory under My Documents/My Games)
After failing to do the naming a popup should come up, the contents of which should be written to My Docs/My Games/Civ 4/Logs/PythonErr.log. If you post that log up then it should be faily easy to see what is going wrong.
If you don't get a popup, then something more fundamental is wrong (the code isn't being called, or for some reason is being cut). I'm pretty sure you'll get a popup...
No popup :crazyeye:
An error log was found in that directory, but I can't be sure how long the contents have been there. Additionally, the log was called PythonErr2.log. I took a look at it, and I'm probably wrong, but it seemed to indicate a failure to import the entire SevoEventManager. I've attached that log to this post.
you might want to comment out all RealSlavery related items in the event manager and see if that resolves it.
I did that, but still no random names. There were 3 instances of RealSlavery - I deleted each line, but left the surrounding module.
TheLopez Jun 06, 2006, 04:14 PM I wasn't sure which INI file you meant, so I entered them into the mod's ini file (in the mod root directory) and the game's ini file (in the Civ4 directory under My Documents/My Games)
[code]
No popup :crazyeye:
An error log was found in that directory, but I can't be sure how long the contents have been there. Additionally, the log was called PythonErr2.log. I took a look at it, and I'm probably wrong, but it seemed to indicate a failure to import the entire SevoEventManager. I've attached that log to this post.
I did that, but still no random names. There were 3 instances of RealSlavery - I deleted each line, but left the surrounding module.
Please upload your CvEventInterface file.
zulu9812 Jun 06, 2006, 04:28 PM Sure. I took a look at it and the part inbetween #<RUN START> and #<RUN END> looked like it might be interfering with the call for the SevoEventManager, so I deleted it and tried again - but still no luck.
TheLopez Jun 06, 2006, 05:22 PM zulu,
Are you only trying to combine the random unit mod and the latest release of the Sevo mod?
zulu9812 Jun 06, 2006, 07:03 PM That and GIR's add-on to the Sevo mod - http://forums.civfanatics.com/showthread.php?t=170012
(I'm not trying to mod-in GIR's add-on myself, I just installed it).
zulu9812 Jun 09, 2006, 10:49 AM Any updates?
TheLopez Jun 09, 2006, 11:25 AM Any updates?
Here you go, I am attaching a new version of the event manager and random unit name utils file.
Just add these to a fresh copy of the Sevo mod and it should work like expected.
zulu9812 Jun 09, 2006, 04:16 PM Cheers for that. It seems to be working now. What was the problem in the end?
mikezang Aug 05, 2006, 08:41 PM Does anyone tell me what different from onUnitBuilt and onUnitCreated?
May I have to handle both of them for making Unit Name?
mikezang Aug 05, 2006, 09:29 PM I also what to know where I can find the unit name, I used this mod and no error for python code. but it looks like no any unit name in my unit.
mikezang Aug 05, 2006, 09:49 PM Here's one that works with SimCutie's event manager:
#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.
I tried to use this code, but I can't find unit name, how can I know if my unit with name?
TheLopez Aug 05, 2006, 11:32 PM Mike, why are you using simcutie's event manager with this mod? You should use Dr. Elmer Jiggle's event manager. Anyways thats beside the point. Change your onUnitBuilt to be this.
def onUnitBuilt(argsList):
city = argsList[0]
unit = argsList[1]
#unit.setName(findOrdinal(getCityNumber(city)) + " " + unit.getName() + " of " + city.getName())
iOwner = gc.getPlayer(unit.getOwner())
iCivilizationType = iOwner.getCivilizationType()
unit.setName(RandomNameUtils.getRandomCivilization Name(iCivilizationType))
#unit.setName(RandomNameUtils.getRandomName())
return 0
mikezang Aug 05, 2006, 11:40 PM Thanks for your advise and answer, TheLopez, I will try it.
By the way, can you tell me what different from onUnitBuilt and onUnitCreated?
TheLopez Aug 05, 2006, 11:42 PM onUnitBuilt is called when a unit is actually built at a city and onUnitCreated is called when a unit is created buy a goodie hut, world builder etc. This means that when a unit is built both onUnitBuilt and onUnitCreated are called, though I cannot remember right now off the top of my head in what order.
mikezang Aug 06, 2006, 12:23 AM Well, I see.
By the way, I want to name the first unit when a game is started, is it possible? how can I do it if it is possible?
mikezang Aug 06, 2006, 02:31 AM Then, What different from these two as below?
# unitS = objUnit.getName()
# unitS = PyInfo.UnitInfo(objUnit.getUnitType()).getDescript ion()
The Great Apple Aug 06, 2006, 04:56 AM Mike, why are you using simcutie's event manager with this mod? You should use Dr. Elmer Jiggle's event manager.
Without sounding rude... why? IMO SimCutie's is better - it does a similar job, and is alot more pluggable. The only reason against using it may be because it isn't as mainstream as Doc Jiggle's. I personally work with SCs, as I find it easier to use.
Jeckel Aug 06, 2006, 06:54 AM When a unit is built in a city, onUnitCreated is called first, then onUnitBuilt is called. So if both event handlers give the unit a name, the onUnitBuilt name will be the one the unit ends up with. :)
mikezang Aug 06, 2006, 09:26 PM I solved this problems. I gave any unit a "Wild" prefix and count it in onUnitCreated, then I check if it has a name in onUnitBuilt, count down "Wild" if it named, then gave a cityname.
As default onUnitBuild is called before custom onUnitBuilt, the CvAdvisorUtils.unitBuiltFeats(city, unit) in CvEventManager.py should be moved to custom's onUnitBuilt, or the prompt message will be wrong.
mikezang Aug 09, 2006, 08:59 AM Hi, I coded as below to name my unit. My problem is The Great Person is also named so that I can't use GP MOD to show picture, what can I do? How can I check the unit type to know if it is a GP?
def onUnitCreated(self, argsList):
'Unit Completed'
unit = argsList[0]
cityname = PyPlayer(unit.getOwner()).getCivilizationShortDesc ription()
zsName = getUnitNameWithCity(cityname, unit)
unit.setName(zsName)
def onUnitBuilt(self, argsList):
'Unit Completed'
city = argsList[0]
unit = argsList[1]
cityname = city.getName()
if (len(unit.getNameNoDesc()) > 0):
cityunitS = PyPlayer(unit.getOwner()).getCivilizationShortDesc ription() + PyInfo.UnitInfo(unit.getUnitType()).getDescription ()
unitCount = sdGetVal(zsModName, cityunitS, "Cnt")
unitCount = unitCount - 1
sdSetVal(zsModName, cityunitS, "Cnt", unitCount)
zsName = getUnitNameWithCity(cityname, unit)
unit.setName(zsName)
CvAdvisorUtils.unitBuiltFeats(city, unit)
mikezang Aug 09, 2006, 09:26 AM I did it by code as below:
def onUnitCreated(self, argsList):
'Unit Completed'
unit = argsList[0]
if (len(unit.getNameNoDesc()) > 0):
return
prefix = PyPlayer(unit.getOwner()).getCivilizationShortDesc ription()
zsName = getUnitNameWithCity(prefix, unit)
unit.setName(zsName)
oxygen@civ Aug 24, 2006, 09:38 PM Random Unit Names Mod
By: TheLopez
Last Updated 06/09/06
Version: v0.5.2
Patch Compatibility: v1.52, 1.61
MP Compatible: ?
Download Mod v0.5.2 (http://www.aracnet.com/~opus/Civiv/RandomUnitNamesv0.5.2.zip)
Description:
This mod will give any unit created in the game a unique name. The current
version of this mod can generate over well to many names to count. There are
two ways to use this mod. The first is to just call the getRandomName method
which will return just that, a random name. The second and new way to use this
mod is to use the getRandomCivilizationName passing in the civilization type ID
number. This mod should NOT be used as a stand-alone mod. You should just use
the RandomNameUtils.py file instead. The other files are just used to show
how the RandomNameUtils.py can be used.
Installation Instructions:
1) Unzip this into the "civ4_install_folder\Mods\" folder.
2) Open the CivilizationIV.ini configuration file
3) Change the Mod line to read: Mod = Mods\Random Unit Names
4) Load the game.
5) Then play as normal.
-----Version Information-----
-----v0.5.x------
- Tweaked the Japan names so they don't always produce really long names
- 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.
-----v0.4------
- Forked off the mercenaries mod random name generation code
- Stripped the mercenary specific code from the mod
-----===Credits & Thanks===-----
- Exavier
Composite Mod - readme.txt format
hi, guys. very nice work.
but i am playing WL now.
Do we have another patch which the function is same as this for WL?
Gaurav Dec 29, 2006, 09:26 AM If someone wants to add other names they will have to do it themselves :p.
I was wondering where you came up with the names for each of the civilizations. I googled around a bit and found first names easily, but usually way too many, and usually designed for naming your baby. :lol: Last names and middle names are much harder to come up with. :sad:
jbolton0421 Jan 01, 2007, 12:22 PM This discussion was last winter. Did anyone make progress on it?
I try to do something similar manually when I play, but bog down when I have to mobilize for a big war.
:blush:
Personally, I would like a mod that numbers units by type,
For example, the first archer you build would be named "1st Militia"
Militia would be city defense units.
Infantry would be walking attack units (Swordsman, etc)
Cavalry would be mounted units.
etc etc.
So the idea is early in the game you create a Horse Archer which gets named "5th Cavalry"
Eventually, that unit could upgrade into a gunship, but would have the historical name "5th Cavalry"
Just like the Scottish Black Watch used to use muskets, now they use Armoured Personnel Carriers.
Hey Lopez, give me insight as to how you did this one and maybe I'll do my idea myself.
Hmmm..... well that is a very interesting idea. When I put out the random unit names mod I just ripped out the code from my Merc. Mod and made it available since someone had requested it. I am planning to extend it by making the random names a bit more specific depending on the civilization for the unit. Though I could introduce an option to do the type of naming that you are asking for as well. Let me mull this over and I'll see what I can do after I release my Merc. mod.
Well, you can download the mod and see for yourself how I did it.
Gaurav Jan 01, 2007, 01:25 PM This discussion was last winter. Did anyone make progress on it?
I try to do something similar manually when I play, but bog down when I have to mobilize for a big war.
:blush:
Nexus did something like this. I don't think he ever separated out the final version of his component. See here (http://forums.civfanatics.com/showthread.php?t=163524).
On the other hand, you can find it included in the best combined unit naming pack: JRandomNames (http://forums.civfanatics.com/showthread.php?t=178107) by Jeckel.
I'm not sure if any of these work in Warlords.
|
|