lists in python are driving me nuts!

Ploeperpengel

academic precarity
Joined
Feb 2, 2006
Messages
4,748
Location
Berlin
The code below is written in onCityDoTurn. It automatically spreads a certain Religion and removes all other Religions from cities owned by one of the 4 listed civs as long the city isn't under occupation(at least I hope that part works too). The bolded part was supposed to remove the Religion from all cities not own by one of the listed civs. However it also removes them for the listed ones. I tried all kinds of changes and only got errors or the unwanted effect. Can anyone help me noob get out of this?
Code:
		lDestCivs = ['CIVILIZATION_ORCS','CIVILIZATION_GOBLINS','CIVILIZATION_HOBGOB','CIVILIZATION_OGRELORDS']
		for i in range( len( lDestCivs ) ):
			if pPlayer.getCivilizationType() == CvUtil.findInfoTypeNum(gc.getCivilizationInfo, gc.getNumCivilizationInfos, lDestCivs[i]):
				for iReligion in range(gc.getNumReligionInfos()): 
					if ( pCity.isHasReligion(iReligion) and iReligion != gc.getInfoTypeForString('RELIGION_DESTRUCTION') and not pCity.isOccupation()):
						pCity.setHasReligion(iReligion, False, True, True)
				if (pCity.isHasReligion(gc.getInfoTypeForString('RELIGION_DESTRUCTION')) == False and not pCity.isOccupation()):
					pCity.setHasReligion(gc.getInfoTypeForString('RELIGION_DESTRUCTION'), True, True, True)
			[B]for j in range(gc.getNumCivilizationInfos()):
				if pPlayer.getCivilizationType() != CvUtil.findInfoTypeNum(gc.getCivilizationInfo, gc.getNumCivilizationInfos, lDestCivs[i]):
					if (pCity.isHasReligion(gc.getInfoTypeForString('RELIGION_DESTRUCTION')) == True and not pCity.isOccupation()):
						pCity.setHasReligion(gc.getInfoTypeForString('RELIGION_DESTRUCTION'), False, True, True)[/B]
 
Edit : sorry , made an error .
 
There are two errors in your code i think . j have no use . Even if the civilization is in lDestCivs ( let's say indice 1 ) , the code will consider that is not in the list when you pass to indice 2 . I've rewritten the function , should work :

Code:
lDestCivs = ['CIVILIZATION_ORCS','CIVILIZATION_GOBLINS','CIVILIZATION_HOBGOB','CIVILIZATION_OGRELORDS']
lDestCivsType = [ CvUtil.findInfoTypeNum(gc.getCivilizationInfo, gc.getNumCivilizationInfos, item ) for item in lDestCivs]
religionDestruction = gc.getInfoTypeForString('RELIGION_DESTRUCTION')

if not pCity.isOccupation() :
        if pPlayer.getCivilizationType() in lDestCivsType :
                for iReligion in range(gc.getNumReligionInfos()): 
                        if ( pCity.isHasReligion(iReligion) and iReligion != religionDestruction ):
                                pCity.setHasReligion(iReligion, False, True, True)
                if not pCity.isHasReligion(religionDestruction):
                        pCity.setHasReligion(religionDestruction, True, True, True)
        else :
                if (pCity.isHasReligion(religionDestruction):
                        pCity.setHasReligion(religionDestruction, False, True, True)

Another thing to take care , is what to do if one of the city you want to remove a religion is a holy city ? ( but i don't know how your MOD deal with religion )

Tcho !
 
Sto you're awesome! That made it work. I think I was sitting about 5 hours on this with endless trial and error and you solved it for me in a couple of minutes:)

Yeah the holycitything might become a problem yet. Holy cities are founded as soon one of those listed civs builds the shrine(I copied some code from Gods of Old for that and it works so far). The civs have their proper religion and can race for the shrine to get the advantage of a holy city.

If the Greenskins conquer a holy city of another religion they will likely conquer the shrine for that Religion as well but the Religion will get removed with this code. Since a shrine also spreads its Religion the other religion will probably constantly be added and removed again though I couldn't test that yet. Though I don't bother about the religion being removed temporarily I could imagine that the constant messages and sounds might get annoying so I will have to find a workaround for that.
Another problem will come up as I plan to have two religions founded the ordinary way and for this will need some alterations to the doHolyCity and doHolyCityTech functions. Well I think you won't see me the last time posting here:crazyeye:
 
Back
Top Bottom