Unit Naming

Is it possible to have the unit's you start with renamed? You know that first warrior or scout?
I'll take a look at this tonight. It's absolutely possible, just gotta see how much work it is. If the API to access the naming is done well, it'll be a snap: loop over all units and call naming function for each.
I think it is possible in the 'GameStart' event (or something like that) ... just check that it is Turn 0 before you call loop over all of the players units and call the rename unit function.

Actually, I would do it in the 'end turn' event (again, checking for turn 0) so that you don't destroy the ability to regenerate the map (unit naming stores value in the save and doing that removes the regenerate option.

BTW - what happens with free units from huts?
 
BTW - what happens with free units from huts?

It doesn't generate a name, just the standard civ name. I was going to look into that next. I believe there's a hook like "onGiftReceived" or "onGoodyGifted" or some such that I saw in the main EventHandler last night that I believe you could hook into.
 
Well I've been playing with for a few hours now and I can't seem to get the eventhandlers for either onGameStart or onEndGameTurn to fire.

Here's the code I used to hook up the event in UnitNameEventManager.py:

Code:
def __init__(self, eventManager, *args, **kwargs):
		super(BuildUnitName, self).__init__(eventManager, *args, **kwargs)

		eventManager.addEventHandler("kbdEvent", self.onKbdEvent)
		eventManager.addEventHandler("unitBuilt", self.onUnitBuilt)
		eventManager.addEventHandler("endTurn", self.onEndGameTurn)

		self.eventMgr = eventManager
		self.config = None

And here's the coded for the event:

Code:
def onEndGameTurn(self, argsList):
		'Called at the end of the end of each turn'
		iGameTurn = argsList[0]

		for iPlayer in range(gc.getMAX_PLAYERS()):
			pPlayer = gc.getPlayer(iPlayer)
			lUnitReName = UnitReName()

			if (pPlayer.isAlive() and pPlayer.isHuman()):
				(pUnit, iter) = pPlayer.firstUnit(false)
				while (pUnit):
					zsEra = gc.getEraInfo(pPlayer.getCurrentEra()).getType()
					zsUnitCombat = lUnitReName.getUnitCombat(pUnit)
					zsUnitClass = gc.getUnitClassInfo(pUnit.getUnitClassType()).getType()

					BUGPrint("ERA(%s)" % (zsEra))
					BUGPrint("Combat(%s)" % (zsUnitCombat))
					BUGPrint("Class(%s)" % (zsUnitClass))

					zsUnitNameConv = lUnitReName.getUnitNameConvFromIniFile(zsEra, zsUnitClass, zsUnitCombat)
					zsUnitName = lUnitReName.getUnitName(zsUnitNameConv, pUnit, pCity, True)

					BUGPrint("onUnitBuild-D")

					if not (zsUnitName == ""):
						pUnit.setName(zsUnitName)

					BUGPrint("onUnitBuild-E")

					(pUnit, iter) = pPlayer.nextUnit(iter, false)
		return

My python's not that good so it's probably buggy as hell, but I believe something like that is what should happen.
 
A couple random ideas:

  1. Name initial units in onEndTurnReady event (fires after you've moved all your units).
  2. Name initial units when the first city is founded. This way there's also a city to use for the name.
  3. Name goody hut units using the capital as well.
  4. Or use the civilization name (England) for all free units.
 
As for detecting units from goody huts, it looks like I can handle it inside onGoodyReceived. The event is fired before the unit that takes the hut moves to the plot, so if the GoodyType gifts a unit I can assume the one unit on the goody plot is the unit to be named. :)
 
Units from goody huts and initial units are now named, the latter when you found your first city. If you don't have a city when you get a unit from a goody hut, and the naming code for that unit type includes the city name, your civilization's empire name is used instead (e.g. Scout 1 of England).
 
I like that it waits on the first city to name your starting units, because that gives you the opportunity to turn off unit naming before it starts doing it automatically. :)
 
Should I add a little warning on the screen?

zOMG YOUR UNITS WILL BE RENAMED IF YOU DON'T TURN IT OFF!!1!!11!1!
 
zOMG YOUR UNITS WILL BE RENAMED IF YOU DON'T TURN IT OFF!!1!!11!1!
ummm - you have to work on your interpersonal skills EF ... his name is 'MadmanAtW', not 'zOMG'.
 
If i put in ^dm^ i get for example "DOMAIN_LAND" instead of "Land"
"^cntd[o]^ ^dm^ Army" will give "1st DOMAIN_LAND Army".

