Bazaar developer reference

CvHomelandAI::PlotWorkerSeaMoves()

Defined in
CvHomelandAI.cpp, line 1347
Class
CvHomelandAI
Hook name
CivHooks::CvHomelandAI_PlotWorkerSeaMoves

Hooks

static bool BeforeCvHomelandAI_PlotWorkerSeaMoves(CvHomelandAI* self);static void AfterCvHomelandAI_PlotWorkerSeaMoves(CvHomelandAI* self);static void ReplaceCvHomelandAI_PlotWorkerSeaMoves(void (*original)(CvHomelandAI*), CvHomelandAI* self);CivRegisterBefore<CivHooks::CvHomelandAI_PlotWorkerSeaMoves>(host, &BeforeCvHomelandAI_PlotWorkerSeaMoves);CivRegisterAfter<CivHooks::CvHomelandAI_PlotWorkerSeaMoves>(host, &AfterCvHomelandAI_PlotWorkerSeaMoves);CivRegisterReplace<CivHooks::CvHomelandAI_PlotWorkerSeaMoves>(host, &ReplaceCvHomelandAI_PlotWorkerSeaMoves);

Code

1346/// Send out work boats to harvest resources1347void CvHomelandAI::PlotWorkerSeaMoves()1348{1349	ClearCurrentMoveUnits();1350	// Loop through all recruited units1351	for(list<int>::iterator it = m_CurrentTurnUnits.begin(); it != m_CurrentTurnUnits.end(); ++it)1352	{1353		UnitHandle pUnit = m_pPlayer->getUnit(*it);1354		if(pUnit)1355		{1356			if(pUnit->AI_getUnitAIType() == UNITAI_WORKER_SEA  ||1357			   pUnit->IsAutomated() && pUnit->getDomainType() == DOMAIN_SEA && pUnit->GetAutomateType() == AUTOMATE_BUILD)1358			{1359				CvHomelandUnit unit;1360				unit.SetID(pUnit->GetID());1361				m_CurrentMoveUnits.push_back(unit);1362			}1363		}1364	}13651366	FStaticVector< CvHomelandUnit, 64, true, c_eCiv5GameplayDLL >::iterator moveUnitIt;1367	for(moveUnitIt = m_CurrentMoveUnits.begin(); moveUnitIt != m_CurrentMoveUnits.end(); ++moveUnitIt)1368	{1369		UnitHandle pUnit = m_pPlayer->getUnit(moveUnitIt->GetID());1370		int iTargetIndex = -1;1371		int iTargetMoves = MAX_INT;13721373		// See how many moves of this type we can execute1374		for (unsigned int iI = 0; iI < m_TargetedNavalResources.size(); iI++)1375		{1376			// See what units we have who can reach target this turn1377			CvPlot* pTarget = GC.getMap().plot(m_TargetedNavalResources[iI].GetTargetX(), m_TargetedNavalResources[iI].GetTargetY());13781379			if (!pUnit->canBuild(pTarget, (BuildTypes)m_TargetedNavalResources[iI].GetAuxIntData()))1380			{1381				continue;1382			}13831384			int iMoves = TurnsToReachTarget(pUnit.pointer(), pTarget);1385			if (iMoves < iTargetMoves)1386			{1387				iTargetMoves = iMoves;1388				iTargetIndex = iI;1389			}1390		}13911392		if (iTargetIndex != -1)1393		{1394			// Queue best one up to capture it1395			int iTargetX = m_TargetedNavalResources[iTargetIndex].GetTargetX();1396			int iTargetY = m_TargetedNavalResources[iTargetIndex].GetTargetY();1397			CvPlot* pTarget = GC.getMap().plot(iTargetX, iTargetY);13981399			bool bResult = false;1400			if(pUnit->UnitPathTo(iTargetX, iTargetY, 0) > 0)1401			{1402				pUnit->PushMission(CvTypes::getMISSION_MOVE_TO(), iTargetX, iTargetY);1403				if(pUnit->plot() == pTarget)1404				{1405					pUnit->PushMission(CvTypes::getMISSION_BUILD(), m_TargetedNavalResources[iTargetIndex].GetAuxIntData(), -1, 0, (pUnit->GetLengthMissionQueue() > 0), false, MISSIONAI_BUILD, pTarget);1406					bResult = true;1407				}1408				else1409				{1410					pUnit->finishMoves();1411				}14121413				// Delete this unit from those we have to move1414				UnitProcessed(m_CurrentMoveUnits.begin()->GetID());1415			}1416			else1417			{1418				if(pUnit->plot() == pTarget)1419				{1420					pUnit->PushMission(CvTypes::getMISSION_BUILD(), m_TargetedNavalResources[iTargetIndex].GetAuxIntData(), -1, 0, (pUnit->GetLengthMissionQueue() > 0), false, MISSIONAI_BUILD, pTarget);1421					bResult = true;1422				}1423			}1424		1425			if (bResult)1426			{1427				if(GC.getLogging() && GC.getAILogging())1428				{1429					CvString strLogString;1430					strLogString.Format("Harvesting naval resource at, X: %d, Y: %d", m_TargetedNavalResources[iTargetIndex].GetTargetX(), m_TargetedNavalResources[iTargetIndex].GetTargetY());1431					LogHomelandMessage(strLogString);1432				}1433			}1434			else1435			{1436				if(GC.getLogging() && GC.getAILogging())1437				{1438					CvString strLogString;1439					strLogString.Format("Moving toward naval resource at, X: %d, Y: %d", m_TargetedNavalResources[iTargetIndex].GetTargetX(), m_TargetedNavalResources[iTargetIndex].GetTargetY());1440					LogHomelandMessage(strLogString);1441				}1442			}1443		}1444	}1445}

Calls

Called by