/// 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);
				}
			}
		}
	}
Example #2
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);
				}
			}
		}
	}
Example #3
0
/* Check if corrent admin password is given and set player password to new value.
 * I do not test specical chars in passwords. Simply omit them...
 * */
int CyGame::setCivPassword(int ePlayer, const char *szNewPw, const char *szAdminPw)
{
	//convert adminpassword to CvString
	CvString adminPW;
	adminPW.Convert ( GC.getInitCore().getAdminPassword() );
	if( strcmp( adminPW.GetCString(), szAdminPw ) == 0 ){
		CvWString newCivPW( szNewPw );
		GC.getInitCore().setCivPassword((PlayerTypes)ePlayer, newCivPW );
	}else{
		return -1;
	}
	return 0;
}
/// 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++)
/// 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);
				}
			}
		}
	}
/// 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);
		}
	}
}
/// 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;
}
Example #8
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 #9
0
	for(int iI = 0; iI < iNumEntries; iI++)
	{
		kStream >> sTemp;
		if(sTemp != "NO_UNIT")
		{
			iType = GC.getInfoTypeForString(sTemp);
			if(iType != -1)
			{
				kStream >> paiUnitArray[iType];
			}
			else
			{
				CvString szError;
				szError.Format("LOAD ERROR: Unit Type not found: %s", sTemp);
				GC.LogMessage(szError.GetCString());
				CvAssertMsg(false, szError);
				int iDummy;
				kStream >> iDummy;	// Skip it.
			}
		}
	}
}

/// Helper function to write out an integer array of data sized according to number of unit types
void UnitArrayHelpers::Write(FDataStream& kStream, int* paiUnitArray, int iArraySize)
{
	FStringFixedBuffer(sTemp, 64);

	kStream << iArraySize;