Counting Buildings under Construction

tesb

Emperor
Joined
Jan 16, 2010
Messages
1,593
Hi,

i want to implement a restriction for a certain type of buildings in such a way that you need a minimum amount of a certain building before you can construct them,e.g.

Code:
if eBuilding == iBuilding1 or eBuilding == iBuilding2 or eBuilding == iBuilding3:
			iBuildCount = pPlayer.countNumBuildings(iBuilding1) + pPlayer.countNumBuildings(iBuilding2) + pPlayer.countNumBuildings(iBuilding3)
			iBaseBuildCount = pPlayer.countNumBuildings(iBuilding4)
			if iBuildCount*3 >= iBaseBuildCount and iBaseBuildCount > 2:
				return True
with this bit of code in CvGameUtils.py in the def cannotConstruct function, forces you to build at least 3 iBuilding4 for every iBuilding1, iBuilding,2 or iBuilding3.

However it only checks if i can start production, i.e. once i have 3 iBuilding4 i can build and finish multiple iBuilding1, iBuilding2 or iBuilding3.

Is there a function that checks if iBuilding1, iBuilding2, or iBuilding3 is already contructing, so i can add those to iBuildCount as well?
 
hmm how do i get those functions to work though?

edit:
it still does not work:
Code:
if eBuilding == iNexPower or eBuilding == iNexWealth or eBuilding == iNexKnow:
			iNexCount = pPlayer.getBuildingClassCountPlusMaking(iNexWealthClass) + pPlayer.getBuildingClassCountPlusMaking(iNexPowerClass) + pPlayer.getBuildingClassCountPlusMaking(iNexKnowClass)
			iDefCount = pPlayer.countNumBuildings(iDefCat)
			if iNexCount*3 <= iDefCount and iDefCount < 3:
				return True
iNexPower, iNexWealth and iNexKnow belong to buildingclass iNexPowerClass, iNexWealthClass and iNexKnowClass

i want that you need 3 iDefCat for any choice of iNexPower, iNexWealth or iNexKnow

i am also terribly tired. perhaps i miss something obvious.
 
Half asleep, so can't type codes.
My js Bach cathedral does something similar
Allows users to build cathedrals with 1 less temple requirement
 
ok i looked at your function for cathedral and made some adjustments.


i also added two messages to see if the counting of the building is correct:
Code:
		#need work	
		if eBuilding == iNexPower or eBuilding == iNexWealth or eBuilding == iNexKnow:
			inumNexW = pPlayer.getBuildingClassCountPlusMaking(iNexWealthClass)
			inumNexP = pPlayer.getBuildingClassCountPlusMaking(iNexPowerClass)
			inumNexK = pPlayer.getBuildingClassCountPlusMaking(iNexKnowClass)
			inumDefC = pPlayer.getBuildingClassCount(iDefCClass)
			
			inumNex = inumNexW + inumNexP + inumNexK
			
			message = "Number of Nexi *3: %d" %(inumNex*3)
			message2 = "Number of %s : %d" %(gc.getBuildingInfo(iDefCat).getDescription(), inumDefC)
			CyInterface().addMessage(pCity.getOwner(),True,25,message,'',3,'',ColorTypes(7),-1,-1,False,False)
			CyInterface().addMessage(pCity.getOwner(),True,25,message2,'',1,'',ColorTypes(8),-1,-1,False,False)
			
			if inumNex*3 > inumDefC or inumDefC < 3:
				return True

and i works, but with one weird behavior with the last condition:
if i have less than 3 inumDefC, i cannot build any of the nexus (inumNexW, inumNexP or inumDefC)
if i have more than 3 inumDefC i can build any of the nexus, so far so good. but if one city is already constructing a nexus i can still choose to start a nexus in another city. however it will be canceled when i end the turn.
at the start of the next turn i can start construction on a nexus again and again it will be canceled.

so it works as intended, but i would prefer if the option to build would not even be there instead of being canceled at the end of the turn. is there any way to fix that?

secondly is there a possibility to have buildings that are blocked that way in python be grayed out with a little mouseover help text, instead of just not being there?
edit: i tried this:
http://forums.civfanatics.com/showpost.php?p=8277262&postcount=16
however it only works for the buildings construction menu in the city screen. is there a way to get the same behavior for the construction popup if a city is idle?
 
Code:
					if pCity.getProductionBuilding() == eBuilding:
						if numTemples >= numCathedrals * (numPreReqTemple - 1):
							return True
					else:
						if numTemples >= (numCathedrals + 1) * (numPreReqTemple - 1):
							return True

That is what this portion takes care of.
Whether the city is building the cathedral or not, the comparison is different
 
hm i don't understand.

if i start a nexus in one city inumNex increases by 1 before second city is selected. i verified this with the displayed python messages.i guess i just don't know why i am able to start construction even though the condition is not met.

edit:
i fixed it thank you. although i still do not understand as to why it is necessary :)
 
any idea how to fix this:


secondly is there a possibility to have buildings that are blocked that way in python be grayed out with a little mouseover help text, instead of just not being there?
edit: i tried this:
http://forums.civfanatics.com/showpo...2&postcount=16
however it only works for the buildings construction menu in the city screen. is there a way to get the same behavior for the construction popup if a city is idle?
 
hm i don't understand.

if i start a nexus in one city inumNex increases by 1 before second city is selected. i verified this with the displayed python messages.i guess i just don't know why i am able to start construction even though the condition is not met.

edit:
i fixed it thank you. although i still do not understand as to why it is necessary :)

It is necessary because getBuildingClassCountPlusMaking includes the cathedral being built in that current city.

Thus, whether the city is currently building the cathedral or not matters, so equation will change.
 
Back
Top Bottom