Random bonuses.

ArneHD

Just a little bit mad
Joined
May 16, 2006
Messages
3,153
Location
Tromsø, Norway
I have been thinking about making a mod that allows special units to "prospect". That is, permanently place a random resource at a paticular spot. Now the unit itself i have under control, but I found that I couldn't find a value that gave a 50% chance or a 25%. So I went into the SDK and had a look at it, and found this code:
Code:
if (getImprovementType() != NO_IMPROVEMENT)
	{
		if (getBonusType() == NO_BONUS)
		{
			FAssertMsg((0 < GC.getNumBonusInfos()), "GC.getNumBonusInfos() is not greater than zero but an array is being allocated in CvPlot::doImprovement");
			for (iI = 0; iI < GC.getNumBonusInfos(); iI++)
			{
				if (GET_TEAM(getTeam()).isHasTech((TechTypes)(GC.getBonusInfo((BonusTypes) iI).getTechReveal())))
				{
					if (GC.getImprovementInfo(getImprovementType()).getImprovementBonusDiscoverRand(iI) > 0)
					{
						if (GC.getGameINLINE().getSorenRandNum(GC.getImprovementInfo(getImprovementType()).getImprovementBonusDiscoverRand(iI), "Bonus Discovery") == 0)
						{
							setBonusType((BonusTypes)iI);

							pCity = GC.getMapINLINE().findCity(getX_INLINE(), getY_INLINE(), getOwnerINLINE(), NO_TEAM, false);

							if (pCity != NULL)
							{
								swprintf(szBuffer, gDLL->getText("TXT_KEY_MISC_DISCOVERED_NEW_RESOURCE", GC.getBonusInfo((BonusTypes) iI).getTextKeyWide(), pCity->getNameKey()).GetCString());
								gDLL->getInterfaceIFace()->addMessage(getOwnerINLINE(), false, GC.getDefineINT("EVENT_MESSAGE_TIME"), szBuffer, "AS2D_DISCOVERBONUS", MESSAGE_TYPE_MINOR_EVENT, GC.getBonusInfo((BonusTypes) iI).getButton(), (ColorTypes)GC.getInfoTypeForString("COLOR_WHITE"), getX_INLINE(), getY_INLINE(), true, true);
							}

							break;
						}
					}
				}
			}
		}

		if (GC.getImprovementInfo(getImprovementType()).getImprovementUpgrade() != NO_IMPROVEMENT)
		{
			changeUpgradeProgress(GET_PLAYER(getOwnerINLINE()).getImprovementUpgradeRate());

			if (getUpgradeProgress() >= GC.getGameINLINE().getImprovementUpgradeTime(getImprovementType()))
			{
				setImprovementType((ImprovementTypes)(GC.getImprovementInfo(getImprovementType()).getImprovementUpgrade()));
			}
		}
	}
}

My question is, what does this acctualy do? I think it adds a random resource when an improvement is built, but how does it work?

Also, what do I have to change in order to make it give a 25% or 50% etc. chance?
 
There is a chance to find resources when you work a mine on a hill with no resources. That's the specific case where this slightly more general code occures.

You can get a random number by GC.getGameINLINE().getSorenRandNum(range, "String") in C++, or gc.getGame().getSorenRand(range, "String") in python (I think).
 
The Great Apple said:
There is a chance to find resources when you work a mine on a hill with no resources. That's the specific case where this slightly more general code occures.

You can get a random number by GC.getGameINLINE().getSorenRandNum(range, "String") in C++, or gc.getGame().getSorenRand(range, "String") in python (I think).

Do you know what random number I get when I use either or these? Is it a number between 1 and 0 or some other value?
 
ArneHD said:
Do you know what random number I get when I use either or these? Is it a number between 1 and 0 or some other value?

To be clear, mathematically it is:

[0,range)

So if your code is:
randVal = gc.getGame().getSorenRand(10, "Testing")
Then randVal is now one of: 0,1,2,3,4,5,6,7,8,9
 
surt said:
To be clear, mathematically it is:

[0,range)

So if your code is:
randVal = gc.getGame().getSorenRand(10, "Testing")
Then randVal is now one of: 0,1,2,3,4,5,6,7,8,9

So, if I set "randVal = gc.getGame().getSorenRand(1, "Testing")" I would get a 50% chance? Right?
 
ArneHD said:
So, if I set "randVal = gc.getGame().getSorenRand(1, "Testing")" I would get a 50% chance? Right?

No, because the possible values would be:
All integer numbers between 0 and (range-1) inclusive. when range is 1 as you suggested, that would be 0 to 0, inclusive. Or in otherwords, just 0.

So you'd get 0 every time.

What you probably want instead is something like:

randVal = gc.getGame().getSorenRand(100, "Testing")

if randVal > 50:
doSomething()
 
Or just:

PHP:
randVal = gc.getGame().getSorenRand(2, "Testing")

if randVal == 1:
      doSomething()
One thing you can remember if you ever get confused is that the number you put in is always the number of optoins available, with the first option being 0.
 
surt said:
No, because the possible values would be:
All integer numbers between 0 and (range-1) inclusive. when range is 1 as you suggested, that would be 0 to 0, inclusive. Or in otherwords, just 0.

So you'd get 0 every time.

What you probably want instead is something like:

randVal = gc.getGame().getSorenRand(100, "Testing")

if randVal > 50:
doSomething()

OK, thank you.

Oh and RogerBacon, is that the mylon mod? If not could you show me which one it is?
 
ArneHD said:
OK, thank you.

Oh and RogerBacon, is that the mylon mod? If not could you show me which one it is?

No, it was made by tywiggins. I added the Python events to it. You can find it here: http://apolyton.net/forums/showthread.php?s=&threadid=143500
My Python update that adds random resources is on page two of that thread. I don't believe the mod was ever posted to this forum so many people don't know about it but I consider it one of the most useful mods for Civ. It gives you hope that, even if you have to build a city in the middle of the desert, that one day you will be able to trun it in to a thriving city.

Roger Bacon
 
Back
Top Bottom