Platyping's Python

hmmm thats odd can you post the for loop of mine that you were using?
 
Code:
for i in range(21):
	pPlot = pCity.getCityIndexPlot(i)
 
might wanna use xrange anyway, faster. I will look through it in context later! but This is what we used in Jamie's Rome and it worked perfectly then. might be a problem applicable only in this situation
 
Thanks for the complements.
No idea either, because I seldom use that city index for loop myself.
Only saw it being used by jamie for his natural wonder codes, so use it to replace my own for loop since it seems shorter.

But if it is causing problems, try using my original loop:
Code:
			iX = pCity.getX()
			iY = pCity.getY()
			for x in range(iX - 2, iX + 3):
				for y in range(iY - 2, iY + 3):
					if abs(x - iX) != 2 or abs(y - iY) != 2:
						pPlot = CyMap().plot(x,y)
						if pPlot.isWater() and  pPlot.getBonusType(-1) == -1:
							randBonus = CyGame().getSorenRandNum(15, "Freebie")
							if randBonus < 3:
								pPlot.setBonusType(MarineResource[randBonus])
								pPlot.setImprovementType(fboat)
								CyInterface().addMessage(iPlayer,true,15,CyTranslator().getText("TXT_TSUKIJI_BONUS",(gc.getBonusInfo(MarineResource[randBonus]).getDescription(),)),'',0, gc.getBonusInfo(MarineResource[randBonus]).getButton(),ColorTypes(11), x, y, true,true)
## Tsukiji Fish Market End ##

It may be clearer if you enable python exceptions to see exactly which line went wrong because the list index may be pointing to MarineResource rather than the for loop

This is under onBuildingBuilt, the rest of the codes shouldn't be causing problems.

Thanks, but this doesn't work either. The Python exception simply is: "IndexError: list index out of range". It does place new resources, but it doesn't run for all water tiles - it simply stops the loop after some runs. I checked with a city with 20 water tiles and BUG debugging...

It points to that line of code:

Code:
pPlot.setBonusType(MarineResource[randBonus])

Doesn't make a whole lot of sense to me...
 
Scratch everything I've said. I'm just dumb :D. Your code works fine. And the error makes a whole lot of sense if one thinks about it.

Code:
pPlot.setBonusType(MarineResource[randBonus])

randBonus is the index of the list here. Of course, if one adds resources and then doesn't check that the amount of resources matches randBonus, the index list is out of range. I feel stupid now. ;)
 
Just as I suspected, list index error points to Marine Resource rather than the for loop.
However, not sure why randBonus gives you an error, unless you changed the integer value because there are only 3 values in MarineResource list.

If you never change anything, there shouldn't be an error for that line
 
That was the problem. I changed the integer value, misreading it for a simple check to determine the probability of the resource spawn...now I have 5 marine resources and a matching integer. Works perfectly now.
 
Glad to hear that it works.
If you wish to adjust the probability, you can change the "15" to another value.
The original codes have 20% chance of spawning something.
Since you seems pretty well verse in python, I leave it to you to decide the probability.

You can use back the original for loop as well, much shorter :D
 
@platyping:

Yeah, I figured that out. :)

@jamie6:

Thanks for the hint ;) . Btw, if you hate the world thinks you are a villain - I've written code for a wonder which reduces the effect to 1 turn ;)
 
:eek: :love: that could be a useful piece of code to adapt to a wonder in my next mod where the Apostolic palace is built turn 0 :p In the case of my mod it would really have to be a religious wonder to be able to appease the religious people complaining that I am a villain :lol:
 
Okay, here it is:

Code:
# Volkshalle Wonder Start

def anger_check(iPlayer):

	pPlayer = gc.getPlayer(iPlayer)
	iRefCityList = PyPlayer(iPlayer).getCityList()
	b_Volkshalle = gc.getInfoTypeForString("BUILDING_VOLKSHALLE")
	obsoleteTech = gc.getBuildingInfo(b_Volkshalle).getObsoleteTech()
	if ( gc.getTeam(pPlayer.getTeam()).isHasTech(obsoleteTech) == false or obsoleteTech == -1 ):

		for pyCity in iRefCityList:
			pCity = pyCity.GetCy()
			if pCity.getNumActiveBuilding(b_Volkshalle) == 1:
				for pyCity in iRefCityList:
					pCity = pyCity.GetCy()
					anger = pCity.getDefyResolutionAngerTimer()
					if (anger > 0):
						pCity.changeDefyResolutionAngerTimer(-anger)

# Volkshalle Wonder End

Probably the code could be optimized, but I'm lazy, and it works :D . I applied it to the Volkshalle wonder - I figured it somehow appropriate the worshippers of a cruel and bloodthirsty dictator couldn't care less about what the world outside thinks...

You can just call the function within onBeginPlayerTurn or onEndPlayerTurn, whichever you like...
 
@xrange
I cant be bothered to use that when the for loop is looping for less than 20 times. No difference :D

@Volkshalle
I did something similar before, but not pretty efficient as it is going to loop through every city of yours every turn.

Lascaux Caves
Spoiler :
Civ4ScreenShot0000-18.jpg

Here comes the Great Artist version :D

When GP is born in any city, culture boost to that city.
Culture Boost = 5% of Culture required for next culture level, capped at 1000
If Great Artist present in that city:
Culture Boost = 10% of Culture required for next culture level, capped at 2000

Let me know if too high

Artwork by Chamaedrys
 
Why do you use for Matsumoto Castle such complicated code and "def onEndGameTurn" instead of just "def onCityDoTurn" and "getNumActiveBuilding"?
 
@Cybah
For efficiency.
Using def onCityDoTurn means, every single turn, you are gonna check every city of each player, does this city has Matsumoto? If yes, blah blah blah
Using the slightly more complicated method, the location of Matsumoto is checked and stored during loading once and for all.
Then every turn, you are just asking once where is Matsumoto, and do blah blah blah
And as you see, the check is done onEndGameTurn instead of EndPlayerTurn. Thus, I am not checking once for each player either

Tianning Temple
Spoiler :
Civ4ScreenShot0004-15.jpg

Civ4ScreenShot0003-14.jpg

Grants a free new promotion based on current state religion.
If city itself has all 7 religions, grants all 7 new promotions to units built in that city.

Notes:
To make it not so OP, all 7 new promotions can be gained through leveling just like normal promotions. You are just getting them free...
Too lazy to make each of them different, so for now, all are just granting 10% combat strength. (I leave it to modders to do the balancing)
If the 7 religions all present part is too OP, let me know :D

Artwork by Hrochland


Edit:
Civilopedia Text and Movie switched to Changzhou's instead of Beijing's (Thanks to Civciv5)
 
Specialized Trait
SpecializedTrait.jpg


Short and Sweet, too simple or OP?

Edits:
Traits Updated
 
Hmm, I guess +1 Research may be less OP compared to Production then

Edits:
Gigapack has been updated till Lascaux Caves.
Tianning not yet included since the promotions are not balanced yet obviously :D
 
Back
Top Bottom