void CvPlot::doImprovement()

vincentz

Programmer
Joined
Feb 4, 2009
Messages
3,614
Location
Denmark
Got a couple of improvements in my mod that "discovers" resources, but while its ok with mines, it becomes a bit silly when fur is discovered in the tropical and bananas in the polar regions, so I wanted to add a min/max longitude check.

So... void CvPlot::doImprovement()

if ((GET_TEAM(getTeam()).isHasTech((TechTypes)(GC.getBonusInfo((BonusTypes) iI).getTechReveal()))) && (canHaveBonus((BonusTypes)iI, false)))


Does this makes sense? I didnt get error or warning when compiling, but I doubt its correct.

Also, I'd really like if it was scaled on gamespeed.
if (GC.getGameINLINE().getSorenRandNum(GC.getImprovementInfo(getImprovementType()).getImprovementBonusDiscoverRand(iI) * iMaxTurns / 1000, "Bonus Discovery") == 0)

This is clearly wrong though. Any suggestions?
 
I will not tell you about C++ as I'm not more advanced in it than you are, but from my experience in Python, iMaxTurns can be tricky as:

- iMaxTurns returns 1 if Time Victory is off

- iMaxTurns returns the remaining turns in advanced start

Thought I'd let you know.

PS: In Python, I had to do this to get a correct iMaxTurns all the time:

Code:
	iSpeedInfo = gc.getGameSpeedInfo(gc.getGame().getGameSpeedType())
	iMaxTurns = 0
	for i in xrange(iSpeedInfo.getNumTurnIncrements()):
		iTurns = iSpeedInfo.getGameTurnInfo(i).iNumGameTurnsPerIncrement
		iMaxTurns += iTurns
 
So why use iMaxTurns? Just use iGrowthPercent or some other values which are easier to obtain in that file.
 
The C++ code looks fine to me and should do precisely what you expect when you read the code. The problem is the math in the last line. The question is what the correct math would be.

Presumably either "getMultiplier() / 100" or "100 / getMultiplier()". This new function then calculates a number based on gamespeed and era.

Alternatively you make a version of CvImprovementInfo::getImprovementBonusDiscoverRand(), which gives different scores based on era/gamespeed. This will allow you to add more xml data to improvements, saying something like "change starts with -10 and gets +10 for each era". In other words you need to pass two eras before it comes active.

You also might want to consider if knowledge of certain techs can affect the chance. There are plenty of options to make the bonuses appear more rapidly in late game and rarely if at all early on.
 
@ isenchine
Thanks for heads up on iMaxTurns

@ platy
Good idea. Thought it would be clever somehow with MaxTurns, but considering the next function in CvPlot uses the getImprovementUpgradeRate(), it just serves it to me :D

@ Nightinggale

Presumably either "getMultiplier() / 100" or "100 / getMultiplier()". This new function then calculates a number based on gamespeed and era
Was in doubt about this. And since its a Random, I cant check easily.
I assume that a new resource appears when a random between 0 and iDiscoverRand becomes 0, so the iImprovementPercent / 100 which decreases the chance the higher the iImprovementPercent is, would be the way to go.
I used it like this
if (GC.getGameINLINE().getSorenRandNum(GC.getImprovementInfo(getImprovementType()).getImprovementBonusDiscoverRand(iI) * GET_PLAYER(getOwnerINLINE()).getImprovementUpgradeRate() / 100, "Bonus Discovery") == 0)

Regarding expanding the idea. Atm Im just trying to fix small stuff in my mod that have bugged me for a while. While it certainly would be cool to have some modifiers on it, I still have quite a few small ideas I want to fix first.

edit : build went without errors :D Gonna do a bit of testing. Thanks for the assistance everyone. I really appreciate it. :goodjob:
 
Dealing with randomness is like this:
PHP:
GC.getGameINLINE().getSorenRandNum(iX, "string")
string is just what it should write in the log, which mean you can type whatever you like.

iX is the limit for the random number you want. If you set iX = 4, then you get an int in the range 0 to 3. This is general for all randomness in the game and yes, it's a bit tricky to test. Fixed random seeds in savegames helps a bit here, but...

Since the code in question only triggers when the result is 0, then increasing the number will decrease the chance. This mean to increase the change of getting a bonus, you should multiply with 100 / upgradeRate(). This way if the upgrade rate is 100, you just multiply with one. However if you increase the upgrade rate, you lower the range for the random number, hence a higher probability of a bonus.

Precisely which numbers to use depends on game balance and how you want it to work. This mean I can't answer you directly on what would be best.
 
Back
Top Bottom