Hooks
static bool BeforeCvPlayerAI_FindBestMusicianTargetPlot(CvPlayerAI* self, CvUnit* pGreatMusician, bool bOnlySafePaths, CvPlot*& result);static void AfterCvPlayerAI_FindBestMusicianTargetPlot(CvPlayerAI* self, CvUnit* pGreatMusician, bool bOnlySafePaths, CvPlot*& result);static CvPlot* ReplaceCvPlayerAI_FindBestMusicianTargetPlot(CvPlot* (*original)(CvPlayerAI*, CvUnit*, bool), CvPlayerAI* self, CvUnit* pGreatMusician, bool bOnlySafePaths);CivRegisterBefore<CivHooks::CvPlayerAI_FindBestMusicianTargetPlot>(host, &BeforeCvPlayerAI_FindBestMusicianTargetPlot);CivRegisterAfter<CivHooks::CvPlayerAI_FindBestMusicianTargetPlot>(host, &AfterCvPlayerAI_FindBestMusicianTargetPlot);CivRegisterReplace<CivHooks::CvPlayerAI_FindBestMusicianTargetPlot>(host, &ReplaceCvPlayerAI_FindBestMusicianTargetPlot);
Code
1544CvPlot* CvPlayerAI::FindBestMusicianTargetPlot(CvUnit* pGreatMusician, bool bOnlySafePaths)1545{1546 CvAssertMsg(pGreatMusician, "pGreatMusician is null");1547 if(!pGreatMusician)1548 {1549 return NULL;1550 }15511552 int iBestTurnsToReach = MAX_INT;1553 CvPlot* pBestTargetPlot = NULL;1554 CvCity* pBestTargetCity = NULL;1555 int iPathTurns;1556 UnitHandle pMusician = UnitHandle(pGreatMusician);15571558 // Find target civ1559 PlayerTypes eTargetPlayer = GetCulture()->GetCivLowestInfluence(true /*bCheckOpenBorders*/);1560 if (eTargetPlayer == NO_PLAYER)1561 {1562 return NULL;1563 }15641565 CvPlayer &kTargetPlayer = GET_PLAYER(eTargetPlayer);15661567 // Loop through each of that player's cities1568 int iLoop;1569 CvCity *pLoopCity;1570 for(pLoopCity = kTargetPlayer.firstCity(&iLoop); pLoopCity != NULL; pLoopCity = kTargetPlayer.nextCity(&iLoop))1571 {1572 // Search all the plots adjacent to this city1573 for(int jJ = 0; jJ < NUM_DIRECTION_TYPES; jJ++)1574 {1575 CvPlot* pAdjacentPlot = plotDirection(pLoopCity->getX(), pLoopCity->getY(), ((DirectionTypes)jJ));1576 if(pAdjacentPlot != NULL)1577 {1578 // Make sure this is still owned by target and is revealed to us1579 bool bRightOwner = (pAdjacentPlot->getOwner() == eTargetPlayer);1580 bool bIsRevealed = pAdjacentPlot->isRevealed(getTeam());1581 if(bRightOwner && bIsRevealed)1582 {1583 iPathTurns = TurnsToReachTarget(pMusician, pAdjacentPlot, true /*bReusePaths*/, !bOnlySafePaths/*bIgnoreUnits*/);1584 if(iPathTurns < iBestTurnsToReach)1585 {1586 iBestTurnsToReach = iPathTurns;1587 pBestTargetCity = pLoopCity;1588 }1589 }1590 }1591 }1592 }15931594 // Found a city now look at ALL the plots owned by that player near that city1595 if (pBestTargetCity)1596 {1597 iBestTurnsToReach = MAX_INT;1598 CvPlot *pLoopPlot;1599#if defined(MOD_GLOBAL_CITY_WORKING)1600 for(int iJ = 0; iJ < pBestTargetCity->GetNumWorkablePlots(); iJ++)1601#else1602 for(int iJ = 0; iJ < NUM_CITY_PLOTS; iJ++)1603#endif1604 {1605 pLoopPlot = plotCity(pBestTargetCity->getX(), pBestTargetCity->getY(), iJ);1606 if(pLoopPlot != NULL)1607 {1608 // Make sure this is still owned by target and is revealed to us1609 bool bRightOwner = (pLoopPlot->getOwner() == eTargetPlayer);1610 bool bIsRevealed = pLoopPlot->isRevealed(getTeam());1611 if(bRightOwner && bIsRevealed)1612 {1613 iPathTurns = TurnsToReachTarget(pMusician, pLoopPlot, true /*bReusePaths*/, !bOnlySafePaths/*bIgnoreUnits*/);1614 if(iPathTurns < iBestTurnsToReach)1615 {1616 iBestTurnsToReach = iPathTurns;1617 pBestTargetPlot = pLoopPlot;1618 }1619 }1620 } 1621 }1622 }16231624 return pBestTargetPlot;1625}