DirectionTypes directionXY(const CvPlot* pFromPlot, const CvPlot* pToPlot) { #if defined(MOD_BALANCE_CORE) CvPlot** aPlotsToCheck = GC.getMap().getNeighborsUnchecked(pFromPlot); for(int iI=0; iI<NUM_DIRECTION_TYPES; iI++) { if (aPlotsToCheck[iI]==pToPlot) { return (DirectionTypes)iI; } } //if the direct lookup fails, use the real method return estimateDirection(pFromPlot->getX(),pFromPlot->getY(),pToPlot->getX(),pToPlot->getY()); #else return directionXY(pFromPlot->getX(), pFromPlot->getY(), pToPlot->getX(), pToPlot->getY()); #endif }
///TKs Med CvCity* CvMap::findCity(int iX, int iY, PlayerTypes eOwner, TeamTypes eTeam, bool bSameArea, bool bCoastalOnly, TeamTypes eTeamAtWarWith, DirectionTypes eDirection, CvCity* pSkipCity, bool bRandom) { int iBestValue = MAX_INT; CvCity* pBestCity = NULL; std::vector<CvCity*> aCitys; for (int iI = 0; iI < MAX_PLAYERS; iI++) { if (GET_PLAYER((PlayerTypes)iI).isAlive()) { if ((eOwner == NO_PLAYER) || (iI == eOwner)) { if ((eTeam == NO_TEAM) || (GET_PLAYER((PlayerTypes)iI).getTeam() == eTeam)) { int iLoop; for (CvCity* pLoopCity = GET_PLAYER((PlayerTypes)iI).firstCity(&iLoop); pLoopCity != NULL; pLoopCity = GET_PLAYER((PlayerTypes)iI).nextCity(&iLoop)) { if (!bSameArea || (pLoopCity->area() == plotINLINE(iX, iY)->area()) || (bCoastalOnly && (pLoopCity->waterArea() == plotINLINE(iX, iY)->area()))) { if (!bCoastalOnly || pLoopCity->isCoastal(GC.getMIN_WATER_SIZE_FOR_OCEAN())) { if ((eTeamAtWarWith == NO_TEAM) || atWar(GET_PLAYER((PlayerTypes)iI).getTeam(), eTeamAtWarWith)) { if ((eDirection == NO_DIRECTION) || (estimateDirection(dxWrap(pLoopCity->getX_INLINE() - iX), dyWrap(pLoopCity->getY_INLINE() - iY)) == eDirection)) { if ((pSkipCity == NULL) || (pLoopCity != pSkipCity)) { if (!bRandom) { int iValue = plotDistance(iX, iY, pLoopCity->getX_INLINE(), pLoopCity->getY_INLINE()); if (iValue < iBestValue) { iBestValue = iValue; pBestCity = pLoopCity; } } else { aCitys.push_back(pLoopCity); } } } } } } } } } } } if (bRandom) { int iRandom = aCitys.size(); if (iRandom >= 1) { iRandom = GC.getGameINLINE().getSorenRandNum(iRandom, "Random Find City"); return aCitys[iRandom]; } else { return NULL; } } return pBestCity; }
DirectionTypes cyEstimateDirection(int iDX, int iDY) { return estimateDirection(iDX, iDY); }