Creating new AI - How to check if a player has a tech?

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Creating new AI - How to check if a player has a tech?

kmat
Hi

I am trying to make a new AI to the game. I have a problem. I don't know how to check if a player has a tech. I found the TechTracker class, but i don't know how to access it.

Greate game!

Kim
Reply | Threaded
Open this post in threaded view
|

Re: Creating new AI - How to check if a player has a tech?

ComradeKev
Administrator
It's best to have a private method within the class you're coding (for efficiency purposes).  Here's an example of that method for technology.

private static boolean isMechanizedInfantry(PlayerID player)    
{
    TechAttachment ta = (TechAttachment) player.getAttachment(Constants.TECH_ATTATCHMENT_NAME);
    if(ta == null)
        return false;
    return ta.hasMechanizedInfantry();
}


Then within your class, you can call the method to see if that partic. tech is avail for the player.
if (isMechanizedInfantry(player) ...


Incidentally, all the techs are defined within TechAttachment so you can see what's avail to call.

Cheers!
Kev
If emailing me at ComradeKev at yahoo.com , please add TripleA to the subject line