a little help I need, please

The biggest difference is that he builds the lists first and then converts the entire list from a string ("BUILDING_A") to the infotype where I convert the strings first and build the list using the infotypes. Performance wise they should be identical but Sto's uses fewer lines of code making it look cleaner.
 
Good day, Seven05, Sto ( in alphabetical order ) and others. :hatsoff:
I have one problem here, if you have a while for me :please:

You made here two code systems. One for improvements in first circle round the city a nd second for improvement in all city plot.
Is possible write one code with possibility set for:
Improvement_A = first circle round the city
Improvement_B = all city plot
etc.
is this possible, please? :please:

thanks

HROCHland
 
Hi ! here the code :

Code:
# make a dict of buildings ,improvement ,ring check
dictInfo = {
        "BUILDING_A" : {
                "imprs" : ["IMPROVEMENT_A"] ,
                "rings" : [1]
                } ,
        "BUILDING_B" : {
                "imprs" : ["IMPROVEMENT_B"] ,
                "rings" : [2]
                } ,
        "BUILDING_C" : {
                "imprs" : ["IMPROVEMENT_C1", "IMPROVEMENT_C2"] ,
                "rings" : [1, 2]
                }
        }

buildingType = gc.getBuildingInfo(eBuilding).getType()

# Then, break out of this check if we don't need to be here
if not buildingType in dictInfo.keys():
        return False

# first check if the city argument is valid
if pCity.isNone() :
        return True

#Get the city plot, and check the surrounding plots for the required improvement.

iX = pCity.getX()
iY = pCity.getY()
iCityOwner = pCity.getOwner()
bCantBuild = True

improvementsToCheck = [gc.getInfoTypeForString(item) for item in dictInfo[buildingType]["imprs"]]

playerCityRing1 = [(-1,-1),(-1,0),(-1,1),(0,-1),(0,1),(1,-1),(1,0),(1,1)]
playerCityRing2 = [(-2,-1),(-2,0),(-2,1),(2,-1),(2,0),(2,1),(-1,2),(0,2),(1,2),(-1,-2),(0,-2),(1,-2)]

plotsToCheck = []
if 1 in dictInfo[buildingType]["rings"] : plotsToCheck += playerCityRing1
if 2 in dictInfo[buildingType]["rings"] : plotsToCheck += playerCityRing2

for dX, dY in plotsToCheck:
        pPlot = CyMap().plot(iX+dX, iY+dY)

        # check if the plot is valid if you are at the border of the map.
        if pPlot.isNone() :
                continue

        elif not pCity.canWork(pPlot):
                continue
        
        if pPlot.getOwner() == iCityOwner:
                if pPlot.getImprovementType() in improvementsToCheck:
                        bCantBuild = False
                        break

return bCantBuild

Be carefull when you add remove buildings infos in the dictionnary : you can copy paste the 4 lines to add remove info but all must have a "} ," except the last with "}" .

in the example , A check if improvementA is in the first city ring , B check if improvementB is in the second city ring , C check if improvementC1 or improvementC2 are in the two city rings . You can play with that like you wish

Tcho !
 
Hi, Sto. If you, please, have a bit time for me I have a little problem.
I pasted your new code with two rings system to "cvgameutils" and game print me these errors. Can you, please, check, where may be problem? I switch on errorlog as you advice me

Here is error message after paste code:

load_module CvGameUtils
Traceback (most recent call last):
File "<string>", line 1, in ?
File "<string>", line 52, in load_module
File "CvEventInterface", line 14, in ?
File "<string>", line 52, in load_module
File "CvCustomEventManager", line 24, in ?
File "<string>", line 52, in load_module
File "CvEventManager", line 12, in ?
File "<string>", line 52, in load_module
File "CvScreensInterface", line 19, in ?
File "<string>", line 52, in load_module
File "CvDanQuayle", line 8, in ?
File "<string>", line 35, in load_module
File "<string>", line 13, in _get_code
File "CvGameUtils", line 263
continue
^
IndentationError: expected an indented block
load_module CvAppInterface


