[PYTHONCOMP] Random Unit Names

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 ...

PHP:
civtype = gc.getPlayer(unit.getOwner()).getCivilizationType()
civtype = unit.getOwner().getCivilizationType()

... but they caused errors. Suggestions?
 
This code works for me:
Code:
		objOwner = gc.getPlayer(unit.getOwner())
		iCivilizationType = objOwner.getCivilizationType()
		unit.setName(RandomNameUtils.getRandomCivilizationName(iCivilizationType))
 
Ok, that works - thx. I thought that I did try a combination that looked like that. Is there a problem with something like this ...
Code:
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?
 
Code:
objOwner = gc.getPlayer(unit.getOwner())
if(objOwner.isHuman()):
	iCivilizationType = objOwner.getCivilizationType()
	unit.setName(RandomNameUtils.getRandomCivilizationName(iCivilizationType))
 
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
 
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.
 
@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.
 
@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!
 
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:
Code:
	unit.setName(RandomNameUtils.getRandomName())

to

Code:
		iOwner = gc.getPlayer(unit.getOwner())
		iCivilizationType = iOwner.getCivilizationType()
		unit.setName(RandomNameUtils.getRandomCivilizationName(iCivilizationType))
 
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.
 
Can you please post a copy of your event manager class so I can see what you did in it?
 
zulu9812 said:
do you mean this?

Yep, your onUnitCreated method should be like this:
Code:
	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.getRandomCivilizationName(iCivilizationType))
 
It's the indentation. Python treats white space as syntax.

Instead of
Code:
		self.parent.onUnitCreated(self, argsList)
		iOwner = gc.getPlayer(unit.getOwner())
		iCivilizationType = iOwner.getCivilizationType()

unit.setName(RandomNameUtils.getRandomCivilizationName(iCivilizationType))
you need:
Code:
		self.parent.onUnitCreated(self, argsList)
		iOwner = gc.getPlayer(unit.getOwner())
		iCivilizationType = iOwner.getCivilizationType()

		unit.setName(RandomNameUtils.getRandomCivilizationName(iCivilizationType))
That should work.
 
zulu9812 said:
Lol, I'd forgotten about that - cheers.

Man, are all programming languages as sensitive as that?


Nope, only some as silly as python.
 
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.
 
zulu9812 said:
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:

Spoiler :

Code:
#
# 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.getRandomCivilizationName(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.getRandomCivilizationName(iCivilizationType))

	def onUnitPromoted(self,argsList):
		self.parent.onUnitPromoted(self, argsList)
		
		
	def onCombatResult(self, argsList):
		realSlavery.onCombatResult(argsList)
		self.parent.onCombatResult(self, argsList)
 
Top Bottom