Bazaar developer reference

CvHomelandAI::FindPatrolTarget(CvUnit *)

Defined in
CvHomelandAI.cpp, line 5565
Class
CvHomelandAI
Hook name
CivHooks::CvHomelandAI_FindPatrolTarget

Hooks

static bool BeforeCvHomelandAI_FindPatrolTarget(CvHomelandAI* self, CvUnit* pUnit, CvPlot*& result);static void AfterCvHomelandAI_FindPatrolTarget(CvHomelandAI* self, CvUnit* pUnit, CvPlot*& result);static CvPlot* ReplaceCvHomelandAI_FindPatrolTarget(CvPlot* (*original)(CvHomelandAI*, CvUnit*), CvHomelandAI* self, CvUnit* pUnit);CivRegisterBefore<CivHooks::CvHomelandAI_FindPatrolTarget>(host, &BeforeCvHomelandAI_FindPatrolTarget);CivRegisterAfter<CivHooks::CvHomelandAI_FindPatrolTarget>(host, &AfterCvHomelandAI_FindPatrolTarget);CivRegisterReplace<CivHooks::CvHomelandAI_FindPatrolTarget>(host, &ReplaceCvHomelandAI_FindPatrolTarget);

Code

5564/// See if there is an adjacent plot we can wander to5565CvPlot* CvHomelandAI::FindPatrolTarget(CvUnit* pUnit)5566{5567	CvPlot* pAdjacentPlot;5568	CvPlot* pBestPlot;5569	int iValue;5570	int iBestValue;5571	int iI;55725573	iBestValue = 0;5574	pBestPlot = NULL;55755576	for(iI = 0; iI < NUM_DIRECTION_TYPES; iI++)5577	{5578		pAdjacentPlot = plotDirection(pUnit->getX(), pUnit->getY(), ((DirectionTypes)iI));55795580		if(pAdjacentPlot != NULL)5581		{5582			if(pUnit->PlotValid(pAdjacentPlot))5583			{5584				if(!(pAdjacentPlot->isVisibleEnemyUnit(pUnit)))5585				{5586					if(pUnit->GeneratePath(pAdjacentPlot, 0, true))5587					{5588						iValue = (1 + GC.getGame().getJonRandNum(10000, "AI Patrol"));55895590						// Prefer wandering in our own territory5591						if(pAdjacentPlot->getOwner() == pUnit->getOwner())5592						{5593							iValue += 10000;5594						}55955596						if(GC.getLogging() && GC.getAILogging()){5597							CvString strLogString;5598							strLogString.Format("Adjacent Patrol Plot Score, %i, %i, %i", iValue, pAdjacentPlot->getX(), pAdjacentPlot->getY());5599							LogPatrolMessage(strLogString, pUnit);5600						}56015602						if(iValue > iBestValue)5603						{5604							iBestValue = iValue;5605							pBestPlot = pAdjacentPlot;5606						}5607					}5608					else5609					{5610						if(GC.getLogging() && GC.getAILogging()){5611							CvString strLogString;5612							strLogString.Format("Adjacent Patrol Plot !GeneratePath(), , %i, %i", pAdjacentPlot->getX(), pAdjacentPlot->getY());5613							LogPatrolMessage(strLogString, pUnit);5614						}5615					}5616				}5617				else5618				{5619					if(GC.getLogging() && GC.getAILogging()){5620						CvString strLogString;5621						strLogString.Format("Adjacent Patrol Plot !isVisibleEnemyUnit(), , %i, %i", pAdjacentPlot->getX(), pAdjacentPlot->getY());5622						LogPatrolMessage(strLogString, pUnit);5623					}5624				}5625			}5626			else5627			{5628				if(GC.getLogging() && GC.getAILogging()){5629					CvString strLogString;5630					strLogString.Format("Adjacent Patrol Plot not valid, , %i, %i", pAdjacentPlot->getX(), pAdjacentPlot->getY());5631					LogPatrolMessage(strLogString, pUnit);5632				}5633			}5634		}5635		else5636		{5637			if(GC.getLogging() && GC.getAILogging()){5638				CvString strLogString;5639				strLogString.Format("Adjacent Patrol Plot not found");5640				LogPatrolMessage(strLogString, pUnit);5641			}5642		}5643	}56445645	if(pBestPlot != NULL)5646	{5647		if(GC.getLogging() && GC.getAILogging()){5648			CvString strLogString;5649			strLogString.Format("Patrol Target FOUND, %i, %i, %i", iBestValue, pBestPlot->getX(), pBestPlot->getY());5650			LogPatrolMessage(strLogString, pUnit);5651		}56525653		CvAssert(!pUnit->atPlot(*pBestPlot));5654		return pBestPlot;5655	}5656	else5657	{5658		if(GC.getLogging() && GC.getAILogging()){5659			CvString strLogString;5660			strLogString.Format("Patrol Target NOT FOUND");5661			LogPatrolMessage(strLogString, pUnit);5662		}5663	}56645665	return NULL;5666}

Calls

Called by