Religion Pathfinding Algorithm

Linkman226

#anarchy
Joined
Sep 14, 2007
Messages
2,493
I spent the better part of the last thirty minutes working on a pathfinding algorithm for spreading religions. Specifically I created a method that gets the 'real distance' between two cities. I'm using the A* pathfinding algorithm. I'm opening this thread up to any suggestions on what should affect the 'real distance'. So far terrains do, modified slightly by religion (Islam/ Shia don't get maluses from desert, for example, while Orthodoxy doesn't get a malus in tundra). This is what I have so far, I expect to finish tomorrow:

Spoiler :
Code:
void CvCity::getRealDistance(CvCity* pTargetCity, CvReligionInfo* pReligion) //Linkman226- Pathfinding algorithm for religion spreading using A*
{
	CvPlot* pPlot = plot();
	CvPlot* pTargetPlot = pTargetCity->plot();
	CvPlot* pLoopPlot;
	int iValue;
	int iBaseModifier;
	CvPlot* m_aiPlotValues;
	for (int iI = 0; iI < GC.getMapINLINE().numPlotsINLINE(); iI++)
	{
		pLoopPlot = GC.getMapINLINE().plotByIndexINLINE(iI);
		iValue = 10;
		iBaseModifier = plotDistance(getX_INLINE(), getY_INLINE(), pLoopPlot->getX_INLINE(), pLoopPlot->getY_INLINE());
		if (pLoopPlot->isImpassable())
		{
			iValue = 0;
			m_aiPlotValues[iI] = iValue;
			continue;
		}
		if (pLoopPlot->isHills())
			iValue /= 2;
		else if (pLoopPlot->getTerrainType() == (TerrainTypes)DESERT && pReligion != (ReligionTypes)ISLAM && pReligion != (ReligionTypes)SHIA)
			iValue /= 3;
		else if (pLoopPlot->getTerrainType() == (TerrainTypes)TUNDRA && pReligion != (ReligionTypes)ORTHODOXY)
			iValue /= 3;
		else if (pLoopPlot->getTerrainType() == (TerrainTypes)FOREST)
			iValue /= 2;
		else if (pLoopPlot->getTerrainType() == (TerrainTypes)JUNGLE && pReligion != (ReligionTypes)BUDDHISM && pReligion != (ReligionTypes)HINDUISM)
			iValue /= 3;
		else if (pLoopPlot->getTerrainType() == (TerrainTypes)PLAINS)
			iValue *= 2;
		else if (pLoopPlot->getTerrainType() == (TerrainTypes)GRASSLANDS)
			iValue *= 3;
		else if (pLoopPlot->getTerrainType() == (TerrainTypes)OCEAN)
			iValue /= 2;
			
		if (pLoopPlot->isRiver)
			iValue *= 3;
			
		if (!pLoopPlot->isRoute())
			iValue /= 3;
			
		if (pLoopPlot->getCulture() != 0)
			iValue *= 2;
		
		iValue +=iBaseModifier;
		m_aiPlotValues[iI] = iValue;
	}
	
	pLoopPlot = pPlot;
	while (!pLoopPlot == pTargetPlot)
	{
		CvPlot* m_aiAdjacentPlot;
		for (int iI = 0; iI < GC.getMapINLINE().numPlotsINLINE(); iI++)
		{
			if (GC.getMapINLINE().plotByIndexINLINE(iI)

Now my rationale behind changing the normal code for religion spread is that, quite frankly, it's crappy and makes no sense since things like terrain DO affect the spread of religion. Feel free to offer suggestions.
 
I'm not much for deciphering programming, so correct me if I have something wrong. What you just described gives numerical values to each type of terrain, then traces a route through the higher valued tiles, right? This seems counterintuitive to me. I would think you'd want to give values such that the route is traced through lower valued tiles so that you could then add the values together and use the sum as some sort of modifier when spreading the religion. Or maybe I'm totally misunderstanding.
 
I'm on the same page as Caesar Augustus here ... shouldn't tiles with quick spread have lower numbers, which results in a lower distance? Or am I missing something?

Which kinds of spread are affected by this anyway?
 
Religions do not spread neatly according to distance from the founding location. If they did:
- Australia would be Buddhist
- Ethiopia would be fervently Islamic
- Poland would be Protestant
- Britain would be Marxist
etc.

Of course, you can do whatever you want with your Mod. But I don't think anything's presently broken in DoC.
 
Religions do not spread neatly according to distance from the founding location. If they did:
- Australia would be Buddhist
- Ethiopia would be fervently Islamic
- Poland would be Protestant
- Britain would be Marxist
etc.

Of course, you can do whatever you want with your Mod. But I don't think anything's presently broken in DoC.


I agree with another quote by a guy with a leopard avatar. Religion spread should only be by conquest, state church, or missionaries.
 
I respectfully disagree. How else are religions like Buddhism and Taoism going to spread, since they'll be founded in civs which already have state religions? I doubt very much that the Indian AI is going to build tons of Buddhist missionaries to spread it within India, let alone get it into China or elsewhere.
 
Oh, you don't know their AIs then ;) But I agree that at least for certain religion combination there should be free spread.
 
Top Bottom