[Development Thread]CIVILIZATION 4: World of Pokiphlanon

In C++, const has several usages.
When used for variables, then yes - it means they're not really variables but have constant values which cannot be changed (there are more options there with regards to pointers, but let's really not go there right now).

You can also define methods (= member functions) as const. That means that you declare them as 'not changing the instance for which you called this method'.
Technically what it means, is that the 'this' pointer which this method receives (and with which you actually call other methods and use variables of this instance) is also const, so you cannot:
1. Modify member variables
2. Call other non-const methods, because they might change member variables values.

const is a type 'qualifier' because it is considered something that modifies an existing type to another type. non-const variables can be converted implicitly to the const qualified type (because you only add a restriction), but the opposite does not apply.

So if you have a const method, and from it you try to call a non-const method, the compiler cannot implicitly convert the current const instance to a non-const instance.

I hope I didn't complicate you too much...
 
I understand, but that doesn't explain this behavior.

I am doing this:
Code:
int iTotalCityGrowthRoom = getTotalCityGrowthRoom();

And the method getTotalCityGrowthRoom()
Code:
int CvPlayer::getTotalCityGrowthRoom()
{
	return m_iTotalCityGrowthRoom;
}

Neither of these are const.
 
I assume the line:
Code:
int iTotalCityGrowthRoom = getTotalCityGrowthRoom();

is called from inside a const method.

In this case, it falls under 'a const method cannot call non-const methods'.
 
Great, thanks. Now this is my first time with AI modding, so I want to get this right. I have this code:
Code:
//Voyhkah Tweak START *************************************************

								if (iTotalCityGrowthRoom / getNumCities() <=2)
								{
//Code here
								}

//Tweak END ************************************************************

And I need to put in in the method CvvPlayerAI::AI_bestTech(args).

Where do I put it? And what do I put inside it?
 
I guess you want to modify the value of the tech.

You should place this inside the loop that goes over the techs, after all the conditions were tested:

