Bazaar developer reference

CvMilitaryAI::ShouldAttackBySea(PlayerTypes, CvMilitaryTarget &)

Defined in
CvMilitaryAI.cpp, line 1184
Class
CvMilitaryAI
Hook name
CivHooks::CvMilitaryAI_ShouldAttackBySea

Hooks

static bool BeforeCvMilitaryAI_ShouldAttackBySea(CvMilitaryAI* self, PlayerTypes eEnemy, CvMilitaryTarget& target);static void AfterCvMilitaryAI_ShouldAttackBySea(CvMilitaryAI* self, PlayerTypes eEnemy, CvMilitaryTarget& target);static void ReplaceCvMilitaryAI_ShouldAttackBySea(void (*original)(CvMilitaryAI*, PlayerTypes, CvMilitaryTarget&), CvMilitaryAI* self, PlayerTypes eEnemy, CvMilitaryTarget& target);// CivHooks.h gives this hook point no types, so nothing checks these hooks' parameters.host->RegisterHook(host->pluginIndex, CivHooks::CvMilitaryAI_ShouldAttackBySea::ID, CIV_HOOK_BEFORE, (void*)&BeforeCvMilitaryAI_ShouldAttackBySea);host->RegisterHook(host->pluginIndex, CivHooks::CvMilitaryAI_ShouldAttackBySea::ID, CIV_HOOK_AFTER, (void*)&AfterCvMilitaryAI_ShouldAttackBySea);host->RegisterHook(host->pluginIndex, CivHooks::CvMilitaryAI_ShouldAttackBySea::ID, CIV_HOOK_REPLACE, (void*)&ReplaceCvMilitaryAI_ShouldAttackBySea);

Code

1183/// Is it better to attack this target by sea?1184void CvMilitaryAI::ShouldAttackBySea(PlayerTypes eEnemy, CvMilitaryTarget& target)1185{1186	CvAStarNode* pPathfinderNode;1187	int iPathLength = 0;1188	int iPlotDistance = plotDistance(target.m_pMusterCity->getX(), target.m_pMusterCity->getY(), target.m_pTargetCity->getX(), target.m_pTargetCity->getY());11891190	// Can embark1191	if(GET_TEAM(m_pPlayer->getTeam()).canEmbark())1192	{1193		// On different landmasses?1194		if(target.m_pMusterCity->getArea() != target.m_pTargetCity->getArea())1195		{1196			target.m_bAttackBySea = true;1197			target.m_iPathLength = iPlotDistance;1198			return;1199		}12001201		// No step path between muster point and target?1202		if(!GC.getStepFinder().DoesPathExist(m_pPlayer->GetID(), eEnemy, target.m_pMusterCity->plot(), target.m_pTargetCity->plot()))1203		{1204			target.m_bAttackBySea = true;1205			target.m_iPathLength = iPlotDistance;1206			return;1207		}12081209		// Land path is over twice as long as direct path1210		pPathfinderNode = GC.getStepFinder().GetLastNode();1211		if(pPathfinderNode != NULL)1212		{1213			iPathLength = pPathfinderNode->m_iData1;1214			if(iPathLength > (2 * iPlotDistance))1215			{1216				target.m_bAttackBySea = true;1217				target.m_iPathLength = iPlotDistance;1218				return;1219			}1220		}1221	}12221223	// Can't embark yet1224	else1225	{1226		if(!GC.getStepFinder().DoesPathExist(m_pPlayer->GetID(), eEnemy, target.m_pMusterCity->plot(), target.m_pTargetCity->plot()))1227		{1228			target.m_iPathLength = -1;  // Call off attack, no path1229			return;1230		}12311232		else1233		{1234			pPathfinderNode = GC.getStepFinder().GetLastNode();1235			if(pPathfinderNode != NULL)1236			{1237				iPathLength = pPathfinderNode->m_iData1;1238			}1239		}1240	}12411242	target.m_bAttackBySea = false;1243	target.m_iPathLength = iPathLength;1244}

Calls

Called by