void CvGameObjectPlot::foreachNear(GameObjectTypes eType, boost::function<void(CvGameObject *)> func, int iDistance) { int iPlotX = m_pPlot->getX_INLINE(); int iPlotY = m_pPlot->getY_INLINE(); for (int iX=iPlotX - iDistance; iX <= iPlotX + iDistance; iX++) { for (int iY=iPlotY - iDistance; iY <= iPlotY + iDistance; iY++) { CvPlot* pPlot = GC.getMapINLINE().plotINLINE(iX, iY); if (pPlot) pPlot->getGameObject()->foreachOn(eType, func); } } }
void CvGameObjectTeam::foreach(GameObjectTypes eType, boost::function<void (CvGameObject*)> func) { switch(eType) { case GAMEOBJECT_GAME: func(GC.getGameINLINE().getGameObject()); break; case GAMEOBJECT_PLAYER: for (int iPlayer = 0; iPlayer < MAX_CIV_PLAYERS; ++iPlayer) { CvPlayer& kLoopPlayer = GET_PLAYER((PlayerTypes)iPlayer); if (kLoopPlayer.isAlive()) { if (kLoopPlayer.getTeam() == m_pTeam->getID()) { func((CvGameObject*)&CvGameObjectPlayer(&kLoopPlayer)); } } } break; case GAMEOBJECT_CITY: foreach(GAMEOBJECT_PLAYER, boost::bind(callForeach, _1, GAMEOBJECT_CITY, func)); break; case GAMEOBJECT_UNIT: foreach(GAMEOBJECT_PLAYER, boost::bind(callForeach, _1, GAMEOBJECT_UNIT, func)); break; case GAMEOBJECT_PLOT: for (int iI = 0; iI < GC.getMapINLINE().numPlotsINLINE(); iI++) { CvPlot* pLoopPlot = GC.getMapINLINE().plotByIndexINLINE(iI); if (pLoopPlot->getTeam() == m_pTeam->getID()) { func(pLoopPlot->getGameObject()); } } break; case GAMEOBJECT_TEAM: func(this); break; } }
void CvGameObjectPlayer::foreach(GameObjectTypes eType, boost::function<void (CvGameObject*)> func) { int iLoop; switch(eType) { case GAMEOBJECT_GAME: func(GC.getGameINLINE().getGameObject()); break; case GAMEOBJECT_TEAM: func(GET_TEAM(m_pPlayer->getTeam()).getGameObject()); break; case GAMEOBJECT_CITY: for (CvCity* pCity = m_pPlayer->firstCity(&iLoop); pCity != NULL; pCity = m_pPlayer->nextCity(&iLoop)) { func(pCity->getGameObject()); } break; case GAMEOBJECT_UNIT: for (CvUnit* pUnit = m_pPlayer->firstUnit(&iLoop); pUnit != NULL; pUnit = m_pPlayer->nextUnit(&iLoop)) { func(pUnit->getGameObject()); } break; case GAMEOBJECT_PLOT: for (int iI = 0; iI < GC.getMapINLINE().numPlotsINLINE(); iI++) { CvPlot* pLoopPlot = GC.getMapINLINE().plotByIndexINLINE(iI); if (pLoopPlot->getOwnerINLINE() == m_pPlayer->getID()) { func(pLoopPlot->getGameObject()); } } break; case GAMEOBJECT_PLAYER: func(this); break; } }
void CvGameObjectCity::foreachRelated(GameObjectTypes eType, RelationTypes eRelation, boost::function<void(CvGameObject *)> func, int iData) { if (eRelation == RELATION_TRADE) { if (eType == GAMEOBJECT_CITY) { int iRoutes = m_pCity->getTradeRoutes(); for (int i=0; i<iRoutes; i++) { CvCity* pTradeCity = m_pCity->getTradeCity(i); if (pTradeCity) { func(pTradeCity->getGameObject()); } } } } else if (eRelation == RELATION_WORKING) { if (eType == GAMEOBJECT_PLOT) { for (int iI = 0; iI < m_pCity->getNumCityPlots(); iI++) { CvPlot* pLoopPlot = plotCity(m_pCity->getX_INLINE(), m_pCity->getY_INLINE(), iI); if (pLoopPlot) { if (pLoopPlot->getWorkingCity() == m_pCity) { func(pLoopPlot->getGameObject()); } } } } } else { CvGameObject::foreachRelated(eType, eRelation, func, iData); } }