CvEconomicAI::UpdatePlots()
- Defined in
- CvEconomicAI.cpp, line 2533
- Class
- CvEconomicAI
- Hook name
CivHooks::CvEconomicAI_UpdatePlots
Hooks
static bool BeforeCvEconomicAI_UpdatePlots(CvEconomicAI* self);static void AfterCvEconomicAI_UpdatePlots(CvEconomicAI* self);static void ReplaceCvEconomicAI_UpdatePlots(void (*original)(CvEconomicAI*), CvEconomicAI* self);CivRegisterBefore<CivHooks::CvEconomicAI_UpdatePlots>(host, &BeforeCvEconomicAI_UpdatePlots);CivRegisterAfter<CivHooks::CvEconomicAI_UpdatePlots>(host, &AfterCvEconomicAI_UpdatePlots);CivRegisterReplace<CivHooks::CvEconomicAI_UpdatePlots>(host, &ReplaceCvEconomicAI_UpdatePlots);
Code
2532/// Go through the plots for the exploration automation to evaluate2533void CvEconomicAI::UpdatePlots()2534{2535 // reset all plots2536 for(uint ui = 0; ui < m_aiExplorationPlots.size(); ui++)2537 {2538 m_aiExplorationPlots[ui] = -1;2539 m_aiExplorationPlotRatings[ui] = -1;2540 }25412542 for(uint ui = 0; ui < m_aiGoodyHutPlots.size(); ui++)2543 {2544 m_aiGoodyHutPlots[ui] = -1;2545 m_aiGoodyHutUnitAssignments[ui].Clear();2546 }25472548 // find the center of all the cities2549 int iTotalX = 0;2550 int iTotalY = 0;2551 int iCityCount = 0;2552 int iLoopCity = 0;2553 CvCity* pLoopCity = NULL;2554 for(pLoopCity = m_pPlayer->firstCity(&iLoopCity); pLoopCity != NULL; pLoopCity = m_pPlayer->nextCity(&iLoopCity))2555 {2556 iTotalX += pLoopCity->getX();2557 iTotalY += pLoopCity->getY();2558 iCityCount++;2559 }25602561 int iCivCenterX = -1;2562 int iCivCenterY = -1;2563 if(iCityCount > 0)2564 {2565 iCivCenterX = iTotalX / iCityCount;2566 iCivCenterY = iTotalY / iCityCount;2567 }25682569 uint uiExplorationPlotIndex = 0;2570 uint uiGoodyHutPlotIndex = 0;2571 TeamTypes ePlayerTeam = m_pPlayer->getTeam();25722573 CvPlot* pPlot;2574 for(int i = 0; i < GC.getMap().numPlots(); i++)2575 {2576 pPlot = GC.getMap().plotByIndexUnchecked(i);2577 if(pPlot == NULL)2578 {2579 continue;2580 }25812582 if(!pPlot->isRevealed(ePlayerTeam))2583 {2584 continue;2585 }25862587 if(pPlot->isRevealedGoody(ePlayerTeam) && !pPlot->isVisibleEnemyUnit(m_pPlayer->GetID()))2588 {2589 if(m_aiGoodyHutPlots.size() <= uiGoodyHutPlotIndex)2590 {2591 m_aiGoodyHutPlots.push_back(-1);2592 m_aiGoodyHutUnitAssignments.push_back(GoodyHutUnitAssignment(-1, -1));2593 }2594 m_aiGoodyHutPlots[uiGoodyHutPlotIndex] = i;2595 m_aiGoodyHutUnitAssignments[uiGoodyHutPlotIndex].Clear();2596 ++uiGoodyHutPlotIndex;2597 }2598 if(pPlot->HasBarbarianCamp())2599 {2600 if(pPlot->getNumDefenders(BARBARIAN_PLAYER) == 0)2601 {2602 if(m_aiGoodyHutPlots.size() <= uiGoodyHutPlotIndex)2603 {2604 m_aiGoodyHutPlots.push_back(-1);2605 m_aiGoodyHutUnitAssignments.push_back(GoodyHutUnitAssignment(-1, -1));2606 }2607 m_aiGoodyHutPlots[uiGoodyHutPlotIndex] = i;2608 m_aiGoodyHutUnitAssignments[uiGoodyHutPlotIndex].Clear();2609 ++uiGoodyHutPlotIndex;2610 }2611 }26122613 DomainTypes eDomain = DOMAIN_LAND;2614 if(pPlot->isWater())2615 {2616 eDomain = DOMAIN_SEA;2617 }26182619 int iScore = ScoreExplorePlot(pPlot, ePlayerTeam, 1, eDomain);2620 if(iScore <= 0)2621 {2622 continue;2623 }26242625 // add an entry for this plot2626 if(m_aiExplorationPlots.size() <= uiExplorationPlotIndex)2627 {2628 m_aiExplorationPlots.push_back(-1);2629 m_aiExplorationPlotRatings.push_back(-1);2630 }26312632 m_aiExplorationPlots[uiExplorationPlotIndex] = i;2633 m_aiExplorationPlotRatings[uiExplorationPlotIndex] = iScore;2634 uiExplorationPlotIndex++;2635 }26362637 // assign explorers to goody huts26382639 // build explorer list2640 CvUnit* pLoopUnit;2641 int iLoopUnit;2642 m_apExplorers.clear();2643 for(pLoopUnit = m_pPlayer->firstUnit(&iLoopUnit); pLoopUnit != NULL; pLoopUnit = m_pPlayer->nextUnit(&iLoopUnit))2644 {2645 // non-automated human-controlled units should not be considered2646 if(m_pPlayer->isHuman() && !pLoopUnit->IsAutomated())2647 {2648 continue;2649 }26502651 if(pLoopUnit->AI_getUnitAIType() == UNITAI_EXPLORE_SEA)2652 {2653 continue;2654 }26552656 if(pLoopUnit->AI_getUnitAIType() != UNITAI_EXPLORE && pLoopUnit->GetMissionAIType() != MISSIONAI_EXPLORE)2657 {2658 continue;2659 }26602661 if(pLoopUnit->getArmyID() != FFreeList::INVALID_INDEX)2662 {2663 continue;2664 }26652666 m_apExplorers.push_back(pLoopUnit);2667 }26682669 if(m_apExplorers.size() >= m_aiGoodyHutPlots.size())2670 {2671 AssignExplorersToHuts();2672 }2673 else2674 {2675 AssignHutsToExplorers();2676 }26772678 m_bExplorationPlotsDirty = false;2679}
Calls
BaseVector::clearBaseVector::operator[]BaseVector::operator[]BaseVector::sizeBaseVector::size- CvCity::getX() const
- CvCity::getY() const
- CvEconomicAI::AssignExplorersToHuts()
- CvEconomicAI::AssignHutsToExplorers()
- CvEconomicAI::GoodyHutUnitAssignment::Clear()
- CvEconomicAI::GoodyHutUnitAssignment::GoodyHutUnitAssignment(int, int)
- CvEconomicAI::ScoreExplorePlot(CvPlot *, TeamTypes, int, DomainTypes)
- CvGlobals::getMap()
- CvMap::numPlots() const
- CvMap::plotByIndexUnchecked(int) const
- CvPlayer::firstCity(int *, bool)
- CvPlayer::firstUnit(int *, bool)
- CvPlayer::GetID() const
- CvPlayer::getTeam() const
- CvPlayer::isHuman() const
- CvPlayer::nextCity(int *, bool)
- CvPlayer::nextUnit(int *, bool)
- CvPlot::getNumDefenders(PlayerTypes) const
- CvPlot::HasBarbarianCamp()
- CvPlot::isRevealed(TeamTypes) const
- CvPlot::isRevealedGoody(TeamTypes) const
- CvPlot::isVisibleEnemyUnit(PlayerTypes) const
- CvPlot::isWater() const
- CvUnit::AI_getUnitAIType() const
- CvUnit::getArmyID() const
- CvUnit::GetMissionAIType()
- CvUnit::IsAutomated() const
FFastVector::push_backFFastVector::push_backFFastVector::push_back