コード例 #1
0
//	---------------------------------------------------------------------------
bool CvGameQueries::AreUnitsSameType(UnitTypes eFirstUnitType, UnitTypes eSecondUnitType)
{
	CvUnitEntry* pkFirstUnitInfo = GC.getUnitInfo(eFirstUnitType);
	CvUnitEntry* pkSecondUnitInfo = GC.getUnitInfo(eSecondUnitType);

	if(pkFirstUnitInfo == NULL || pkSecondUnitInfo == NULL)
		return false;

	int eFirstDomain = pkFirstUnitInfo->GetDomainType();
	int eSecondDomain = pkSecondUnitInfo->GetDomainType();

	// antonjs: Added for Smoky Skies scenario. 
	// If unit is DOMAIN_HOVER, its effective domain is a wildcard, equal to the other unit's domain. This prevents HOVER units from disobeying 1UPT.
	if (eFirstDomain == DOMAIN_HOVER && eSecondDomain == DOMAIN_HOVER)
	{
		// Already a match
	}
	else if (eFirstDomain == DOMAIN_HOVER)
	{
		eFirstDomain = eSecondDomain; // Make it a match
	}
	else if (eSecondDomain == DOMAIN_HOVER)
	{
		eSecondDomain = eFirstDomain; // Make it a match
	}

	// Must be in the same domain
	if(eFirstDomain == eSecondDomain)
	{
		// Conversely air units can always stack
		if(eFirstDomain == DOMAIN_AIR)
		{
			return false;
		}

		bool bUnit1Combat = false;
		bool bUnit2Combat = false;

		// Unit 1 is a combat unit?
		if(pkFirstUnitInfo->GetCombat() > 0 || pkFirstUnitInfo->GetRange() > 0)
		{
			bUnit1Combat = true;
		}

		// Unit 2 is a combat unit?
		if(pkSecondUnitInfo->GetCombat() > 0 || pkSecondUnitInfo->GetRange() > 0)
		{
			bUnit2Combat = true;
		}

		// Looped unit matches combat or non-combat type?
		if(bUnit1Combat == bUnit2Combat)
		{
			// Unit is the same domain & combat type, so we have a match
			return true;
		}
	}

	return false;
}
コード例 #2
0
ファイル: CvGameQueries.cpp プロジェクト: Be1eriand/Civ5-DLL
//	---------------------------------------------------------------------------
bool CvGameQueries::AreUnitsSameType(UnitTypes eFirstUnitType, UnitTypes eSecondUnitType)
{
	CvUnitEntry* pkFirstUnitInfo = GC.getUnitInfo(eFirstUnitType);
	CvUnitEntry* pkSecondUnitInfo = GC.getUnitInfo(eSecondUnitType);

	if(pkFirstUnitInfo == NULL || pkSecondUnitInfo == NULL)
		return false;

	int eFirstDomain = pkFirstUnitInfo->GetDomainType();
	int eSecondDomain = pkSecondUnitInfo->GetDomainType();

	// Must be in the same domain
	if (eFirstDomain == eSecondDomain)
	{
		// Only one sea unit per plot!
		if (eFirstDomain == DOMAIN_SEA)
		{
			return true;
		}

		// Conversely air units can always stack
		if (eFirstDomain == DOMAIN_AIR)
		{
			return false;
		}

		bool bUnit1Combat = false;
		bool bUnit2Combat = false;

		// Unit 1 is a combat unit?
		if (pkFirstUnitInfo->GetCombat() > 0 || pkFirstUnitInfo->GetRange() > 0)
		{
			bUnit1Combat = true;
		}

		// Unit 2 is a combat unit?
		if (pkSecondUnitInfo->GetCombat() > 0 || pkSecondUnitInfo->GetRange() > 0)
		{
			bUnit2Combat = true;
		}

		// Looped unit matches combat or non-combat type?
		if (bUnit1Combat == bUnit2Combat)
		{
			// Unit is the same domain & combat type, so we have a match
			return true;
		}
	}

	return false;
}