1. We have added a Gift Upgrades feature that allows you to gift an account upgrade to another member, just in time for the holiday season. You can see the gift option when going to the Account Upgrades screen, or on any user profile screen.
    Dismiss Notice

Still don't get python, need help finding error.

Discussion in 'Civ4 - SDK/Python' started by Thanatosimii, Aug 12, 2008.

  1. Thanatosimii

    Thanatosimii Chieftain

    Joined:
    Jun 29, 2004
    Messages:
    26
    Warlords' Rise of Rome mod included a research a tech, get a great person idea that I've been trying to clone in other mods, but I can't seem to isolate the code I need.

    In assets\python\CvRiseOfRomeEventManager.py we have
    Code:
    #		if iTechType == CvUtil.findInfoTypeNum(gc.getTechInfo,gc.getNumTechInfos(),"TECH_ROR_TRAIN_WARLORD"):
    		if iTechType == CvUtil.findInfoTypeNum(gc.getTechInfo,gc.getNumTechInfos(),"TECH_ROR_TRAIN_MERCHANT"):
    			gc.getPlayer(iPlayer).initUnit(iMerchant, pCapitalCity.getX(), pCapitalCity.getY(), UnitAITypes.UNITAI_MERCHANT)
    		if iTechType == CvUtil.findInfoTypeNum(gc.getTechInfo,gc.getNumTechInfos(),"TECH_ROR_TRAIN_SCIENTIST"):
    			gc.getPlayer(iPlayer).initUnit(iScientist, pCapitalCity.getX(), pCapitalCity.getY(), UnitAITypes.UNITAI_SCIENTIST)	
    		if iTechType == CvUtil.findInfoTypeNum(gc.getTechInfo,gc.getNumTechInfos(),"TECH_ROR_TRAIN_ARTIST"):
    			gc.getPlayer(iPlayer).initUnit(iArtist, pCapitalCity.getX(), pCapitalCity.getY(), UnitAITypes.UNITAI_ARTIST)
    		if iTechType == CvUtil.findInfoTypeNum(gc.getTechInfo,gc.getNumTechInfos(),"TECH_ROR_TRAIN_PROPHET"):
    			gc.getPlayer(iPlayer).initUnit(iProphet, pCapitalCity.getX(), pCapitalCity.getY(), UnitAITypes.UNITAI_PROPHET)
    		if iTechType == CvUtil.findInfoTypeNum(gc.getTechInfo,gc.getNumTechInfos(),"TECH_ROR_TRAIN_ENGINEER"):
    			gc.getPlayer(iPlayer).initUnit(iEngineer, pCapitalCity.getX(), pCapitalCity.getY(), UnitAITypes.UNITAI_ENGINEER)
    
    and in assets\xml\technologies\Civ4TechInfos.xml we have
    Code:
    		<TechInfo>
    			<Type>TECH_ROR_TRAIN_PROPHET</Type>
    			<Description>TXT_KEY_TECH_ROR_TRAIN_PROPHET</Description>
    			<Civilopedia>TXT_KEY_TECH_ROR_TRAIN_PROPHET_PEDIA</Civilopedia>
    			<Help/>
    			<Strategy>TXT_KEY_TECH_ROR_TRAIN_PROPHET_STRATEGY</Strategy>
    			<Advisor>ADVISOR_GROWTH</Advisor>
    			<iAIWeight>0</iAIWeight>
    			<iAITradeModifier>0</iAITradeModifier>
    			<iCost>1000</iCost>
    			<Era>ERA_CLASSICAL</Era>
    			<FirstFreeUnitClass>NONE</FirstFreeUnitClass>
    			<iFeatureProductionModifier>0</iFeatureProductionModifier>
    			<iWorkerSpeedModifier>0</iWorkerSpeedModifier>
    			<iTradeRoutes>0</iTradeRoutes>
    			<iHealth>0</iHealth>
    			<iHappiness>0</iHappiness>
    			<iFirstFreeTechs>0</iFirstFreeTechs>
    			<iAsset>16</iAsset>
    			<iPower>4</iPower>
    			<bRepeat>1</bRepeat>
    			<bTrade>0</bTrade>
    			<bDisable>0</bDisable>
    			<bGoodyTech>0</bGoodyTech>
    			<bExtraWaterSeeFrom>0</bExtraWaterSeeFrom>
    			<bMapCentering>0</bMapCentering>
    			<bMapVisible>0</bMapVisible>
    			<bMapTrading>0</bMapTrading>
    			<bTechTrading>0</bTechTrading>
    			<bGoldTrading>0</bGoldTrading>
    			<bOpenBordersTrading>0</bOpenBordersTrading>
    			<bDefensivePactTrading>0</bDefensivePactTrading>
    			<bPermanentAllianceTrading>0</bPermanentAllianceTrading>
    			<bVassalTrading>0</bVassalTrading>
    			<bBridgeBuilding>0</bBridgeBuilding>
    			<bIrrigation>0</bIrrigation>
    			<bIgnoreIrrigation>0</bIgnoreIrrigation>
    			<bWaterWork>0</bWaterWork>
    			<iGridX>1</iGridX>
    			<iGridY>1</iGridY>
    			<DomainExtraMoves/>
    			<CommerceFlexible/>
    			<TerrainTrades/>
    			<Flavors>
    				<Flavor>
    					<FlavorType>FLAVOR_RELIGION</FlavorType>
    					<iFlavor>1</iFlavor>
    				</Flavor>
    			</Flavors>
    			<OrPreReqs/>
    			<AndPreReqs/>
    			<Quote>TXT_KEY_TECH_PRIESTHOOD_QUOTE</Quote>
    			<Sound>AS2D_TECH_PRIESTHOOD</Sound>
    			<SoundMP>AS2D_TECH_MP_PRIESTHOOD</SoundMP>
    			<Button>,Art/Interface/Buttons/Units/GreatProphet.dds,Art/Interface/Buttons/Unit_Resource_Atlas.dds,5,1</Button>
    		</TechInfo>
    
    So I transposed these into the chineese unification mod, but nothing happens. I don't really know python. I'm assuming that I'm missing something. Anyone notice anything?
     
  2. Jeckel

    Jeckel Great Reverend

    Joined:
    Nov 16, 2005
    Messages:
    1,637
    Location:
    Peoria, IL
    Put the python code you post in [ CODE ] [ /CODE ] tags so that the tabing is preserved, tabing is very important in python.
     
  3. xienwolf

    xienwolf Deity

    Joined:
    Oct 4, 2007
    Messages:
    10,589
    Location:
    Location! Location!
    If you want EVERYONE to get it, then you want to use the Python:

    Code:
    if iTechType == CvUtil.findInfoTypeNum(gc.getTechInfo,gc.getNumTec hInfos(),"TECH_ROR_TRAIN_SCIENTIST"):
        gc.getPlayer(iPlayer).initUnit(iScientist, pCapitalCity.getX(), pCapitalCity.getY(), UnitAITypes.UNITAI_SCIENTIST)
    This placed in the def section for completion of research would check if that research they just completed was TECH_ROR_TRAIN_SCIENTIST and if so, give them a Scientist unit (identified earlier and stored as iScientist). In the case of normal BtS you would use a normal tech type, like TECH_AGRICULTURE.


    If you only want to reward the first person to discover the tech, use the XML field <FirstFreeUnitClass>NONE</FirstFreeUnitClass> and replace NONE with something like UNIT_SCIENTIST.
     
  4. davidlallen

    davidlallen Deity

    Joined:
    Apr 28, 2008
    Messages:
    4,743
    Location:
    California
    Let's start further back.
    a. Turn on python exceptions and logging. Probably you have a syntax error.
    b. You didn't post the rest of your changed code. Possibly you put the correct code you showed, into the wrong place.
    c. After you turn on exceptions and logging and ensure you have no syntax error, you should add a print statement just above the code you showed to make sure the routine is being called when you expect it.
     
  5. Thanatosimii

    Thanatosimii Chieftain

    Joined:
    Jun 29, 2004
    Messages:
    26
    Ok, I changed to code, and here is the context of the code I modified in Chineese unification.

    Code:
    	def onTechAcquired(self, argsList):
    		'Tech Acquired'
    		iTechType, iTeam, iPlayer, bAnnounce = argsList
    		# Note that iPlayer may be NULL (-1) and not a refer to a player object
    		pCapitalCity = gc.getPlayer(iPlayer).getCapitalCity()
    		iMerchant = CvUtil.findInfoTypeNum(gc.getUnitInfo,gc.getNumUnitInfos(),"UNIT_MERCHANT")
    		iScientist = CvUtil.findInfoTypeNum(gc.getUnitInfo,gc.getNumUnitInfos(),"UNIT_SCIENTIST")
    		iArtist = CvUtil.findInfoTypeNum(gc.getUnitInfo,gc.getNumUnitInfos(),"UNIT_ARTIST")
    		iProphet = CvUtil.findInfoTypeNum(gc.getUnitInfo,gc.getNumUnitInfos(),"UNIT_PROPHET")
    		iEngineer = CvUtil.findInfoTypeNum(gc.getUnitInfo,gc.getNumUnitInfos(),"UNIT_ENGINEER")
    		
    		# Show tech splash when applicable
    		if (iPlayer > -1 and bAnnounce and not CyInterface().noTechSplash()):
    			if (gc.getGame().isFinalInitialized() and not gc.getGame().GetWorldBuilderMode()):
    				if ((not CyGame().isNetworkMultiPlayer()) and (iPlayer == CyGame().getActivePlayer())):
    					popupInfo = CyPopupInfo()
    					popupInfo.setButtonPopupType(ButtonPopupTypes.BUTTONPOPUP_PYTHON_SCREEN)
    					popupInfo.setData1(iTechType)
    					popupInfo.setText(u"showTechSplash")
    					popupInfo.addPopup(iPlayer)
    		
    #               if iTechType == CvUtil.findInfoTypeNum(gc.getTechInfo,gc.getNumTechInfos(),"TECH_ROR_TRAIN_WARLORD"):
    		if iTechType == CvUtil.findInfoTypeNum(gc.getTechInfo,gc.getNumTechInfos(),"TECH_ROR_TRAIN_MERCHANT"):
    			gc.getPlayer(iPlayer).initUnit(iMerchant, pCapitalCity.getX(), pCapitalCity.getY(), UnitAITypes.UNITAI_MERCHANT)
    		if iTechType == CvUtil.findInfoTypeNum(gc.getTechInfo,gc.getNumTechInfos(),"TECH_ROR_TRAIN_SCIENTIST"):
    			gc.getPlayer(iPlayer).initUnit(iScientist, pCapitalCity.getX(), pCapitalCity.getY(), UnitAITypes.UNITAI_SCIENTIST)	
    		if iTechType == CvUtil.findInfoTypeNum(gc.getTechInfo,gc.getNumTechInfos(),"TECH_ROR_TRAIN_ARTIST"):
    			gc.getPlayer(iPlayer).initUnit(iArtist, pCapitalCity.getX(), pCapitalCity.getY(), UnitAITypes.UNITAI_ARTIST)
    		if iTechType == CvUtil.findInfoTypeNum(gc.getTechInfo,gc.getNumTechInfos(),"TECH_ROR_TRAIN_PROPHET"):
    			gc.getPlayer(iPlayer).initUnit(iProphet, pCapitalCity.getX(), pCapitalCity.getY(), UnitAITypes.UNITAI_PROPHET)
    		if iTechType == CvUtil.findInfoTypeNum(gc.getTechInfo,gc.getNumTechInfos(),"TECH_ROR_TRAIN_ENGINEER"):
    			gc.getPlayer(iPlayer).initUnit(iEngineer, pCapitalCity.getX(), pCapitalCity.getY(), UnitAITypes.UNITAI_ENGINEER)
    
    		if (not self.__LOG_TECH):
    			return
    		CvUtil.pyPrint('%s was finished by Team %d' 
    			%(PyInfo.TechnologyInfo(iTechType).getDescription(), iTeam))
    	
    
    I'm really new to python, so I'm not exactly sure how to turn on exceptions and logging.
     
  6. davidlallen

    davidlallen Deity

    Joined:
    Apr 28, 2008
    Messages:
    4,743
    Location:
    California

Share This Page