Example #1
0
/// Log chosen policy
void CvPolicyAI::LogPolicyChoice(PolicyTypes ePolicy)
{
    if(GC.getLogging() && GC.getAILogging())
    {
        CvString strOutBuf;
        CvString strBaseString;
        CvString strTemp;
        CvString playerName;
        CvString strDesc;

        // Find the name of this civ and city
        playerName = m_pCurrentPolicies->GetPlayer()->getCivilizationShortDescription();

        FILogFile* pLog;
        pLog = LOGFILEMGR.GetLog(GetLogFileName(playerName), FILogFile::kDontTimeStamp);

        // Get the leading info for this line
        strBaseString.Format("%03d, ", GC.getGame().getElapsedGameTurns());
        strBaseString += playerName + ", ";

        CvPolicyEntry* pPolicyEntry = GC.getPolicyInfo(ePolicy);
        const char* szPolicyType = (pPolicyEntry != NULL)? pPolicyEntry->GetType() : "Unknown";
        strTemp.Format("CHOSEN, %s", szPolicyType);

        strOutBuf = strBaseString + strTemp;
        pLog->Msg(strOutBuf);
    }
}
Example #2
0
/// Log chosen policy
void CvPolicyAI::LogBranchChoice(PolicyBranchTypes eBranch)
{
    if(GC.getLogging() && GC.getAILogging())
    {
        CvString strOutBuf;
        CvString strBaseString;
        CvString strTemp;
        CvString playerName;
        CvString strDesc;

        // Find the name of this civ and city
        playerName = m_pCurrentPolicies->GetPlayer()->getCivilizationShortDescription();

        FILogFile* pLog;
        pLog = LOGFILEMGR.GetLog(GetLogFileName(playerName), FILogFile::kDontTimeStamp);

        // Get the leading info for this line
        strBaseString.Format("%03d, ", GC.getGame().getElapsedGameTurns());
        strBaseString += playerName + ", ";

        strTemp.Format("CHOSEN, Branch %d", eBranch);

        strOutBuf = strBaseString + strTemp;
        pLog->Msg(strOutBuf);
    }
}
Example #3
0
/// Logging function to write out info on Ideology choices
void CvPolicyAI::LogIdeologyChoice(CvString &decisionState, int iWeightFreedom, int iWeightAutocracy, int iWeightOrder)
{
    if(GC.getLogging() && GC.getAILogging())
    {
        CvString strOutBuf;
        CvString strBaseString;
        CvString strTemp;
        CvString playerName;

        // Find the name of this civ
        playerName = m_pCurrentPolicies->GetPlayer()->getCivilizationShortDescription();

        FILogFile* pLog;
        pLog = LOGFILEMGR.GetLog(GetLogFileName(playerName), FILogFile::kDontTimeStamp);

        // Get the leading info for this line
        strBaseString.Format("%03d, ", GC.getGame().getElapsedGameTurns());
        strBaseString += playerName + ", ";

        strTemp.Format("%s, Freedom: %d, Order: %d, Autocracy: %d", decisionState.c_str(), iWeightFreedom, iWeightOrder, iWeightAutocracy);

        strOutBuf = strBaseString + strTemp;
        pLog->Msg(strOutBuf);
    }
}
Example #4
0
/// Log all possible tech choices
void CvTechAI::LogPossibleResearch()
{
	if(GC.getLogging() && GC.getAILogging())
	{
		CvString strOutBuf;
		CvString strBaseString;
		CvString strTemp;
		CvString playerName;
		CvString strDesc;

		// Find the name of this civ
		playerName = m_pCurrentTechs->GetPlayer()->getCivilizationShortDescription();

		FILogFile* pLog = LOGFILEMGR.GetLog(GetLogFileName(playerName), FILogFile::kDontTimeStamp);

		// Get the leading info for this line
		strBaseString.Format("%03d, ", GC.getGame().getElapsedGameTurns());
		strBaseString += playerName + ", ";

		// Dump out the weight of each Researchable Tech
		for(int iI = 0; iI < m_ResearchableTechs.size(); iI++)
		{
			TechTypes eTech = (TechTypes) m_ResearchableTechs.GetElement(iI);
			int iWeight = m_ResearchableTechs.GetWeight(iI);

			CvTechEntry* pTechEntry = GC.getTechInfo(eTech);
			const char* szTechType = (pTechEntry != NULL)? pTechEntry->GetType() : "Unknown Tech";

			strTemp.Format("%s, %d", szTechType, iWeight);

			strOutBuf = strBaseString + strTemp;
			pLog->Msg(strOutBuf);
		}
	}
}
Example #5
0
/// Log GrandStrategy state: what are the Priorities and who is Active?
void CvGrandStrategyAI::LogGrandStrategies(const FStaticVector< int, 5, true, c_eCiv5GameplayDLL >& vModifiedGrandStrategyPriorities)
{
	if(GC.getLogging() && GC.getAILogging())
	{
		CvString strOutBuf;
		CvString strBaseString;
		CvString strTemp;
		CvString playerName;
		CvString strDesc;
		CvString strLogName;

		// Find the name of this civ and city
		playerName = GetPlayer()->getCivilizationShortDescription();

		// Open the log file
		if(GC.getPlayerAndCityAILogSplit())
		{
			strLogName = "GrandStrategyAI_Log_" + playerName + ".csv";
		}
		else
		{
			strLogName = "GrandStrategyAI_Log.csv";
		}

		FILogFile* pLog;
		pLog = LOGFILEMGR.GetLog(strLogName, FILogFile::kDontTimeStamp);

		AIGrandStrategyTypes eGrandStrategy;

		// Loop through Grand Strategies
		for(int iGrandStrategyLoop = 0; iGrandStrategyLoop < GC.getNumAIGrandStrategyInfos(); iGrandStrategyLoop++)
		{
			// Get the leading info for this line
			strBaseString.Format("%03d, ", GC.getGame().getElapsedGameTurns());
			strBaseString += playerName + ", ";

			eGrandStrategy = (AIGrandStrategyTypes) iGrandStrategyLoop;

			// GrandStrategy Info
			CvAIGrandStrategyXMLEntry* pEntry = GC.getAIGrandStrategyInfo(eGrandStrategy);
			const char* szAIGrandStrategyType = (pEntry != NULL)? pEntry->GetType() : "Unknown Type";

			if(GetActiveGrandStrategy() == eGrandStrategy)
			{
				strTemp.Format("*** %s, %d, %d", szAIGrandStrategyType, GetGrandStrategyPriority(eGrandStrategy), vModifiedGrandStrategyPriorities[eGrandStrategy]);
			}
			else
			{
				strTemp.Format("%s, %d, %d", szAIGrandStrategyType, GetGrandStrategyPriority(eGrandStrategy), vModifiedGrandStrategyPriorities[eGrandStrategy]);
			}
			strOutBuf = strBaseString + strTemp;
			pLog->Msg(strOutBuf);
		}
	}
}
void CvFlavorManager::LogFlavors(FlavorTypes eFlavor)
{
    CvString strOutBuf;
    CvString strBaseString;
    CvString strTemp;
    CvString playerName;
    CvString strDesc;
    CvString strLogName;

    if(GC.getLogging() && GC.getAILogging())
    {
        // Find the name of this civ
        playerName = m_pPlayer->getCivilizationShortDescription();

        // Open the log file
        if(GC.getPlayerAndCityAILogSplit())
        {
            strLogName = "FlavorAILog_" + playerName + ".csv";
        }
        else
        {
            strLogName = "FlavorAILog.csv";
        }

        FILogFile* pLog;
        pLog = LOGFILEMGR.GetLog(strLogName, FILogFile::kDontTimeStamp);

        // Get the leading info for this line
        strBaseString.Format("%03d, ", GC.getGame().getElapsedGameTurns());
        strBaseString += playerName + ", ";

        // Dump out the setting for each flavor
        if(eFlavor == NO_FLAVOR)
        {
            for(int iI = 0; iI < GC.getNumFlavorTypes(); iI++)
            {
                // Only dump if non-zero
                //		if (m_piLatestFlavorValues[iI] > 0)
                {
                    strTemp.Format("Flavor, %s, %d", GC.getFlavorTypes((FlavorTypes)iI).GetCString(), GetIndividualFlavor((FlavorTypes) iI));
                    strOutBuf = strBaseString + strTemp;
                    pLog->Msg(strOutBuf);
                }
            }
        }
        else
        {
            strTemp.Format("Flavor, %s, %d", GC.getFlavorTypes(eFlavor).GetCString(), GetIndividualFlavor(eFlavor));
            strOutBuf = strBaseString + strTemp;
            pLog->Msg(strOutBuf);
        }
    }
}
CvPlot* CvArmyAI::DetectNearbyEnemy(PlayerTypes eEnemy, bool bNaval)
{
	UnitHandle pUnit = GetFirstUnit();
	while(pUnit)
	{
		for(int iDirectionLoop = 0; iDirectionLoop < NUM_DIRECTION_TYPES; ++iDirectionLoop)
		{
			CvPlot* pAdjacentPlot = plotDirection(pUnit->getX(), pUnit->getY(), ((DirectionTypes)iDirectionLoop));
			if(pAdjacentPlot != NULL && pAdjacentPlot->isWater()==bNaval && pAdjacentPlot->getOwner() == eEnemy)
			{
				UnitHandle pOtherUnit = pAdjacentPlot->getBestDefender(eEnemy);
				if(pOtherUnit)
				{
					if(GC.getLogging() && GC.getAILogging())
					{
						CvString strMsg;
						strMsg.Format("Ran into enemy unit during attack (x=%d y=%d). Need to declare war to continue!", pAdjacentPlot->getX(), pAdjacentPlot->getY());
						GET_PLAYER(m_eOwner).getAIOperation(m_iOperationID)->LogOperationSpecialMessage(strMsg);
					}

					return pAdjacentPlot;
				}
			}
		}
		pUnit = GetNextUnit();
	}

	return NULL;
}
/// Helper function to read a single type (as a string) and find its ID in a database table.
/// Assumes the type is in the table's field "Type"
int ReadDBLookup(FDataStream& kStream, const char* szTable, bool* bValid /*= NULL*/)
{
	FStringFixedBuffer(sTemp, 256);
	kStream >> sTemp;
	if (bValid) *bValid = true;
	if(sTemp.GetLength() > 0 && sTemp != "NO_TYPE")
	{
		Database::Connection* pDB = GC.GetGameDatabase();
		if(pDB)
		{
			Database::Results kResults;
			CvString szCommand;
			szCommand.Format("SELECT ID from %s where Type = ? LIMIT 1", szTable);
			if(pDB->Execute(kResults, szCommand.c_str()))
			{
				kResults.Bind(1, sTemp.c_str());
				if(kResults.Step())
				{
					return kResults.GetInt(0);
				}
				else
					if (bValid) *bValid = false;
			}
		}
		else
			if (bValid) *bValid = false;
	}
	
	return -1;
}
Example #9
0
void TreasuryHelpers::AppendToLog(CvString& strHeader, CvString& strLog, CvString strHeaderValue, float fValue)
{
	strHeader += strHeaderValue;
	strHeader += ",";
	CvString str;
	str.Format("%.2f,", fValue);
	strLog += str;
}
Example #10
0
void TreasuryHelpers::AppendToLog(CvString& strHeader, CvString& strLog, CvString strHeaderValue, int iValue)
{
	strHeader += strHeaderValue;
	strHeader += ",";
	CvString str;
	str.Format("%d,", iValue);
	strLog += str;
}
/// Serialization read
void CvUnitProductionAI::Read(FDataStream& kStream)
{
	// Version number to maintain backwards compatibility
	uint uiVersion;
	kStream >> uiVersion;

	int iWeight;

	// Reset vector
	m_UnitAIWeights.clear();

	// Loop through reading each one and adding it to our vector
	if(m_pUnits)
	{
#ifdef AUI_WARNING_FIXES
		for (uint i = 0; i < m_pUnits->GetNumUnits(); i++)
#else
		for(int i = 0; i < m_pUnits->GetNumUnits(); i++)
#endif
		{
			m_UnitAIWeights.push_back(i, 0);
		}

#ifdef AUI_WARNING_FIXES
		uint iNumEntries;
		int iType;

		kStream >> iNumEntries;

		for (uint iI = 0; iI < iNumEntries; iI++)
#else
		int iNumEntries;
		int iType;

		kStream >> iNumEntries;

		for(int iI = 0; iI < iNumEntries; iI++)
#endif
		{
			bool bValid = true;
			iType = CvInfosSerializationHelper::ReadHashed(kStream, &bValid);
			if(iType != -1 || !bValid)
			{
				kStream >> iWeight;
				if(iType != -1)
				{
					m_UnitAIWeights.IncreaseWeight(iType, iWeight);
				}
				else
				{
					CvString szError;
					szError.Format("LOAD ERROR: Unit Type not found");
					GC.LogMessage(szError.GetCString());
					CvAssertMsg(false, szError);
				}
			}
		}
	}
/// Log dominance zone data
void CvTacticalAnalysisMap::LogZones()
{
	if(GC.getLogging() && GC.getAILogging())
	{
		CvString szLogMsg;
		CvTacticalDominanceZone* pZone;

		for(unsigned int iI = 0; iI < m_DominanceZones.size(); iI++)
		{
			pZone = &m_DominanceZones[iI];

			szLogMsg.Format("Zone ID: %d, Area ID: %d, Value: %d, FRIENDLY Str: %d (%d), Ranged: %d (%d), ENEMY Str: %d (%d), Ranged: %d (%d), Closest Enemy: %d",
			                pZone->GetDominanceZoneID(), pZone->GetAreaID(), pZone->GetDominanceZoneValue(),
			                pZone->GetFriendlyStrength(), pZone->GetFriendlyUnitCount(), pZone->GetFriendlyRangedStrength(), pZone->GetFriendlyRangedUnitCount(),
			                pZone->GetEnemyStrength(), pZone->GetEnemyUnitCount(), pZone->GetEnemyRangedStrength(), pZone->GetEnemyRangedUnitCount(), pZone->GetRangeClosestEnemyUnit());
			if(pZone->GetDominanceFlag() == TACTICAL_DOMINANCE_FRIENDLY)
			{
				szLogMsg += ", Friendly";
			}
			else if(pZone->GetDominanceFlag() == TACTICAL_DOMINANCE_ENEMY)
			{
				szLogMsg += ", Enemy";
			}
			else if(pZone->GetDominanceFlag() == TACTICAL_DOMINANCE_EVEN)
			{
				szLogMsg += ", Even";
			}
			else if(pZone->GetDominanceFlag() == TACTICAL_DOMINANCE_NO_UNITS_VISIBLE)
			{
				szLogMsg += ", No Units Visible";
			}

			if(pZone->IsWater())
			{
				szLogMsg += ", Water";
			}
			else
			{
				szLogMsg += ", Land";
			}

			if(pZone->GetTerritoryType() == TACTICAL_TERRITORY_TEMP_ZONE)
			{
				szLogMsg += ", Temporary Zone";
			}
			else if(pZone->GetClosestCity())
			{
				szLogMsg += ", " + pZone->GetClosestCity()->getName();
				if (m_pPlayer->GetTacticalAI()->IsTemporaryZoneCity(pZone->GetClosestCity()))
				{
					szLogMsg += " (Temp)";
				}
			}

			m_pPlayer->GetTacticalAI()->LogTacticalMessage(szLogMsg, true /*bSkipLogDominanceZone*/);
		}
	}
}
Example #13
0
/// Log all possible policy choices
void CvPolicyAI::LogPossiblePolicies()
{
    if(GC.getLogging() && GC.getAILogging())
    {
        CvString strOutBuf;
        CvString strBaseString;
        CvString strTemp;
        CvString playerName;
        CvString strDesc;

        // Find the name of this civ and city
        playerName = m_pCurrentPolicies->GetPlayer()->getCivilizationShortDescription();

        FILogFile* pLog;
        pLog = LOGFILEMGR.GetLog(GetLogFileName(playerName), FILogFile::kDontTimeStamp);

        // Get the leading info for this line
        strBaseString.Format("%03d, ", GC.getGame().getElapsedGameTurns());
        strBaseString += playerName + ", ";

        int iNumBranches = GC.getNumPolicyBranchInfos();

        // Dump out the weight of each possible policy
        for(int iI = 0; iI < m_AdoptablePolicies.size(); iI++)
        {
            int iWeight = m_AdoptablePolicies.GetWeight(iI);

            if(m_AdoptablePolicies.GetElement(iI) < iNumBranches)
            {
                strTemp.Format("Branch %d, %d", m_AdoptablePolicies.GetElement(iI), iWeight);
            }
            else
            {

                PolicyTypes ePolicy = (PolicyTypes)(m_AdoptablePolicies.GetElement(iI) - iNumBranches);
                CvPolicyEntry* pPolicyEntry = GC.getPolicyInfo(ePolicy);
                const char* szPolicyType = (pPolicyEntry != NULL)? pPolicyEntry->GetType() : "Unknown";
                strTemp.Format("%s, %d", szPolicyType, iWeight);
            }
            strOutBuf = strBaseString + strTemp;
            pLog->Msg(strOutBuf);
        }
    }
}
/// Log all potential builds
void CvProjectProductionAI::LogPossibleBuilds()
{
	if(GC.getLogging() && GC.getAILogging())
	{
		CvString strOutBuf;
		CvString strBaseString;
		CvString strTemp;
		CvString playerName;
		CvString cityName;
		CvString strDesc;
		CvString strLogName;

		CvAssert(m_pCity);
		if(!m_pCity) return;

		// Find the name of this civ and city
		playerName = GET_PLAYER(m_pCity->getOwner()).getCivilizationShortDescription();
		cityName = m_pCity->getName();

		// Open the log file
		FILogFile* pLog;
		pLog = LOGFILEMGR.GetLog(m_pCity->GetCityStrategyAI()->GetLogFileName(playerName, cityName), FILogFile::kDontTimeStamp);
		CvAssert(pLog);
		if(!pLog) return;

		// Get the leading info for this line
		strBaseString.Format("%03d, ", GC.getGame().getElapsedGameTurns());
		strBaseString += playerName + ", " + cityName + ", ";

		// Dump out the weight of each buildable item
		for(int iI = 0; iI < m_Buildables.size(); iI++)
		{
			CvProjectEntry* pProjectEntry = GC.GetGameProjects()->GetEntry(m_Buildables.GetElement(iI));

			strDesc = (pProjectEntry != NULL)? pProjectEntry->GetDescription() : "Unknown";
			strTemp.Format("Project, %s, %d", strDesc.GetCString(), m_Buildables.GetWeight(iI));
			strOutBuf = strBaseString + strTemp;
			pLog->Msg(strOutBuf);
		}
	}
}
Example #15
0
/// Serialization read
void CvUnitProductionAI::Read(FDataStream& kStream)
{
	// Version number to maintain backwards compatibility
	uint uiVersion;
	kStream >> uiVersion;
	// modVersion - v1, Snarko
	// We are using our own value here to keep backwards compatibility.
	// While we could use the Firaxis value that would cause issues when they update it, so we use our own for maximum backward compatibility. 
	// Old firaxis patch and old mod version? No problem! Except if you weren't using our mod before...
	uint modVersion;
	kStream >> modVersion;
	// END modVersion

	int iWeight;

	// Reset vector
	m_UnitAIWeights.clear();

	// Loop through reading each one and adding it to our vector
	if(m_pUnits)
	{
		for(int i = 0; i < m_pUnits->GetNumUnits(); i++)
		{
			m_UnitAIWeights.push_back(i, 0);
		}

		int iNumEntries;
		int iType;

		kStream >> iNumEntries;

		for(int iI = 0; iI < iNumEntries; iI++)
		{
			bool bValid = true;
			iType = CvInfosSerializationHelper::ReadHashed(kStream, &bValid);
			if(iType != -1 || !bValid)
			{
				kStream >> iWeight;
				if(iType != -1)
				{
					m_UnitAIWeights.IncreaseWeight(iType, iWeight);
				}
				else
				{
					CvString szError;
					szError.Format("LOAD ERROR: Unit Type not found");
					GC.LogMessage(szError.GetCString());
					CvAssertMsg(false, szError);
				}
			}
		}
	}
/// Serialization read
void CvUnitProductionAI::Read(FDataStream& kStream)
{
	// Version number to maintain backwards compatibility
	uint uiVersion;
	kStream >> uiVersion;

	int iWeight;

	// Reset vector
	m_UnitAIWeights.clear();

	// Loop through reading each one and adding it to our vector
	if(m_pUnits)
	{
		if(uiVersion >= 2)
		{
			for(int i = 0; i < m_pUnits->GetNumUnits(); i++)
			{
				m_UnitAIWeights.push_back(i, 0);
			}

			int iNumEntries;
			FStringFixedBuffer(sTemp, 64);
			int iType;

			kStream >> iNumEntries;

			for(int iI = 0; iI < iNumEntries; iI++)
			{
				kStream >> sTemp;
				if(sTemp != "NO_UNIT")
				{
					iType = GC.getInfoTypeForString(sTemp);
					kStream >> iWeight;
					if(iType != -1)
					{
						m_UnitAIWeights.IncreaseWeight(iType, iWeight);
					}
					else
					{
						CvString szError;
						szError.Format("LOAD ERROR: Unit Type not found: %s", sTemp);
						GC.LogMessage(szError.GetCString());
						CvAssertMsg(false, szError);
					}
				}
			}
		}
		else
		{
			for(int i = 0; i < 90 /* Units in gold master */; i++)
Example #17
0
// TODO Make this function more useful.
void CvPlayerAI::AI_LogEvent(int iEvent, int iOption)
{
	if(GC.getLogging() && GC.getAILogging())
	{
		CvString strOutBuf;
		CvString strBaseString;
		CvString playerName;
		CvString strDesc;
		CvString strLogName;
		CvString strTemp;

		// Find the name of this civ and city
		playerName = getCivilizationShortDescription();

		// Open the log file
		if(GC.getPlayerAndCityAILogSplit())
		{
			strLogName = "EventAILog_" + playerName + ".csv";
		}
		else
		{
			strLogName = "EventAILog.csv";
		}

		FILogFile* pLog;
		pLog = LOGFILEMGR.GetLog(strLogName, FILogFile::kDontTimeStamp);

		// Get the leading info for this line
		strBaseString.Format("%03d, EVENT, ", GC.getGame().getElapsedGameTurns());
		strBaseString += playerName;

		strTemp.Format("%d, %d", iEvent, iOption);

		strOutBuf = strBaseString + ", " + strTemp;

		pLog->Msg(strOutBuf);
	}
}
void CvArmyAI::RemoveStuckUnits()
{
	CvAIOperation* pOperation = GET_PLAYER(GetOwner()).getAIOperation(GetOperationID());

	for(unsigned int iI = 0; iI < m_FormationEntries.size(); iI++)
	{
		if(m_FormationEntries[iI].GetUnitID() > ARMYSLOT_NO_UNIT && m_FormationEntries[iI].GetTurnAtCheckpoint()==ARMYSLOT_UNKNOWN_TURN_AT_CHECKPOINT)
		{
			CvString strMsg;
			strMsg.Format("Removing unit %d from army %d because no path to checkpoint",m_FormationEntries[iI].GetUnitID(),GetID());
			pOperation->LogOperationSpecialMessage(strMsg);

			RemoveUnit(m_FormationEntries[iI].GetUnitID());
		}
	}
}
/// Serialization read
void CvBuildingProductionAI::Read(FDataStream& kStream)
{
	// Version number to maintain backwards compatibility
	uint uiVersion;
	kStream >> uiVersion;
	MOD_SERIALIZE_INIT_READ(kStream);

	// Reset vector
	m_BuildingAIWeights.clear();

	// Loop through reading each one and adding it to our vector
	if(m_pCityBuildings)
	{
		for(int i = 0; i < m_pCityBuildings->GetPossibleBuildings()->GetNumBuildings(); i++)
		{
			m_BuildingAIWeights.push_back(i, 0);
		}

		int iNumEntries;
		FStringFixedBuffer(sTemp, 64);
		int iType;

		kStream >> iNumEntries;

		for(int iI = 0; iI < iNumEntries; iI++)
		{
			bool bValid = true;
			iType = CvInfosSerializationHelper::ReadHashed(kStream, &bValid);
			if(iType != -1 || !bValid)
			{
				int iWeight;
				kStream >> iWeight;
				if(iType != -1)
				{
					m_BuildingAIWeights.IncreaseWeight(iType, iWeight);
				}
				else
				{
					CvString szError;
					szError.Format("LOAD ERROR: Building Type not found");
					GC.LogMessage(szError.GetCString());
					CvAssertMsg(false, szError);
				}
			}
		}
	}
CvPlot* CvArmyAI::CheckTargetReached(PlayerTypes eEnemy, bool bNavalOp, int iMaxDistance)
{
	//check if we're at the target
	CvPlot *pTargetPlot = GetGoalPlot();
	CvPlot *pCenterOfMass = GetCenterOfMass(NO_DOMAIN);
	if(pCenterOfMass && pTargetPlot && plotDistance(*pCenterOfMass,*pTargetPlot) <= iMaxDistance)
		return pTargetPlot;

	//check early termination if we ran into the enemy
	if(GetArmyAIState() == ARMYAISTATE_MOVING_TO_DESTINATION)
	{
		CvPlot*	pEnemyPlot = DetectNearbyEnemy(eEnemy, bNavalOp);
		if(pEnemyPlot != NULL)
		{
			CvCity* pCity = pEnemyPlot->getWorkingCity();
			if(pCity != NULL)
			{
				if (bNavalOp && pCity->isCoastal() && pCity->waterArea()==pTargetPlot->area())
					pEnemyPlot = pCity->plot();

				if (!bNavalOp && pCity->area()==pTargetPlot->area())
					pEnemyPlot = pCity->plot();

				if (pEnemyPlot!=GetGoalPlot())
				{
					if(GC.getLogging() && GC.getAILogging())
					{
						CvString strMsg;
						strMsg.Format("Switching target from %d,%d to closest city at %d,%d", GetGoalX(), GetGoalY(), pEnemyPlot->getX(), pEnemyPlot->getY() );
						GET_PLAYER(m_eOwner).getAIOperation(m_iOperationID)->LogOperationSpecialMessage(strMsg);
					}
				}

				return pEnemyPlot;
			}
		}
	}

	return NULL;
}
/// Add a unit to our army (and we know which slot)
void CvArmyAI::AddUnit(int iUnitID, int iSlotNum)
{
	CvPlayer& thisPlayer = GET_PLAYER(m_eOwner);
	CvUnit* pThisUnit = thisPlayer.getUnit(iUnitID);
	if (!pThisUnit)
		return;

	// remove this unit from an army if it is already in one
	thisPlayer.removeFromArmy(pThisUnit->getArmyID(), GetID());
	m_FormationEntries[iSlotNum] = CvArmyFormationSlot(); //reset
	m_FormationEntries[iSlotNum].SetUnitID(iUnitID);
	pThisUnit->setArmyID(GetID());

#if defined(MOD_BALANCE_CORE)
	//just for avoiding confusion
	pThisUnit->setTacticalMove(NO_TACTICAL_MOVE);
#endif

	// Finally, compute when we think this unit will arrive at the next checkpoint
	CvPlot* pMusterPlot = GC.getMap().plot(GetX(), GetY());
	if(pMusterPlot)
	{
		int iFlags = CvUnit::MOVEFLAG_APPROX_TARGET_RING2 | CvUnit::MOVEFLAG_IGNORE_STACKING | CvUnit::MOVEFLAG_IGNORE_ZOC;
		int iTurnsToReachCheckpoint = pThisUnit->TurnsToReachTarget(pMusterPlot, iFlags, GC.getAI_OPERATIONAL_MAX_RECRUIT_TURNS_ENEMY_TERRITORY());
		if(iTurnsToReachCheckpoint < MAX_INT)
		{
			m_FormationEntries[iSlotNum].SetTurnsToCheckpoint(iTurnsToReachCheckpoint);
		}

		if (GC.getLogging() && GC.getAILogging())
		{
			CvAIOperation* pOperation = GET_PLAYER(GetOwner()).getAIOperation(GetOperationID());
			CvString strMsg;
			strMsg.Format("Added %s %d to slot %d in army %d. ETA at (%d:%d) is %d ", pThisUnit->getName().c_str(),
				m_FormationEntries[iSlotNum].GetUnitID(), iSlotNum, GetID(), pMusterPlot->getX(), pMusterPlot->getY(), iTurnsToReachCheckpoint);
			pOperation->LogOperationSpecialMessage(strMsg);
		}
	}
}
/// Helper function to read a single resource type ID as a hash and convert it to an ID
int ReadHashed(FDataStream& kStream, bool* bValid /*= NULL*/)
{
	uint uiHash;
	if(bValid) *bValid = true;
	kStream >> uiHash;
	if(uiHash != 0)
	{
		int iType = GC.getInfoTypeForHash(uiHash);
		if(iType != -1)
		{
			return iType;
		}
		else
		{
			CvString szError;
			szError.Format("LOAD ERROR: Type not found for hash: %u", uiHash);
			GC.LogMessage(szError.GetCString());
			CvAssertMsg(false, szError);
			if(bValid) *bValid = false;
		}
	}

	return -1;
}
/// Recalculate when each unit will arrive at the current army position, whatever that is
void CvArmyAI::UpdateCheckpointTurnsAndRemoveBadUnits()
{
	CvAIOperation* pOperation = GET_PLAYER(GetOwner()).getAIOperation(GetOperationID());
	//should be updated before calling this ...
	CvPlot* pCurrentArmyPlot = GC.getMap().plot(GetX(), GetY());

	//kick out damaged units, but if we're defending or escorting, no point in running away
	if (pOperation->IsOffensive())
	{
		for (unsigned int iI = 0; iI < m_FormationEntries.size(); iI++)
		{
			if (!m_FormationEntries[iI].IsUsed())
				continue;

			CvUnit* pUnit = GET_PLAYER(m_eOwner).getUnit(m_FormationEntries[iI].m_iUnitID);
			if (pUnit == NULL)
				continue;

			//failsafe - make sure the army ID is set
			if (pUnit->getArmyID() != GetID())
				pUnit->setArmyID(GetID());

			//let tactical AI handle those
			if (pUnit->GetCurrHitPoints() < pUnit->GetMaxHitPoints() / 3)
				RemoveUnit(m_FormationEntries[iI].GetUnitID());
		}
	}

	//update for all units in this army. ignore the ones still being built
	int iGatherTolerance = pOperation->GetGatherTolerance(this, pCurrentArmyPlot);
	for(unsigned int iI = 0; iI < m_FormationEntries.size(); iI++)
	{
		if (!m_FormationEntries[iI].IsUsed())
			continue;

		CvUnit* pUnit = GET_PLAYER(m_eOwner).getUnit(m_FormationEntries[iI].GetUnitID());
		if(pUnit && pCurrentArmyPlot)
		{
			if(plotDistance(*pUnit->plot(),*pCurrentArmyPlot)<iGatherTolerance)
			{
				m_FormationEntries[iI].SetTurnsToCheckpoint(0);
			}
			else
			{
				//be generous with the flags here, for some ops the muster point may be far away and intermittendly occupied by foreign units ...
				int iFlags = CvUnit::MOVEFLAG_APPROX_TARGET_RING2 | CvUnit::MOVEFLAG_IGNORE_STACKING | CvUnit::MOVEFLAG_IGNORE_ZOC;
				int iTurnsToReachCheckpoint = pUnit->TurnsToReachTarget(pCurrentArmyPlot, iFlags, pOperation->GetMaximumRecruitTurns());

				//if we're already moving to target, the current army plot is moving, so we cannot check progress against ...
				if ( iTurnsToReachCheckpoint==INT_MAX ||
					 (GetArmyAIState()==ARMYAISTATE_WAITING_FOR_UNITS_TO_CATCH_UP && !m_FormationEntries[iI].IsMakingProgressTowardsCheckpoint(iTurnsToReachCheckpoint)) )
				{
					CvString strMsg;
					strMsg.Format("Removing %s %d from army %d because no progress to checkpoint (%d:%d). ETA %d, previously %d.", 
						pUnit->getName().c_str(), m_FormationEntries[iI].GetUnitID(), GetID(), pCurrentArmyPlot->getX(), pCurrentArmyPlot->getY(),
						iTurnsToReachCheckpoint, m_FormationEntries[iI].m_iPrevEstimatedTurnsToCheckpoint);
					pOperation->LogOperationSpecialMessage(strMsg);
					RemoveUnit(m_FormationEntries[iI].GetUnitID());
				}
				else
					m_FormationEntries[iI].SetTurnsToCheckpoint(iTurnsToReachCheckpoint);
			}
		}
	}
}
Example #24
0
//	--------------------------------------------------------------------------------
/// Gameplay informing us when a Camp has either been created or spawned a Unit so we can reseed the spawn counter
void CvBarbarians::DoCampActivationNotice(CvPlot* pPlot)
{
	CvGame& kGame = GC.getGame();
	// Default to 6 turns (also changed to double to accomodate decimals.
#ifdef Imperial_Barbarian_Algorithm
	double iNumTurnsToSpawn = 7 + kGame.getJonRandNum(2, "Barb Spawn Rand call");
	// Raging barbs; reduced to 4 turns.
	if (kGame.isOption(GAMEOPTION_RAGING_BARBARIANS))
	{
		iNumTurnsToSpawn -= 3 + kGame.getJonRandNum(1, "Barb Spawn Rand call");
	}
#else
	int iNumTurnsToSpawn = 6 + kGame.getJonRandNum(5, "Barb Spawn Rand call");

	// Raging
	if (kGame.isOption(GAMEOPTION_RAGING_BARBARIANS))
		iNumTurnsToSpawn /= 2;
#endif
	

	// Reduce turns between spawn if we've pumped out more guys (meaning we're further into the game)
#ifdef Imperial_Barbarian_Algorithm
	// Number of units this camp has already spawned
	double dNumUnitsSpawned = m_aiPlotBarbCampNumUnitsSpawned[pPlot->GetPlotIndex()];

	/* For every unit this camp has spawned (through official channels, does not include spawns handled by other AI classes)
	 reduce the counter by 0.3 turns, up to a maximum reduction of 2 turns (@ 7 units spawned in). */
	dNumUnitsSpawned = min((dNumUnitsSpawned * 0.3), (double)2);

	iNumTurnsToSpawn -= dNumUnitsSpawned; 
#else
	// Num Units Spawned
	int iNumUnitsSpawned = m_aiPlotBarbCampNumUnitsSpawned[pPlot->GetPlotIndex()];
	iNumTurnsToSpawn -= min(3, iNumUnitsSpawned);	// -1 turns if we've spawned one Unit, -3 turns if we've spawned three
#endif
	// Increment # of barbs spawned from this camp
	m_aiPlotBarbCampNumUnitsSpawned[pPlot->GetPlotIndex()]++;	// This starts at -1 so when a camp is first created it will bump up to 0, which is correct

	// Difficulty level can add time between spawns (e.g. Settler is +8 turns)
	CvHandicapInfo* pHandicapInfo = GC.getHandicapInfo(kGame.getHandicapType());
	if (pHandicapInfo)
	{
		iNumTurnsToSpawn += pHandicapInfo->getBarbSpawnMod();
	}

	// Game Speed can increase or decrease amount of time between spawns (ranges from 67 on Quick to 400 on Marathon)
	CvGameSpeedInfo* pGameSpeedInfo = GC.getGameSpeedInfo(kGame.getGameSpeedType());
	if (pGameSpeedInfo)
	{
		iNumTurnsToSpawn *= pGameSpeedInfo->getBarbPercent();
		iNumTurnsToSpawn /= 100;
	}

#ifdef Imperial_Barbarian_Algorithm
	iNumTurnsToSpawn = max((double)0, iNumTurnsToSpawn); // never below zero! zero = spawn a barb every turn!
	// Round up if above 0.4, round down otherwise.
	if (fmod(iNumTurnsToSpawn, 1) > 0.4)
	{
		iNumTurnsToSpawn = ceil(iNumTurnsToSpawn);
	}
	else
	{
		iNumTurnsToSpawn = floor(iNumTurnsToSpawn);		
	}
#ifdef Imperial_Barbarians_Logging_
	CvString sCount;
	sCount.Format("Barbarian spawned C!, Number of turns until next spawn:, %d", (int)iNumTurnsToSpawn);
	kGame.ImperialGameLogging(sCount, BARBARIAN_PLAYER);
#endif
#endif

	m_aiPlotBarbCampSpawnCounter[pPlot->GetPlotIndex()] = iNumTurnsToSpawn;
}
Example #25
0
// WARNING WARNING WARNING WARNING
// the p_szLogWrite->XmlArtTagVerification can cause CTD because of memory overflow
// If too much is parsed into the XmlArtTagVerification method!!
void CvXMLLoadUtilityModTools::setLocationName( CvString *pszTextVal, const char* szDirName)
{
#if (DEBUG_IS_MODULAR_ART == 1)
	CvString szDebugBuffer;
	szDebugBuffer.Format("=== setLocationName BEGIN ===");
	gDLL->logMsg("CvXMLLoadUtilityModTools_setLocationName.log", szDebugBuffer.c_str());

	szDebugBuffer.Format(" Text value: '%s', Directory name: '%s'", pszTextVal->c_str(), szDirName);
	gDLL->logMsg("CvXMLLoadUtilityModTools_setLocationName.log", szDebugBuffer.c_str());
#endif

	std::string szFiraxisLoad = "NONE";
	if (szDirName == szFiraxisLoad) //non modular loading doesn't need this method
	{
//#if (DEBUG_IS_MODULAR_ART == 1)
//	szDebugBuffer.Format("DirName == NONE, exiting?");
//	gDLL->logMsg("CvXMLLoadUtilityModTools_setLocationName.log", szDebugBuffer.c_str());
//
//	szDebugBuffer.Format("=== setLocationName END ===");
//	gDLL->logMsg("CvXMLLoadUtilityModTools_setLocationName.log", szDebugBuffer.c_str());
//#endif

		return;
	}
	CvString szModular = szDirName;
	CvString szTextVal = *pszTextVal;
	szModular = szModular + szTextVal;

	CvXMLLoadUtility* p_szLogWrite = new CvXMLLoadUtility;

	if (isExcludedFile(szTextVal)) // These are special files that are relative to the Directory of Civ4BeyondSword.exe
	{
		if ( isModularArt(szModular))
		{			
			szTextVal = gDLL->getModName();
			szTextVal += "Assets\\";
			szTextVal += szModular;
			writeThm(szTextVal);
		}
		else
		{
#ifdef _DEBUG
		//the passed is crap, we don't want to continue anything with it
/*
		if ( szTextVal == "" )	// this shouldn't exist
		{
			p_szLogWrite->XmlArtTagVerification("CRASH WARNING, Your theme <Path> tag is found emtpy in: %s\\%s", szDirName.GetCString(), GC.getCurrentXMLFile().GetCString());
		}
		else if (szTextVal == "None")	// this shouldn't exist!
		{
			p_szLogWrite->XmlArtTagVerification("CRASH WARNING, Your theme <Path> tag is set to: %s in: %s\\%s", szTextVal.GetCString(), szDirName.GetCString(), GC.getCurrentXMLFile().GetCString());		
		}
		else
		{
		}
*/
			p_szLogWrite->XmlArtTagVerification("CRASH WARNING, Your theme <Path> %s, seems not to be relative to the Module path: %s", szTextVal.GetCString(), szDirName);		
#endif
		}
	}
	else if (isCommaFile(&szTextVal, szDirName)) // These are tags with a comma, mostly having 2button types even
	{
#ifdef _DEBUG
		//the passed is crap, we don't want to continue anything with it
		if ( szTextVal == "" )
		{
			p_szLogWrite->XmlArtTagVerification("One art tag is found emtpy in: %s", GC.getCurrentXMLFile().GetCString());
		}
		else if (szTextVal == "None")
		{
			p_szLogWrite->XmlArtTagVerification("One art tag is set to: %s in: %s", szTextVal.GetCString(), GC.getCurrentXMLFile().GetCString());		
		}
		else
		{		
			p_szLogWrite->XmlArtTagVerification("One art tag: %s, seems not to be relative to the module path in: %s", szTextVal.GetCString(), GC.getCurrentXMLFile().GetCString());		
		}
#endif
	}	
	else
	{
		if ( isModularArt(szModular))
		{
			szTextVal = szModular;
		}
		else
		{
#ifdef _DEBUG
		//the passed is crap, we don't want to continue anything with it
		if ( szTextVal == "" )
		{
			p_szLogWrite->XmlArtTagVerification("One art tag is found emtpy in: %s", GC.getCurrentXMLFile().GetCString());
		}
		else if (szTextVal == "None")
		{
			p_szLogWrite->XmlArtTagVerification("One art tag is set to: %s in: %s", szTextVal.GetCString(), GC.getCurrentXMLFile().GetCString());		
		}
		else
		{		
			p_szLogWrite->XmlArtTagVerification("One art tag: %s, seems not to be relative to the module path in: %s", szTextVal.GetCString(), GC.getCurrentXMLFile().GetCString());		
		}
#endif
		}
	}
	*pszTextVal = szTextVal;

#if (DEBUG_IS_MODULAR_ART == 1)
	szDebugBuffer.Format(" Assigned OUT text value: '%s'", pszTextVal->c_str());
	gDLL->logMsg("CvXMLLoadUtilityModTools_setLocationName.log", szDebugBuffer.c_str());

	szDebugBuffer.Format("=== setLocationName END ===");
	gDLL->logMsg("CvXMLLoadUtilityModTools_setLocationName.log", szDebugBuffer.c_str());
#endif

	SAFE_DELETE(p_szLogWrite);
}
Example #26
0
/// Log our guess as to other Players' Active Grand Strategy
void CvGrandStrategyAI::LogGuessOtherPlayerGrandStrategy(const FStaticVector< int, 5, true, c_eCiv5GameplayDLL >& vGrandStrategyPriorities, PlayerTypes ePlayer)
{
	if(GC.getLogging() && GC.getAILogging())
	{
		CvString strOutBuf;
		CvString strBaseString;
		CvString strTemp;
		CvString playerName;
		CvString otherPlayerName;
		CvString strDesc;
		CvString strLogName;

		// Find the name of this civ and city
		playerName = GetPlayer()->getCivilizationShortDescription();

		// Open the log file
		if(GC.getPlayerAndCityAILogSplit())
		{
			strLogName = "GrandStrategyAI_Guess_Log_" + playerName + ".csv";
		}
		else
		{
			strLogName = "GrandStrategyAI_Guess_Log.csv";
		}

		FILogFile* pLog;
		pLog = LOGFILEMGR.GetLog(strLogName, FILogFile::kDontTimeStamp);

		AIGrandStrategyTypes eGrandStrategy;
		int iPriority;

		// Loop through Grand Strategies
		for(int iGrandStrategyLoop = 0; iGrandStrategyLoop < GC.getNumAIGrandStrategyInfos(); iGrandStrategyLoop++)
		{
			// Get the leading info for this line
			strBaseString.Format("%03d, ", GC.getGame().getElapsedGameTurns());
			strBaseString += playerName + ", ";

			eGrandStrategy = (AIGrandStrategyTypes) iGrandStrategyLoop;
			iPriority = vGrandStrategyPriorities[iGrandStrategyLoop];

			CvAIGrandStrategyXMLEntry* pEntry = GC.getAIGrandStrategyInfo(eGrandStrategy);
			const char* szGrandStrategyType = (pEntry != NULL)? pEntry->GetType() : "Unknown Strategy";

			// GrandStrategy Info
			if(GetActiveGrandStrategy() == eGrandStrategy)
			{
				strTemp.Format("*** %s, %d", szGrandStrategyType, iPriority);
			}
			else
			{
				strTemp.Format("%s, %d", szGrandStrategyType, iPriority);
			}
			otherPlayerName = GET_PLAYER(ePlayer).getCivilizationShortDescription();
			strOutBuf = strBaseString + otherPlayerName + ", " + strTemp;

			if(GetGuessOtherPlayerActiveGrandStrategy(ePlayer) == eGrandStrategy)
			{
				// Confidence in our guess
				switch(GetGuessOtherPlayerActiveGrandStrategyConfidence(ePlayer))
				{
				case GUESS_CONFIDENCE_POSITIVE:
					strTemp.Format("Positive");
					break;
				case GUESS_CONFIDENCE_LIKELY:
					strTemp.Format("Likely");
					break;
				case GUESS_CONFIDENCE_UNSURE:
					strTemp.Format("Unsure");
					break;
				default:
					strTemp.Format("XXX");
					break;
				}

				strOutBuf += ", " + strTemp;
			}

			pLog->Msg(strOutBuf);
		}

		// One more entry for NO GRAND STRATEGY
		// Get the leading info for this line
		strBaseString.Format("%03d, ", GC.getGame().getElapsedGameTurns());
		strBaseString += playerName + ", ";

		iPriority = vGrandStrategyPriorities[GC.getNumAIGrandStrategyInfos()];

		// GrandStrategy Info
		strTemp.Format("NO_GRAND_STRATEGY, %d", iPriority);
		otherPlayerName = GET_PLAYER(ePlayer).getCivilizationShortDescription();
		strOutBuf = strBaseString + otherPlayerName + ", " + strTemp;
		pLog->Msg(strOutBuf);
	}
}
Example #27
0
void CvCityAI::AI_chooseProduction(bool bInterruptWonders)
{
	VALIDATE_OBJECT
	CvPlayerAI& kOwner = GET_PLAYER(getOwner());
	CvCitySpecializationAI* pSpecializationAI = kOwner.GetCitySpecializationAI();
	bool bBuildWonder = false;

	// See if this is the one AI city that is supposed to be building wonders
	if(pSpecializationAI->GetWonderBuildCity() == this)
	{
		// Is it still working on that wonder and we don't want to interrupt it?
		if(!bInterruptWonders)
		{
			const BuildingTypes eBuilding = getProductionBuilding();
			CvBuildingEntry* pkBuilding = (eBuilding != NO_BUILDING)? GC.getBuildingInfo(eBuilding) : NULL;
			if(pkBuilding && kOwner.GetWonderProductionAI()->IsWonder(*pkBuilding))
			{
				return;  // Stay the course
			}
		}

		// So we're the wonder building city but it is not underway yet...

		// Has the designated wonder been poached by another civ?
		BuildingTypes eNextWonder = pSpecializationAI->GetNextWonderDesired();
		if(!canConstruct(eNextWonder))
		{
			// Reset city specialization
			kOwner.GetCitySpecializationAI()->SetSpecializationsDirty(SPECIALIZATION_UPDATE_WONDER_BUILT_BY_RIVAL);
		}
		else
		{
			// to prevent us from continuously locking into building wonders in one city when there are other high priority items to build
			int iFlavorWonder = kOwner.GetGrandStrategyAI()->GetPersonalityAndGrandStrategy((FlavorTypes)GC.getInfoTypeForString("FLAVOR_WONDER"));
			int iFlavorGP = kOwner.GetGrandStrategyAI()->GetPersonalityAndGrandStrategy((FlavorTypes)GC.getInfoTypeForString("FLAVOR_GREAT_PEOPLE"));
			int iFlavor = (iFlavorWonder > iFlavorGP ) ? iFlavorWonder : iFlavorGP;
			if (GC.getGame().getJonRandNum(11, "Random roll for whether to continue building wonders") <= iFlavor)
				bBuildWonder = true;
		}
	}

	if(bBuildWonder)
	{
		CvCityBuildable buildable;
		buildable.m_eBuildableType = CITY_BUILDABLE_BUILDING;
		buildable.m_iIndex = pSpecializationAI->GetNextWonderDesired();
		buildable.m_iTurnsToConstruct = getProductionTurnsLeft((BuildingTypes)buildable.m_eBuildableType, 0);
		pushOrder(ORDER_CONSTRUCT, buildable.m_iIndex, -1, false, false, false, false);

		if(GC.getLogging() && GC.getAILogging())
		{
			CvString playerName;
			FILogFile* pLog;
			CvString strBaseString;
			CvString strOutBuf;

			m_pCityStrategyAI->LogCityProduction(buildable, false);

			playerName = kOwner.getCivilizationShortDescription();
			pLog = LOGFILEMGR.GetLog(kOwner.GetCitySpecializationAI()->GetLogFileName(playerName), FILogFile::kDontTimeStamp);
			strBaseString.Format("%03d, ", GC.getGame().getElapsedGameTurns());
			strBaseString += playerName + ", ";
			strOutBuf.Format("%s, WONDER - Started %s, Turns: %d", getName().GetCString(), GC.getBuildingInfo((BuildingTypes)buildable.m_iIndex)->GetDescription(), buildable.m_iTurnsToConstruct);
			strBaseString += strOutBuf;
			pLog->Msg(strBaseString);
		}
	}

	else
	{
		m_pCityStrategyAI->ChooseProduction(false);
		AI_setChooseProductionDirty(false);
	}

	return;
}
/// Log dominance zone data
void CvTacticalAnalysisMap::LogZones()
{
	if(GC.getLogging() && GC.getAILogging())
	{
		CvString szLogMsg;
		CvTacticalDominanceZone* pZone;

		for(unsigned int iI = 0; iI < m_DominanceZones.size(); iI++)
		{
			pZone = &m_DominanceZones[iI];

			//don't blow up the logs for empty zones
			if ( pZone->GetOverallFriendlyStrength()==0 &&  pZone->GetOverallEnemyStrength()==0)
				continue;

			szLogMsg.Format("Zone ID: %d, Size: %d, City: %s, Area ID: %d, Value: %d, FRIENDLY Str: %d (%d), Ranged: %d (naval %d), ENEMY Str: %d (%d), Ranged: %d (naval %d), Closest Enemy: %d",
			                pZone->GetDominanceZoneID(), pZone->GetNumPlots(), pZone->GetZoneCity() ? pZone->GetZoneCity()->getName().c_str() : "none", pZone->GetAreaID(), pZone->GetDominanceZoneValue(),
			                pZone->GetOverallFriendlyStrength(), pZone->GetTotalFriendlyUnitCount(), pZone->GetFriendlyRangedStrength(), pZone->GetFriendlyNavalRangedStrength(),
			                pZone->GetOverallEnemyStrength(), pZone->GetTotalEnemyUnitCount(), pZone->GetEnemyRangedStrength(), pZone->GetEnemyNavalRangedStrength(), pZone->GetRangeClosestEnemyUnit());
			if(pZone->GetOverallDominanceFlag() == TACTICAL_DOMINANCE_FRIENDLY)
			{
				szLogMsg += ", Friendly";
			}
			else if(pZone->GetOverallDominanceFlag() == TACTICAL_DOMINANCE_ENEMY)
			{
				szLogMsg += ", Enemy";
			}
			else if(pZone->GetOverallDominanceFlag() == TACTICAL_DOMINANCE_EVEN)
			{
				szLogMsg += ", Even";
			}
			else if(pZone->GetOverallDominanceFlag() == TACTICAL_DOMINANCE_NO_UNITS_VISIBLE)
			{
				szLogMsg += ", No Units Visible";
			}

			if(pZone->IsWater())
			{
				szLogMsg += ", Water";
			}
			else
			{
				szLogMsg += ", Land";
			}

			if(pZone->GetTerritoryType() == TACTICAL_TERRITORY_TEMP_ZONE)
			{
				szLogMsg += ", Temporary Zone";
			}
			else if(pZone->GetZoneCity())
			{
				if (GET_PLAYER(m_ePlayer).GetTacticalAI()->IsTemporaryZoneCity(pZone->GetZoneCity()))
				{
					szLogMsg += " (Temp)";
				}
			}
			if (pZone->IsNavalInvasion())
			{
				szLogMsg += ", NAVAL INVASION";
			}

			GET_PLAYER(m_ePlayer).GetTacticalAI()->LogTacticalMessage(szLogMsg, true /*bSkipLogDominanceZone*/);
		}
	}
}
Example #29
0
bool CvXMLLoadUtilityModTools::isModularArt(const char* szLocationName)
{
/************************************************************************************************/
/* DEBUG_IS_MODULAR_ART                    05/12/08                                Faichele     */
/*                                                                                              */
/*                                                                                              */
/************************************************************************************************/
#if (DEBUG_IS_MODULAR_ART == 1)
	CvString szDebugBuffer;
	szDebugBuffer.Format("=== isModularArt BEGIN ===");
	gDLL->logMsg("CvXMLLoadUtilityModTools_isModularArt.log", szDebugBuffer.c_str());

	szDebugBuffer.Format(" Location name: '%s'", szLocationName);
	gDLL->logMsg("CvXMLLoadUtilityModTools_isModularArt.log", szDebugBuffer.c_str());
#endif

	//the passed is crap, we don't want to continue anything with it
	if (szLocationName == NULL || szLocationName == "" || szLocationName == "None" || szLocationName == "NONE" )
	{
#if (DEBUG_IS_MODULAR_ART == 1)
		szDebugBuffer.Format(" EMPTY location, aborting.");
		gDLL->logMsg("CvXMLLoadUtilityModTools_isModularArt.log", szDebugBuffer.c_str());
#endif	
		return false;
	}

	// Dir where the Civ4BeyondSword.exe is started from
/************************************************************************************************/
/* Afforess	                  Start		 06/15/10                                               */
/*                                                                                              */
/*                                                                                              */
/************************************************************************************************/
	CvString m_szFolderPath = GC.getInitCore().getDLLPath() + "\\";
/************************************************************************************************/
/* Afforess	                     END                                                            */
/************************************************************************************************/


	#if (DEBUG_IS_MODULAR_ART == 1)
		szDebugBuffer.Format(" Complete path (with Assets dir): %s", m_szFolderPath.c_str());
		gDLL->logMsg("CvXMLLoadUtilityModTools_isModularArt.log", szDebugBuffer.c_str());
	#endif

	m_szFolderPath += szLocationName;		// where the tag points to, usually "Art\filename.xxx"

#if (DEBUG_IS_MODULAR_ART == 1)
	szDebugBuffer.Format("  Path WITH given location: '%s'", m_szFolderPath.c_str());
	gDLL->logMsg("CvXMLLoadUtilityModTools_isModularArt.log", szDebugBuffer.c_str());
#endif
	int iReplaced = 0;
	
	iReplaced = m_szFolderPath.Replace('/','\\');
#if (DEBUG_IS_MODULAR_ART == 1)
	
	szDebugBuffer.Format("  Replaced %i occurrences of '/' with '\\'.", iReplaced);
	gDLL->logMsg("CvXMLLoadUtilityModTools_isModularArt.log", szDebugBuffer.c_str());

#endif

	iReplaced = m_szFolderPath.Replace(CvString("\\\\"),CvString("\\"));
#if (DEBUG_IS_MODULAR_ART == 1)
	szDebugBuffer.Format("  Replaced %i occurrences of '\\\\' with '\\'.", iReplaced);
	gDLL->logMsg("CvXMLLoadUtilityModTools_isModularArt.log", szDebugBuffer.c_str());	

	szDebugBuffer.Format("  Path WITH given location: '%s'", m_szFolderPath.c_str());
	gDLL->logMsg("CvXMLLoadUtilityModTools_isModularArt.log", szDebugBuffer.c_str());
#endif
	FILE *file;
	DWORD dwAttr = GetFileAttributes(m_szFolderPath.c_str());
	if(dwAttr != 0xffffffff && (dwAttr & FILE_ATTRIBUTE_DIRECTORY)) 
	{
#if (DEBUG_IS_MODULAR_ART == 1)
		szDebugBuffer.Format(" '%s' is a DIRECTORY, no modular art?", m_szFolderPath.c_str());
		gDLL->logMsg("CvXMLLoadUtilityModTools_isModularArt.log", szDebugBuffer.c_str());
#endif
		return false;
	}
	else
	{
		file = fopen(m_szFolderPath.c_str(), "rb");
	}

/************************************************************************************************/
/* DEBUG_IS_MODULAR_ART                    END                                                  */
/************************************************************************************************/

	if (file == NULL) 
	{
		return false;		
	}
	fclose(file);

#if (DEBUG_IS_MODULAR_ART == 1)
	szDebugBuffer.Format("=== isModularArt END ===");
	gDLL->logMsg("CvXMLLoadUtilityModTools_isModularArt.log", szDebugBuffer.c_str());
#endif	

	return true;
}
Example #30
0
bool CvXMLLoadUtilityModTools::isCommaFile(CvString *pszTextVal, const char* szDirName)
{
#if (DEBUG_IS_MODULAR_ART == 1)
	CvString szDebugBuffer;
	szDebugBuffer.Format("=== isCommaFile BEGIN ===");
	gDLL->logMsg("CvXMLLoadUtilityModTools_isCommaFile.log", szDebugBuffer.c_str());

	szDebugBuffer.Format(" Text value: %s,  Directory name: '%s'", pszTextVal->c_str(), szDirName);
	gDLL->logMsg("CvXMLLoadUtilityModTools_isCommaFile.log", szDebugBuffer.c_str());
#endif

	string::size_type posComma = (*pszTextVal).find_first_of(',');

	if(posComma != string::npos) //if no comma found at all, return false
	{

#if (DEBUG_IS_MODULAR_ART == 1)
		szDebugBuffer.Format(" Found a ',' at position %i (total length %i)", (int)posComma, (*pszTextVal).GetLength());
		gDLL->logMsg("CvXMLLoadUtilityModTools_isCommaFile.log", szDebugBuffer.c_str());
#endif
		CvString szTempLocation;
		CvString szAppend = " ";
		int iCountComma = 0;
		CvString szLocationNameStripComma;
		// Check how many comma's we have in the string and how many Button Files		

#if (DEBUG_IS_MODULAR_ART == 1)
		std::vector<CvString> asTagParts;
		pszTextVal->getTokens(CvString(","), asTagParts);
		iCountComma = asTagParts.size();

		szDebugBuffer.Format(" Total number of ',' in pszTextVal: %i", iCountComma);
		gDLL->logMsg("CvXMLLoadUtilityModTools_isCommaFile.log", szDebugBuffer.c_str());
		for (std::vector<CvString>::iterator it = asTagParts.begin(); it != asTagParts.end(); it++)
		{
			szDebugBuffer.Format("  - Token %s", (*it).c_str());
			gDLL->logMsg("CvXMLLoadUtilityModTools_isCommaFile.log", szDebugBuffer.c_str());
		}
#else
		szLocationNameStripComma = *pszTextVal;
		for ( int i = 0; i < szLocationNameStripComma.GetLength(); i++)
		{
			if (szLocationNameStripComma[i] == 44) // "," = 44 (ASCII)
			{
			  iCountComma++;
			}
		}		
#endif

		

#if (DEBUG_IS_MODULAR_ART == 1)
		CvString szButtonsString;
		for (std::vector<CvString>::iterator it = asTagParts.begin(); it != asTagParts.end(); it++)
		{
			bool bDigitsOnly = true;
			for (int i = 0; i < (*it).GetLength(); i++)
			{
				if (!isdigit((*it)[i]))
					bDigitsOnly = false;
			}
			if (!bDigitsOnly)
				szButtonsString += ((*it) + ",");
		}
		// Eliminate comma at end of string, if there is one
		if (szButtonsString.GetLength() > 0 && szButtonsString[szButtonsString.GetLength()] == ',')
			szButtonsString = szButtonsString.substr(0, szButtonsString.GetLength() - 1);

		szDebugBuffer.Format(" Button art string after eliminating numerical indices: %s", szButtonsString.c_str());
		gDLL->logMsg("CvXMLLoadUtilityModTools_isCommaFile.log", szDebugBuffer.c_str());

#else
		// determine the append string at the end of the tag
		bool bContinue = true;
		szTempLocation = *pszTextVal;
		while ( bContinue)
		{
			posComma = szTempLocation.find_first_of(',');
			if(posComma != string::npos) //Prevent Null pointer deletion
			{
				szTempLocation = szTempLocation.substr(szTempLocation.find(",")+1);
				if (isdigit(szTempLocation[0]))  //We found the Append
				{					
					bContinue = false;
				}
			}
			else break;			
		}
		if (!bContinue )
		{
			szAppend = "," + szTempLocation;
		}
#endif

std::vector<CvString> vecButtonArtFile;
#if (DEBUG_IS_MODULAR_ART == 1)
	szButtonsString.getTokens(CvString(","), vecButtonArtFile);
	szDebugBuffer.Format(" Button art vector size after tokenizing by ',': %i", vecButtonArtFile.size());
	gDLL->logMsg("CvXMLLoadUtilityModTools_isCommaFile.log", szDebugBuffer.c_str());
#else
		// set Button Array
		// Array to hold the Button art files
		CvString szTempLocationSubstr;
		szTempLocation = *pszTextVal;
		while (true)
		{
			posComma = szTempLocation.find_first_of(',');
			if(posComma != string::npos) //Prevent Null pointer deletion
			{
				if (szTempLocation[0] == 44) // "," = 44 (ASCII)
				{
					szTempLocation = szTempLocation.substr(szTempLocation.find(",")+1);
				}
				szTempLocationSubstr = szTempLocation;
				posComma = szTempLocationSubstr.find_first_of(',');
				if(posComma != string::npos) //Prevent Null pointer deletion
				{
					szTempLocationSubstr.erase(posComma);
					if (!isdigit(szTempLocationSubstr[0]))
					{
						vecButtonArtFile.push_back(szTempLocationSubstr);
					}
					else break;
				}
				szTempLocation = szTempLocation.substr(szTempLocation.find(",")+1);
			}
			else if (szTempLocation.GetLength() >= 1)
			{
				if (!isdigit(szTempLocationSubstr[0]))
				{
					vecButtonArtFile.push_back(szTempLocationSubstr);
				}
				break;
			}
			else break;
		}		
#endif

		//Check if we need to modularize the files
		bool bNeedChange = false;
/************************************************************************************************/
/* Afforess	                  Start		 06/15/10                                               */
/*                                                                                              */
/*                                                                                              */
/************************************************************************************************/
		CvString m_szFolderPath = GC.getInitCore().getDLLPath() + "//";
/************************************************************************************************/
/* Afforess	                     END                                                            */
/************************************************************************************************/

		m_szFolderPath += szDirName;			// "Modules\Modules\ModuleXXX" 
		for ( unsigned int i = 0; i < vecButtonArtFile.size(); i++)
		{
			szTempLocation = m_szFolderPath;
			szTempLocation += vecButtonArtFile[i];
			//set the Slash properly
			for ( int j = 0; j < szTempLocation.GetLength(); j++)
			{
				if ( szTempLocation[j] == 47)  // 47 = "/"
				{
					szTempLocation[j] = 92;  //92 = "\\", actually 1 backslash of course
				}
			}

			FILE *file = fopen(szTempLocation , "rb");
			if (file != NULL)
			{
				vecButtonArtFile[i] = szDirName + vecButtonArtFile[i];
				fclose(file);
				bNeedChange = true;
			}
		}

		// Now set the new tag string properly
		if (bNeedChange)
		{
			if (szLocationNameStripComma[0] == 44)
			{
				szTempLocation = ",";
			}
			else
			{
				szTempLocation = 0;
			}
			for ( unsigned int i = 0; i < vecButtonArtFile.size(); i++)
			{
				if (i != 0) szTempLocation += ",";
				szTempLocation += vecButtonArtFile[i];
			}
			if (szAppend[0] == 44)   // "," = 44 (ASCII)
			{
				szTempLocation += szAppend;
			}
			*pszTextVal = szTempLocation;
			return true;
		}	
	} 
	return false;
}