Code
2684void CvEconomicAI::AssignExplorersToHuts()2685{2686#if defined(PATH_PLAN_LAST)2687 WeightedUnitVector aBestUnitList;2688 aBestUnitList.reserve(m_apExplorers.size());2689#endif26902691 CvTwoLayerPathFinder& kPathFinder = GC.getPathFinder();2692 for(uint uiGoodyPlots = 0; uiGoodyPlots < m_aiGoodyHutPlots.size(); uiGoodyPlots++)2693 {2694 if(m_aiGoodyHutPlots[uiGoodyPlots] == -1)2695 {2696 continue;2697 }26982699 CvPlot* pGoodyPlot = GC.getMap().plotByIndex(m_aiGoodyHutPlots[uiGoodyPlots]);2700#if !defined(PATH_PLAN_LAST)2701 int iClosestEstimateTurns = MAX_INT;2702#endif2703 int iUnitID = NO_UNIT;2704 int iStepPlotID = -1;27052706 aBestUnitList.clear();27072708 for(uint uiExplorer = 0; uiExplorer < m_apExplorers.size(); uiExplorer++)2709 {2710 CvUnit* pUnit = m_apExplorers[uiExplorer];27112712 int iDistance = plotDistance(pUnit->getX(), pUnit->getY(), pGoodyPlot->getX(), pGoodyPlot->getY());27132714#if defined(PATH_PLAN_LAST)2715 if(pUnit->maxMoves() >= 1)2716 {2717 int iEstimateTurns = iDistance / (pUnit->maxMoves() / GC.getMOVE_DENOMINATOR());2718 aBestUnitList.push_back(pUnit, iEstimateTurns);2719 }2720#else2721 int iEstimateTurns = MAX_INT;2722 if(pUnit->maxMoves() >= 1)2723 {2724 iEstimateTurns = iDistance / (pUnit->maxMoves() / GC.getMOVE_DENOMINATOR());2725 }27262727 if(iEstimateTurns < iClosestEstimateTurns)2728 {2729 // Now check path2730 bool bCanFindPath = kPathFinder.GenerateUnitPath(pUnit, pUnit->getX(), pUnit->getY(), pGoodyPlot->getX(), pGoodyPlot->getY(), MOVE_TERRITORY_NO_ENEMY | MOVE_MAXIMIZE_EXPLORE | MOVE_UNITS_IGNORE_DANGER /*iFlags*/, true/*bReuse*/);2731 if(bCanFindPath)2732 {2733 iClosestEstimateTurns = iEstimateTurns;2734 iUnitID = pUnit->GetID();2735 CvPlot* pPlot = kPathFinder.GetPathEndTurnPlot();2736 if(pPlot)2737 iStepPlotID = pPlot->GetPlotIndex();2738 }2739 }2740#endif2741 }27422743#if defined(PATH_PLAN_LAST)2744 uint uiListSize;2745 if ((uiListSize = aBestUnitList.size()) > 0)2746 {2747 aBestUnitList.SortItems(); // highest score will be first.2748 for (uint i = uiListSize; i--; ) // Go backward, we want the lowest score (distance)2749 {2750 CvUnit* pUnit = aBestUnitList.GetElement(i);2751 bool bCanFindPath = kPathFinder.GenerateUnitPath(pUnit, pUnit->getX(), pUnit->getY(), pGoodyPlot->getX(), pGoodyPlot->getY(), MOVE_TERRITORY_NO_ENEMY | MOVE_MAXIMIZE_EXPLORE | MOVE_UNITS_IGNORE_DANGER /*iFlags*/, true/*bReuse*/);2752 if(bCanFindPath)2753 {2754 iUnitID = pUnit->GetID();2755 // Since we've gone through the trouble of calculating a path, save where our turn will end so the Homeland AI doesn't need to re-do the path.2756 CvPlot* pPlot = kPathFinder.GetPathEndTurnPlot();2757 if(pPlot)2758 iStepPlotID = pPlot->GetPlotIndex();2759 break;2760 }2761 }2762 }2763#endif27642765 if(iUnitID != NO_UNIT)2766 {2767 m_aiGoodyHutUnitAssignments[uiGoodyPlots] = GoodyHutUnitAssignment(iUnitID, iStepPlotID);27682769 FFastVector<CvUnit*> tempExplorers = m_apExplorers;2770 m_apExplorers.clear();2771 for(uint uiExplorer = 0; uiExplorer < tempExplorers.size(); uiExplorer++)2772 {2773 if(tempExplorers[uiExplorer]->GetID() != iUnitID)2774 {2775 m_apExplorers.push_back(tempExplorers[uiExplorer]);2776 }2777 }2778 }2779 }2780}