Question about prerequisite buildings and other civilisation's UB

T.c.w7468

...
Joined
Jan 23, 2008
Messages
88
Location
US
Hello,

I am currently using this mod component (from a long time ago): Essentially what it does is that if you build this wonder, there will be a chance you will receive another civilisation's UB rather than the default building depending on various circumstances (vassal status, etc).

This mod works, but with one really annoying quirk... if the UB you received is part of a building class that is required for another building, it doesn't count as satisifying the building class prerequisite. For example, if the wonder gives you an Assembly Plant instead of a Factory in one of your cities, the city does not let you build an Industrial Park or a Power Plant, etc... apparently only default buildings and your own civilization's UB count toward this. I haven't tested this, but I reckon that this problem also applies for building that require a number of building class types built elsewhere (such as Wall Street requiring Banks).

I tried a python script uncer CvGameUtils.py saying that if any building in the building class that satisfies the building requirement, it can be constructed. This works, but causes a worse side effect: it will have the prerequiste building be the sole requirement for the buidling: regardless of technology or if the building is a wonder that has been built, you will be able to build the building.

How would one go about fixing this problem, allowing other civ's UBs to qualify as prerequisites for other buildings?

Relevant Code (don't know if you need this, just in case):

The Petra Mod by GIR:
Spoiler :


@CivGameUtils.py at def cannotConstruct
Code:
### Petra Mod begins ###
		### Note: the code identifies the first building of a certain buildingclass in the CIV4BuildingInfos.xml file to be the default building
		###########################################################################################

		### find buildings with the same buildingClassType ###
		lgleicheBC = []
		buildingClassType = gc.getBuildingInfo(eBuilding).getBuildingClassType()
		for i in range(gc.getNumBuildingInfos()):
			if ( buildingClassType == gc.getBuildingInfo(i).getBuildingClassType() ):
				lgleicheBC.append(i)

		if ( len(lgleicheBC) >= 2 ):
			### is eBuilding the default building? ###
			if ( eBuilding == lgleicheBC[0] ):
				### do you have a "foreign" UB in the city? ###
				for i in range(len(lgleicheBC)-1):
					if ( pCity.getNumActiveBuilding(lgleicheBC[i +1])==true ):
						return True

		###########################################################################################
### Petra Mod ends ###

@CvEventManager.py at onBuildingBuilt:

Code:
## Petra ##
	###########################
	### ub chance home city ###
	###########################
		if pCity.getNumActiveBuilding(gc.getInfoTypeForString("BUILDING_PETRA"))==true:

			### chance to get a UB instead of the DB ###
			chance = CyGame().getSorenRandNum(100, "chance for UB")
			if ( chance <= 25):

				### note: the code identifies the first building of a certain buildingclass in the CIV4BuildingInfos.xml file to be the default building
				### find buildings with the same buildingClassType ###
				lgleicheBC = []
				buildingClassType = gc.getBuildingInfo(iBuildingType).getBuildingClassType()
				for i in range(gc.getNumBuildingInfos()):
					if ( buildingClassType == gc.getBuildingInfo(i).getBuildingClassType() ):
						lgleicheBC.append(i)

				if ( len(lgleicheBC) >= 2 ):

					### is Building the default building? ###
					if ( iBuildingType == lgleicheBC[0] ):

						### get a random UB of the same building class like the DB ###
						chance = CyGame().getSorenRandNum(len(lgleicheBC) - 1, "Random for UB")

						### replace DB with UB ###
						pCity.setNumRealBuilding(lgleicheBC[0],0)
						pCity.setNumRealBuilding(lgleicheBC[chance + 1],1)

						### ausgabe ###
						CyInterface().addMessage(pCity.plot().getOwner(),false,15,CyTranslator().getText("TXT_KEY_PETRA_GAMETXT2",( pCity.getName(), PyHelpers.PyInfo.BuildingInfo(lgleicheBC[chance + 1]).getDescription() , PyHelpers.PyInfo.BuildingInfo(lgleicheBC[0]).getDescription() )),'',0,gc.getBuildingInfo(lgleicheBC[chance + 1]).getButton(),ColorTypes(11),pCity.getX(),pCity.getY(),True,True)
						### message: In %s1 the Petra Wonder provides a %s2 instead of a %s3 ###


	########################
	### vassal ub chance ###
	########################
		else:

			### is building obsolete? ###
			pPlayer = gc.getPlayer(pCity.plot().getOwner())
			b_BUILDING_PETRA = gc.getInfoTypeForString("BUILDING_PETRA")
			obsoleteTech = gc.getBuildingInfo(b_BUILDING_PETRA).getObsoleteTech()
			if ( gc.getTeam(pPlayer.getTeam()).isHasTech(obsoleteTech) == false or obsoleteTech == -1 ):

				### check for Petra in one of your cities ###
				petra = false
				for iCity in range(pPlayer.getNumCities()):
					if petra == false:
						ppCity = pPlayer.getCity(iCity)
						if ppCity.getNumActiveBuilding(b_BUILDING_PETRA) == true:
							petra = true

				if ( petra == true ):

					### check for vassals ###
					iTeam = pPlayer.getTeam()
					pTeam = gc.getTeam(iTeam)
					l_vassalUB = []
					for iPlayer in range(gc.getMAX_PLAYERS()):
						ppPlayer = gc.getPlayer(iPlayer)
						if ( (ppPlayer.isAlive()==true) and (ppPlayer.isBarbarian()==false) ):
							if ( gc.getTeam(ppPlayer.getTeam()).isVassal(iTeam) == true ):

								### find UB and DB ###
								civ_type = gc.getPlayer(iPlayer).getCivilizationType()
								for iBuilding in range(gc.getNumBuildingClassInfos()):
									iUniqueBuilding = gc.getCivilizationInfo(civ_type).getCivilizationBuildings(iBuilding);
									iDefaultBuilding = gc.getBuildingClassInfo(iBuilding).getDefaultBuildingIndex();
									if (iDefaultBuilding > -1 and iUniqueBuilding > -1 and iDefaultBuilding != iUniqueBuilding):

										### check if you built a DB or a UB and if it is a match with the vassal UB ### 
										if ( iBuildingType == iDefaultBuilding ):
											l_vassalUB.append(iUniqueBuilding)

					if ( len(l_vassalUB) >= 1 ):

						### get a random UB from your l_vassalUB ###
						chance = CyGame().getSorenRandNum(len(l_vassalUB), "Random for UB")

						### replace DB with UB ###
						pCity.setNumRealBuilding(iBuildingType,0)
						pCity.setNumRealBuilding(l_vassalUB[chance],1)

						### ausgabe ###
						CyInterface().addMessage(pPlayer.getID(),false,15,CyTranslator().getText("TXT_KEY_PETRA_GAMETXT3",( pCity.getName(), PyHelpers.PyInfo.BuildingInfo(l_vassalUB[chance]).getDescription() , PyHelpers.PyInfo.BuildingInfo(iBuildingType).getDescription() )),'',0,gc.getBuildingInfo(l_vassalUB[chance]).getButton(),ColorTypes(11),pCity.getX(),pCity.getY(),True,True)
						### message: In %s1 the our Vassal and the Petra Wonder provides a %s2 instead of a %s3 ###
## Petra ##

My attempted fix that ended up waaay overcorrecting for the problem

@CivGameUtils.py at def cannotConstruct
Code:
		for i in range(gc.getNumBuildingInfos()):
			if pCity.getNumActiveBuilding (i) >= 1:
				aBuild = gc.getBuildingInfo (eBuilding)
				bBuild = gc.getBuildingInfo (i)
				if aBuild.isBuildingClassNeededInCity (bBuild.getBuildingClassType()):
					return True

Sorry if the way I explained this was confusing and thanks in advance for any help!
 
Give up. It causes more problems elsewhere.
 
Yeah, without modding the DLL I don't think you will be able to solve this problem. As you have already realized, using the Python function makes the function the only deciding factor for when a building can be built, which is not what you want.
 
Top Bottom