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:
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.
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.