Python Help - Get tech flavors

ww2commander

Emperor
Joined
Aug 23, 2003
Messages
1,243
Location
Australia
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?
 
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.

Code:
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 )
 [COLOR=red]       for f in range(gc.getNumFlavorTypes()):[/COLOR]
[COLOR=red]               if gc.getTechInfo.getFlavorTypes(f) == "FLAVOR_MILITARY":[/COLOR]
[COLOR=red]                       iRed = 89[/COLOR]
[COLOR=red]                       iGreen = 133[/COLOR]
[COLOR=red]                       iBlue = 39[/COLOR]
[COLOR=red]               if gc.getTechInfo.getFlavorTypes(f) == "FLAVOR_GOLD":[/COLOR]
[COLOR=red]                       iRed = 255[/COLOR]
[COLOR=red]                       iGreen = 244[/COLOR]
[COLOR=red]                       iBlue = 104[/COLOR]
[COLOR=red]               if gc.getTechInfo.getFlavorTypes(f) == "FLAVOR_SCIENCE":[/COLOR]
[COLOR=red]                       iRed = 168[/COLOR]
[COLOR=red]                       iGreen = 99[/COLOR]
[COLOR=red]                       iBlue = 168[/COLOR]
[COLOR=red]               if gc.getTechInfo.getFlavorTypes(f) == "FLAVOR_PRODUCTION":[/COLOR]
[COLOR=red]                       iRed = 68[/COLOR]
[COLOR=red]                       iGreen = 140[/COLOR]
[COLOR=red]                       iBlue = 202                            [/COLOR]
[COLOR=red]               if gc.getTechInfo.getFlavorTypes(f) == "FLAVOR_CULTURE":[/COLOR]
[COLOR=red]                       iRed = 165[/COLOR]
[COLOR=red]                       iGreen = 124[/COLOR]
[COLOR=red]                       iBlue = 82                                    [/COLOR]
[COLOR=red]               if gc.getTechInfo.getFlavorTypes(f) == "FLAVOR_RELIGION":[/COLOR]
[COLOR=red]                       iRed = 242[/COLOR]
[COLOR=red]                       iGreen = 101[/COLOR]
[COLOR=red]                       iBlue = 34[/COLOR]
[COLOR=red]               if gc.getTechInfo.getFlavorTypes(f) == "FLAVOR_GROWTH":[/COLOR]
[COLOR=red]                       iRed = 245[/COLOR]
[COLOR=red]                       iGreen = 152[/COLOR]
[COLOR=red]                       iBlue = 157  [/COLOR]                  
        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, [COLOR=red]iRed, iGreen, iBlue[/COLOR])
                g_iCurrentState.append(CIV_IS_RESEARCHING)
        elif ( gc.getPlayer(g_civSelected).isResearchingTech(i) ):                      
                screen.setPanelColor(szTechRecord, [COLOR=red]iRed, iGreen, iBlue[/COLOR])
                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, [COLOR=red]iRed, iGreen, iBlue[/COLOR])
                g_iCurrentState.append(CIV_TECH_AVAILABLE)

Any ideas what I am doing wrong. Its not easy learning python :sad:
 
You can try that (not tested):

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

                bestValue = -1
                if gc.getTechInfo(i).getFlavorValue(gc.getInfoTypeForString("FLAVOR_MILITARY")) > bestValue :
                        bestValue = gc.getTechInfo(i).getFlavorValue(gc.getInfoTypeForString("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 fro the functions you use . It's important to see what are your bugs .

Tcho !
 
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 ;)
 
Top Bottom