View Full Version : Python Help - Get tech flavors


ww2commander
May 06, 2007, 01:20 AM
Wondering if someone could help me with getting the tech flavor for a specific tech. I am new to python so if someone could provide the code necessary then it would be greatly appreciated.

I am trying to get a tech and then fogure out what the flavor type is. I want to then pass this flavor value against a case statement to do something.

The part I am stumped at is actually getting the flavor type for the tech. The function getFlavorValue(intI) expects a value rather than returning one so I am confused. :confused: How do I tell it to to return the value of a flavor assigned to a tech?

ww2commander
May 06, 2007, 02:06 AM
Ok...heres what I tried to do but it does not work. When I load the mod, it goes straight to a blank tech screen and the interface disappears...obviously a hint that the game does not like my changes :(

I am trying to set the colour of the tech box depending on the flavor type. The changes I have made in the CvTechChooser.py file are in red.


for i in range(gc.getNumTechInfos()):
# Create and place a tech in its proper location
iX = 30 + ( (gc.getTechInfo(i).getGridX() - 1) * ( ( BOX_INCREMENT_X_SPACING + BOX_INCREMENT_WIDTH ) * PIXEL_INCREMENT ) )
iY = ( gc.getTechInfo(i).getGridY() - 1 ) * ( BOX_INCREMENT_Y_SPACING * PIXEL_INCREMENT ) + 5
szTechRecord = "TechRecord" + str(i)

if ( iMaxX < iX + self.getXStart() ):
iMaxX = iX + self.getXStart()
if ( iMaxY < iY + ( BOX_INCREMENT_HEIGHT * PIXEL_INCREMENT ) ):
iMaxY = iY + ( BOX_INCREMENT_HEIGHT * PIXEL_INCREMENT )

screen.attachPanelAt( "TechList", szTechRecord, u"", u"", True, False, PanelStyles.PANEL_STYLE_TECH, iX - 6, iY - 6, self.getXStart() + 6, 12 + ( BOX_INCREMENT_HEIGHT * PIXEL_INCREMENT ), WidgetTypes.WIDGET_TECH_TREE, i, -1 )
screen.setActivation( szTechRecord, ActivationTypes.ACTIVATE_MIMICPARENTFOCUS)
screen.hide( szTechRecord )
for f in range(gc.getNumFlavorTypes()):
if gc.getTechInfo.getFlavorTypes(f) == "FLAVOR_MILITARY":
iRed = 89
iGreen = 133
iBlue = 39
if gc.getTechInfo.getFlavorTypes(f) == "FLAVOR_GOLD":
iRed = 255
iGreen = 244
iBlue = 104
if gc.getTechInfo.getFlavorTypes(f) == "FLAVOR_SCIENCE":
iRed = 168
iGreen = 99
iBlue = 168
if gc.getTechInfo.getFlavorTypes(f) == "FLAVOR_PRODUCTION":
iRed = 68
iGreen = 140
iBlue = 202
if gc.getTechInfo.getFlavorTypes(f) == "FLAVOR_CULTURE":
iRed = 165
iGreen = 124
iBlue = 82
if gc.getTechInfo.getFlavorTypes(f) == "FLAVOR_RELIGION":
iRed = 242
iGreen = 101
iBlue = 34
if gc.getTechInfo.getFlavorTypes(f) == "FLAVOR_GROWTH":
iRed = 245
iGreen = 152
iBlue = 157
if ( gc.getTeam(gc.getPlayer(g_civSelected).getTeam()). isHasTech(i) ):
screen.setPanelColor(szTechRecord, 85, 150, 87)
g_iCurrentState.append(CIV_HAS_TECH)
elif ( gc.getPlayer(g_civSelected).getCurrentResearch() == i ):
screen.setPanelColor(szTechRecord, iRed, iGreen, iBlue)
g_iCurrentState.append(CIV_IS_RESEARCHING)
elif ( gc.getPlayer(g_civSelected).isResearchingTech(i) ):
screen.setPanelColor(szTechRecord, iRed, iGreen, iBlue)
g_iCurrentState.append(CIV_IS_RESEARCHING)
elif ( gc.getPlayer(g_civSelected).canEverResearch(i) ):
screen.setPanelColor(szTechRecord, 100, 104, 160)
g_iCurrentState.append(CIV_NO_RESEARCH)
else:
screen.setPanelColor(szTechRecord, iRed, iGreen, iBlue)
g_iCurrentState.append(CIV_TECH_AVAILABLE)



Any ideas what I am doing wrong. Its not easy learning python :sad:

Sto
May 06, 2007, 03:47 AM
You can try that (not tested):

# assign default value in case there is no specific flavor
iRed = 89
iGreen = 133
iBlue = 39

bestValue = -1
if gc.getTechInfo(i).getFlavorValue(gc.getInfoTypeFor String("FLAVOR_MILITARY")) > bestValue :
bestValue = gc.getTechInfo(i).getFlavorValue(gc.getInfoTypeFor String("FLAVOR_MILITARY"))
iRed = 89
iGreen = 133
iBlue = 39

etc ...

If you want to begin to learn python , go to the tutorial to see how to enable the debugger and check the API (http://civilization4.net/files/modding/PythonAPI_v160/) fro the functions you use . It's important to see what are your bugs .

Tcho !

ww2commander
May 06, 2007, 07:15 AM
Thanks for the help Sto. Your code worked, but then I realised that what I was after was getAdvisorType. Your code guided me thru getting this right.

I have a good idea of how to do this now :)

By the way, I have the API site bookmarked already and thats what I reference normally. I just have problems with the syntex and what the functions actually do...but with time I will get better ;)