[Python] Getting available tech list for a given civ

LoD

Chieftain
Joined
Dec 28, 2001
Messages
35
Location
Warsaw, Poland
As in the thread title. I don't know why, but I can't find a way to do this. In short, I need either:
-a method that returns the list of techs that are available for a given civ (either researched or traded in),
-a method that checks whether a given tech is available for a given civ (would also work, but less efficiently).

I require a method accessible anywhere in the Python API given the gc and the player ID, so using event hooks is out of the question unfortunately.

Would some kind soul inform me about such a method? I've researched the Python API reference by Zebra 9 (for more than an hour in total), and I've searched these forums, but, sadly, found nothing.

Thanks in advance :).

PS. Just to clarify, if there are any doubts: by "available" I mean a tech that the civ possesses - i.e. can build units/building/wonders, can trade it, can research the next techs in the tree, etc. etc.; and not a tech that the civ can research, but has not obtained it yet.
 
The BUG Mod includes a file, TechUtil.py, with methods to handle this. Here's the appropriate function extracted from it:

Code:
def getKnownTechs(ePlayer):
	"""Returns a set of tech IDs that ePlayer's team knows."""
	knowingTeam = gc.getTeam(gc.getPlayer(ePlayer).getTeam())
	techs = set()
	for eTech in range(gc.getNumTechInfos()):
		if knowingTeam.isHasTech(eTech):
			techs.add(eTech)
	return techs

This function takes a player ID such as gc.getGame().getActivePlayer() and returns all techs known by the player's team in a set of tech IDs.

Code:
ePlayer = gc.getGame().getActivePlayer()
techs = getKnownTechs(ePlayer)
if gc.getInfoTypeForString("TECH_GRILLING") in techs:
    print "BBQ at active player's house!"
 
Apparently, I haven't thanked you yet... so, thank you :).

Later I've discovered you can obtain the same effect with the PyPlayer wrapper - which coincidentally contains very similar code to what you've posted.
 
Top Bottom