Separating food from population growth

Phaedris

Chieftain
Joined
Jan 20, 2009
Messages
13
I've being trying to find a way to have pop growth independent of food production and rely on other factors.
While food would still be consumed by the population in the same way as is currently implemented, population growth would come from a special birth rate yield that each colonist produces and also have other factors that would effect this yield (hospitals etc.)

I was wondering if anyone knew how to change the yield type used for population growth. (I've found a few references to population growth in CvCity.cpp and how much food is kept afterwards) but as the height of my abilities at the moment is merging mods I do not fully understand what to edit to get the desired effect.

Any help would be appreciated.
 
I was wondering if anyone knew how to change the yield type used for population growth. (I've found a few references to population growth in CvCity.cpp)
Indeed, it is in CvCity.cpp
You will find what you want in the "doGrowth" fonction.
Now, the stock of food isn't limitate, so you must change it in the "doYields" fonction (always in CvCity.cpp).

If you want a special birth rate, you must make your own fonction that you can insert in
"doGrowth " fonction for example :p.
You have mentioned "hospitals" but there are only present in my mod, no?

I had already thought about doing that :). In any case, if you need more detailed help, let me know!
 
I've got it working :) well mostly :( , I have a new yield type for growth now all I have to do is find a way to have each colonist produce the new YIELD_BIRTH (like the way food is consumed only in reverse).

I just checked out your mod it seems really interesting, does the hospital reduce the % of food needed for pop growth is that how it works?

Anyway thanks for pointing me in the right direction. :goodjob:
 
I have a new yield type for growth now all I have to do is find a way to have each colonist produce the new YIELD_BIRTH (like the way food is consumed only in reverse).
It is not necessary to create a new ressource, you can create a variable (for example m_iGrowth), you can serve you of "m_iGameTurnFounded" as model in CvCity.cpp.
Every turn, each citizen of your population increases this variable. When it is equal to 100, you can do a growth in this city. And if there are an hospital in city, the growth will be done when it is equal to 75 for instance.
I just checked out your mod it seems really interesting, does the hospital reduce the % of food needed for pop growth is that how it works?
No, I did an easy work :lol:, I was a beginner. Instead of consuming 200 foods, it consumes 30% less.(I think it is 30%).
But, I will change that :p!
 
Well the reason I decided to use a yield was because I wanted it to be effected by traits/founding fathers.
Plus wouldn't it be easier to make buildings effect it if I use a resource?
 
Well the reason I decided to use a yield was because I wanted it to be effected by traits/founding fathers.
I don't like how this game has used the founding fathers, so I don't like that they can increase the growth.
But, why not :p!
You can add a variable in the CIV4TraitInfos.xml file that will permit to increase the growth in all your cities.

Plus wouldn't it be easier to make buildings effect it if I use a resource?
On the contrary, I think it is easier.
For example :
Code:
int iGrowth = getPopulation()/2;

for (int i = 0; i < GC.getNumBuildingInfos(); ++i)
{
	BuildingTypes eBuilding = (BuildingTypes) i;
	CvBuildingInfo& kBuilding = GC.getBuildingInfo(eBuilding);
	if (isHasBuilding(eBuilding))
	{
		int iGrowthPercent = kBuilding.getGrowthPercent();
		if (iGrowthPercent > 0)
		{
			iGrowth += iGrowth*iGrowthPercent/100;
		}	
	}
}
changeGrowth(iGrowth);
 
It is not necessary to create a new ressource, you can create a variable (for example m_iGrowth), you can serve you of "m_iGameTurnFounded" as model in CvCity.cpp.
Every turn, each citizen of your population increases this variable. When it is equal to 100, you can do a growth in this city. And if there are an hospital in city, the growth will be done when it is equal to 75 for instance.

Hi.

I'm extremely interested in this kind of variable..

but I'm afraid that I'm not so SDK-skilled to create it correctly. :(

My aim is exactly what you wrote:
every turn, each citizen of the city population increases this variable.
when it reachs a certain number, it generates a new Free Colonist in the city and the variable get resetted.

and, meanwhile, I'd like to avoid the population growth from food surplus.

is it simple as you said?



M07, can you give me some suggestion on what to do, please? I beg you. :(
 
I will try to explain you.
In CvCity.cpp and CvCity.h file you must find all the "m_iMissionaryRate", it's just an example we could choice an other variable.
And you copy the line and you add your own variable:

For example in the reset function in CvCity.cpp you will find this line
Code:
m_iMissionaryRate = 0;
you replace it by this two lines
Code:
m_iMissionaryRate = 0;
m_iGrowth = 0;
Then you will find this code:
Code:
int CvCity::getMissionaryRate() const
{
	return m_iMissionaryRate;
}

void CvCity::setMissionaryRate(int iRate)
{
	m_iMissionaryRate = iRate;
}
and you will replace it by
Code:
int CvCity::getMissionaryRate() const
{
	return m_iMissionaryRate;
}

void CvCity::setMissionaryRate(int iRate)
{
	m_iMissionaryRate = iRate;
}
int CvCity::getGrowth() const
{
	return m_iGrowth;
}

void CvCity::setGrowth(int iRate)
{
	m_iGrowth= iRate;
}
void CvCity::changeGrowth(int iChange)
{
	setGrowth(getGrowth() + iChange);
}
Don't forget the variables and functions declarations in CvCity.h!!
Then you can use this functions as u like.
In the function doGrowth() you can replace this function part
Code:
if (getFood() >= growthThreshold())
	{
		if (AI_isEmphasizeAvoidGrowth())
		{
			setFood(growthThreshold());
		}
		else
		{
/*
			UnitTypes eUnit = (UnitTypes)GC.getCivilizationInfo(getCivilizationType()).getCivilizationUnits(GC.getDefineINT("DEFAULT_POPULATION_UNIT"));
			if (NO_UNIT != eUnit)
			{
				CvUnit* pUnit = GET_PLAYER(getOwnerINLINE()).initUnit(eUnit, (ProfessionTypes) GC.getCivilizationInfo(GET_PLAYER(getOwnerINLINE()).getCivilizationType()).getDefaultProfession(), getX_INLINE(), getY_INLINE());
				pUnit->setRebelSentiment(getRebelPercent());
				doRebelSentiment();
				changeFood(-(std::max(0, (growthThreshold() - getFoodKept()))));
			}

			gDLL->getInterfaceIFace()->addMessage(getOwnerINLINE(), false, GC.getEVENT_MESSAGE_TIME(), gDLL->getText("TXT_KEY_CITY_GROWTH", getNameKey()), "AS2D_POSITIVE_DINK", MESSAGE_TYPE_INFO, GC.getYieldInfo(YIELD_FOOD).getButton(), (ColorTypes)GC.getInfoTypeForString("COLOR_GREEN"), getX_INLINE(), getY_INLINE(), true, true);


			// ONEVENT - City growth
			gDLL->getEventReporterIFace()->cityGrowth(this, getOwnerINLINE());
*/
		}
	}
For me it is easy to do, but long to explain :p
You can in the the function doGrowth() do what you want with the new functions we had just created.
 
In the following version of my mod, this system will be implemented. I will lauched it in late July. I don't think there are an other mod that incorporated it :rolleyes:.
 
sounds really cool, I recently got back into Colonization, and I find it annoying how my 2 population farming city is pumping out citizens every 12 turns, while my 10 population production city is starving and so wont ever grow. (however I have a nearby city that is sending all its food to my population to stagnate growth)

It would make sense if I could just send all my food to my major cities, however that would slow my population rate.
 
Top Bottom