Build unique unit of captured city

Discussion in 'Civ4 - Creation & Customization' started by dood100125, Dec 13, 2010.

  1. dood100125

    dood100125 Chieftain

    Joined:
    Sep 13, 2010
    Messages:
    34
    Location:
    Manitoba
    I saw this option in the star trek mod. The option allows you to build unique units of the other civilizations city's if you capture them. Is there a way I can implement this into my mod?
     
  2. Admiral Armada

    Admiral Armada The Admiral of Armadas

    Joined:
    Sep 11, 2004
    Messages:
    462
    Location:
    Terra
  3. Baldyr

    Baldyr "Hit It"

    Joined:
    Dec 5, 2009
    Messages:
    5,530
    Location:
    Sweden
    It should be possible to do this in Python by enabling the canTrain callback found in CvGameUtils. Firstly you need to compare the city's current owner with its original owner with CyCity.getOwner() and CyCity.getOriginalOwner() respectively. If they don't match up, then you need to figure out if the current unit type is available to the original owner.

    Firstly you need to get the CyPlayer instance of the original owner with CyGlobalContext.getPlayer() and then you need to invoke CyPlayer.canTrain() on that object. If this check clears you make the CvGameUtils.canTrain() method return a True value.

    It should be noted however that such a Python mod will cause the game to run slower, as this code would be executed by the game pretty much all the time. :rolleyes: I don't know how much lag it would cause, but I guess you could try it to see...

    If the above doesn't mean much to you, then I can make the code for you to test out. In case this is what you're looking for. (What mod/version is your own mod based upon? Does it already have custom Python elements in it?)
     
  4. Thomas SG

    Thomas SG CCV-designer

    Joined:
    Aug 10, 2007
    Messages:
    1,164
    Location:
    Germany
    :yup: But the stand alone version is not bugfree! I remember that it can even cause a CTD and the plot yield calculation and city building list can be wrong for cities with captured UBs.

    :( I fear not. But if you like it so much CCV includes this mod and I have fixed the bugs in the past. But please don't ask me for the bugfixes in detail. It's too long ago that I fixed them.
     
  5. Baldyr

    Baldyr "Hit It"

    Joined:
    Dec 5, 2009
    Messages:
    5,530
    Location:
    Sweden
    It occurred to me that it probably would be prudent to also check if the player who is building the foreign unique unit can build the unit's domestic counterpart. So the script would include more code. With a standard BtS v3.19 setup, this is what would be added to CvGameUtils.py:
    Spoiler :
    Code:
    	def canTrain(self,argsList):
    		pCity = argsList[0]
    		eUnit = argsList[1]
    		bContinue = argsList[2]
    		bTestVisible = argsList[3]
    		bIgnoreCost = argsList[4]
    		bIgnoreUpgrades = argsList[5]
    
    [B]		eOwner = pCity.getOwner()
    		eFounder = pCity.getOriginalOwner()
    		if eOwner != eFounder:
    			pUnitInfo = gc.getUnitInfo(eUnit)
    			eUnitClass = pUnitInfo.getUnitClassType()
    			pPlayer = gc.getPlayer(eOwner)
    			eCivilization = pPlayer.getCivilizationType()
    			pCivInfo = gc.getCivilizationInfo(eCivilization)
    			eUnit = pCivInfo.getCivilizationUnits(eUnitClass)
    			return pPlayer.canTrain(eUnit, False, False)[/B]
    		return False
    I haven't tested any of this myself, but in order for it to work the canTrain callback itself has to be enabled in PythonCallbackDefines.xml.
     
  6. Thomas SG

    Thomas SG CCV-designer

    Joined:
    Aug 10, 2007
    Messages:
    1,164
    Location:
    Germany
    Why? When I'm a civ that can build a type of swordsman with iron and the UU of the conquered city civ is a swordman that can be build without iron why should I check for my unit? The allowed lack of iron may be the major advantage of the UU.
     
  7. The_J

    The_J Say No 2 Net Validations Super Moderator Supporter

    Joined:
    Oct 22, 2008
    Messages:
    33,996
    Location:
    DE/NL/FR
    Sadly not, because the UU restriction gets checked before the unit variable gets passed to the callback (...er...i think it might even be a unit class variable).
     
  8. dood100125

    dood100125 Chieftain

    Joined:
    Sep 13, 2010
    Messages:
    34
    Location:
    Manitoba
    Thanks for the information will have to play with them a little;)
     
  9. Baldyr

    Baldyr "Hit It"

    Joined:
    Dec 5, 2009
    Messages:
    5,530
    Location:
    Sweden
    I'm not checking whether or not the city can build the unit, but the player. So I guess CyPlayer.canTrain() only takes Techs into account? :confused:

    Aha, the callback never even gets made for a UU? In that case it wouldn't work... :p
     
  10. Thomas SG

    Thomas SG CCV-designer

    Joined:
    Aug 10, 2007
    Messages:
    1,164
    Location:
    Germany
    I've had a look at the code and you are right.

    But what about for example a type of horseman? The standard unit may require archery and horseback riding while a UU requires only horseback riding. There is no need that the technologies are the same. I can't remember BTS and I'm too lazy to check it but I have got the feeling that their is something like that.
     
  11. The_J

    The_J Say No 2 Net Validations Super Moderator Supporter

    Joined:
    Oct 22, 2008
    Messages:
    33,996
    Location:
    DE/NL/FR
    yup, right.
    You can easily test that. Just let it always return True.
    You'll then be able to build everything, including GPs and animals, but no UUs.
     
  12. dood100125

    dood100125 Chieftain

    Joined:
    Sep 13, 2010
    Messages:
    34
    Location:
    Manitoba
    I am having trouble merging the Assimilation mod into my mod. I have located the problem but cant figure out how to fix it. The problem is when ever I replace the CvGameCoreDLL.dll with the Assimilation one it crashes. I don't know how to fix this any suggestions?
     
  13. Admiral Armada

    Admiral Armada The Admiral of Armadas

    Joined:
    Sep 11, 2004
    Messages:
    462
    Location:
    Terra
    Does your mod have SDK changes? if it does thats the answer, you need to merge the two and compile your own dll.
     
  14. Baldyr

    Baldyr "Hit It"

    Joined:
    Dec 5, 2009
    Messages:
    5,530
    Location:
    Sweden
    Sounds like you're using a custom DLL for another version of the game (than the one you're using yourself).

    Make sure you're using the current version of BtS - and don't use the auto-updater! That doesn't work.
     
  15. dood100125

    dood100125 Chieftain

    Joined:
    Sep 13, 2010
    Messages:
    34
    Location:
    Manitoba
    Ya I want to merge it with the orbis mod and is there any tutorials to merge and compile dll?
     

Share This Page