home *** CD-ROM | disk | FTP | other *** search
/ GameStar 2006 January / Gamestar_80_2006-01_dvd.iso / Dema / Civilization4 / data1.cab / Civ4DemoComponent / Assets / Python / PyHelpers.py < prev    next >
Encoding:
Python Source  |  2005-11-09  |  59.4 KB  |  2,133 lines

  1. ## Sid Meier's Civilization 4
  2. ## Copyright Firaxis Games 2005
  3. from CvPythonExtensions import *
  4. #import Info as PyInfo
  5. import CvUtil
  6. gc = CyGlobalContext()
  7.  
  8. class PyPlayer:
  9.     ' CyPlayer Helper Functions - Requires Player ID to initialize instance '
  10.     
  11.     def __init__(self, iPlayer):
  12.         ' Called whenever a new PyPlayer instance is created '
  13.         if iPlayer:
  14.             self.player = gc.getPlayer(iPlayer)
  15.         else:
  16.             self.player = gc.getPlayer(0)
  17.     
  18.     def CyGet(self):
  19.         ' used to get the CyUnit instance for quick calls '
  20.         return self.player
  21.     
  22.     def getPlayer(self):
  23.         return self.player
  24.     
  25.     def isNone(self):
  26.         ' bool - Is the CyPlayer Instance Valid? '
  27.         return self.player.isNone()
  28.  
  29.     def isAlive(self):
  30.         return self.player.isAlive()
  31.     
  32.     def getID(self):
  33.         ' int - ID # '
  34.         return self.player.getID()
  35.  
  36.     def getName(self):
  37.         return self.player.getName()
  38.  
  39. # Players Team
  40.     def getTeamID(self):
  41.         ' int - gets the players teamID '
  42.         return self.player.getTeam()
  43.     
  44.     def getTeam(self):
  45.         ' obj - returns Team Instance '
  46.         return gc.getTeam( self.getTeamID() )
  47.  
  48.     def canTradeNetworkWith(self, iPlayer):
  49.         return self.player.canTradeNetworkWith(iPlayer)
  50.     
  51. # AI
  52.     def AI_getAttitude(self, iTeam):
  53.         return self.player.AI_getAttitude(iTeam)
  54.     
  55. # Players Gold
  56.     def getGold(self):
  57.         return self.player.getGold()
  58.     
  59.     def changeGold(self, iGold):
  60.         self.player.changeGold(iGold)
  61.     
  62.     def setGold(self, iGold):
  63.         ' none - Sets Gold to iGold '
  64.         self.player.setGold( iGold )
  65.     
  66.     def hasGold(self, iNumGold):
  67.         ' bool - Has at least iNumGold? '
  68.         if ( self.player.getGold() >= iNumGold ):
  69.             return True
  70.     
  71.     def getTotalMaintenance(self):
  72.         return self.player.getTotalMaintenance()
  73.         
  74.     def calculateUnitCost(self):
  75.         return self.player.calculateUnitCost()
  76.     
  77.     def calculateUnitSupply(self):
  78.         return self.player.calculateUnitSupply()
  79.  
  80. # Players Yields / Commerce    
  81.     def getGoldCommerceRate(self):
  82.         ' int - Players gold commerce rate '
  83.         return self.player.getCommerceRate( CommerceTypes.COMMERCE_GOLD )
  84.     
  85.     def getResearchCommerceRate(self):
  86.         ' int - Players research commerce rate '
  87.         return self.player.getCommerceRate( CommerceTypes.COMMERCE_RESEARCH )
  88.     
  89.     def getCultureCommerceRate(self):
  90.         ' int - Players culture commerce rate '
  91.         return self.player.getCommerceRate( CommerceTypes.COMMERCE_CULTURE )
  92.     
  93.     def calculateResearchRate(self):
  94.         ' int - Total Research Rate per Turn '
  95.         return self.player.calculateResearchRate( TechTypes.NO_TECH )
  96.     
  97.     def getCommerceYieldRateModifier(self):
  98.         ' int '
  99.         return self.player.getYieldRateModifier( YieldTypes.YIELD_COMMERCE )
  100.     
  101.     def getFoodYieldRateModifier(self):
  102.         ' int '
  103.         return self.player.getYieldRateModifier( YieldTypes.YIELD_FOOD )
  104.     
  105.     def getProductionYieldRateModifier(self):
  106.         ' int '
  107.         return self.player.getYieldRateModifier( YieldTypes.YIELD_PRODUCTION )
  108.     
  109.     def getCommerceSeaPlotYield(self):
  110.         ' int '
  111.         return self.player.getSeaPlotYield( YieldTypes.YIELD_COMMERCE )
  112.     
  113.     def getFoodSeaPlotYield(self):
  114.         ' int '
  115.         return self.player.getSeaPlotYield( YieldTypes.YIELD_FOOD )
  116.         
  117.     def getProductionSeaPlotYield(self):
  118.         ' int '
  119.         return self.player.getSeaPlotYield( YieldTypes.YIELD_PRODUCTION )
  120.     
  121.     def getGoldPerTurn(self):
  122.         return self.player.getGoldPerTurn()
  123.     
  124. # Players Research
  125.     def getResearchedTechList(self):
  126.         ' intlist - list of researched techs '
  127.         lTechs = []
  128.         for i in range(gc.getNumTechInfos()):
  129.             if self.hasResearchedTech(i):
  130.                 lTechs.append(i)
  131.         return lTechs
  132.         
  133.     def hasResearchedTech(self, iTech):
  134.         ' bool - Has researched iTech '
  135.         if self.getTeam().isHasTech( iTech ):
  136.             return True
  137.     
  138.     def setHasTech(self, iTech):
  139.         ' gives the player iTech '
  140.         #int /*TechTypes*/ eIndex, bool bNewValue, int /*PlayerTypes*/ ePlayer, bool bFirst, bool bAnnounce
  141.         self.getTeam().setHasTech( iTech, True, self.getID(), False, False )
  142.     
  143.     def getResearchTurnsLeft(self, iTech, bOverflow = 1):
  144.         ' int '
  145.         return self.player.getResearchTurnsLeft( iTech, bOverflow )
  146.         
  147.     def getCurrentTechName(self):
  148.         ' str - Current Research Tech Name '
  149.         iTech = self.player.getCurrentResearch()
  150.         if ( iTech > 0 and iTech < gc.getNumTechInfos() ):
  151.             return str( gc.getTechInfo( iTech ).getDescription() )
  152.         # "No Research"
  153.         return "No Research"
  154.  
  155.     def isBarbarian(self):
  156.         return self.player.isBarbarian()
  157.     
  158.     def isMinorCiv(self):
  159.         return self.player.isMinorCiv()
  160.     
  161.     def getNumTradeableBonuses(self, iBonus):
  162.         return self.player.getNumTradeableBonuses(iBonus)
  163.     
  164.     def calculateInflatedCosts(self):
  165.         return self.player.calculateInflatedCosts()
  166.     
  167.     def calculatePreInflatedCosts(self):
  168.         return self.player.calculatePreInflatedCosts()
  169.     
  170.     def calculateGoldRate(self):
  171.         return self.player.calculateGoldRate()
  172.     
  173. # Players Civ
  174.     def getCivilizationInfo(self):
  175.         ' CivilizationInfo - Civ Info instance '
  176.         return gc.getCivilizationInfo( self.player.getCivilizationType() )
  177.     
  178.     def getCivDescription(self):
  179.         ' str - Civ Description '
  180.         return self.player.getCivilizationDescription(0)
  181.  
  182.     def getCivilizationName(self):
  183.         ' str - Civ Description '
  184.         return self.player.getCivilizationDescription(0)
  185.         
  186.     def getCivilizationShortDescription(self):
  187.         ' str - Civ Description '
  188.         return self.player.getCivilizationShortDescription(0)
  189.  
  190.     def getCivilizationAdjective(self):
  191.         ' str - Civ Ajective '
  192.         return self.player.getCivilizationAdjective(0)
  193.  
  194. # Players LeaderHead
  195.     def getLeaderName(self):
  196.         return self.getLeaderHeadInfo().getDescription()
  197.     
  198.     def getLeaderType(self):
  199.         return self.player.getLeaderType()
  200.     
  201.     def getLeaderHeadInfo(self):
  202.         ' LeaderHeadInfo - Leaders info instance '
  203.         return gc.getLeaderHeadInfo( self.player.getLeaderType() )
  204.     
  205.     def getLeaderHeadDescription(self):
  206.         ' str - Leader Name '
  207.         return self.getLeaderHeadInfo().getDescription()
  208.     
  209.     def getLeaderHeadImage(self):
  210.         "str - location of the regular size leaderhead image"
  211.         return self.getLeaderHeadInfo().getLeaderHead()
  212.  
  213. # Players Traits    
  214.     def getTraitList(self):
  215.         ' intList - Trait List '
  216.         lTrait = []
  217.         for i in range( gc.getNumTraitInfos() ):
  218.             if ( self.getLeaderHeadInfo().hasTrait(i) ):
  219.                 lTrait.append(i)
  220.         return lTrait
  221.     
  222.     def getTraitInfos(self):
  223.         ' TraitInfoList '
  224.         lTrait = []
  225.         for iTrait in self.getTraitList():
  226.             lTrait.append( gc.getTraitInfo(iTrait) )
  227.         return lTrait
  228.     
  229. # Players Civics 
  230.     def getCurrentCivicByOption(self, iCivicOption):
  231.         ' int - current civic for iCivicOption '
  232.         return self.player.getCivics( iCivicOption )
  233.     
  234.     def getCurrentCivicList(self):
  235.         ' intList - list of current Civic IDs '
  236.         lCivics = []
  237.         for i in range( CyGlobalContext().getNumCivicOptionInfos() ):
  238.             lCivics.append( self.player.getCivics( i ) )
  239.         return lCivics
  240.     
  241.     def getCurrentCivicDescriptions(self):
  242.         ' strList - description list of current civics '
  243.         lCivics = self.getCurrentCivicList()
  244.         for i in range( len(lCivics) ):
  245.             lCivics[i] = CyGlobalContext().getCivicInfo( lCivics[i] ).getDescription()
  246.         return lCivics
  247.  
  248.     def getCivicUpkeep(self):
  249.         ' int - total Civic Upkeep '
  250.         return self.player.getCivicUpkeep([], False)    # pass in an empty list
  251.  
  252. # Players Units
  253.     def getUnitList(self):
  254.         ' UnitList - All of the players alive units '
  255.         lUnit = []
  256.         (loopUnit, iter) = self.player.firstUnit(false)
  257.         while( loopUnit ):
  258.             if ( not loopUnit.isDead() ): #is the unit alive and valid?
  259.                 lUnit.append(loopUnit) #add unit instance to list
  260.             (loopUnit, iter) = self.player.nextUnit(iter, false)
  261.         return lUnit
  262.     
  263.     def getNumUnits(self):
  264.         return self.player.getNumUnits()
  265.     
  266.     def getUnitByScriptData(self, scriptData):
  267.         for unit in self.getUnitList():
  268.             if unit.getScriptData() == scriptData:
  269.                 return unit
  270.                 
  271.         return 0
  272.     
  273.     def centerCameraByScriptData(self, scriptData):
  274.         unit = self.getUnitByScriptData(scriptData)
  275.         CyCamera().LookAtUnit(unit)
  276.     
  277.     def initUnit(self, unitID, X, Y, iNum = 1):
  278.         "none - spawns unitIdx at X, Y - ALWAYS use default UnitAIType"
  279.         if (iNum > 1): #multiple units
  280.             for i in range(iNum):
  281.                 self.player.initUnit(unitID, X, Y, UnitAITypes.NO_UNITAI)
  282.         else:
  283.             self.player.initUnit(unitID, X, Y, UnitAITypes.NO_UNITAI)
  284.     
  285.     def hasUnitType(self, iUnit):
  286.         ' bool - Has iUnit? '
  287.         for unit in self.getUnitList():
  288.             if ( unit.getUnitType() == iUnit ):
  289.                 return True
  290.  
  291.     def getUnitsOfType(self, iUnit):
  292.         ' UnitList - of iUnit '
  293.         lUnits = []
  294.         for unit in self.getUnitList():
  295.             if ( unit.getUnitType() == iUnit ):
  296.                 lUnits.append(unit)
  297.         return lUnits
  298.         
  299.     def getNumUnitsLevel(self, iLevel):
  300.         ' int - num units at iLevel '
  301.         iCounter = 0
  302.         for unit in self.getUnitList():
  303.             if ( unit.getLevel() >= iLevel ):
  304.                 iCounter+=1
  305.         return iCounter
  306.     
  307. # Players Cities
  308.     def getTotalPopulation(self):
  309.         return self.player.getTotalPopulation()
  310.     
  311.     def getCityList(self):
  312.         ' PyCitylist - list of PyCity player owns '
  313.         lCity = []
  314.         (loopCity, iter) = self.player.firstCity(false)
  315.         while(loopCity):
  316.             cityOwner = loopCity.getOwner()
  317.             if ( not loopCity.isNone() and loopCity.getOwner() == self.getID() ): #only valid cities
  318.                 city = PyCity( self.getID(), loopCity.getID() )
  319.                 lCity.append(city)
  320.             (loopCity, iter) = self.player.nextCity(iter, false)
  321.         return lCity
  322.     
  323.     def getNumCities(self):
  324.         return self.player.getNumCities()
  325.     
  326.     def isFoundedFirstCity(self):
  327.         return self.player.isFoundedFirstCity()
  328.     
  329.     def initCity(self, iX, iY):
  330.         ' adds city to iX, iY '
  331.         self.player.initCity(iX, iY)
  332.     
  333.     def getCapitalCity(self):
  334.         ' PyCity - capital '
  335.         for city in self.getCityList():
  336.             if ( city.GetCy().isCapital() ):
  337.                 return city
  338.         
  339.     def getCity(self, iCity):
  340.         ' PyCity - returns city iCity '
  341.         return self.player.getCityList()[iCity]
  342.  
  343.     def getBuildingClassCount (self, iBuildingClass):
  344.         ' int - total of building class '
  345.         return self.player.getBuildingClassCount( iBuildingClass )
  346.     
  347. # Players Plots    
  348.     def getPlotList(self):
  349.         ' plotList - player plots '
  350.         lPlots = []
  351.         for iIndex in self.getPlotIDList():
  352.             lPlots.append( CyMap().plotByIndex(i) )
  353.         return lPlots
  354.     
  355.     def getTotalLand(self):
  356.         return self.player.getTotalLand()
  357.     
  358.     def getPlotIDList(self):
  359.         ' intList - player plots indexes '
  360.         lPlotIDs = []
  361.         for i in xrange( CyMap().numPlots() ):
  362.             if ( CyMap().sPlotByIndex( i ).getOwner() == self.getID() ):
  363.                 lPlotIDs.append( i )
  364.         return lPlotIDs
  365.     
  366.     def getNumPlots(self):
  367.         ' int - numOwned plots '
  368.         return len( self.getPlotIDList() )
  369.     
  370.     def getPlotsWithBonus(self, iBonus):
  371.         ' plotList with iBonus '
  372.         lPlots = []
  373.         for plot in self.getPlotList():
  374.             if ( not plot.getBonusType() == BonusTypes.NO_BONUS and plot.getBonusType() == iBonus ):
  375.                 lPlots.append(plot)
  376.         return lPlots
  377.  
  378.     def getNumImprovementPlots(self):
  379.         ' int numPlots with iImprovement '
  380.         iCounter = 0
  381.         for plot in self.getPlotList():
  382.             if ( not plot.getImprovementType() == ImprovementTypes.NO_IMPROVEMENT ):
  383.                 iCounter += 1
  384.         return iCounter
  385.  
  386.  
  387. class PyCity:
  388.     "requires player instance & cityID"
  389.     def __init__(self, iPlayerID, iCityID):
  390.         self.player = gc.getPlayer(iPlayerID)
  391.         self.city = self.player.getCity(iCityID)
  392.     
  393.     def isNone(self):
  394.         "bool - Is the city instance valid?"
  395.         return self.city.isNone()
  396.     
  397.     def GetCy(self):
  398.         ' Cy instance of city '
  399.         return self.city
  400.  
  401. #################### G E N E R A L     C I T Y     F U N C T I O N S ####################
  402.  
  403.     def getID(self):
  404.         "int - City ID"
  405.         return self.city.getID()
  406.  
  407.     def getX(self):
  408.         "int - City's X Location"
  409.         return self.city.getX()
  410.  
  411.     def getY(self):
  412.         "int - City's Y Location"
  413.         return self.city.getY()
  414.     
  415.     def getIndex(self):
  416.         return self.city.getIndex()
  417.     
  418.     def getName(self):
  419.         "str - Cities Name"
  420.         return self.city.getName()
  421.     
  422.     def getNameKey(self):
  423.         "str - Cities Name"
  424.         return self.city.getNameKey()
  425.     
  426.     def getScriptData(self):
  427.         "str - City's Script Data member"
  428.         return self.city.getScriptData()
  429.     
  430.     def setScriptData(self, szScriptString):
  431.         "void - set City's Script Data member"
  432.         self.city.setScriptData(szScriptString)
  433.     
  434.     def getOwner(self):
  435.         return self.city.getOwner()
  436.     
  437.     def isBarbarian(self):
  438.         return self.city.isBarbarian()
  439.     
  440.     def setName(self, newName):
  441.         "none - Set Cities Name"
  442.         return self.city.setName(newName, false)
  443.  
  444.     def getPopulation(self):
  445.         "int - City Population"
  446.         return self.city.getPopulation()
  447.     
  448.     def changePopulation(self, iChange):
  449.         "none - Change City Population by iChange"
  450.         return self.city.changePopulation(iChange)
  451.     
  452.     def setPopulation(self, iValue):
  453.         "none - Set City Population"
  454.         return self.city.setPopulation(iValue)
  455.             
  456.     def getAngryPopulation(self):
  457.         "int - Angry Population"
  458.         return self.city.angryPopulation(0)
  459.     
  460.     def getHappyPopulation(self):
  461.         "int - Happy Population"
  462.         return self.city.happyLevel()
  463.         
  464.     def getUnhappyPopulation(self):
  465.         "int - Unhappy Population"
  466.         return self.city.unhappyLevel(0)
  467.         
  468.     def hasBuilding(self, iBuildingID):
  469.         "bool - Whether or not this city has iBuildingID"
  470.         return self.city.hasBuilding(iBuildingID)
  471.         
  472.     def canTrain (self, iUnit):
  473.         return self.city.canTrain(iUnit, False, False)
  474.  
  475.     def canConstruct (self, iBuilding):
  476.         return self.city.canConstruct(iBuilding, False, False, False)
  477.  
  478.     def canCreate (self, iProject):
  479.         return self.city.canCreate(iProject, False, False)
  480.  
  481.     def canMaintain (self, iItem):
  482.         return self.city.canMaintain(iItem, False)
  483.         
  484.     def getProductionBuilding(self):
  485.         "int - What building ID this city is working on"
  486.         return self.city.getProductionBuilding()
  487.         
  488.     def getProductionProject(self):
  489.         "int - What Project ID this city is working on"
  490.         return self.city.getProductionProject()
  491.  
  492.     def getUnitProductionTurnsLeft (self, iUnit, iNum):
  493.         return self.city.getUnitProductionTurnsLeft(iUnit, iNum)
  494.  
  495.     def getBuildingProductionTurnsLeft (self, iBuilding, iNum):
  496.         return self.city.getBuildingProductionTurnsLeft( iBuilding, iNum )
  497.         
  498.     def getBuildingOriginalTime(self, iBuildingID):
  499.         return self.city.getBuildingOriginalTime(iBuildingID)
  500.         
  501.     def getProjectProductionTurnsLeft (self, iProject, iNum):
  502.         return self.city.getProjectProductionTurnsLeft( iProject, iNum )
  503.         
  504.     def foodConsumption(self, bAngry, iExtra):
  505.         return self.city.foodConsumption(bAngry, iExtra)
  506.     
  507.     def getGreatPeopleProgress(self):
  508.         return self.city.getGreatPeopleProgress()
  509.     
  510.     def getGreatPeopleRate(self):
  511.         return self.city.getGreatPeopleRate()
  512.  
  513.     def getGameTurnFounded (self):
  514.         return self.city.getGameTurnFounded()
  515.     
  516.     def getBaseGreatPeopleRate(self):
  517.         return self.city.getBaseGreatPeopleRate()
  518.         
  519.     def getFoodRate(self):
  520.         "int - Total Food Yield"
  521.         return self.city.getYieldRate(YieldTypes.YIELD_FOOD)
  522.     
  523.     def calculateGoldRate(self):
  524.         "int - Total Gold Yield"
  525.         return self.city.getYieldRate(YieldTypes.YIELD_COMMERCE)
  526.     
  527.     def getProductionRate(self):
  528.         "int - Total Production Yield"
  529.         return self.city.getYieldRate(YieldTypes.YIELD_PRODUCTION)
  530.     
  531.     def getResearchRate(self):
  532.         "int - Total Production Yield"
  533.         return self.city.getCommerceRate(CommerceTypes.COMMERCE_RESEARCH)
  534.     
  535.     def getProductionName(self):
  536.         "str - Current Productions Name"
  537.         return self.city.getProductionName()
  538.     
  539.     def getProductionNameKey(self):
  540.         "str - Current Productions Name"
  541.         return self.city.getProductionNameKey()
  542.     
  543.     def isProductionProcess(self):
  544.         return self.city.isProductionProcess()
  545.     
  546.     def getProductionTurnsLeft(self):
  547.         "int - Turns Remaining"
  548.         if self.isProductionProcess():
  549.             return "-"
  550.         return self.city.getProductionTurnsLeft()
  551.     
  552.     def getCultureCommerce(self):
  553.         return self.city.getCommerceRate(CommerceTypes.COMMERCE_CULTURE)
  554.     
  555.     def getCulture(self):
  556.         "int - Culture points"
  557.         return self.city.getCulture(self.player.getID())
  558.     
  559.     def changeCulture(self, iChange, bPlots=True):
  560.         return self.city.changeCulture(self.player.getID(), iChange, bPlots)
  561.     
  562.     def setCulture(self, iChange, bPlots=True):
  563.         self.city.setCulture(self.player.getID(), iChange, bPlots)
  564.     
  565.     def getCultureThreshold(self):
  566.         return self.city.getCultureThreshold()
  567.     
  568.     def getGoodHealth(self):
  569.         "int - Health rating"
  570.         return self.city.goodHealth()
  571.     
  572.     def getBadHealth(self):
  573.         "int - Unhealthy rating"
  574.         return self.city.badHealth(False)
  575.     
  576.     def getMaintenance(self):
  577.         "int - Maintenance rating"
  578.         return self.city.getMaintenance()
  579.         
  580.     def plot(self):
  581.         "obj - Cities plot"
  582.         return self.city.plot()    
  583.     
  584.     def initUnit(self, iUnitID):
  585.         plot = self.plot()
  586.         gc.getActivePlayer().initUnit( iUnitID, plot.getX(), plot.getY(), UnitAITypes.NO_UNITAI )
  587.     
  588.     def hasBuildingIdx(self, buildingIdx):
  589.         "bool - City has buildingIdx?"
  590.         if (self.city.hasBuilding(buildingIdx)):
  591.             return True
  592.         return False
  593.     
  594.     def hasReligion(self, religionIdx):
  595.         "bool - City has religionIdx?"
  596.         if (self.city.isHasReligion(religionIdx)):
  597.             return True
  598.         return False
  599.     
  600.     def isHolyCityByType(self, iReligion):
  601.         if self.city.isHolyCityByType(iReligion):
  602.             return True
  603.         return False
  604.     
  605.     def getHolyCity(self):
  606.         lHolyCity = []
  607.         for i in range(gc.getNumReligionInfos()):
  608.             if self.city.isHolyCityByType(i):
  609.                 lHolyCity.append(i)
  610.         return lHolyCity
  611.     
  612.     def getReligions(self):
  613.         lReligions = []
  614.         for i in range(gc.getNumReligionInfos()):
  615.             if self.hasReligion(i):
  616.                 lReligions.append(i)
  617.         return lReligions
  618.     
  619.     def isCapital(self):
  620.         "bool - City is capital?"
  621.         if self.city.isCapital():
  622.             return True
  623.         return False
  624.     
  625.     def isHealth(self):
  626.         "bool - City is healthy?"
  627.         if (self.getGoodHealth() > self.getBadHealth()):
  628.             return True
  629.         return False
  630.     
  631.     def centerCamera(self):
  632.         "bool - Center camera on city"
  633.         engine = CyEngine()
  634.         plot = self.plot()
  635.         if plot:
  636.             engine.LookAt(plot.getPoint(), true)
  637.     
  638.     def setHasRealBuildingIdx(self, buildingIdx, bAdd):
  639.         "none - Add or Remove (bAdd) by buildingIdx"
  640.         return self.city.setHasRealBuilding(buildingIdx, bAdd)
  641.  
  642.     def getBuildingList(self):
  643.         "intList - List of all buildingIdx in the city"
  644.  
  645.         numBuildingInfos = gc.getNumBuildingInfos()
  646.         buildingList=[]
  647.         
  648.         for buildingIdx in range(numBuildingInfos):
  649.             if (self.hasBuildingIdx( buildingIdx )):
  650.                 buildingList.append( buildingIdx )
  651.         return buildingList
  652.     
  653.     def hasBonusIdx(self, iBonus):
  654.         return self.city.hasBonus(iBonus)
  655.     
  656.     def getBonusList(self):
  657.         "intList - all bonuses connected to city"
  658.         lBonus = []
  659.         for i in range(gc.getNumBonusInfos()):
  660.             if self.hasBonusIdx( i ):
  661.                 lBonus.append(i)
  662.         return lBonus
  663.     
  664.     def getResourceSymbolList(self):
  665.         lBonus = self.getBonusList()
  666.         lBonusFound = []
  667.         lBonusString = ""
  668.         for i in range(len(lBonus)):
  669.             loopBonus = lBonus[i]
  670.             if loopBonus in lBonusFound:
  671.                 continue
  672.             else:
  673.                 lBonusString += "%s" %(PyInfo.BonusInfo(lBonus[i]).getSymbol())
  674.         
  675.         return lBonusString
  676.  
  677.     def getStateReligionHappiness(self, iReligion):
  678.         return self.city.getStateReligionHappiness(iReligion)
  679.         
  680.     def getReligionInfluence(self, iReligion):
  681.         return self.city.getReligionInfluence(iReligion)
  682.         
  683.     def isRevealed(self, iTeam):
  684.         return self.city.isRevealed(iTeam, false)
  685.         
  686.     def isConnectedToCapital(self, iPlayer):
  687.         return self.city.isConnectedToCapital(iPlayer)
  688.  
  689. class PyGame:
  690.     "requires Nothing"
  691.     def __init__(self):
  692.         self.game = CyGame()
  693.     
  694.     def isNone(self):
  695.         "bool - Is the game instance valid?"
  696.         return self.game.isNone()
  697.  
  698. #################### G E N E R A L     G A M E     F U N C T I O N S ####################
  699.  
  700.     def getCivPlayerList(self):
  701.         "objlist - List of valid and Alive players"
  702.         playerList = []
  703.         for i in range(gc.getMAX_CIV_PLAYERS()):
  704.             if (gc.getPlayer(i).isAlive()):
  705.                 loopPlayer = PyPlayer(gc.getPlayer(i).getID())
  706.                 if (loopPlayer.isNone() or not loopPlayer.isAlive()):
  707.                     continue
  708.                 else:
  709.                     playerList.append(loopPlayer)
  710.         return playerList
  711.         
  712.     def getCivTeamList(self, iTeam):
  713.         team=gc.getTeam(iTeam)
  714.         teamPlayerList = []
  715.         playerList = self.getCivPlayerList()
  716.         for player in playerList:
  717.             if player.getTeam() == team.getID():
  718.                 teamPlayerList.append(player)
  719.         return teamPlayerList
  720.  
  721.     def canTeamTradeWith(self, team1ID, team2ID):
  722.         playersTeam1 = self.getCivTeamList(team1ID)
  723.         playersTeam2 = self.getCivTeamList(team2ID)
  724.         
  725.         for i in range(len(playersTeam2)):
  726.             if playersTeam1[i].canTradeNetworkWith(playersTeam2[i].getID()):
  727.                 return True
  728.     
  729.     def getActivePlayer(self):
  730.         return gc.getPlayer(self.game.getActivePlayer())
  731.     
  732.     def getActiveTeam(self):
  733.         "obj - active team instance"
  734.         return self.game.getActiveTeam()
  735.     
  736.     def getGameTurn(self):
  737.         "int - game turn"
  738.         return self.game.getGameTurn()
  739.     
  740.     def getNumCities(self):
  741.         "int - total cities"
  742.         return self.game.getNumCities()
  743.     
  744.     def getTotalPopulation(self):
  745.         "int - total population"
  746.         return self.game.getTotalPopulation()
  747.     
  748.     def isDebugMode(self):
  749.         "bool - debug mode?"
  750.         return self.game.isDebugMode()
  751.         
  752.     def isPitbossHost(self):
  753.         "bool - Pitboss Host?"
  754.         return self.game.isPitbossHost()
  755.     
  756.     def getEraTechList(self, era):
  757.         "listObj -  returns a list of technology infos for a particular era"
  758.         listTechs = []
  759.         for i in range(gc.getNumTechInfos()):
  760.             loopInfo = PyInfo.TechnologyInfo(i)
  761.             if loopInfo.getiEra() == era:
  762.                 listTechs.append(loopInfo)
  763.         return listTechs
  764.     
  765.     def getListUniqueUnits(self):
  766.         lUniqueUnits = self.getListUniqueUnitID()
  767.         lUnitInfos = []
  768.         for i in range(len(lUniqueUnits)):
  769.             lUnitInfos.append(PyInfo.UnitInfo(lUniqueUnits[i]))
  770.         return lUnitInfos
  771.     
  772.     def getListUniqueUnitID(self):
  773.         listUU = []
  774.         unitClass = []
  775.         for i in range(gc.getNumUnitInfos()):
  776.             iUnitClass = PyInfo.UnitInfo(i).getUnitClassType()    
  777.             if iUnitClass in unitClass:
  778.                 listUU.append(i)            
  779.             else:
  780.                 unitClass.append(iUnitClass)
  781.         return listUU
  782.     
  783.     def getListAnimalUnits(self):
  784.         listUnits = []
  785.         for i in range(gc.getNumUnitInfos()):
  786.             loopUnit = PyInfo.UnitInfo(i)
  787.             if loopUnit.isAnimal():
  788.                 listUnits.append(loopUnit)
  789.         return listUnits
  790.  
  791.     def getListUnitCombatTypes(self, combatType, bUnique):
  792.         "listObj - list of unit infos of a particular combat type"
  793.         CombatTypes = {0:(0,'Neutral'),1:(1,'Recon'),2:(2,'Archery'),3:(3,'Mounted'),4:(4,'Melee'),5:(5,'Siege'),6:(6,'Gunpowder')}
  794.         listUnits = []
  795.         if bUnique:
  796.             UUidList = self.getListUniqueUnitID()
  797.         for i in range(gc.getNumUnitInfos()):
  798.             if bUnique:
  799.                 if i in UUidList:
  800.                     continue
  801.             loopUnit = PyInfo.UnitInfo(i)
  802.             if loopUnit.getUnitCombatType() == combatType:
  803.                 listUnits.append(loopUnit)
  804.         return listUnits
  805.     
  806.     def getListSeaUnits(self):
  807.         listUnits = []
  808.         for i in range(gc.getNumUnitInfos()):
  809.             loopUnit = PyInfo.UnitInfo(i)
  810.             domain = loopUnit.getDomainType()
  811.             if domain == DomainTypes.DOMAIN_SEA:
  812.                 listUnits.append(loopUnit)
  813.         return listUnits
  814.  
  815.     def getListAirUnits(self):
  816.         listUnits = []
  817.         for i in range(gc.getNumUnitInfos()):
  818.             loopUnit = PyInfo.UnitInfo(i)
  819.             domain = loopUnit.getDomainType()
  820.             if domain == DomainTypes.DOMAIN_AIR or domain == DomainTypes.DOMAIN_HELICOPTER:
  821.                 listUnits.append(loopUnit)
  822.         return listUnits
  823.  
  824. class PyPlot:
  825.     def __init__(self, plotIdx):
  826.         self.map = CyMap()
  827.         self.plot = self.map.getPlotByID(plotIdx)
  828.         self.player = gc.getActivePlayer()
  829.     
  830.     ############## G E N E R A L ##############
  831.     def getX(self):
  832.         "int - X coordinate"
  833.         return self.plot.getX()
  834.     
  835.     def getY(self):
  836.         "int - Y coordinate"
  837.         return self.plot.getY()
  838.     
  839.     def getOwner(self):
  840.         "int - playerIdx"
  841.         return self.plot.getOwner()
  842.     
  843.     def isUnit(self):
  844.         "int - unit present?"
  845.         return self.plot.isUnit()
  846.     
  847.     def getNumUnits(self):
  848.         "int - number of units"
  849.         return self.plot.getNumUnits()
  850.     
  851.     def isCity(self):
  852.         "bool - city present?"
  853.         return self.plot.isCity()
  854.         
  855.     def getPlotCity(self):
  856.         "obj - city instance"
  857.         if (self.isCity()):
  858.             return self.plot.getPlotCity()
  859.     
  860.     def getFoodYield(self):
  861.         "int - food yield"
  862.         return self.plot.getYield(YieldTypes.YIELD_FOOD)
  863.  
  864.     def getProductionYield(self):
  865.         "int - production yield"
  866.         return self.plot.getYield(YieldTypes.YIELD_PRODUCTION)
  867.  
  868.     def getCommerceYield(self):
  869.         "int - commerce yield"
  870.         return self.plot.getYield(YieldTypes.YIELD_COMMERCE)
  871.     
  872.     ############## T E R R A I N ##############    
  873.     def getTerrainType(self):
  874.         "int - terrain type XML ID"
  875.         return self.plot.getTerrainType()
  876.     
  877.     ############## B O N U S ##############
  878.     def getBonusType(self):
  879.         "int - Bonus Xml ID"
  880.         return self.plot.getBonusType(-1)
  881.     
  882.     def isBonus(self):
  883.         "bool - Any bonuses at all?"
  884.         if (self.getBonusType()):
  885.             return True
  886.         return False
  887.  
  888.     ############## F E A T U R E S ##############
  889.     def getFeatureType(self):
  890.         "int - Feature Type XML ID"
  891.         return self.plot.getFeatureType()
  892.     
  893.     def isFeature(self):
  894.         "bool - any feature at all?"
  895.         if (self.getFeatureType()):
  896.             return True
  897.         return False
  898.     
  899.     ############## I M P R O V E M E N T ##############    
  900.     def getImprovementType(self):
  901.         "int - Improvement Type XML ID"
  902.         return self.plot.getImprovementType()
  903.     
  904.     def isImprovement(self):
  905.         "bool - Any improvements at all?"
  906.         if (self.getImprovementType()):
  907.             return True
  908.         return False
  909.         
  910.     ############## R O U T E ##############
  911.     def getRouteType(self):
  912.         "int - route type XML ID"
  913.         return self.plot.getRouteType()
  914.         
  915. class PyInfo:
  916.     
  917.     def getInfoID(strInfoType, iID):
  918.         strInfoType = strInfoType.lower()
  919.         infoDict = InfoDictionary.get(strInfoType)
  920.         return infoDict['GET'](iID)
  921.     
  922.     def getPyInfoID(strPyInfoType, iID):
  923.         PyInfoTypes = {'unit':UnitInfo,'building':BuildingInfo,'tech':TechnologyInfo}
  924.         strInfoType = strPyInfoType.lower()
  925.         return PyInfoTypes.get(strInfoType)(iID)
  926.         
  927.     def getInfo(strInfoType, strInfoName):    # returns info for InfoType
  928.         #set Type to lowercase
  929.         strInfoType = strInfoType.lower()
  930.         strInfoName = strInfoName.capitalize()
  931.         
  932.         #get the appropriate dictionary item
  933.         infoDict = InfoDictionary.get(strInfoType)
  934.         #get the number of infos
  935.         numInfos = infoDict['NUM']()
  936.         #loop through each info
  937.         for i in range(numInfos):
  938.             loopInfo = infoDict['GET'](i)
  939.             
  940.             if loopInfo.getDescription() == strInfoName:
  941.                 #and return the one requested
  942.                 return loopInfo
  943.         
  944.     class BonusInfo:
  945.         "Bonus Info helper class"
  946.         def __init__(self, bonusID):
  947.             self.ID = bonusID
  948.             self.info = gc.getBonusInfo(self.ID)
  949.         
  950.         def isNone(self):
  951.             if not self.info:
  952.                 return True
  953.             return False
  954.             
  955.         def isValid(self):
  956.             if self.info:
  957.                 if self.ID >= 0 and self.ID < gc.getNumBonusInfos():
  958.                     return True
  959.             return False
  960.         
  961.         def getDescription(self):
  962.             "str - description of Bonus"
  963.             return self.info.getDescription()
  964.         
  965.         def getButton(self):
  966.             return CyArtFileMgr().getBonusArtInfo(self.info.getArtDefineTag()).getButton()
  967.                 
  968.         def getSymbol(self):
  969.             "unicode - iChar Symbol"
  970.             return u"%c" %(self.info.getChar(),)
  971.         
  972.         def getName(self):
  973.             "unicode - Bonuses Name"
  974.             return self.info.getDescription()
  975.         
  976.         def getPrereqImprovementID(self):
  977.             lImprovements = []
  978.             for i in range(gc.getNumImprovementInfos()):
  979.                 if self.ID in ImprovementInfo(i).getAffectedBonusIDList():
  980.                     lImprovements.append(i)
  981.             return lImprovements
  982.         
  983.         def getAPrereqImprovementID(self):
  984.             lImprovement = self.getPrereqImprovementID()
  985.             return lImprovement[0]
  986.         
  987.         def getPrereqImprovementTechPrereqID(self):
  988.             rTech = []
  989.             reqImprovement = self.getPrereqImprovementID()
  990.             for i in range(len(reqImprovement)):
  991.                 info = ImprovementInfo(reqImprovement[i])
  992.                 rTech.append(info.getTechPrereq())
  993.             return rTech
  994.         
  995.         def getATechPrereqID(self):
  996.             lTech = self.getPrereqImprovementTechPrereqID()
  997.             lenTech = len(lTech)
  998.             if lenTech > 0:
  999.                 return lTech[0]
  1000.             
  1001.             
  1002.         def getRevealTechDesc(self):
  1003.             "str - Tech the bonus is revealed"
  1004.             techReveal = self.info.getTechReveal()
  1005.             if techReveal and not techReveal == -1:
  1006.                 techInfo = TechnologyInfo(techReveal)
  1007.                 return techInfo.getDescription()
  1008.             return 0
  1009.         
  1010.         def getRevealTechID(self):
  1011.             "str - Tech the bonus is revealed"
  1012.             techReveal = self.info.getTechReveal()
  1013.             if techReveal and not techReveal == -1:
  1014.                 return techReveal
  1015.             return -1
  1016.                 
  1017.         def getRevealTechButton(self):
  1018.             "str - Location of button art for tech that reveals this bonus"
  1019.             techReveal = self.getRevealTechID()
  1020.             if techReveal and not techReveal == -1:
  1021.                 techInfo = TechnologyInfo(techReveal)
  1022.                 if techInfo:
  1023.                     return techInfo.getButton()
  1024.             return 0
  1025.             
  1026.         def getTradeTechDesc(self):
  1027.             "str - Tech required for Trading"
  1028.             techTrade = self.info.getTechCityTrade()
  1029.             if techTrade and not techTrade == -1:
  1030.                 techInfo = TechnologyInfo(techTrade)
  1031.                 return techInfo.getDescription()
  1032.             return 0
  1033.         
  1034.         def getTradeTechID(self):
  1035.             "str - Tech required for Trading"
  1036.             techTrade = self.info.getTechCityTrade()
  1037.             if techTrade and not techTrade == -1:
  1038.                 return techTrade
  1039.             return -1
  1040.         
  1041.         def getTradeTechButton(self):
  1042.             "str - location of button art for tech that allows trading of this resource"
  1043.             techTrade = self.getTradeTechID()
  1044.             if techTrade and not techTrade == -1:
  1045.                 techInfo = TechnologyInfo(techTrade)
  1046.                 if techInfo:
  1047.                     return techInfo.getButton()
  1048.             return 0
  1049.             
  1050.         def getHappy(self):
  1051.             "int - Happiness bonus"
  1052.             happy = self.info.getHappiness()
  1053.             if not happy == -1:
  1054.                 return happy
  1055.             return -1
  1056.         
  1057.         def getHealth(self):
  1058.             "int - Health bonus"
  1059.             health = self.info.getHealth()
  1060.             if not health == -1:
  1061.                 return health
  1062.             return -1
  1063.         
  1064.         def getFoodBonus(self):
  1065.             "int - Adjustment to Food yield"
  1066.             yieldChange = self.info.getYieldChange(YieldTypes.YIELD_FOOD)
  1067.             if yieldChange > 0:
  1068.                 return yieldChange
  1069.             return 0
  1070.         
  1071.         def getProductionBonus(self):
  1072.             "int - Adjustment to Production yield"
  1073.             yieldChange = self.info.getYieldChange(YieldTypes.YIELD_PRODUCTION)
  1074.             if yieldChange > 0:
  1075.                 return yieldChange
  1076.             return 0
  1077.             
  1078.         def getCommerceBonus(self):
  1079.             "int - Adjustment to Commerce yield"
  1080.             yieldChange = self.info.getYieldChange(YieldTypes.YIELD_COMMERCE)
  1081.             if yieldChange > 0:
  1082.                 return yieldChange
  1083.             return 0
  1084.         
  1085.         def checkTerrain(self,terrainID):
  1086.             "bool - does the bonus appear on terrainID?"
  1087.             return self.info.isTerrain(terrainID)
  1088.         
  1089.         def getBonusTerrainList(self):
  1090.             "int-list of terrainID's the bonus will spawn on"
  1091.             bonusTerrainList = []
  1092.             numTerrain = gc.getNumTerrainInfos()
  1093.             for i in range(numTerrain):
  1094.                 if self.info.isTerrain(i):
  1095.                     bonusTerrainList.append(i)
  1096.             return bonusTerrainList
  1097.         
  1098.         def getNumPossibleTerrains(self):
  1099.             "int - total terrains the bonus can appear on"
  1100.             return len(self.getBonusTerrainList())
  1101.         
  1102.         def checkFeature(self, featureID):
  1103.             "bool - does the bonus spawn on featureID?"
  1104.             return self.info.isFeature(featureID)
  1105.         
  1106.         def getFeatureTerrainList(self):
  1107.             "int-list of featureID's the bonus will spawn on"
  1108.             featureTerrainList = []
  1109.             numFeature = gc.getNumFeatureInfos()
  1110.             for i in range(numFeature):
  1111.                 if self.info.isFeature(i):
  1112.                     featureTerrainList.append(i)
  1113.             return featureTerrainList
  1114.         
  1115.         def getNumPossibleFeatures(self):
  1116.             "int - total features bonus can spawn on"
  1117.             return len(self.getFeatureTerrainList)
  1118.         
  1119.         def getImprovementChangeList(self):
  1120.             "int-list of ImprovementID's the bonus affects"
  1121.             ImprovementList = []
  1122.             for i in range(gc.getNumImprovementInfos()):
  1123.                 loopInfo = ImprovementInfo(i)
  1124.                 if self.ID in loopInfo.getAffectedBonusIDList():
  1125.                     ImprovementList.append(loopInfo)
  1126.             return ImprovementList
  1127.         
  1128.         def getImprovementChangeIDList(self):
  1129.             iList = []
  1130.             for i in range(gc.getNumImprovementInfos()):
  1131.                 loopInfo = ImprovementInfo(i)
  1132.                 idList = loopInfo.getAffectedBonusIDList()
  1133.                 if self.ID in idList:
  1134.                     iList.append(i)
  1135.             return iList
  1136.         
  1137.         def getNumImprovementChanges(self):
  1138.             return len(self.getImprovementChangeList())
  1139.         
  1140.         def getImprovementModifierInfo(self):
  1141.             iImprovement = self.getAPrereqImprovementID()
  1142.             info = ImprovementInfo(iImprovement)
  1143.             lEffects = []
  1144.             for i in range(YieldTypes.NUM_YIELD_TYPES):
  1145.                 iResult = info.getImprovementBonusYield(self.ID, i)
  1146.                 lEffects.append((i, iResult))
  1147.             return lEffects
  1148.         
  1149.         def getImprovementFoodBonus(self):
  1150.             return self.getImprovementModifierInfo()[0][1]
  1151.         
  1152.         def getImprovementProductionBonus(self):
  1153.             return self.getImprovementModifierInfo()[1][1]
  1154.     
  1155.         def getImprovementCommerceBonus(self):
  1156.             return self.getImprovementModifierInfo()[2][1]
  1157.         
  1158.         def isImprovement(self, ImprovementID):
  1159.             iList = self.getImprovementChangeIDList()
  1160.             if ImprovementID in iList:
  1161.                 return True
  1162.             return False
  1163.         
  1164.         def getListImprovementButtons(self):
  1165.             lButtons = []
  1166.             lImprovements = self.getImprovementChangeList()
  1167.             for i in range(len(lImprovements)):
  1168.                 lButtons.append(lImprovements[i].getButton())
  1169.             return lButtons
  1170.         
  1171.         def getScale(self):
  1172.             "int - the bonuses scale"
  1173.             return self.info.fScale
  1174.         
  1175.     class UnitInfo:
  1176.         "Unit Info helper class"
  1177.         def __init__(self, unitTypeID):
  1178.             self.unitTypeID = unitTypeID
  1179.             self.info = gc.getUnitInfo(self.unitTypeID)
  1180.         
  1181.         def isValid(self):
  1182.             if self.info:
  1183.                 return True
  1184.             return False
  1185.         
  1186.         def getID(self):
  1187.             return self.unitTypeID
  1188.             
  1189.         def getDescription(self):
  1190.             "str - Units Name"
  1191.             return self.info.getDescription()
  1192.         
  1193.         def getButton(self):
  1194.             "str - Units KFM Button - DDS Format"
  1195.             return CyArtFileMgr().getUnitArtInfo(self.info.getArtDefineTag(0)).getButton()
  1196.         
  1197.         def isAnimal(self):
  1198.             "bool - an animal?"
  1199.             if self.info.isAnimal():
  1200.                 return True
  1201.             return False
  1202.         
  1203.         def isFoodProduction(self):
  1204.             "bool - requires food production?"
  1205.             if self.info.isFoodProduction():
  1206.                 return True
  1207.             return False
  1208.             
  1209.         def getCombatStrength(self):
  1210.             "int - base combat strength"
  1211.             return self.info.getCombat()
  1212.         
  1213.         def getMoves(self):
  1214.             "int - base unit movements"
  1215.             return self.info.getMoves()
  1216.         
  1217.         def getProductionCost(self):
  1218.             "int - production cost"
  1219.             return self.info.getProductionCost()
  1220.         
  1221.         def getDomainType(self):
  1222.             "int - domain type"
  1223.             return self.info.getDomainType()
  1224.         
  1225.         def getUnitClassType(self):
  1226.             "str - unit class type"
  1227.             return self.info.getUnitClassType()
  1228.         
  1229.         def isUniqueUnit(self):
  1230.             "bool - is this unit a unique unit"
  1231.             lUniqueUnits = PyGame.PyGame().getListUniqueUnitID()
  1232.             if self.unitID in lUniqueUnits:
  1233.                 return True
  1234.             return False
  1235.         
  1236.         def getListUnitClassID(self):
  1237.             "intList - id list of all unit infos that match combat type with current unit"
  1238.             lUnitClassID = []
  1239.             for i in range(gc.getNumUnitInfos()):
  1240.                 if UnitInfo(i).getUnitClassType() == self.getUnitClassType():
  1241.                     lUnitClassID.append(i)
  1242.             return lUnitClassID
  1243.             
  1244.         def getUnitCombatType(self):
  1245.             "int - combat type"
  1246.             return self.info.getUnitCombatType()
  1247.         
  1248.         def getUnitAITypes(self, AIType):
  1249.             "objlist - list of units of AIType"
  1250.             UnitAIList=[]
  1251.             for i in range(UnitAITypes.NUM_UNITAI_TYPES):
  1252.                 if self.info.getUnitAITypes(i) == AIType:
  1253.                     UnitAIList.append(i)
  1254.             return UnitAIList
  1255.         
  1256.         def isTechPrereq(self,techID):
  1257.             "bool - is techID a prereq of this tech?"
  1258.             if techID == self.getTechPrereqID():
  1259.                 return True
  1260.             elif techID in self.getPrereqOrTechIDList():
  1261.                 return True
  1262.             return False        
  1263.         
  1264.         def isLatestTechPrereq(self,techID):
  1265.             pTechOr = self.getPrereqOrTechIDList()
  1266.             if pTechOr:
  1267.                 pTechOr = pTechOr.sort()
  1268.                 for i in range(len(pTechOr)):
  1269.                     if techID < pTechOr[i]:
  1270.                         return True
  1271.             return False
  1272.         
  1273.         def getTechPrereq(self):
  1274.             "str - prerequisite technology"
  1275.             pTech = self.info.getPrereqAndTech()
  1276.             if pTech >= 0 and pTech < gc.getNumTechInfos():
  1277.                 return TechnologyInfo(pTech).getDescription()
  1278.         
  1279.         def getTechPrereqID(self):
  1280.             "int - prerequisite techs xml id"
  1281.             pTech = self.info.getPrereqAndTech()
  1282.             if pTech >= 0 and pTech < gc.getNumTechInfos():
  1283.                 return pTech
  1284.             return -1
  1285.         
  1286.         def getTechPrereqButton(self):
  1287.             "str - location of techs button art"
  1288.             pTech = self.getTechPrereqID()
  1289.             if pTech and not pTech == 0:
  1290.                 return TechnologyInfo(pTech).getButton()
  1291.         
  1292.         def getPrereqOrTechIDList(self):
  1293.             "intList - IDList of multiple tech requirements"
  1294.             pTechIDList = []
  1295.             for i in range(gc.getDefineINT("NUM_UNIT_OR_TECH_PREREQS")):
  1296.                 iResult = self.info.getPrereqOrTechs(i)
  1297.                 if iResult >= 0:
  1298.                     pTechIDList.append(iResult)
  1299.             return pTechIDList
  1300.         
  1301.         def getPrereqOrTechInfoList(self):
  1302.             "objList - Info list of IDList items"
  1303.             pTechIDList = self.getPrereqOrTechIDList()
  1304.             pTechInfos = []
  1305.             for i in range(len(pTechIDList)):
  1306.                 pTechInfos.append(UnitInfo(pTechIDList[i]))
  1307.             return pTechInfos
  1308.         
  1309.         def getPrereqBonusID(self):
  1310.             "int - required bonus ID"
  1311.             if self.info.getPrereqAndBonus():
  1312.                 return self.info.getPrereqAndBonus()
  1313.             return -1
  1314.             
  1315.         def getPrereqBonusInfo(self):
  1316.             "obj - info for required bonus ID"
  1317.             pBonus = self.info.getPrereqAndBonus()
  1318.             if pBonus >= 0 and pBonus <= gc.getNumBonusInfos():
  1319.                 return pBonus
  1320.     
  1321.         def getPrereqBonusIcon(self):
  1322.             "str - prerequisite bonus"
  1323.             pBonus = self.info.getPrereqAndBonus()
  1324.             if pBonus >= 0 and pBonus < gc.getNumBonusInfos():
  1325.                 return "%c" %(BonusInfo(pBonus).getSymbol())
  1326.             return ""
  1327.         
  1328.         def getPrereqBonusIDList(self):
  1329.             "intList - ID list of multiple bonus requirements"
  1330.             preqBonusIDList = []
  1331.             for i in range(gc.getNUM_UNIT_PREREQ_OR_BONUSES()):
  1332.                 iResult = self.info.getPrereqOrBonuses(i)
  1333.                 if iResult >=0:
  1334.                     preqBonusIDList.append(iResult)
  1335.             return preqBonusIDList
  1336.         
  1337.         def getPrereqBonusInfoList(self):
  1338.             "objList - Info list of multiple bonus requirements"
  1339.             bInfos = []
  1340.             pBonuses = self.getPrereqBonusIDList()
  1341.             for item in pBonuses:
  1342.                 bInfos.append(UnitInfo(item))
  1343.             return bInfos
  1344.     
  1345.         def getPrereqBonusIcons(self):
  1346.             "str - string with all required bonuses"
  1347.             bonusIcons = ""
  1348.             pBonuses = self.getPrereqBonusIDList()
  1349.             for i in range(len(pBonuses)):
  1350.                 loopID = pBonuses[i]
  1351.                 loopIcon = BonusInfo(loopID).getSymbol()
  1352.                 bonusIcons+= loopIcon
  1353.             return bonusIcons
  1354.         
  1355.     class SpecialistInfo:
  1356.         "Specialist Info helper class"
  1357.         def __init__(self, specialistID):
  1358.             self.specialistID = specialistID
  1359.             self.info = gc.getSpecialistInfo(self.specialistID)
  1360.         
  1361.         def isValid(self):
  1362.             if self.info:
  1363.                 return True
  1364.             return False
  1365.         
  1366.         def getName(self):
  1367.             "str - Specialist Name"
  1368.             return self.info.getDescription()
  1369.         
  1370.         def getIcon(self):
  1371.             "str - Specialist Icon"
  1372.             return CvUtil.getIcon('GREATPEOPLE')
  1373.             
  1374.         def getGoldCommerce(self):
  1375.             "int - generated Gold Commerce"
  1376.             return self.info.getCommerceChange(CommerceTypes.COMMERCE_GOLD)
  1377.         
  1378.         def getResearchCommerce(self):
  1379.             "int - generated Research Commerce"
  1380.             return self.info.getCommerceChange(CommerceTypes.COMMERCE_RESEARCH)
  1381.         
  1382.         def getCultureCommerce(self):
  1383.             "int - generated Culture Commerce"
  1384.             return self.info.getCommerceChange(CommerceTypes.COMMERCE_CULTURE)
  1385.         
  1386.         def getFoodYield(self):
  1387.             "int - generated Food Yield"
  1388.             return self.info.getYieldChange(YieldTypes.YIELD_FOOD)
  1389.         
  1390.         def getProductionYield(self):
  1391.             "int - generated Production Yield"
  1392.             return self.info.getYieldChange(YieldTypes.YIELD_PRODUCTION)
  1393.         
  1394.         def getCommerceYield(self):
  1395.             "int - generated Commerce Yield"
  1396.             return self.info.getYieldChange(YieldTypes.YIELD_COMMERCE)
  1397.         
  1398.         def getRequiredBuildingID(self):
  1399.             "int - Required Buildings XML ID"
  1400.             numBuildings = gc.getNumBuildingInfos()
  1401.             for i in range(numBuildings):
  1402.                 buildingInfo = gc.getBuildingInfo(i)
  1403.                 if ( buildingInfo and buildingInfo.iSpecialist == self.specialistID ):
  1404.                     return i
  1405.             return -1
  1406.     
  1407.         def getRequiredBuildingName(self):
  1408.             "str - Required Buildings Name"
  1409.             reqBuildingID = self.getRequiredBuildingID()
  1410.             if not reqBuildingID == -1:
  1411.                 return BuildingInfo(reqBuildingID).getDescription()
  1412.         
  1413.         def getRequiredBuildingButton(self):
  1414.             "int - Required Buildings Button"
  1415.             reqBuildingID = self.getRequiredBuildingID()
  1416.             if not reqBuildingID == -1:
  1417.                 return BuildingInfo(reqBuildingID).getButton()
  1418.             return 0
  1419.         
  1420.         def getBuildingRequiredTechID(self):
  1421.             "int - required buildings ID"
  1422.             reqBuildingID = self.getRequiredBuildingID()
  1423.             if not reqBuildingID == -1:
  1424.                 return BuildingInfo(reqBuildingID).getTechPrereq()
  1425.             return -1
  1426.         
  1427.         def getBuildingRequiredTechnologyButton(self):
  1428.             "str - building requireds technology button path"
  1429.             techID = self.getBuildingRequiredTechID()
  1430.             if not techID == -1:
  1431.                 return TechnologyInfo(techID).getButton()
  1432.             return ""
  1433.         
  1434.     class TechnologyInfo:
  1435.         "Technology Info class for easier manipulation of this object"
  1436.         def __init__(self, techID):
  1437.             self.techID = techID
  1438.             self.info = gc.getTechInfo(techID)
  1439.         
  1440.         def isValid(self):
  1441.             if self.info:
  1442.                 return True
  1443.             return False
  1444.         
  1445.         def getID(self):
  1446.             "int - tech instances id"
  1447.             return self.techID
  1448.         
  1449.         def getDescription(self):
  1450.             "str - techs name"
  1451.             return self.info.getDescription()
  1452.         
  1453.         def getButton(self):
  1454.             "str - location of kfm button"
  1455.             if self.isValid():
  1456.                 return self.info.getButton()
  1457.             return 0
  1458.         
  1459.         def createPrereqDictionary(self):
  1460.             pDict = {}
  1461.             for i in range(gc.getNumTechInfos()):
  1462.                 TechInfo = TechnologyInfo(i)
  1463.                 pDict[i]=(i,"%s" %(TechInfo.getDescription()), TechInfo.getTechPreqIdxList())
  1464.             return pDict
  1465.         
  1466.         def createNamePrereqDictionary(self):
  1467.             pDict = {}
  1468.             f = file('TechPrereq.txt', "w")
  1469.             f.write("### CIV Tech Prereq List ###\n\n")
  1470.             for i in range(gc.getNumTechInfos()):
  1471.                 lInfo = TechnologyInfo(i)
  1472.                 f.write("\n   (%d)%s - %s" %(i, lInfo.getDescription(), lInfo.getTechPreqDescList()))
  1473.             f.close()
  1474.         
  1475.         def getTechPreqIdxList(self):
  1476.             "intList - list of prerequisite techs in nested forum ((mining,agriculture),(agriculture,thewheel))"
  1477.             techInfo = self.info
  1478.             preqList = []
  1479.             info = ()
  1480.             for i in range(4):
  1481.                 for j in range(4):
  1482.                     result = techInfo.getTechPrereqs(i,j)
  1483.                     if not result == -1:
  1484.                         info = info + (result,)
  1485.                     if j == 3 and not len(info) < 1:
  1486.                         if len(info) == 0:
  1487.                             pass            
  1488.                         preqList.append(info)
  1489.                         info = ()
  1490.             return preqList
  1491.         
  1492.         def getTechPreqDescList(self):
  1493.             lPrereqID=self.getTechPreqIdxList()
  1494.             lPrereqDesc = []
  1495.             lInfo = []
  1496.             for i in range(len(lPrereqID)):
  1497.                 lGroup = lPrereqID[i]
  1498.                 if len(lGroup) > 0:
  1499.                     for j in range(len(lPrereqID[i])):
  1500.                         lGroup2 = lPrereqID[i][j]
  1501.                         lInfo.append(TechnologyInfo(lGroup2).getDescription())
  1502.                 lPrereqDesc.append(lInfo)
  1503.                 lInfo=[]
  1504.             return lPrereqDesc
  1505.         
  1506.         def getTechPreqInfoList(self):
  1507.             "objList - takes the ID functions and returns them in info form"
  1508.             preqList = self.getTechPreqIdxList()
  1509.             infoList = []
  1510.             infoGroup = ()
  1511.             if preqList:
  1512.                 for i in range(len(preqList)):
  1513.                     loopGroup = preqList[i]                
  1514.                     for j in range(len(loopGroup)):
  1515.                         loopID = loopGroup[j]
  1516.                         loopInfo = TechnologyInfo(loopID)
  1517.                         if loopInfo:
  1518.                             infoGroup = infoGroup + (loopInfo,)
  1519.                     if infoGroup:
  1520.                         infoList.append(infoGroup)
  1521.                         infoGroup = ()
  1522.             return infoList
  1523.         
  1524.         def getTechPreqButtonList(self):
  1525.             "objList - list of preqtechs buttons locations"
  1526.             pTechButtons = []
  1527.             for info in self.getTechPreqInfoList():
  1528.                 button = info.getButton()
  1529.                 pTechButtons.append(button)
  1530.             return pTechButtons
  1531.         
  1532.         def getResearchCost(self):
  1533.             "int - research cost"
  1534.             return self.info.getResearchCost()
  1535.         
  1536.         def getiEra(self):
  1537.             "int - the techs era"
  1538.             return self.info.getEra()
  1539.         
  1540.         def isWorkerSpeedModifier(self):
  1541.             "bool - tech modify worker speed?"
  1542.             return self.info.iWorkerSpeedModifier
  1543.         
  1544.         def getTradeRouteModifer(self):
  1545.             "int - trade route modifier"
  1546.             if self.info.iTradeRoutes:
  1547.                 return self.info.iTradeRoutes
  1548.             return 0
  1549.         
  1550.         def getWorkerSpeedModifier(self):
  1551.             "int - how much are they modified?"
  1552.             if self.info.iWorkerSpeedModifier > 0:
  1553.                 return self.info.iWorkerSpeedModifier
  1554.             return 0
  1555.         
  1556.         def isGoodyTech(self):
  1557.             "bool - can this tech be researched from popping a goodie hut?"
  1558.             if self.info.bGoodyTech:
  1559.                 return True
  1560.             return False
  1561.         
  1562.         def getHealthBonus(self):
  1563.             if self.info.getHealth():
  1564.                 return self.info.getHealth()
  1565.             return 0
  1566.             
  1567.         def getUnlockedBuildingIdxList(self):
  1568.             "intList - IDList of unlocked Buildings"
  1569.             buildingList=[]
  1570.             numBuilding = gc.getNumBuildingInfos()
  1571.             for i in range(numBuilding):
  1572.                 loopBuilding = gc.getBuildingInfo(i)
  1573.                 if loopBuilding.getPrereqAndTech() == self.techID:
  1574.                     buildingList.append(i)
  1575.             return buildingList
  1576.         
  1577.         def getListUnlockedBuildingInfos(self):
  1578.             "objList - info list of unlocked buildings"
  1579.             idList = self.getUnlockedBuildingIdxList()
  1580.             buildingList = []
  1581.             for i in range(len(idList)):
  1582.                 buildingList.append(BuildingInfo(idList[i]))
  1583.             return buildingList            
  1584.         
  1585.         def getUnlockedUnitIdxList(self):
  1586.             "intList - IDList of unlocked Units"
  1587.             unitList=[]
  1588.             for i in range(gc.getNumUnitInfos()):
  1589.                 loopUnit = UnitInfo(i)
  1590.                 if loopUnit.isTechPrereq(self.techID):
  1591.                     unitList.append(i)
  1592.             return unitList
  1593.         
  1594.         def getNoUniqueUnlockedUnitIDList(self):
  1595.             lUniqueUnits = PyGame.PyGame().getListUniqueUnitID()
  1596.             lAllUnits = self.getUnlockedUnitIdxList()
  1597.             lUnits = []
  1598.             for i in range(len(lAllUnits)):
  1599.                 loopUnit = lAllUnits[i]
  1600.                 if loopUnit in lUniqueUnits:
  1601.                     continue
  1602.                 else:
  1603.                     lUnits.append(loopUnit)
  1604.             return lUnits
  1605.     
  1606.         def getListUnlockedUnitInfos(self):
  1607.             "objList - info list of unlocked units"
  1608.             unitList = []
  1609.             for i in range(len(self.getUnlockedUnitIdxList())):
  1610.                 unitList.append(UnitInfo(idList[i]))
  1611.             return unitList
  1612.         
  1613.         def getNoUniqueUnlockedUnitInfoList(self):
  1614.             lUnitInfos = []
  1615.             for unitID in self.getNoUniqueUnlockedUnitIDList():
  1616.                 lUnitInfos.append(UnitInfo(unitID))
  1617.             return lUnitInfos
  1618.     
  1619.         def getUnlockedReligionIdxList(self):
  1620.             "intList - IDList of unlocked Religions"
  1621.             religionlist = []
  1622.             for i in range(gc.getNumReligionInfos()):
  1623.                 if ( gc.getReligionInfo(i).getTechPrereq() == self.techID ): 
  1624.                     religionList.append(i)
  1625.             return religionList
  1626.         
  1627.         def getReligionButton(self):
  1628.             "str - religion icon"
  1629.             for i in range(gc.getNumReligionInfos()):
  1630.                 if ( gc.getReligionInfo(i).getTechPrereq() == self.techID ):
  1631.                     return "%c" %(gc.getReligionInfo(i).getChar(),)
  1632.             return 0
  1633.         
  1634.         def isBuildTech(self):
  1635.             "bool - unlocks build"
  1636.             for i in range(gc.getNumBuildInfos()):
  1637.                 if ( BuildInfo(i).getTechPrereq() == self.techID ):
  1638.                     return True
  1639.             return False
  1640.         
  1641.         def getUnlockedBuildInfos(self):
  1642.             "objList - list of build infos the tech unlocks"
  1643.             lBuilds = []
  1644.             for i in range(gc.getNumBuildInfos()):
  1645.                 if ( BuildInfo(i).getTechPrereq() == self.techID ):
  1646.                     lBuilds.append(BuildInfo(i))
  1647.             return lBuilds
  1648.         
  1649.         def isCivicTech(self):
  1650.             "bool - tech unlocks Civic?"
  1651.             for i in range(gc.getNumCivicInfos()):
  1652.                 if ( gc.getCivicInfo(i).getTechPrereq() == self.techID ):
  1653.                     return True
  1654.             return False
  1655.         
  1656.         def getUnlockedCivicInfos(self):
  1657.             "objList - list of civic infos the tech unlocks"
  1658.             lCivics=[]
  1659.             for i in range(gc.getNumCivicInfos()):
  1660.                 if ( gc.getCivicInfo(i).getTechPrereq() == self.techID ):
  1661.                     lCivics.append(i)
  1662.             return lCivics
  1663.     
  1664.     class ImprovementInfo:
  1665.         def __init__(self, improvementID):
  1666.             self.ID = improvementID
  1667.             self.info = gc.getImprovementInfo(self.ID)
  1668.         
  1669.         def getID(self):
  1670.             return self.ID
  1671.         
  1672.         def getDescription(self):
  1673.             return self.info.getDescription()
  1674.         
  1675.         def getButton(self):
  1676.             return CyArtFileMgr().getImprovementArtInfo(self.info.getArtDefineTag()).getButton()
  1677.         
  1678.         def isValid(self):
  1679.             if self.info:
  1680.                 return True
  1681.             return False
  1682.         
  1683.         # XXX Should this be isWater? - JShafer
  1684.         def isFreshWater(self):
  1685.             if self.info.isFreshWater():
  1686.                 return True
  1687.             return False
  1688.         
  1689.         def isGoody(self):
  1690.             if self.info.isGoody():
  1691.                 return True
  1692.             return False
  1693.         
  1694.         def getTilesPerGoody(self):
  1695.             return self.info.getTilesPerGoody()
  1696.         
  1697.         def getGoodyUniqueRange(self):
  1698.             return self.info.getGoodyUniqueRange()
  1699.         
  1700.         def getUpgradeTime(self):
  1701.             return self.info.getUpgradeTime()
  1702.         
  1703.         def getPillageGold(self):
  1704.             return self.info.getPillageGold()
  1705.         
  1706.         def getImprovementUpgrade(self):
  1707.             return self.info.getImprovementUpgrade()
  1708.         
  1709.         # XXX Do these exist? - JShafer
  1710.         def getScale(self):
  1711.             return self.info.fScale
  1712.         
  1713.         def canTerrain(self, iTerrain):
  1714.             return self.info.getTerrain(iTerrain)
  1715.         
  1716.         def canFeature(self, iFeature):
  1717.             return self.info.getFeature(iFeature)
  1718.         
  1719.         def getYieldChange(self, iYield):
  1720.             return self.info.getYieldChange(iYield)
  1721.         
  1722.         def getHillsYieldChange(self, iYield):
  1723.             return self.info.getHillsYieldChange(iYield)
  1724.         
  1725.         def getRiverSideYieldChange(self, iYield):
  1726.             return self.info.getRiverSideYieldChange(iYield)
  1727.         
  1728.         def getPrereqNatureYield(self, i):
  1729.             return self.info.getPrereqNatureYield(i)
  1730.         
  1731.         def getIrrigatedYieldChange(self, iYield):
  1732.             return self.info.getIrrigatedYieldChange(iYield)
  1733.         
  1734.         def getImprovementBonusYield(self, i, j):
  1735.             return self.info.getImprovementBonusYield(i, j)
  1736.         
  1737.         def getBuildInfo(self):
  1738.             for i in range(gc.getNumBuildInfos()):
  1739.                 if gc.getBuildInfo(i).iImprovement == self.ID:
  1740.                     return gc.getBuildInfo(i)
  1741.         
  1742.         def getTechPrereq(self):
  1743.             return self.getBuildInfo().getTechPrereq()
  1744.         
  1745.         def getValidTerrainIDList(self):
  1746.             "intList - terrain ID's the improvement can be built on"
  1747.             lTerrain = []
  1748.             for i in range(gc.getNumTerrainInfos()):
  1749.                 if self.canTerrain(i):
  1750.                     lTerrain.append(i)
  1751.             return lTerrain
  1752.         
  1753.         def getValidTerrainInfoList(self):
  1754.             "objList - terrain infos"
  1755.             lTerrain = self.getValidTerrainIDList()
  1756.             if lTerrain > 0:
  1757.                 for i in range(len(lTerrain)):
  1758.                     lTerrain[i] = gc.getTerrainInfo(i)
  1759.                 return lTerrain
  1760.         
  1761.         def getValidFeatureIDList(self):
  1762.             "intList - feature ID's the improvement can be built on"
  1763.             lFeature = []
  1764.             for i in range(gc.getNumFeatureInfos()):
  1765.                 if self.canFeature(i):
  1766.                     lFeature.append(i)
  1767.             return lFeature
  1768.         
  1769.         def getValidFeatureInfoList(self):
  1770.             "objList - features info"
  1771.             lFeature = self.getValidFeatureIDList()
  1772.             if lFeature > 0:
  1773.                 for i in range(len(lFeature)):
  1774.                     lFeature[i] = gc.getFeatureInfo(i)
  1775.                 return lFeature
  1776.         
  1777.         def getBonusList(self):
  1778.             "loops through all of the bonuses and determines the effect this improvement has on it"
  1779.             lBonus = []
  1780.             for i in range(gc.getNumBonusInfos()):
  1781.                 for j in range(YieldTypes.NUM_YIELD_TYPES):
  1782.                     iResult = self.getImprovementBonusYield(i, j)     
  1783.                     if iResult:
  1784.                         item = (i, j, iResult)
  1785.                         lBonus.append(item)
  1786.             return lBonus
  1787.         
  1788.         def getAffectedBonusIDList(self):
  1789.             "intList - just the Bonus ID's that are affected"
  1790.             lBonus = self.getBonusList()
  1791.             lBonusID = []
  1792.             if lBonus:
  1793.                 for i in range(len(lBonus)):
  1794.                     loopEntry = lBonus[i]
  1795.                     lBonusID.append(loopEntry[0])
  1796.             return lBonusID
  1797.         
  1798.         def getAffectedBonusInfoList(self):
  1799.             "objList - affected bonuses infos"
  1800.             lBonusID = self.getAffectedBonusIDList()
  1801.             lBonus=[]
  1802.             lBonusTrack = []
  1803.             if lBonusID:
  1804.                 for i in range(len(lBonusID)):
  1805.                     loopID = lBonusID[i]
  1806.                     if loopID in lBonusTrack: #dont need multiple infos for the same bonus
  1807.                         continue
  1808.                     lBonus.append(BonusInfo(loopID))
  1809.                     lBonusTrack.append(loopID)
  1810.             return lBonus
  1811.         
  1812.         def getBonusInfoList(self):
  1813.             lBonus = self.getBonusList()
  1814.             nlBonus = []
  1815.             if lBonus:
  1816.                 for i in range(len(lBonus)):
  1817.                     loopEntry = lBonus[i]
  1818.                     loopBonus = BonusInfo(loopEntry[0])
  1819.                     loopYield = gc.getYieldInfo(loopEntry[1])
  1820.                     loopModifier = loopEntry[2]
  1821.                     loopItem = (loopBonus,loopYield,loopModifier)
  1822.                     nlBonus.append(loopItem)
  1823.             return nlBonus
  1824.         
  1825.         def getBonusIcons(self):
  1826.             lBonus = self.getAffectedBonusInfoList()
  1827.             lIcons = ""
  1828.             if lBonus:
  1829.                 for i in range(len(lBonus)):
  1830.                     lIcons += lBonus[i].getSymbol()
  1831.             return lIcons
  1832.     
  1833.     class CivicInfo:
  1834.         def __init__(self, iCivicInfoID):
  1835.             self.ID = iCivicInfoID
  1836.             self.TYPE = gc.getCivicInfo(self.ID).getCivicOptionType()
  1837.             self.info = gc.getCivicInfo(self.TYPE, self.ID)
  1838.         
  1839.         def getID(self):
  1840.             return self.ID
  1841.             
  1842.         def getDescription(self):
  1843.             return self.info.getDescription()
  1844.         
  1845.         def getName(self):
  1846.             return self.getDescription()
  1847.         
  1848.         def getMaintenance(self):
  1849.             if self.info.getMaintenance():
  1850.                 return self.info.getMaintenance()
  1851.             return 0
  1852.             
  1853.         def getButton(self):
  1854.             return TechnologyInfo(self.getTechPrereq()).getButton()
  1855.         
  1856.         def getTechPrereq(self):
  1857.             return self.info.getTechPrereq()
  1858.     
  1859.     class PromotionInfo:
  1860.         def __init__(self, iPromotionID):
  1861.             self.ID = iPromotionID
  1862.             self.info = gc.getPromotionInfo(self.ID)
  1863.         
  1864.         def getDescription(self):
  1865.             return self.info.getDescription()
  1866.         
  1867.         def getButton(self):
  1868.             return self.info.getButton()
  1869.         
  1870.         def getCityAttackPercent(self):
  1871.             if self.info.getCityAttackPercent():
  1872.                 return self.info.getCityAttackPercent()
  1873.             return 0
  1874.         
  1875.         def getCityDefensePercent(self):
  1876.             if self.info.getCityDefensePercent():
  1877.                 return self.info.getCityDefensePercent()
  1878.             return 0
  1879.         
  1880.         def getCombatPercent(self):
  1881.             if self.info.getCombatPercent():
  1882.                 return self.info.getCombatPercent()
  1883.             return 0
  1884.         
  1885.         def getHillsDefensePercent(self):
  1886.             if self.info.getHillsDefensePercent():
  1887.                 return self.info.getHillsDefensePercent()
  1888.             return 0
  1889.         
  1890.         def getChanceFirstStrikesChange(self):
  1891.             if self.info.getChanceFirstStrikesChange():
  1892.                 return self.info.getChanceFirstStrikesChange()
  1893.             return 0
  1894.         
  1895.         def getCollateralDamageChange(self):
  1896.             if self.info.getCollateralDamageChange():
  1897.                 return self.info.getCollateralDamageChange()
  1898.             return 0
  1899.         
  1900.         def getEnemyHealChange(self):
  1901.             if self.info.getEnemyHealChange():
  1902.                 return self.info.getEnemyHealChange()
  1903.             return 0
  1904.         
  1905.         def getFirstStrikesChange(self):
  1906.             if self.info.getFirstStrikesChange():
  1907.                 return self.info.getFirstStrikesChange()
  1908.             return 0
  1909.         
  1910.         def getFriendlyHealChange(self):
  1911.             if self.info.getFriendlyHealChange():
  1912.                 return self.info.getFriendlyHealChange()
  1913.             return 0
  1914.         
  1915.         def getNeutralHealChange(self):
  1916.             if self.info.getNeutralHealChange():
  1917.                 return self.info.getNeutralHealChange()
  1918.             return 0
  1919.     
  1920.         def getPrereqPromotionID(self):
  1921.             return self.info.iPrereqPromotion
  1922.         
  1923.         def getMoveDiscountChange(self):
  1924.             if self.info.iMoveDiscountChange:
  1925.                 return self.info.iMoveDiscountChange
  1926.             return 0
  1927.         
  1928.         def getVisibilityChange(self):
  1929.             if self.info.getVisibilityChange():
  1930.                 return self.info.getVisibilityChange()
  1931.             return 0
  1932.         
  1933.         def getWithdrawalChange(self):
  1934.             if self.info.getWithdrawalChange():
  1935.                 return self.info.getWithdrawalChange()
  1936.             return 0
  1937.         
  1938.         def getFeatureDefensePercent(self, iFeature):
  1939.             return self.info.getFeatureDefensePercent(iFeature)
  1940.         
  1941.         def getTerrainDefensePercent(self, iTerrain):
  1942.             return self.info.getTerrainDefensePercent(iTerrain)
  1943.         
  1944.         def getFeatureDefenseIDList(self):
  1945.             lFeatures = []
  1946.             for i in range(gc.getNumFeatureInfos()):
  1947.                 if self.getFeatureDefensePercent(i):
  1948.                     lFeatures.append(i)
  1949.             return lFeatures
  1950.         
  1951.         def getFeatureDefenseInfoList(self):
  1952.             lFeatures = self.getFeatureDefenseIDList()
  1953.             lInfo = []
  1954.             for i in range(len(lFeatures)):
  1955.                 lInfo.append(gc.getFeatureInfo(lFeatures[i]))
  1956.             return lInfo
  1957.         
  1958.         def getTerrainDefenseIDList(self):
  1959.             lTerrain = []
  1960.             for i in range(gc.getNumTerrainInfos()):
  1961.                 if self.getTerrainDefensePercent(i):
  1962.                     lTerrain.append(i)
  1963.             return lTerrain
  1964.         
  1965.         def getTerrainDefenseInfoList(self):
  1966.             lTerrain = self.getTerrainDefenseIDList()
  1967.             lInfo = []
  1968.             for i in range(len(lTerrain)):
  1969.                 lInfo.append(gc.getTerrainInfo(lTerrain[i]))
  1970.             return lInfo    
  1971.         
  1972.             
  1973.     class BuildingInfo:
  1974.         "Building Info helper class"
  1975.         def __init__(self, buildingID):    
  1976.             self.buildingID = buildingID
  1977.             self.info = gc.getBuildingInfo(self.buildingID)
  1978.         
  1979.         def isValid(self):
  1980.             if self.info:
  1981.                 return True
  1982.             return False
  1983.         
  1984.         def getID(self):
  1985.             return self.buildingID
  1986.         
  1987.         def getDescription(self):
  1988.             return self.info.getDescription()
  1989.         
  1990.         def getButton(self):
  1991.             return CyArtFileMgr().getBuildingArtInfo(self.info.getArtDefineTag()).getButton()
  1992.         
  1993.         def getTechPrereq(self):
  1994.             return self.info.getPrereqAndTech()
  1995.     
  1996.     class FeatureInfo:
  1997.         def __init__(self, featureID):
  1998.             self.featureID = featureID
  1999.             self.info = gc.getFeatureInfo(self.featureID)
  2000.         
  2001.         def isValid(self):
  2002.             "is it a valid instance?"
  2003.             if self.info:
  2004.                 return True
  2005.             return False
  2006.         
  2007.         def getDescription(self):
  2008.             "string - name of feature"
  2009.             return self.info.getDescription()
  2010.         
  2011.         def getButton(self):
  2012.             "string - returns Button"
  2013.             return self.info.getButton()    
  2014.         
  2015.         def getMovementCost(self):
  2016.             "int - movement cost for passing through feature"
  2017.             return self.info.getMovementCost()
  2018.         
  2019.         def getDefenseModifier(self):
  2020.             "float - defense modifier"
  2021.             return self.info.getDefenseModifier()
  2022.         
  2023.         def isImpassable(self):
  2024.             return self.isImpassable()
  2025.             
  2026.         def checkTerrain(self, terrainID):
  2027.             "bool - can the feature appear on terrainID?"
  2028.             if self.info.checkTerrain(terrainID):
  2029.                 return True
  2030.             return False
  2031.         
  2032.         def getFeatureTerrainList(self, terrainList):
  2033.             featureTerrainList = []
  2034.             numTerrain = gc.getNumTerrainInfos()
  2035.             for i in range(numTerrain):
  2036.                 if self.info.checkTerrain(i):
  2037.                     featureTerrainList.append()
  2038.             return featureTerrainLIst
  2039.         
  2040.         def getFoodYieldChange(self):
  2041.             return self.info.getYieldChange(YieldTypes.YIELD_FOOD)
  2042.         
  2043.         def getProductionYieldChange(self):
  2044.             return self.info.getYieldChange(YieldTypes.YIELD_PRODUCTION)
  2045.         
  2046.         def getCommerceYieldChange(self):
  2047.             return self.info.getYieldChange(YieldTypes.YIELD_COMMERCE)
  2048.     
  2049.         def getHillsFoodYieldChange(self):
  2050.             return self.info.getHillsYieldChange(YieldTypes.YIELD_FOOD)
  2051.         
  2052.         def getHillsProductionYieldChange(self):
  2053.             return self.info.getHillsProductionYieldChange(YieldTypes.YIELD_PRODUCTION)
  2054.         
  2055.         def getHillsCommerceYieldChange(self):
  2056.             return self.info.getHillsCommerceYieldChange(YieldTypes.YIELD_COMMERCE)
  2057.         
  2058.         
  2059.     
  2060.     class TerrainInfo:
  2061.         "Terrain Info helper class"
  2062.         def __init__(self, terrainID):
  2063.             self.terrainID = terrainID
  2064.             self.info = gc.getTerrainInfo(self.terrainID)
  2065.         
  2066.         def isValid(self):
  2067.             if self.info:
  2068.                 return True
  2069.             return False
  2070.         
  2071.         def isWater(self):
  2072.             return self.info.isWater()
  2073.         
  2074.         def isImpassable(self):
  2075.             return self.info.isbImpassable()
  2076.         
  2077.         def getMovementCost(self):
  2078.             return self.info.getMovementCost()
  2079.         
  2080.         def getDefenseModifier(self):
  2081.             return self.info.getDefenseModifier()
  2082.         
  2083.         def getFoodYield(self):
  2084.             return self.info.getYield(YieldTypes.YIELD_FOOD)
  2085.     
  2086.         def getProductionYield(self):
  2087.             return self.info.getYield(YieldTypes.YIELD_PRODUCTION)
  2088.     
  2089.         def getCommerceYield(self):
  2090.             return self.info.getYield(YieldTypes.YIELD_COMMERCE)    
  2091.         
  2092.         def getHillsFoodYieldChange(self):
  2093.             return self.info.getHillsYieldChange(YieldTypes.YIELD_FOOD)
  2094.     
  2095.         def getHillsProductionYieldChange(self):
  2096.             return self.info.getHillsYieldChange(YieldTypes.YIELD_PRODUCTION)
  2097.             
  2098.         def getHillsCommerceYieldChange(self):
  2099.             return self.info.getHillsYieldChange(YieldTypes.YIELD_COMMERCE)
  2100.     
  2101.     class BuildInfo:
  2102.         def __init__(self, ID):
  2103.             self.ID = ID
  2104.             self.info = gc.getBuildInfo(self.ID)
  2105.         
  2106.         def getID(self):
  2107.             return self.ID
  2108.         
  2109.         def getName(self):
  2110.             return self.info.getDescription()
  2111.         
  2112.         def getButton(self):
  2113.             return self.info.getButton()
  2114.         
  2115.         def getTechPrereq(self):
  2116.             return self.info.getTechPrereq()
  2117.         
  2118.     
  2119.     InfoDictionary = {
  2120.         'bonus': {'NUM': gc.getNumBonusInfos, 'GET': gc.getBonusInfo},
  2121.         'improvement': {'NUM': gc.getNumImprovementInfos, 'GET': gc.getImprovementInfo},
  2122.         'yield': {'NUM': YieldTypes.NUM_YIELD_TYPES, 'GET': gc.getYieldInfo},
  2123.         'religion': {'NUM': gc.getNumReligionInfos, 'GET': gc.getReligionInfo},
  2124.         'tech': {'NUM': gc.getNumTechInfos, 'GET': TechnologyInfo},
  2125.         'unit': {'NUM': gc.getNumUnitInfos, 'GET': UnitInfo},
  2126.         'civic': {'NUM': gc.getNumCivicInfos, 'GET': gc.getCivicInfo},
  2127.         'building': {'NUM': gc.getNumBuildingInfos, 'GET': BuildingInfo},
  2128.         'terrain': {'NUM': gc.getNumTerrainInfos, 'GET': gc.getTerrainInfo},
  2129.         'trait': {'NUM': gc.getNumTraitInfos, 'GET': gc.getTraitInfo},
  2130.         }
  2131.     
  2132.     
  2133.