Bazaar developer reference

CvGameTrade::StepUnit(int)

Defined in
CvTradeClasses.cpp, line 1487
Class
CvGameTrade
Hook name
CivHooks::CvGameTrade_StepUnit

Hooks

static bool BeforeCvGameTrade_StepUnit(CvGameTrade* self, int iIndex, bool& result);static void AfterCvGameTrade_StepUnit(CvGameTrade* self, int iIndex, bool& result);static bool ReplaceCvGameTrade_StepUnit(bool (*original)(CvGameTrade*, int), CvGameTrade* self, int iIndex);CivRegisterBefore<CivHooks::CvGameTrade_StepUnit>(host, &BeforeCvGameTrade_StepUnit);CivRegisterAfter<CivHooks::CvGameTrade_StepUnit>(host, &AfterCvGameTrade_StepUnit);CivRegisterReplace<CivHooks::CvGameTrade_StepUnit>(host, &ReplaceCvGameTrade_StepUnit);

Code

1486/// move a trade unit a single step along its path (called by MoveUnit)1487bool CvGameTrade::StepUnit (int iIndex)1488{1489	CvAssertMsg(iIndex >= 0 && iIndex < (int)m_aTradeConnections.size(), "iIndex out of bounds");1490	if (iIndex < 0 || iIndex >= (int)m_aTradeConnections.size())1491	{1492		return false;1493	}14941495	// if the unit needs to turn around1496	TradeConnection &kTradeConnection = m_aTradeConnections[iIndex];1497	bool bAtEndGoingForward = (kTradeConnection.m_bTradeUnitMovingForward && kTradeConnection.m_iTradeUnitLocationIndex >= ((int)kTradeConnection.m_aPlotList.size() - 1));1498	bool bAtEndGoingBackward = (!kTradeConnection.m_bTradeUnitMovingForward && kTradeConnection.m_iTradeUnitLocationIndex <= 0);1499	if (bAtEndGoingForward || bAtEndGoingBackward)1500	{1501		kTradeConnection.m_bTradeUnitMovingForward = !kTradeConnection.m_bTradeUnitMovingForward;1502	}15031504	// if moving forward1505	if (kTradeConnection.m_bTradeUnitMovingForward)1506	{1507		kTradeConnection.m_iTradeUnitLocationIndex += 1;1508	}1509	else // if moving back1510	{1511		kTradeConnection.m_iTradeUnitLocationIndex -= 1;1512		if (kTradeConnection.m_iTradeUnitLocationIndex == 0)1513		{1514			kTradeConnection.m_iCircuitsCompleted += 1;1515		}1516	}15171518	// Move the visualization1519	CvUnit *pkUnit = GetVis(iIndex);1520	if (pkUnit)1521	{1522		pkUnit->setXY(kTradeConnection.m_aPlotList[kTradeConnection.m_iTradeUnitLocationIndex].m_iX, kTradeConnection.m_aPlotList[kTradeConnection.m_iTradeUnitLocationIndex].m_iY, true, false, true, true);1523	}15241525	// auto-pillage when a trade unit moves under an enemy unit1526	CvPlot* pPlot = GC.getMap().plot(kTradeConnection.m_aPlotList[kTradeConnection.m_iTradeUnitLocationIndex].m_iX, kTradeConnection.m_aPlotList[kTradeConnection.m_iTradeUnitLocationIndex].m_iY);1527	if (pPlot)1528	{1529		CvUnit* pEnemyUnit = pPlot->getVisibleEnemyDefender(kTradeConnection.m_eOriginOwner);1530		if (pEnemyUnit)1531		{1532			if (pEnemyUnit->canPlunderTradeRoute(pPlot, false))1533			{1534#if defined(MOD_API_EXTENSIONS)1535				GET_PLAYER(pEnemyUnit->getOwner()).GetTrade()->PlunderTradeRoute(kTradeConnection.m_iID, pEnemyUnit);1536#else1537				GET_PLAYER(pEnemyUnit->getOwner()).GetTrade()->PlunderTradeRoute(kTradeConnection.m_iID);1538#endif1539				// done died!1540				return false;1541			}1542		}1543	}15441545	return true;1546}

Calls

Called by