HTML:
	def cannotConstruct(self,argsList):
		pCity = argsList[0]
		eBuilding = argsList[1]
		bContinue = argsList[2]
		bTestVisible = argsList[3]
		bIgnoreCost = argsList[4]

		### MachuPicchu Mod begins ###
		###########################################################################################

		if ( eBuilding == gc.getInfoTypeForString("BUILDING_MACHU_PICCHU") ):

			### find peaks within the city radius controlled by your team ###
			pPlayer = gc.getPlayer(pCity.plot().getOwner())
			iPID = pPlayer.getID()
			iTID = pPlayer.getTeam()
			iX = pCity.getX()
			iY = pCity.getY()
			for iXLoop in range(iX - 2, iX + 3, 1):
				for iYLoop in range(iY - 2, iY + 3, 1):
					pPlot = CyMap().plot(iXLoop, iYLoop)
					if ( pPlot.isPlayerCityRadius(iPID)==true ):
						if ( pPlot.getTeam()==iTID ):
							if ( pPlot.isPeak()==true  ):
								return False
			return True

		###########################################################################################
		### MachuPicchu Mod ends ###


		# make a dict of buildings ,improvement ,ring check
		dictInfo = {
		        "BUILDING_A" : {
		                "imprs" : ["IMPROVEMENT_EXPLORETEMPLE"] ,
		                "rings" : [1]
		                } ,
		        "BUILDING_B" : {
		                "imprs" : ["IMPROVEMENT_SKLARNA"] ,
		                "rings" : [2]
		                } ,
		        "BUILDING_C" : {
		                "imprs" : ["IMPROVEMENT_BOJKLASTER", "IMPROVEMENT_BOJKLASTER"] ,
		                "rings" : [1, 2]
		                }
		        }

		buildingType = gc.getBuildingInfo(eBuilding).getType()

		# Then, break out of this check if we don't need to be here
		if not buildingType in dictInfo.keys():
		        return False

		# first check if the city argument is valid
		if pCity.isNone() :
		        return True

		#Get the city plot, and check the surrounding plots for the required improvement.

		iX = pCity.getX()
		iY = pCity.getY()
		iCityOwner = pCity.getOwner()
		bCantBuild = True

		improvementsToCheck = [gc.getInfoTypeForString(item) for item in dictInfo[buildingType]["imprs"]]

		playerCityRing1 = [(-1,-1),(-1,0),(-1,1),(0,-1),(0,1),(1,-1),(1,0),(1,1)]
		playerCityRing2 = [(-2,-1),(-2,0),(-2,1),(2,-1),(2,0),(2,1),(-1,2),(0,2),(1,2),(-1,-2),(0,-2),(1,-2)]

		plotsToCheck = []
		if 1 in dictInfo[buildingType]["rings"] : plotsToCheck += playerCityRing1
		if 2 in dictInfo[buildingType]["rings"] : plotsToCheck += playerCityRing2

		for dX, dY in plotsToCheck:
		        pPlot = CyMap().plot(iX+dX, iY+dY)

		        # check if the plot is valid if you are at the border of the map.
		        if pPlot.isNone() :
		                continue

		        elif not pCity.canWork(pPlot):
                continue
        
		        if pPlot.getOwner() == iCityOwner:
		                if pPlot.getImprovementType() in improvementsToCheck:
		                        bCantBuild = False
		                        break

		return bCantBuild


		return False

	def canCreate(self,argsList):
 
Lol , i think you can see the indentation error at the line where continue is not a the good place ( using python , press alt G to go the line you want to ... the one define in the error log ) . I've tried to copy paste the code from the forum with notePad , notePad ++ and python and get no indentation error . I don't know what you use but python is the best to edit python . You can reindent an entire region with one fonction .

There is still BUILDING_A ,B ,C in the keys , ( if you want to test the code , put some buildings here ).

after "return bCantBuild" the "return False" is useless , you can remove it

Tcho !
 
I don´t work with pyth at all I paste your code by notepad only. SOrry I do not understand it. Therefore I ask you...

In my mod I have pasted right buildings name ;)

As regards "return False" -- it is in the end of every function. When I remove it, will not it miss for machupicchu part in this function?
 
