Python callback and city function question

Pickly

Prince
Joined
Jun 5, 2009
Messages
535
1. When adding various python callbacks to the DLL, what (if anything) would I need to add to tell the game which file to use for the calback?

2. In the function below, what does the bolded + underlined 1 do?

Code:
int CvCity::getOvercrowdingPercentAnger(int iExtra) const
{
	int iOvercrowding;
	int iAnger;

	iAnger = 0;

	iOvercrowding = (getPopulation() + iExtra) ;

	if (iOvercrowding > 0)
	{
		iAnger += (((iOvercrowding * GC.getPERCENT_ANGER_DIVISOR()) / std::max(1, (getPopulation() + iExtra))) + [B][I][U]1[/U][/I][/B]);
	}

	return iAnger;
}

If the rest code works the way it seems to, it divides the population, plus the "extra" by either 1 or the population + extra, which is than multiplied back by population when computing total happiness. The 1 seems extra, though, so am curious if anyone knows what it does.
 
2. In the function below, what does the bolded + underlined 1 do?
I dunno any C++, but I'm betting on that the +1 has to do with integer division - fractions are rounded down and by adding one you basically get rounding up instead.
 
1. When adding various python callbacks to the DLL, what (if anything) would I need to add to tell the game which file to use for the calback?

For example, in:
Code:
gDLL->getPythonIFace()->callFunction([B]PYGameModule[/B], "cannotTrain", argsList2.makeFunctionArgs(), &lResult);

You have PYGameModule which is CvGameInterface.py. All files are in the EntryPoints subfolder.

You already have these defined in CvDefines.h:
Spoiler :
Code:
// python module names
#define PYDebugToolModule			"CvDebugInterface"
#define PYScreensModule				"CvScreensInterface"
#define PYCivModule						"CvAppInterface"
#define PYWorldBuilderModule	"CvWBInterface"
#define PYPopupModule					"CvPopupInterface"
#define PYDiplomacyModule			"CvDiplomacyInterface"
#define PYUnitControlModule		"CvUnitControlInterface"
#define PYTextMgrModule				"CvTextMgrInterface"
#define PYPerfTestModule			"CvPerfTest"
#define PYDebugScriptsModule	"DebugScripts"
#define PYPitBossModule				"PbMain"
#define PYTranslatorModule		"CvTranslator"
#define PYGameModule					"CvGameInterface"
#define PYEventModule					"CvEventInterface"
#define PYRandomEventModule					"CvRandomEventInterface"

But you can just write your file name.

2. In the function below, what does the bolded + underlined 1 do?

It looks like iOvercrowding is always 0, so the function always returns 0... Weird.. Am I reading it wrong?

EDIT: It seems that the BTS code doesn't contain the iPopulationModifier, so it's probably your code...
Anyway, I guess it's meant to make sure that the anger is never 0?
 
On the callbacks: Thanks for the help.

On the overcrowding: the "iPopulationModifier" is actually not supposed to be there. (I'm adding the ability for buildings to change the happiness and health per population, so the population modifier variable will control how this is done. I had deleted the code that gives this modifier an actual value) your comments did help avoid a stupid programming goof due to rounding issues, though, so did help out with that.



The actual original code is now correctly written in the first post. Looking at the parentheses, what it seems to be doing is dividing the population+extra by either the population + extra, or by 1, and than adding 1 to that result, which seems a bit strange given what it does. (Parentheses were tested in notepad++, although I might have the positioning off.)
 
The actual original code is now correctly written in the first post. Looking at the parentheses, what it seems to be doing is dividing the population+extra by either the population + extra, or by 1, and than adding 1 to that result, which seems a bit strange given what it does. (Parentheses were tested in notepad++, although I might have the positioning off.)

You're right. I imagine that +1 is so that iAnger is equal to at least 1 if overcrowding is greater than 0. I don't find that particularly strange. The function only wants a 0 returned if there is no overcrowding.
 
Back
Top Bottom