Bazaar developer reference

CvTacticalAnalysisMap::AddToDominanceZones(int, CvTacticalAnalysisCell *)

Defined in
CvTacticalAnalysisMap.cpp, line 623
Class
CvTacticalAnalysisMap
Hook name
CivHooks::CvTacticalAnalysisMap_AddToDominanceZones

Hooks

static bool BeforeCvTacticalAnalysisMap_AddToDominanceZones(CvTacticalAnalysisMap* self, int iIndex, CvTacticalAnalysisCell* pCell);static void AfterCvTacticalAnalysisMap_AddToDominanceZones(CvTacticalAnalysisMap* self, int iIndex, CvTacticalAnalysisCell* pCell);static void ReplaceCvTacticalAnalysisMap_AddToDominanceZones(void (*original)(CvTacticalAnalysisMap*, int, CvTacticalAnalysisCell*), CvTacticalAnalysisMap* self, int iIndex, CvTacticalAnalysisCell* pCell);CivRegisterBefore<CivHooks::CvTacticalAnalysisMap_AddToDominanceZones>(host, &BeforeCvTacticalAnalysisMap_AddToDominanceZones);CivRegisterAfter<CivHooks::CvTacticalAnalysisMap_AddToDominanceZones>(host, &AfterCvTacticalAnalysisMap_AddToDominanceZones);CivRegisterReplace<CivHooks::CvTacticalAnalysisMap_AddToDominanceZones>(host, &ReplaceCvTacticalAnalysisMap_AddToDominanceZones);

Code