You should install python (go to the python tutorial for the link) . Even with notepad you can see where is the error going to the line 263 (and i've copy paste my code from the site with notepad without error ). I can't do it for you ( merging 2 files i don't have ) .

Code:
		# Then, break out of this check if we don't need to be here
		if not buildingType in dictInfo.keys():
		        return False

This return false if the building is not in the directory . the entire function i give you must always been at the last of "def cannotConstruct(self,argsList):"

Tcho !
 
Python I have installed. Only not know how make with it these stuffs :( :(
I have installed python for Blender functioning. I´m 3D modeler, not coder :(
 
Python I have installed. Only not know how make with it these stuffs :( :(
I have installed python for Blender functioning. I´m 3D modeler, not coder :(

Right click on the python file and click (Edit with IDLE) . Then copy paste the code from the forum with the python editor . Look into the menu there is some functions to regulate the indentation ( play with them to learn how that work ) .

Tcho !
 
I for my copy and paste system asociated *,py files with notepad. I have not here allow Edit with IDLE :( :( Sorry. I´m not experienced with it even in 1%.
I will be testing it at home evening more :)
 
So go to the "start menu" , "python" , "IDLE" . A new window appear and click "file" "open" the python script you want to edit .

Tcho !
 
OK. Works it perfect, Sto. Thanks you very much. I play with it, moved one line right and left and to end I copy and paste "distance before" last "continue" and in this moment code start work
Thanks you very much
HROCHland
 
Here the code that will check every turn if each city can still support the building . Need to be tested :

Spoiler :
Code:
# in CvGameUtils :
# put the dict after the list of import at the beginning

dictInfo = {
        "BUILDING_A" : {
                "imprs" : ["IMPROVEMENT_A"] ,
                "rings" : [1]
                } ,
        "BUILDING_B" : {
                "imprs" : ["IMPROVEMENT_B"] ,
                "rings" : [2]
                } ,
        "BUILDING_C" : {
                "imprs" : ["IMPROVEMENT_C1", "IMPROVEMENT_C2"] ,
                "rings" : [1, 2]
                }
        }

# you can delete dictInfo in cannotConstruct

#change the doCulture function

	def doCulture(self,argsList):
		pCity = argsList[0]

                if pCity.isNone() : return False
                if pCity.isDisorder() : return False
                if pCity.isOccupation() : return False
                
                iCX = pCity.getX()
                iCY = pCity.getY()
                iCityOwner = pCity.getOwner()
                playerCityRing1 = [(-1,-1),(-1,0),(-1,1),(0,-1),(0,1),(1,-1),(1,0),(1,1)]
                playerCityRing2 = [(-2,-1),(-2,0),(-2,1),(2,-1),(2,0),(2,1),(-1,2),(0,2),(1,2),(-1,-2),(0,-2),(1,-2)]
                
                for buildingType in dictInfo.keys() :
                        
                        iBuilding = gc.getInfoTypeForString(buildingType)
                        if pCity.getNumRealBuilding(iBuilding) > 0 :
                                
                                plotToCheck = []
                                if 1 in dictInfo[buildingType]["rings"] : plotToCheck += [item for item in playerCityRing1]
                                if 2 in dictInfo[buildingType]["rings"] : plotToCheck += [item for item in playerCityRing2]
                                improvementsToCheck = [gc.getInfoTypeForString(item) for item in dictInfo[buildingType]["imprs"]]
                                
                                bFoundOne = False
                                for dCX, dCY in plotToCheck :
                                        pLoopPlot = CyMap().plot(iCX+dCX, iCY+dCY)

                                        if pLoopPlot.isNone() : continue
                                        elif not pCity.canWork(pLoopPlot): continue

                                        if pLoopPlot.getOwner() == iCityOwner :
                                                if pLoopPlot.getImprovementType() in improvementsToCheck :
                                                        bFoundOne = True
                                                        break

                                if not bFoundOne :
                                        pCity.setNumRealBuilding(iBuilding, 0)

                return False

Tcho !
 
Here the message added when a building is destroyed (need to be checked) :

Spoiler :
Code:
	def doCulture(self,argsList):
		pCity = argsList[0]

                if pCity.isNone() : return False
                if pCity.isDisorder() : return False
                if pCity.isOccupation() : return False
                
                iCX = pCity.getX()
                iCY = pCity.getY()
                iCityOwner = pCity.getOwner()
                playerCityRing1 = [(-1,-1),(-1,0),(-1,1),(0,-1),(0,1),(1,-1),(1,0),(1,1)]
                playerCityRing2 = [(-2,-1),(-2,0),(-2,1),(2,-1),(2,0),(2,1),(-1,2),(0,2),(1,2),(-1,-2),(0,-2),(1,-2)]
                
                for buildingType in dictInfo.keys() :
                        
                        iBuilding = gc.getInfoTypeForString(buildingType)
                        if pCity.getNumRealBuilding(iBuilding) > 0 :
                                
                                plotToCheck = []
                                ringsToCheck = dictInfo[buildingType]["rings"]
                                if 1 in ringsToCheck : plotToCheck += [item for item in playerCityRing1]
                                if 2 in ringsToCheck : plotToCheck += [item for item in playerCityRing2]
                                improvementsToCheck = [gc.getInfoTypeForString(item) for item in dictInfo[buildingType]["imprs"]]
                                
                                bFoundOne = False
                                for dCX, dCY in plotToCheck :
                                        pLoopPlot = CyMap().plot(iCX+dCX, iCY+dCY)

                                        if pLoopPlot.isNone() : continue
                                        elif not pCity.canWork(pLoopPlot): continue

                                        if pLoopPlot.getOwner() == iCityOwner :
                                                if pLoopPlot.getImprovementType() in improvementsToCheck :
                                                        bFoundOne = True
                                                        break

                                if not bFoundOne :
                                        pCity.setNumRealBuilding(iBuilding, 0)
                                        
                                        sBuilding = gc.getBuildingInfo(iBuilding).getDescription()
                                        sCity = pCity.getName()
                                        sImprovement = ", ".join(gc.getImprovementInfo(iImprovement).getDescription() for iImprovement in improvementsToCheck)

                                        if ringsToCheck == [1] : sTxtTag = "TXT_KEY_BUILDING_LOST_IMPROVEMENT_MISSING_RING1"
                                        elif ringsToCheck == [2] : sTxtTag = "TXT_KEY_BUILDING_LOST_IMPROVEMENT_MISSING_RING2"
                                        else : sTxtTag = "TXT_KEY_BUILDING_LOST_IMPROVEMENT_MISSING"

                                        CyInterface().addMessage(iCityOwner, False , gc.getEVENT_MESSAGE_TIME(), CyTranslator().getText(sTxtTag,(sBuilding, sCity, sImprovement)), "AS2D_BOMBARDED", InterfaceMessageTypes.MESSAGE_TYPE_INFO, gc.getBuildingInfo(iBuilding).getButton(), gc.getInfoTypeForString("COLOR_RED"), iCX, iCY, True, True)

                return False

You must also add this texts in the XML :

Spoiler :
Code:
    <TEXT>
        <Tag>TXT_KEY_BUILDING_LOST_IMPROVEMENT_MISSING</Tag>
        <English>%s1_building in %s2_CityName is destroyed (No more %s3 in the city radius)</English>
        <French>%s1_building in %s2_CityName is destroyed (No more %s3 in the city radius)</French>
        <German>%s1_building in %s2_CityName is destroyed (No more %s3 in the city radius)</German>
        <Italian>%s1_building in %s2_CityName is destroyed (No more %s3 in the city radius)</Italian>
        <Spanish>%s1_building in %s2_CityName is destroyed (No more %s3 in the city radius)</Spanish>
    </TEXT>
    <TEXT>
        <Tag>TXT_KEY_BUILDING_LOST_IMPROVEMENT_MISSING_RING1</Tag>
        <English>%s1_building in %s2_CityName is destroyed (No more %s3 in the first ring of the city radius)</English>
        <French>%s1_building in %s2_CityName is destroyed (No more %s3 in the first ring of the city radius)</French>
        <German>%s1_building in %s2_CityName is destroyed (No more %s3 in the first ring of the city radius)</German>
        <Italian>%s1_building in %s2_CityName is destroyed (No more %s3 in the first ring of the city radius)</Italian>
        <Spanish>%s1_building in %s2_CityName is destroyed (No more %s3 in the first ring of the city radius)</Spanish>
    </TEXT>
    <TEXT>
        <Tag>TXT_KEY_BUILDING_LOST_IMPROVEMENT_MISSING_RING2</Tag>
        <English>%s1_building in %s2_CityName is destroyed (No more %s3 in the second ring of the city radius)</English>
        <French>%s1_building in %s2_CityName is destroyed (No more %s3 in the second ring of the city radius)</French>
        <German>%s1_building in %s2_CityName is destroyed (No more %s3 in the second ring of the city radius)</German>
        <Italian>%s1_building in %s2_CityName is destroyed (No more %s3 in the second ring of the city radius)</Italian>
        <Spanish>%s1_building in %s2_CityName is destroyed (No more %s3 in the second ring of the city radius)</Spanish>
    </TEXT>

Tcho !
 
Back
Top Bottom