SDK help.

Joined
Sep 15, 2006
Messages
511
I've been making an Immigration Mod in the SDK. However the game keeps crashing. I was wondering if some one more experianced could help me find out where my code is faulty. :sad:

I added this to CvCity.cpp
Code:
	doGrowth();

	doCulture();

	doPlotCulture(false);

	doProduction();

	doDecay();

	//ClassicThunder Immigration
	doImmigration();
	//ClassicThunder Immigration

	doReligion();

	doGreatPeople();

	doMeltdown();

I added this to CvCity.h
Code:
	void doGrowth();
	void doCulture();
	void doPlotCulture(bool bUpdate);
	void doProduction();
	void doDecay();
	//ClassicThunder Immigration
	void doImmigration();
	//ClassicThunder Immigration
	void doReligion();
	void doGreatPeople();
	void doMeltdown();

Here is the code that actualy does something
Code:
//ClassicThunder Immigration
void CvCity::doImmigration()
{
	CvCity* pHomeCity;
	int pHomeCity_X, pHomeCity_Y;
	CvCity* pTargetCity;
	int pTargetCity_X, pTargetCity_Y;
	bool CityDistance;

	CvWString szBuffer;
	int iLoop;
	int PossibleImmigrants;
	int iIp;
	int iJ;

	for (pHomeCity = GET_PLAYER((PlayerTypes)iJ).firstCity(&iLoop); pHomeCity != NULL; pHomeCity = GET_PLAYER((PlayerTypes)iJ).nextCity(&iLoop))
	{
		pHomeCity_X = pHomeCity->getX();
		pHomeCity_Y = pHomeCity->getY();
        PossibleImmigrants = pHomeCity->angryPopulation();
		if ( PossibleImmigrants > (pHomeCity->getPopulation() / 8) )
		{
			for (pTargetCity = GET_PLAYER((PlayerTypes)iJ).firstCity(&iLoop); pTargetCity != NULL; pTargetCity = GET_PLAYER((PlayerTypes)iJ).nextCity(&iLoop))
			{
				if( (pTargetCity->happyLevel() - pTargetCity->angryPopulation()) > 4)
				{
					pTargetCity_X = pTargetCity->getX();
					pTargetCity_Y = pTargetCity->getY();
					if((pHomeCity_X - pTargetCity_X) > 4 || (pHomeCity_Y - pTargetCity_Y) > 4)
					{
						pHomeCity->setPopulation(pHomeCity->getPopulation() - 1);
						pTargetCity->setPopulation(pHomeCity->getPopulation() + 1);
					}
				}
			}
		}
	}
}
//ClassicThunder Immigration

Thanks for any help! :D
 
Well, I am not sure that I can tell you where you are going wrong, but I can suggest that you check out TheLopez's Immigration mod. Its really excellent, let me assure you, and it might give you some insights on how to take it even further.

Aussie_Lurker.
 
Oh and, though I am no expert on SDK (I have been playing around with it, but do not yet understand all its intricacies ;) ), the code looks pretty good to me. I also notice that you take a different approach from TheLopez. His had an actual 'Immigrant' unit created, which would select an appropriate city to move to, wheras if I understand your code, you have a direct deduction from 1 city and an addition to another. From what I can see there is nothing wrong with your code. I take it that the thing compiles and builds OK? Beyond that I have no help to offer. Sorry :(.

Aussie_Lurker.
 
Not sure if this is what is causing the crash, but surely the last line of code which currently reads

pTargetCity->setPopulation(pHomeCity->getPopulation() + 1);

should read

pTargetCity->setPopulation(pTargetCity->getPopulation() + 1);
 
Shouldn't iJ default to 0?

Anyways thanks for all the help I - hopefully- fixed the issues and am compiling now.
 
Some compilers will initialize iJ to zero for you (and there are a few languages out there that specify such a behavior), but it is very bad practice to rely on such a feature.
 
Some compilers will initialize iJ to zero for you (and there are a few languages out there that specify such a behavior), but it is very bad practice to rely on such a feature.

My C++ Teacher keeps docking me points for that, I'll have to fix that habbit, but anyways it works now thanks for the help!

One thing though how do you put out a message in the message area on the left side of the game screen?

Here's what I tried.
Code:
//ClassicThunder Immigration
void CvCity::doImmigration()
{
	CvCity* pHomeCity;
	int pHomeCity_X, pHomeCity_Y;
	CvCity* pTargetCity;
	int pTargetCity_X, pTargetCity_Y;

	int iLoop;
	int PossibleImmigrants;
	int iJ = 0;
	CvWString szBuffer;

	for (pHomeCity = GET_PLAYER((PlayerTypes)iJ).firstCity(&iLoop); pHomeCity != NULL; pHomeCity = GET_PLAYER((PlayerTypes)iJ).nextCity(&iLoop))
	{
		pHomeCity_X = pHomeCity->getX();
		pHomeCity_Y = pHomeCity->getY();
        PossibleImmigrants = pHomeCity->angryPopulation();
		if ( PossibleImmigrants > (pHomeCity->getPopulation() / 8) )
		{
			for (pTargetCity = GET_PLAYER((PlayerTypes)iJ).firstCity(&iLoop); pTargetCity != NULL; pTargetCity = GET_PLAYER((PlayerTypes)iJ).nextCity(&iLoop))
			{
				if( pTargetCity->angryPopulation() == 0 )
				{
					pTargetCity_X = pTargetCity->getX();
					pTargetCity_Y = pTargetCity->getY();
					if( (pHomeCity_X - pTargetCity_X) < 4 && (pHomeCity_X - pTargetCity_X) > -4 && (pHomeCity_Y - pTargetCity_Y) < 4 && (pHomeCity_Y - pTargetCity_Y) > -4)
					{
						pHomeCity->setPopulation(pHomeCity->getPopulation() - 1);
						pTargetCity->setPopulation(pTargetCity->getPopulation() + 1);
						szBuffer = gDLL->getText("TXT_KEY_MISC_IMMIGRATION_CITY", pHomeCity->getName, pTargetCity->getName);
						gDLL->getInterfaceIFace()->addMessage(getOwnerINLINE(), false, GC.getDefineINT("EVENT_MESSAGE_TIME"), szBuffer, NULL, MESSAGE_TYPE_MINOR_EVENT, ARTFILEMGR.getInterfaceArtInfo("INTERFACE_UNHEALTHY_PERSON")->getPath(), (ColorTypes)GC.getInfoTypeForString("COLOR_RED"), getX_INLINE(), getY_INLINE(), true, true);
					}
				}
			}
		}
	}
}
//ClassicThunder Immigration

And the XML is this
Code:
	<Tag>TXT_KEY_MISC_IMMIGRATION_CITY</Tag>
		<English>People Have Left %s1_CityName and Moved to %s2_CityName!!!</English>
		<French>People Have Left %s1_CityName and Moved to %s2_CityName!!</French>
		<German>People Have Left %s1_CityName and Moved to %s2_CityName!!</German>
		<Italian>People Have Left %s1_CityName and Moved to %s2_CityName!!</Italian>
		<Spanish>People Have Left %s1_CityName and Moved to %s2_CityName!!</Spanish>
	</TEXT>

The result is this
People Have Left and Moved to <--This is White and bold.

I want it to say People have left homecity and moved to targetcity.

Thanks for any help and for the help you have already given me as I figure this stuff out.
 
Back
Top Bottom