• Our friends from AlphaCentauri2.info are in need of technical assistance. If you have experience with the LAMP stack and some hours to spare, please help them out and post here.

Build unique unit of captured city

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?
 
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?
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?)
 

: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.

It may be in RevDCM, but im not sure.

:( 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.
 
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 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.
 
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.

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.
 
It should be possible to do this in Python by enabling the canTrain callback found in CvGameUtils.

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).
 
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.
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:

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).
Aha, the callback never even gets made for a UU? In that case it wouldn't work... :p
 
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:

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.
 
Aha, the callback never even gets made for a UU? In that case it wouldn't work... :p

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.
 
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?
 
Does your mod have SDK changes? if it does thats the answer, you need to merge the two and compile your own dll.
 
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.
 
Back
Top Bottom