Code:
	for (iI = 0; iI < GC.getNumTechInfos(); iI++)
	{
		if ((eIgnoreTech == NO_TECH) || (iI != eIgnoreTech))
		{
			if ((eIgnoreAdvisor == NO_ADVISOR) || (GC.getTechInfo((TechTypes)iI).getAdvisorType() != eIgnoreAdvisor))
			{
				if (canEverResearch((TechTypes)iI))
				{
					if (!(kTeam.isHasTech((TechTypes)iI)))
					{
						if (GC.getTechInfo((TechTypes)iI).getEra() <= (getCurrentEra() + 1))
						{
							iPathLength = findPathLength(((TechTypes)iI), false);

							if (iPathLength <= iMaxPathLength)
							{
								iValue = 1;

								int iRandomFactor = ((bAsync) ? GC.getASyncRand().get(2000, "AI Research ASYNC") : GC.getGameINLINE().getSorenRandNum(2000, "AI Research"));
								int iRandomMax = 2000;
								iValue += iRandomFactor;

								iValue += kTeam.getResearchProgress((TechTypes)iI);

                    // Place your code here

And here you can modify the iValue however you want.
Inside your 'if' make whatever changes you think the tech value should have (iValue += XXX).
 
Not sure if this would work, haven't tested it yet due to not enough framework to run the mod, but this is my code.

In CvCity.cpp, under the method canConstruct:

Code:
CvBuildingInfo& building = GC.getBuildingInfo(eBuilding);
	int terrainInt = building.getPrereqBorderTerrain();
	TerrainTypes terrain = (TerrainTypes)terrainInt;
	bool border = true;
	if (terrainInt != -1)
	{
		if (!isBorderTerrain(terrain))
		{
			return false;
		}
	}

Also in CvCity.cpp:

Code:
bool CvCity::isBorderTerrain(TerrainTypes terrain) const
{
	int xCoord = getX();
	int yCoord = getY();
	for(int x = -1; x < 2; x++)
	{
		for(int y = -1; y < 2; y++)
		{
			int relXCoord = xCoord + x;
			int relYCoord = yCoord + y;
			CvPlot* plot = GC.getMap().plot(relXCoord,relYCoord);
			if(plot->getTerrainType() == terrain)
			{
				return true;
			}
		}
	}
	return false;
}

In CvGameTextMgr.cpp:

Code:
if (kBuilding.getPrereqBorderTerrain() != NULL)
	{
		CvTerrainInfo& terrain = GC.getTerrainInfo((TerrainTypes)kBuilding.getPrereqBorderTerrain());
		szBuffer.append(NEWLINE);
		szBuffer.append(gDLL->getText("TXT_KEY_DLL_PREREQTERRAIN", terrain.getDescription()));
	}

I just realized that in my post, I had accidentally made <PrereqBorderTerrain> plural. It is not plural. Sorry, but there can be only one PrereqBorderTerrain per building.

I finally got around to doing this, but since I have completely no experience with this kind of modding... Where do I find the method canConstruct:? canConstruct: (with the : ) doesn't exist (which is logical), and simply canConstruct exists 6 times in the file. Maybe this is because I am using RevDCM (which uses Better BTS AI and BUG and such), so I'll include 'my' CvCity.cpp:

http://www.megaupload.com/?d=Q2KG4ESQ

Where should I put the other codes, or does it not matter?
 
Got it. Thanks!

UPDATE: I have finished the city growth limitation code.
 
I've been working to the Enviroment Meter, which is one of my favorite parts of WoP. I need to use a for loop to get an array of the building objects in a CvCity instance. Is there a method in CvCity for that?
 
Not that I'm aware of. Methods which need to go over the buildings, simply do a for loop to go over all building types (GC.getNumBuildingInfos()), and for each check if the city has them.
Well, they actually check how many building of that type the city has (because theoretically the code allows a building to be built more than once).

For that you have (depending on what you need):
Code:
CvCity::getNumRealBuilding()
CvCity::getNumBuilding()
CvCity::getNumFreeBuilding()
CvCity::getNumActiveBuilding()
 
Thanks. I've looked all over, but I can't find any method to get the health of a city. Do you know of any?
 
There are two values, CvCity::goodHealth() and CvCity::badHealth(i,j) (look it up to see what i and j are). The first is all the good things added together and the second is all the bad things. If the first is higher the city is healthy, if the second is higher it is unhealthy (and loosing food because of it).
 
Thanks. BTW, would it be easy to merge an already-partially-completed mod with BUG, or would it be to hard?
 
I've been avoiding dealing with BUG myself, but SDK changes are not affected since BUG doesn't contain any DLL changes (BULL does, though).
Regarding Python changes - well, that depends on the changes.
 
Hmmmm... The installer couldn't install BUG... Does anyone out there have BUG in their mods folder?
 
Could you somehow help me with it (That was implied, sorry if it wasn't).
 
Maybe you could attach it, if it's small enough?
 
Apparently, you can't.

One of the things that I may or may not want to assault now it Minor Civs (Or City-States, if you wish). These are not just a minor component of the game in WoP, they are quite important. Each player starts in a different tree that all the other major players, however, there are many other minor civs in the tree. These minor civs can be conquered or, with the "Nationalism" tech, peacefully absorbed. Each Minor Civ has a unique name that will be randomly chosen from a list, and one of three trait/attitude pairs. I thought a great way to do this would be in XML.

Code:
<MinorCiv>
	<Names>
		<Name>TXT_KEY_MINORCIV_NAME_NAME</Name>
	</Names>
	<Traits>
		<Trait>TRAIT_AGGRESSIVE</Trait>
		<Trait>TRAIT_EXPANSIVE</Trait>
		<Trait>TRAIT_FRIENDLY</Trait>
	</Traits>
	<PlayerColorTypes>
		<PlayerColor>PLAYERCOLOR_COLOR</PlayerColor>
	</PlayerColorTypes>
</MinorCiv>

I will add more names and playercolors.
So on a one to four scale, how ambitious is this?
1. Hard
2. Really Hard
3. Unfathomly hard.
4. Dude! You're out of you're goddamn mind!

Whgy do I get the feeling it's 4? :lol:
 
Back
Top Bottom