How to get UnitType

arcticnightwolf

Emperor
Joined
Jun 8, 2008
Messages
1,301
Doesn't anybody know how to get UnitType from unit? Resp. converting int CyUnit.getUnitType to wstring or reversing gc.getInfoTypeForString ... ?
I have unit (ie Archer) and I want to rename it to "unit of city" (ie Archer of Washington) and I don't want to check unit for each type (( doing "if unit.getUnitType() == gc.getInfoTypeForString('UNITTYPE_ARCHER')" for each unit ))
( Not sure what does wstring getUnitName on not-yet-named unit, but i want to avoid this due to later problems with upgrading already named units. )

I'm quite sure that there have to be some function on this, but I cannot find it ...
 
Would CyUnit.getNameNoDesc() work for you? I think it would always return "Archer" even if you give the unit a custom name.
 
Would CyUnit.getNameNoDesc() work for you? I think it would always return "Archer" even if you give the unit a custom name.

Doesn't work ... returns actual name ... :(

edit: actually no ... CyUnit.getNameNoDesc() returns "MyPreciousUnit", while CyUnit.getName returns "MyPreciousUnit (Archer)" ...
My fault, now I see how to get it ... :)
edit2: if somebody interested ...
Code:
  sUnitType = unit.getName()             ## get name in "blahblah (unittype) format"
  iPos = 0
  for iPos in range(1,len(sUnitType)):   ## for each char in string
    if sUnitType[iPos] == '(':                   ## search for "("
      break;                                             ## if found, exit loop
  sUnitType = sUnitType[iPos+1:-1]       ## get text between "(" ")"
(( this code works only if you didn't use bracket while naming unit ))
 
Last edited:
Oops, sorry about that, I was in a hurry and didn't double check what I typed. This should work if you want to use it - gc.getUnitInfo(unit.getUnitType()).getDescription(). I even tested this one. :crazyeye:
 
This will only work once you've renamed the unit. Until then, getName() should return "Archer". In any case, you'll find this information and much more in the CvUnitInfo object.

Code:
info = gc.getUnitInfo(pUnit.getUnitType())
name = info.getDescription()
 
This will only work once you've renamed the unit. Until then, getName() should return "Archer". In any case, you'll find this information and much more in the CvUnitInfo object.

Code:
info = gc.getUnitInfo(pUnit.getUnitType())
name = info.getDescription()

oh, thanks ...:)
 
Top Bottom