Code
766/// Calculate military presences in each owned dominance zone767void CvTacticalAnalysisMap::CalculateMilitaryStrengths()768{769 // Loop through the dominance zones770 CvTacticalDominanceZone* pZone;771 CvCity* pClosestCity = NULL;772 int iDistance;773 int iMultiplier;774 int iLoop;775 CvUnit* pLoopUnit;776 TeamTypes eTeam;777778 eTeam = m_pPlayer->getTeam();779780 for(unsigned int iI = 0; iI < m_DominanceZones.size(); iI++)781 {782 pZone = &m_DominanceZones[iI];783784 if(pZone->GetTerritoryType() != TACTICAL_TERRITORY_NO_OWNER)785 {786 pClosestCity = pZone->GetClosestCity();787 if(pClosestCity)788 {789 // Start with strength of the city itself790 int iCityHitPoints = pClosestCity->GetMaxHitPoints() - pClosestCity->getDamage();791 int iStrength = m_iTacticalRange * pClosestCity->getStrengthValue() * iCityHitPoints / GC.getMAX_CITY_HIT_POINTS();792 if(pZone->GetTerritoryType() == TACTICAL_TERRITORY_FRIENDLY)793 {794 pZone->AddFriendlyStrength(iStrength);795#if defined(MOD_AI_SMART_V3)796 pZone->AddFriendlyRangedStrength(pClosestCity->getStrengthValue(MOD_AI_SMART_V3));797#else798 pZone->AddFriendlyRangedStrength(pClosestCity->getStrengthValue());799#endif800 }801#if defined(MOD_AI_SMART_V3)802 else if(!MOD_AI_SMART_V3 || pZone->GetTerritoryType() == TACTICAL_TERRITORY_ENEMY)803#else804 else805#endif806 {807 pZone->AddEnemyStrength(iStrength);808#if defined(MOD_AI_SMART_V3)809 pZone->AddEnemyRangedStrength(pClosestCity->getStrengthValue(MOD_AI_SMART_V3));810#else811 pZone->AddEnemyRangedStrength(pClosestCity->getStrengthValue());812#endif813 }814815 // Loop through all of OUR units first816 for(pLoopUnit = m_pPlayer->firstUnit(&iLoop); pLoopUnit != NULL; pLoopUnit = m_pPlayer->nextUnit(&iLoop))817 {818 if(pLoopUnit->IsCombatUnit())819 {820 if(pLoopUnit->getDomainType() == DOMAIN_AIR ||821#if defined(MOD_AI_SMART_V3)822 //ranged power is cross-domain!823 (MOD_AI_SMART_V3 && pLoopUnit->isRanged()) ||824#endif825 (pLoopUnit->getDomainType() == DOMAIN_LAND && !pZone->IsWater()) ||826 (pLoopUnit->getDomainType() == DOMAIN_SEA && pZone->IsWater()))827 {828 iDistance = plotDistance(pLoopUnit->getX(), pLoopUnit->getY(), pClosestCity->getX(), pClosestCity->getY());829 if (iDistance <= m_iTacticalRange)830 {831#if defined(MOD_AI_SMART_V3)832 int iRange = MOD_AI_SMART_V3 ? MIN(4 - iDistance, 0) : 4 - iDistance;833 iMultiplier = m_iTacticalRange + iRange;834#else835 iMultiplier = (m_iTacticalRange + 4 - iDistance); // "4" so unit strength isn't totally dominated by proximity to city836#endif837 if(iMultiplier > 0)838 {839 int iUnitStrength = pLoopUnit->GetBaseCombatStrengthConsideringDamage();840 if(iUnitStrength == 0 && pLoopUnit->isEmbarked() && !pZone->IsWater())841 {842 iUnitStrength = pLoopUnit->GetBaseCombatStrength(true);843 }844 pZone->AddFriendlyStrength(iUnitStrength * iMultiplier * m_iUnitStrengthMultiplier);845 pZone->AddFriendlyRangedStrength(pLoopUnit->GetMaxRangedCombatStrength(NULL, /*pCity*/ NULL, true, true));846 if(pLoopUnit->GetRange() > GetBestFriendlyRange())847 {848 SetBestFriendlyRange(pLoopUnit->GetRange());849 }850 if(pLoopUnit->IsRangeAttackIgnoreLOS())851 {852 SetIgnoreLOS(true);853 }854 pZone->AddFriendlyUnitCount(1);855 if(pLoopUnit->isRanged())856 {857 pZone->AddFriendlyRangedUnitCount(1);858 }859 }860 }861 }862 }863 }864865 // Repeat for all visible enemy units (or adjacent to visible)866 for(int iPlayerLoop = 0; iPlayerLoop < MAX_CIV_PLAYERS; iPlayerLoop++)867 {868 CvPlayer& kPlayer = GET_PLAYER((PlayerTypes) iPlayerLoop);869 if(GET_TEAM(eTeam).isAtWar(kPlayer.getTeam()))870 {871 for(pLoopUnit = kPlayer.firstUnit(&iLoop); pLoopUnit != NULL; pLoopUnit = kPlayer.nextUnit(&iLoop))872 {873 if(pLoopUnit->IsCombatUnit())874 {875 if(pLoopUnit->getDomainType() == DOMAIN_AIR ||876#if defined(MOD_AI_SMART_V3)877 //ranged power is cross-domain!878 (MOD_AI_SMART_V3 && pLoopUnit->isRanged()) ||879#endif880 (pLoopUnit->getDomainType() == DOMAIN_LAND && !pZone->IsWater()) ||881 (pLoopUnit->getDomainType() == DOMAIN_SEA && pZone->IsWater()))882 {883 CvPlot* pPlot;884 pPlot = pLoopUnit->plot();885 if(pPlot)886 {887 bool bVisible = true;888 iDistance = plotDistance(pLoopUnit->getX(), pLoopUnit->getY(), pClosestCity->getX(), pClosestCity->getY());889 if (iDistance <= m_iTacticalRange)890 {891#if defined(MOD_AI_SMART_V3)892 int iRange = MOD_AI_SMART_V3 ? MIN(4 - iDistance, 0) : 4 - iDistance;893 iMultiplier = m_iTacticalRange + iRange; // 4 because action may still be spread out over the zone894#else895 iMultiplier = (m_iTacticalRange + 4 - iDistance); // "4" so unit strength isn't totally dominated by proximity to city896#endif897 if(!pPlot->isVisible(eTeam) && !pPlot->isAdjacentVisible(eTeam, false))898 {899 bVisible = false;900 }901 if(iMultiplier > 0)902 {903 int iUnitStrength = pLoopUnit->GetBaseCombatStrengthConsideringDamage();904 if(iUnitStrength == 0 && pLoopUnit->isEmbarked() && !pZone->IsWater())905 {906 iUnitStrength = pLoopUnit->GetBaseCombatStrength(true);907 }908909 if(!bVisible)910 {911 iUnitStrength /= 2;912 }913914 pZone->AddEnemyStrength(iUnitStrength * iMultiplier * m_iUnitStrengthMultiplier);915916 int iRangedStrength = pLoopUnit->GetMaxRangedCombatStrength(NULL, /*pCity*/ NULL, true, true);917 if(!bVisible)918 {919 iRangedStrength /= 2;920 }921922 pZone->AddEnemyRangedStrength(iRangedStrength);923924 if(bVisible)925 {926 pZone->AddEnemyUnitCount(1);927 if(iDistance < pZone->GetRangeClosestEnemyUnit())928 {929 pZone->SetRangeClosestEnemyUnit(iDistance);930 }931 if(pLoopUnit->isRanged())932 {933 pZone->AddEnemyRangedUnitCount(1);934 }935 if(pLoopUnit->getDomainType() == DOMAIN_SEA)936 {937 pZone->AddEnemyNavalUnitCount(1);938 }939 }940 }941 }942 }943 }944 }945 }946947 }948 }949 }950 }951 }952}