622/// Add data for this cell into dominance zone information623void CvTacticalAnalysisMap::AddToDominanceZones(int iIndex, CvTacticalAnalysisCell* pCell)624{625	CvPlot* pPlot = GC.getMap().plotByIndex(iIndex);626627	// Compute zone data for this cell628	m_TempZone.SetAreaID(pPlot->getArea());629	m_TempZone.SetOwner(pPlot->getOwner());630	m_TempZone.SetWater(pPlot->isWater());631	if(!pPlot->isOwned())632	{633		m_TempZone.SetTerritoryType(TACTICAL_TERRITORY_NO_OWNER);634	}635	else if(pPlot->getTeam() == m_pPlayer->getTeam())636	{637		m_TempZone.SetTerritoryType(TACTICAL_TERRITORY_FRIENDLY);638	}639	else if(GET_TEAM(m_pPlayer->getTeam()).isAtWar(pPlot->getTeam()))640	{641		m_TempZone.SetTerritoryType(TACTICAL_TERRITORY_ENEMY);642	}643	else644	{645		m_TempZone.SetTerritoryType(TACTICAL_TERRITORY_NEUTRAL);646	}647	m_TempZone.SetClosestCity(NULL);648	if(m_TempZone.GetTerritoryType() == TACTICAL_TERRITORY_ENEMY ||649	        m_TempZone.GetTerritoryType() == TACTICAL_TERRITORY_NEUTRAL ||650	        m_TempZone.GetTerritoryType() == TACTICAL_TERRITORY_FRIENDLY)651	{652		int iLoop;653		int iBestDistance = MAX_INT;654		CvCity* pBestCity = NULL;655656		for(CvCity* pLoopCity = GET_PLAYER(m_TempZone.GetOwner()).firstCity(&iLoop); pLoopCity != NULL; pLoopCity = GET_PLAYER(m_TempZone.GetOwner()).nextCity(&iLoop))657		{658			int iDistance = plotDistance(pLoopCity->getX(), pLoopCity->getY(), pPlot->getX(), pPlot->getY());659			if(iDistance < iBestDistance)660			{661				iBestDistance = iDistance;662				pBestCity = pLoopCity;663			}664		}665666		if(pBestCity != NULL)667		{668			m_TempZone.SetClosestCity(pBestCity);669		}670	}671672	// Now see if we already have a matching zone673	CvTacticalDominanceZone* pZone = FindExistingZone(pPlot);674	if(!pZone)675	{676		// Data populated, now add to vector677		m_TempZone.SetDominanceZoneID(m_DominanceZones.size());678		m_DominanceZones.push_back(m_TempZone);679		pZone = &m_DominanceZones[m_DominanceZones.size() - 1];680	}681682	// If this isn't owned territory, update zone with military strength info683	if(pZone->GetTerritoryType() == TACTICAL_TERRITORY_NO_OWNER ||684	        pZone->GetTerritoryType() == TACTICAL_TERRITORY_TEMP_ZONE)685	{686		CvUnit* pFriendlyUnit = pCell->GetFriendlyMilitaryUnit();687		if(pFriendlyUnit)688		{689			if(pFriendlyUnit->getDomainType() == DOMAIN_AIR ||690			        (pFriendlyUnit->getDomainType() == DOMAIN_LAND && !pZone->IsWater()) ||691			        (pFriendlyUnit->getDomainType() == DOMAIN_SEA && pZone->IsWater()))692			{693				int iStrength = pFriendlyUnit->GetBaseCombatStrengthConsideringDamage();694				if(iStrength == 0 && pFriendlyUnit->isEmbarked() && !pZone->IsWater())695				{696					iStrength = pFriendlyUnit->GetBaseCombatStrength(true);697				}698				pZone->AddFriendlyStrength(iStrength * m_iUnitStrengthMultiplier);699				pZone->AddFriendlyRangedStrength(pFriendlyUnit->GetMaxRangedCombatStrength(NULL, /*pCity*/ NULL, true, true));700				if(pFriendlyUnit->GetRange() > GetBestFriendlyRange())701				{702					SetBestFriendlyRange(pFriendlyUnit->GetRange());703				}704				if(pFriendlyUnit->IsRangeAttackIgnoreLOS())705				{706					SetIgnoreLOS(true);707				}708				pZone->AddFriendlyUnitCount(1);709				if(pFriendlyUnit->isRanged())710				{711					pZone->AddFriendlyRangedUnitCount(1);712				}713			}714		}715716		CvUnit* pEnemyUnit = pCell->GetEnemyMilitaryUnit();717		if(pEnemyUnit)718		{719			if(pEnemyUnit->getDomainType() == DOMAIN_AIR ||720			        (pEnemyUnit->getDomainType() == DOMAIN_LAND && !pZone->IsWater()) ||721			        (pEnemyUnit->getDomainType() == DOMAIN_SEA && pZone->IsWater()))722			{723				int iStrength = pEnemyUnit->GetBaseCombatStrengthConsideringDamage();724				if(iStrength == 0 && pEnemyUnit->isEmbarked() && !pZone->IsWater())725				{726					iStrength = pEnemyUnit->GetBaseCombatStrength(true);727				}728#if defined(MOD_AI_SMART_V3)729				int iEnemyRangedStrength = pEnemyUnit->GetMaxRangedCombatStrength(NULL, /*pCity*/ NULL, true, true);730731				if (MOD_AI_SMART_V3)732				{733					if (!pCell->IsVisible())734					{735						iStrength /= 2;736						iEnemyRangedStrength /= 2;737					}738					739					iEnemyRangedStrength = iEnemyRangedStrength * m_iUnitStrengthMultiplier;740				}741#endif				742743				pZone->AddEnemyStrength(iStrength * m_iUnitStrengthMultiplier);744#if defined(MOD_AI_SMART_V3)745				pZone->AddEnemyRangedStrength(iEnemyRangedStrength);746#else747				pZone->AddEnemyRangedStrength(pEnemyUnit->GetMaxRangedCombatStrength(NULL, /*pCity*/ NULL, true, true));748#endif				749				pZone->AddEnemyUnitCount(1);750				if(pEnemyUnit->isRanged())751				{752					pZone->AddEnemyRangedUnitCount(1);753				}754				if (pEnemyUnit->getDomainType() == DOMAIN_SEA)755				{756					pZone->AddEnemyNavalUnitCount(1);757				}758			}759		}760	}761762	// Set zone for this cell763	pCell->SetDominanceZone(pZone->GetDominanceZoneID());764}

Calls

Called by