Good BTS Unit Renaming Mod?

Nkot

Chieftain
Joined
Jul 2, 2007
Messages
58
Location
East Coast, US
Does anyone know a good BTS unit renaming mod? I've looked at several (TheLopez's Random Unit Names and Jeckel's JRandomNames), but they only seem to work for Warlords/Vanilla. I'm not really interested in a mod that provides more features than just naming, since I plan to make my first foray into python programming by tweaking it a little bit.

Also, if anyone knew how the above mentioned mods could be made compatible with BTS that would be great too. As it is right now, I don't know enough to do this myself.
 
What is it about the mods you've found that makes them not compatible with BTS? The core of the mods (the actual event handling and name-changing) shouldn't change much between the different versions but if there's lots of bells and whistles and stuff and easy configuration then I could see how it would be a little daunting to try. As xienwolf said, BUG's unit namer works with BTS but that's probably the most complex example you can find since it includes everything but the kitchen sink in terms of naming options and uses BUG's own event-handling mechanisms.

Anyhow, the big thing about a unit namer is that at its core it's an event handler. A unit namer will override various unit-related events like unitCreated, unitBuilt, unitPromoted, etc. and somewhere in there will call the CyUnit.setName() function to change the name of the given unit. I'm not sure where to point you for an entry-level tutorial on event-overriding though since I'm only really used to the fairly unique BUG event handling, but here are some general pointers.

The simplest (and least portable) approach is to copy the game's original CvEventManager.py to your Custom Assets folder and add your changes to the appropriate event handlers there. For example, the following is the onUnitBuilt handler from the BTS 3.17 CvEventManager:
Code:
	def onUnitBuilt(self, argsList):
		'Unit Completed'
		city = argsList[0]
		unit = argsList[1]
		player = PyPlayer(city.getOwner())

		CvAdvisorUtils.unitBuiltFeats(city, unit)
		
		if (not self.__LOG_UNITBUILD):
			return
		CvUtil.pyPrint('%s was finished by Player %d Civilization %s' 
			%(PyInfo.UnitInfo(unit.getUnitType()).getDescription(), player.getID(), player.getCivilizationName()))
Adding the following line (colored green) would set every unit made to be named "Bob":
Code:
	def onUnitBuilt(self, argsList):
		'Unit Completed'
		city = argsList[0]
		unit = argsList[1]
		[COLOR="Green"]unit.setName("Bob")[/COLOR]
		player = PyPlayer(city.getOwner())

		CvAdvisorUtils.unitBuiltFeats(city, unit)
		
		if (not self.__LOG_UNITBUILD):
			return
		CvUtil.pyPrint('%s was finished by Player %d Civilization %s' 
			%(PyInfo.UnitInfo(unit.getUnitType()).getDescription(), player.getID(), player.getCivilizationName()))

As you might imagine, making many changes to the original event handler like this becomes a bit of a pain when you want to merge your changes with other mods though so most people use custom event managers which are more self-contained. There's an old thread from apolyton about this approach and probably some stuff here at CFC if you do some searching. I think most mods that override events use Dr Elmer Jiggle's Custom Event Manager although I don't have a link for it.
 
Thanks. I've been playing around with this a little bit, but I can't figure out how to name units that are placed in world builder or start in the game. Thoughts?
 
I figured it out.

The whole problem seemed to be with PythonCallbackDefines.xml. By changing

<Define>
<DefineName>USE_ON_UNIT_CREATED_CALLBACK</DefineName>
<iDefineIntVal>0</iDefineIntVal>
</Define>

to

<Define>
<DefineName>USE_ON_UNIT_CREATED_CALLBACK</DefineName>
<iDefineIntVal>1</iDefineIntVal>
</Define>

I fixed the problem to name created units. I suspect that this file is the reason for the old naming mods not working as well. If anyone could tell me more about how to use this file, that would be greatly appreciated.
 
Good job. I always forget about that.

Basically, the SDK provides a way for you to hook into certain functions via Python in order to either supplement or override the normal behavior; these functions are called callbacks. However, for performance reasons, many of them are disabled initially; the idea is that if you aren't actually using all of them, there's no reason for the game to waste time by calling all of them. PythonCallbackDefines.xml is where you enable or disable them. The functions themselves exist mostly in CvGameUtils, but some of them, as you've found, are related to event-handling.
 
Back
Top Bottom