CIV4UnitInfos question

Vadus said:
But, when I say, that we found out, that the UnitInfos Class has no getUnitType( ) method were back on topic :D

with my code I want to display the units on a panel, like in the civliopedia. And with a drop down box (containing all unit descriptions) I can change this unitgraphic.
But I didn't find a sample code for this in the CvPediaUnit.py. The CvMainInterface.py ( there is a unit graphic in the left bottom corner of the city screen) uses
Code:
screen.addUnitGraphicGFC( "InterfaceUnitModel", CyInterface().getHeadSelectedUnit().getUnitType() ... )
but I want to get a unit from a self defined variable (so by description or id )

So I tried a bit on my own and have now this problem, that I only can use the getUnitClassType() from gc.getUnitInfo( ) .. but maybe I need a CyUnit instance .. only this class has the needed getUnitType( ) method

Oh, sorry, my bad. For a unitInfo it's just getType().
 
Belizan said:
Oh, sorry, my bad. For a unitInfo it's just getType().
hm, well .. This would result for the unit lion in "UNIT_LION"
but the CyGInterfaceScreen.addUnitGraphicGFC(string szName, int iUnit, int iX, int iY, ... ) requires an int value for the Unit-Class ( probably the Unit ID , which you get with CvUnitInfo.getUnitClassType( ) , I guess )
I think, unit id refers to the units postion in the xml file. But for this, the graphic shifts (as I already mentioned) from the unit number 7 (fast worker) , so that the unit # 7 has the graphic of unit # 6 ,
the unit # 8 the graphic of unit # 7 .. and so on :(
 
Use gc.getInfoTypeFor(from?)String(name, myUnit.getType()...)
 
talchas said:
Use gc.getInfoTypeFor(from?)String(name, myUnit.getType()...)
SWEET !! :eek: :goodjob:

ok, for all, who want to display a unitgraphic from it's description :

Code:
self.screen.addUnitGraphicGFC( "InterfaceUnitModel", 
                       gc.getInfoTypeForString(
                           gc.getUnitInfo([b]unitList.index(unitDescription)[/b])
                       .getType() 
 ... )

the unitList contains the units descriptions
:)
 
hi !
Vadus said:
hey, is it possible to get the UnitClassType over the GlobalContext only with the Unit-Description ?
like gc.getUnitTypeByDescription(string description)

I didn't find anything like that in the API , but maybe somebody already created such a function? :hmm:

you can have the library of each 'objet' doing 'print dir(objet)':
Code:
        print dir(CvUnitInfo)
you will have more than you want !

then use :
Code:
        gc.getUnitInfo(i).getUnitClassType()
it return an integer attribuate to the specified UnitClassType .

but you can't inspect(import the source text) the object because it's handle in C, so you have to do with the values you get with the function you use .

So ,to determinate wich UnitClassType is associate with the integer the only thing if found is :
Code:
        lUnitClassID = []
	for i in range(gc.getNumUnitInfos()):
	        if UnitInfo(i).getUnitClassType() == UnitInfo(test).getUnitClassType():
	                lUnitClassID.append(i)
	print lUnitClassID
with test is the ID of an unit you know the UnitClassType

Tcho!
 
Houman said:
Hey you have hijacked my thread! ;)

really sorry! i must have misunderstood something ! :confused:
 
Back
Top Bottom