1. We have added the ability to collapse/expand forum categories and widgets on forum home.
    Dismiss Notice
  2. All Civ avatars are brought back and available for selection in the Avatar Gallery! There are 945 avatars total.
    Dismiss Notice
  3. To make the site more secure, we have installed SSL certificates and enabled HTTPS for both the main site and forums.
    Dismiss Notice
  4. Civ6 is released! Order now! (Amazon US | Amazon UK | Amazon CA | Amazon DE | Amazon FR)
    Dismiss Notice
  5. Dismiss Notice
  6. Forum account upgrades are available for ad-free browsing.
    Dismiss Notice

Unit Naming

Discussion in 'Civ4 - BTS Unaltered Gameplay (BUG, BAT and BULL)' started by ruff_hi, Sep 3, 2007.

  1. ruff_hi

    ruff_hi Live 4ever! Or die trying

    Joined:
    Oct 24, 2005
    Messages:
    8,815
    Location:
    an Aussie in Boston
    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?
     
  2. DaddyHolby

    DaddyHolby Chieftain

    Joined:
    Feb 20, 2003
    Messages:
    32
    Location:
    Superior, Co
    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.
     
  3. DaddyHolby

    DaddyHolby Chieftain

    Joined:
    Feb 20, 2003
    Messages:
    32
    Location:
    Superior, Co
    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.
     
  4. EmperorFool

    EmperorFool Chieftain

    Joined:
    Mar 2, 2007
    Messages:
    9,633
    Location:
    Mountain View, California
    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.
     
  5. EmperorFool

    EmperorFool Chieftain

    Joined:
    Mar 2, 2007
    Messages:
    9,633
    Location:
    Mountain View, California
    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. :)
     
  6. EmperorFool

    EmperorFool Chieftain

    Joined:
    Mar 2, 2007
    Messages:
    9,633
    Location:
    Mountain View, California
    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).
     
  7. DaddyHolby

    DaddyHolby Chieftain

    Joined:
    Feb 20, 2003
    Messages:
    32
    Location:
    Superior, Co
  8. MadmanAtW

    MadmanAtW Knight

    Joined:
    Apr 13, 2008
    Messages:
    579
    Location:
    San Leandro, CA
    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. :)
     
  9. EmperorFool

    EmperorFool Chieftain

    Joined:
    Mar 2, 2007
    Messages:
    9,633
    Location:
    Mountain View, California
    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!
     
  10. ruff_hi

    ruff_hi Live 4ever! Or die trying

    Joined:
    Oct 24, 2005
    Messages:
    8,815
    Location:
    an Aussie in Boston
    ummm - you have to work on your interpersonal skills EF ... his name is 'MadmanAtW', not 'zOMG'.
     
  11. caveman1917

    caveman1917 Chieftain

    Joined:
    Oct 1, 2009
    Messages:
    110
    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?
     
  12. ruff_hi

    ruff_hi Live 4ever! Or die trying

    Joined:
    Oct 24, 2005
    Messages:
    8,815
    Location:
    an Aussie in Boston
    probably not - that looks like a bug. I'll take a look at it when I get back from my trip (2 weeks).
     
  13. EmperorFool

    EmperorFool Chieftain

    Joined:
    Mar 2, 2007
    Messages:
    9,633
    Location:
    Mountain View, California
    Fixed in r2131.
     
  14. caveman1917

    caveman1917 Chieftain

    Joined:
    Oct 1, 2009
    Messages:
    110
    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, ...)
     
  15. EmperorFool

    EmperorFool Chieftain

    Joined:
    Mar 2, 2007
    Messages:
    9,633
    Location:
    Mountain View, California
    You can grab the file from our here and place it into [Custom]Assets/Python/Contrib, overwriting the file that's there.
     
  16. ruff_hi

    ruff_hi Live 4ever! Or die trying

    Joined:
    Oct 24, 2005
    Messages:
    8,815
    Location:
    an Aussie in Boston
    and you cannot use multiple counts like that.
     
  17. caveman1917

    caveman1917 Chieftain

    Joined:
    Oct 1, 2009
    Messages:
    110
    Ok thanks.

    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"?
     
  18. caveman1917

    caveman1917 Chieftain

    Joined:
    Oct 1, 2009
    Messages:
    110
    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.
     
  19. EmperorFool

    EmperorFool Chieftain

    Joined:
    Mar 2, 2007
    Messages:
    9,633
    Location:
    Mountain View, California
    Thanks for that. :goodjob: Each counter type has its own current, tt1, and tt2 values. I'll put this into BUG later this weekend.
     
  20. ruff_hi

    ruff_hi Live 4ever! Or die trying

    Joined:
    Oct 24, 2005
    Messages:
    8,815
    Location:
    an Aussie in Boston
    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.
     

Share This Page