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

Adding strength and movement to unit through acquring tech

Discussion in 'Civ4 - SDK/Python' started by CaptainMidnight, Jan 18, 2011.

  1. CaptainMidnight

    CaptainMidnight Warlord

    Joined:
    Apr 16, 2006
    Messages:
    141
    I've been trying to convert tsentom "sea faring trait code" so that it only affects a unique unit. However, my python skills are akin to a monkey tampering with a clockwork device so I was hoping some one could help me out.

    The aim is to have a unit that develops as new techs are acquired. I want to have a tech that increases movement and another to increase strength. Any help will be appreciated!


    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
    		
    		# Show tech splash when applicable
    		if (iPlayer > -1 and bAnnounce and not CyInterface().noTechSplash()):
    			if (gc.getGame().isFinalInitialized() and not gc.getGame().GetWorldBuilderMode()):
    				if (iPlayer == CyGame().getActivePlayer()):
    					popupInfo = CyPopupInfo()
    					popupInfo.setButtonPopupType(ButtonPopupTypes.BUTTONPOPUP_PYTHON_SCREEN)
    					popupInfo.setData1(iTechType)
    					popupInfo.setText(u"showTechSplash")
    					popupInfo.addPopup(iPlayer)
    ## Sea Trait Start ##	
    
    		pPlayer = gc.getPlayer(iPlayer)
    		
    		if iTechType == gc.getInfoTypeForString('TECH_ASTRONOMY'):
    				iSea = gc.getInfoTypeForString('UNIT_VENICE_GALLEAS')
    				pTeam = gc.getTeam(pPlayer.getTeam())
    
    				pTeam.changeExtraMoves(iSea, 1)
    
    ## Sea Trait End ##
    
     
  2. Baldyr

    Baldyr "Hit It"

    Joined:
    Dec 5, 2009
    Messages:
    5,530
    Location:
    Sweden
    This is basically not doable. I guess you figured you could change the string "DOMAIN_SEA" to the unit's XML tag? But it won't work because the method you're using - CyTeam.changeExtraMovement() - only takes DomainTypes as parameters. And there is no method for adding extra movement to UnitTypes in this fashion. Sorry. :p

    Anything would however be doable in C++ working with the SDK. Changing the game rules isn't something that should be done in Python anyways. Its used as a scripting language - not as a replacement for the game's source code.

    edit: I just found a CvUnitInfo.setCombat() method that may or may not allow you to set the combat strength of a unit type. (It depends on what the m_iCombat variable in the SDK is referring to.) The change would be global however, so I doubt that this is what you're looking for.
     
  3. CaptainMidnight

    CaptainMidnight Warlord

    Joined:
    Apr 16, 2006
    Messages:
    141
    Thanks for the quick answer.
     
  4. OrionVeteran

    OrionVeteran Deity

    Joined:
    Dec 25, 2003
    Messages:
    2,443
    Location:
    Newport News VA
    I have an idea that will add an extra movement to a specified unit. :D What you do is create a new movement promotion in CIV4PromotionInfos.xml file and give it the following setting:

    Code:
    <iMovesChange>1</iMovesChange>
    
    You can then run a python function to give the movement promotion to the unit.

    Code:
    iMovement = gc.getInfoTypeForString("PROMOTION_MOVEMENT")
    pUnit.setHasPromotion(iMovement, True)
    
    With this method you can add all the extra moves you want, as the iMovesChange value can be set to more than 1. What I want to know is how to prevent the new movement promotion from showing up on the list of available promotions for a player to choose. I want this promotion to be completely hidden. Any ideas?
     
  5. Baldyr

    Baldyr "Hit It"

    Joined:
    Dec 5, 2009
    Messages:
    5,530
    Location:
    Sweden
    I actually never ever considered these "dirty" modding tricks whereby you use dummy buildings and promotions and traits and whatever to create new "game features". Because its not really the same thing, now is it?

    Instead, I look forward to being able to do thing for real in by editing the SDK - in the future.
     
  6. OrionVeteran

    OrionVeteran Deity

    Joined:
    Dec 25, 2003
    Messages:
    2,443
    Location:
    Newport News VA
    No, but it does work. Any ideas on how I can hide the promotion?
     
  7. Baldyr

    Baldyr "Hit It"

    Joined:
    Dec 5, 2009
    Messages:
    5,530
    Location:
    Sweden
    No, unfortunately not. :p
     
  8. OrionVeteran

    OrionVeteran Deity

    Joined:
    Dec 25, 2003
    Messages:
    2,443
    Location:
    Newport News VA
    Drat! I guess I will have to dream up another "dirty" trick to hide the promotion.
     
  9. Baldyr

    Baldyr "Hit It"

    Joined:
    Dec 5, 2009
    Messages:
    5,530
    Location:
    Sweden
    Why not use the default extra movement promotion, then? Simply give that to every unit of the player on techAcquired and then add it to each unit on unitBuilt.
     
  10. OrionVeteran

    OrionVeteran Deity

    Joined:
    Dec 25, 2003
    Messages:
    2,443
    Location:
    Newport News VA
    That might work for CaptainMidnight, but my case is a bit more complex. I am using this trick for the Combined Forces mod. Say I am creating a fleet out of three ships. The 3 ships all have a different movement values. By code, I select the ship with the least movement points and assign that value to the new fleet via promotion. I am in the process of creating 10 different movement promotions to cover every possible value that a fleet may require. I will have to add even more movement promotions to cover all possible values when I combine 3 or more air units to create an Air Force unit. Thats a lot of new promotions. :crazyeye:
     
  11. Baldyr

    Baldyr "Hit It"

    Joined:
    Dec 5, 2009
    Messages:
    5,530
    Location:
    Sweden
    Why aren't you simply changing the movement points left for those units? Because you want every unit to be as slow as the slowest member, right?
     
  12. OrionVeteran

    OrionVeteran Deity

    Joined:
    Dec 25, 2003
    Messages:
    2,443
    Location:
    Newport News VA
    Because the units combined are deleted and replaced by a fleet unit which has a default movement of 1. I use the respective promotion to bring the movement of the fleet unit up to where it needs to be.
     
  13. Asaf

    Asaf Sleep Deprived

    Joined:
    Mar 22, 2010
    Messages:
    1,326
    This is a little dirty, but it might work: Define DummyPromo1 and DummyPromo2 which require each other, and this should effectively make them inaccessible (I haven't tried it, but I didn't see anything in the code which prevents that).

    Then you could make one of them (DummyPromo1 or DummyPromo2) a prereq for any promotion you want.
     
  14. OrionVeteran

    OrionVeteran Deity

    Joined:
    Dec 25, 2003
    Messages:
    2,443
    Location:
    Newport News VA
    Making the Promotions refer to each other blows up BUG. However, if I make a Dummy Tech, disable the tech and make it a prerequisite for the first Movement promotion; then I can run all the movement promotions in succession; each requiring the previous promotion.
     
  15. God-Emperor

    God-Emperor Deity

    Joined:
    Jul 18, 2009
    Messages:
    3,551
    Location:
    Texas
    You probably don't need to make dummy techs and such.

    One option is to give the fleet unit a different unit combat from anything else and just have all of its promotions applicable only to that unit combat. This disrupts any existing unit combat related combat bonuses/penalties, so you may need to adjust those too.

    Another option: If you set a promotion to have nothing in its UnitCombats then it can not be taken by any unit. However, if a unit has the promotion set in its FreePromotions then it will start with it anyway. So if you make the first promotion in the line have no UnitCombats but give it to the fleet unit for free, then make the next promotion in the series require that one and be set to have the right UnitCombats for the fleet unit then you have a unit-specific series of promotions. (Final Frontier Plus grants otherwise unusable promotions to a some UUs for free this way, specifically the recon ships that the Avowers get as UUs each get one or two free unique sensor range increasing promotions this way. These don't lead to any other promotions, but they could.)

    As for units gaining promotions from techs, you can do that via the "random" events. This would be much like the events in regular BTS that give fre promotions to units like granting cover to all of your axemen (or whatever). These events apply a promotion to all existing units of that type and also all units of that type built by that player from then on. An event trigger with an iWeight of -1 is applied as soon as all of its criteria are met. Make the only criterion be a tech prereq and it is triggered when they player gets the tech. The one event assigned to the event trigger then applies a promotion to the appropriate unit combat or unit class. Doesn't even require any Python, just XML. This lets you apply any effect that a promotion can apply (obviously) which includes +1 movement but not +1 strength (unless it is modded in via DLL changes), although there is always the +X% strength option.

    The way the event sets a unit combat or unit class to get free promotions if built by a specific player is evidently done via methods of CvPlayer that are not exposed to Python (CvPlayer::setFreePromotion, overloaded to take either a unit combat or a unit class as its first argument).
     
  16. OrionVeteran

    OrionVeteran Deity

    Joined:
    Dec 25, 2003
    Messages:
    2,443
    Location:
    Newport News VA
    The disabled Dummy Tech prerequisite worked really well for each promotion. All I need now is a Python method to determine if a player has discovered "The World is Round," which provides one free movement point to all sea units.
     
  17. Baldyr

    Baldyr "Hit It"

    Joined:
    Dec 5, 2009
    Messages:
    5,530
    Location:
    Sweden
    CyPlayer.getTeam()
    CyGlobalContext.getTeam()
    CyTeam.isHasTech()
    CyGlobalContext.getInfoTypeForString()
     
  18. OrionVeteran

    OrionVeteran Deity

    Joined:
    Dec 25, 2003
    Messages:
    2,443
    Location:
    Newport News VA
    I don't understand. Are you saying there is a tech that is triggered when one of your units land or sea circumnavigates the globe? :confused:
     
  19. Baldyr

    Baldyr "Hit It"

    Joined:
    Dec 5, 2009
    Messages:
    5,530
    Location:
    Sweden
    Aha, I though it was a Tech since you said "discovered". :lol:

    That would be trickier though. I'll see what I can find in the API - there seems to be no callbacks for that anyway.
     
  20. OrionVeteran

    OrionVeteran Deity

    Joined:
    Dec 25, 2003
    Messages:
    2,443
    Location:
    Newport News VA
    I solved the problem with a better solution. :) Instead of using:

    Code:
    pUnitMovement = pUnit.baseMoves()
    
    ...which returned a value of 5 for a custom ship that has only 4 moves in the XML; I replace it with this:

    Code:
    pUnitMovement = gc.getUnitInfo(pUnitType).getMoves()
    
    ...which returned a value of 4 and did not include the extra movement the game provided me for circumnavigating the globe. This function now works perfectly when selecting the smallest movement value and applying it to a new fleet unit. The python changes have improved significantly, thanks to you and others out there, who help me solve tough issues. I only have one function left to develop before I can release phase 2 of my Combined Forces mod. I love progress. :)
     

Share This Page