Is this supposed to be like this?
 
probably not - that looks like a bug. I'll take a look at it when I get back from my trip (2 weeks).
 
A question, where can i get the latest release? And how do i update the version currently in BUG (as downloaded about last week)?

Also i seem to be having a problem with using multiple counts.
For example "^ut^ ^cnt[n]^, ^cnt[o][c]^ unit from ^ct^" will give "Warrior 1, ^cnt[o][c]^ unit from Thebes". I tried using the old convention but it gave the same error. It gives this error everytime i use multiple counts (eg unit & city, domain & city, ...)
 
You can grab the file from our here and place it into [Custom]Assets/Python/Contrib, overwriting the file that's there.
 
Also i seem to be having a problem with using multiple counts. For example "^ut^ ^cnt[n]^, ^cnt[o][c]^ unit from ^ct^" will give "Warrior 1, ^cnt[o][c]^ unit from Thebes". I tried using the old convention but it gave the same error. It gives this error everytime i use multiple counts (eg unit & city, domain & city, ...)
and you cannot use multiple counts like that.
 
You can grab the file from our here and place it into [Custom]Assets/Python/Contrib, overwriting the file that's there.

Ok thanks.

and you cannot use multiple counts like that.

Is it possible to implement this? I'm not familiar enough with python syntax to easily code in it, but by looking through the code i noticed there is a one time call to "getCounter". Perhaps it could be looped over a "getNextCounter"?
 
I implemented the multiple counts. Since "getCounter" in essence already functions like a "getNextCounter", all that was needed was a simple while-loop around part of the code.

Code:
#              check if there are any more codes to swap out, return if not
		while (zsName.find("^") > -1):

#			determine what I am counting across
			zsSDKey = self.getCounter(zsName)
			if zsSDKey == "UNIT":		zsSDKey = zsSDKey + zsUnit
			elif zsSDKey == "COMBAT":	zsSDKey = zsSDKey + zsUnitCombat
			elif zsSDKey == "CITY":		zsSDKey = zsSDKey + zsCity
			elif zsSDKey == "UNITCITY": zsSDKey = zsSDKey + zsUnit + zsCity
			elif zsSDKey == "DOMAIN":	zsSDKey = zsSDKey + zsUnitDomain

			#BUGPrint("UnitNameEM-E [" + zsSDKey + "]")

#			see if we have already started this counter
			if (sdEntityExists(sdGroup, zsSDKey) == False):
				#Since no record create entries
				ziTT1 = self.getTotal1(zsName)
				ziTT2 = self.getTotal2(zsName)
				zDic = {'cnt':0, 'tt1':ziTT1, 'tt2':ziTT2}
				sdEntityInit(sdGroup, zsSDKey, zDic)

#			get the count values
			ziCnt = sdGetVal(sdGroup, zsSDKey, "cnt")
			ziTT1 = sdGetVal(sdGroup, zsSDKey, "tt1")
			ziTT2 = sdGetVal(sdGroup, zsSDKey, "tt2")

			#BUGPrint("UnitNameEM-F [" + str(ziCnt) + "] [" + str(ziTT1) + "] [" + str(ziTT2) + "]")

#			increment count, adjust totals if required
			if bIncrementCounter:
				ziCnt = ziCnt + 1
				if (ziCnt > ziTT1
				and ziTT1 > 0):
					ziCnt = 1
					ziTT1 = self.getTotal1(zsName)
					ziTT2 = ziTT2 + 1

#			store the new values
			sdSetVal(sdGroup, zsSDKey, "cnt", ziCnt)
			sdSetVal(sdGroup, zsSDKey, "tt1", ziTT1)
			sdSetVal(sdGroup, zsSDKey, "tt2", ziTT2)

#			swap out the count code items for count value
			zsName = self.swapCountCode(zsName, "^cnt", ziCnt)
			zsName = self.swapCountCode(zsName, "^tt1", ziTT1)
			zsName = self.swapCountCode(zsName, "^tt2", ziTT2)

		return zsName

Seems to work.

Perhaps though there could be problems with tt1 and tt2 as they are incremented multiple times when you use multiple counts, or as it seems they are specific relative to each key so you'd have multiple tt1/tt2 counters.
 
Thanks for that. :goodjob: Each counter type has its own current, tt1, and tt2 values. I'll put this into BUG later this weekend.
 
there was some talk to overhaul the counter code a few pages back - we had a solution for unlimited number of counters - I just never got the time to code it up.
 
Top Bottom