How do I check leader traits of a units owner?

Joined
Jun 27, 2007
Messages
2,248
Location
Hamilton, Ontario
I'm trying to add to a part of CvUnit and have it check the leader trait of the unit. So how do I have it get the owner of the unit and then read the owners leader traits?
 
Could you give an example of the pseudocode you want, in what function so we could have some context?
 
It is for CvUnit::isInvisible. My goal is to have all units of a civ be invisible. I was first going to use the code from FfH2 that allows promotion to give stealth and have it be a free promotion but that code seemed to be spread across a lot of files and thought it might be easier to just check for a trait. I could create a bool for that but I was planning on first testing it with part of existing traits, like have it activate for anything with iUpkeepModifier > 0 just to make sure it works. I could also have it check for a espionage bonus because this trait also has that and not have to create a new bool xml field. Creating a new xml field wouldn't be difficult, it's just a potential shortcut.

I think it would go something like this:
Code:
pPlayer = unit's owner
If (pPlayer's has espionage commerce bonus >99)
    return true
Does that make sense?
 
For python you can get a trait by using:

Code:
pPlayer = gc.getPlayer(iPlayer)
if( pPlayer.hasTrait(gc.getInfoTypeForString("TRAIT_NAMEOFTRAIT")) ):

If you want to look for a specific trait atribute (ie XML tag in TraitInfos) for a player:
Code:
pPlayer = gc.getPlayer(iPlayer)
for i in range(gc.getNumTraitInfos()):
	if pPlayer.hasTrait(i):
		traitInfo = gc.getTraitInfo(i)
		traitEffect = traitInfo.callFuntionForTag()
		if( traitEffect > 0 ) :
Where callFunctionForTag would be whatever the call function, is, get whatever for the specific tag you are asking for (look in the python API for trait atributes exposed to python, and what their call functions are). I'm a bit confused because you're asking about CvUnit, but you're referncing python, so that's what I'm showing.
 
I was looking for SDK. I don't know enough about python to use it, or apparently enough to not refer to it without knowing.
 
I got my plan to work, except for the fact that the units are totally undetectable because they don't have a InvisibleType set and I don't think there is a way to give it one at that point. This would prevent any counter attack on an invading stack. You'd have to guard all you cities extremely well and would probably be quite frustrating for a human player to have to deal with.
Maybe if I move the code from CvUnit::isInvisible to wherever getInvisibleType() is used so I can have it return a value there if it's a "stealth civ" regardless the stealth status of the unit. Probably by adding a new function to CvPlayer to do that more easily.

I've just clicked through the latest additions to the database, and found this modcomp by TC01.
Doesn't do exactly what you want, but fit's maybe even more to the Darloks.

Hmm. Well would the AI know how to use the cloaking device's on/off switch?
 
Top Bottom