Example #1
0
void CFlowGraphModuleManager::RescanModuleNames(bool bGlobal)
{
	CryFixedStringT<512> path = "";

	if(bGlobal)
	{
		path = PathUtil::GetGameFolder().c_str();
		path += "\\Libs\\";
	}
	else
	{
		if(gEnv->IsEditor())
		{
			char *levelName;
			char *levelPath;
			gEnv->pGame->GetIGameFramework()->GetEditorLevel(&levelName, &levelPath);
			path = levelPath;
		}
		else
		{
			ILevel *pLevel = gEnv->pGame->GetIGameFramework()->GetILevelSystem()->GetCurrentLevel();
			if (pLevel)
			{
				path = pLevel->GetLevelInfo()->GetPath();
			}
		}
	}

	if(false == path.empty())
	{
		path += MODULE_FOLDER_NAME;
		ScanFolder(path, bGlobal);	
	}
}
void CCheckpointSystem::RepairLevelName(CryFixedStringT<32> &levelName)
{
	if(levelName.empty())
		return;
	int posSlash = levelName.rfind('/');
	if(posSlash != levelName.npos)	//This is a work-around for the editor/fullgame incompatible level name convention
		levelName = levelName.substr(posSlash+1, levelName.size() - posSlash);
}
bool CCheckpointSystem::LoadGame(const char* fileName)
{
	//make sure not not save/load recursively or multiple times at once
	if(CHECKPOINT_SAVE_XML_NODE || CHECKPOINT_LOAD_XML_NODE)
		return false;

	//set extension
	FixedCheckpointString file(fileName);
	SetFilenameExtension(file);

	CHECKPOINT_LOAD_XML_NODE = ReadXML(file.c_str());
	if(!CHECKPOINT_LOAD_XML_NODE)
		return false;

	CryWarning(VALIDATOR_MODULE_GAME, VALIDATOR_COMMENT, "Loading checkpoint %s", file.c_str());

	//check for EntityId errors
	CHECKPOINT_RESAVE_NECESSARY = false;

	//process meta data
	SCheckpointData metaData;
	if(!ReadMetaData(CHECKPOINT_LOAD_XML_NODE, metaData))
		return false;

	//check version number
	if(metaData.m_versionNumber != CHECKPOINT_VERSION_NUMBER)
	{
		CryWarning(VALIDATOR_MODULE_GAME, VALIDATOR_ERROR, "Checkpoint version number (%i) does not match current version (%i). Please reexport all checkpoints of this level to prevent errors!", metaData.m_versionNumber, CHECKPOINT_VERSION_NUMBER);
	}
 
	//check for level mismatch
	CryFixedStringT<32> curlevelName = CCryAction::GetCryAction()->GetLevelName();
	RepairLevelName(curlevelName);
	if(curlevelName.empty() || stricmp(metaData.m_levelName.c_str(), curlevelName.c_str()))
	{
		if(!LoadCheckpointMap(metaData, curlevelName))
			return false;
	}
	else
	{
		//reset the dynamic parts of the engine
		ResetEngine();
	}

	//read actor data and respawn AI
	// TODO For now, not restoring actor info (AI) - If this happens later, support needs to be added for entity pools
	//RespawnAI(CHECKPOINT_LOAD_XML_NODE);

	//load gametokens again
	ReadGameTokens(CHECKPOINT_LOAD_XML_NODE);

	//let game read
	if (m_pGameHandler)
	{
		m_pGameHandler->OnReadData(CHECKPOINT_LOAD_XML_NODE);
	}

	//resets some gameplay data like action filters etc.
	RestartGameplay();

	//load external entities, that are controlled by flowgraph
	LoadExternalEntities(CHECKPOINT_LOAD_XML_NODE);

	//inform listeners
	UpdateListener(metaData, false);

	//trigger flowgraph node
	OnCheckpointLoaded(metaData);

	//draw text message on screen
	//static const ColorF color (0.0f, 0.85f, 0.2f, 1.0f);
	//g_pGame->GetIGameFramework()->GetIPersistantDebug()->Add2DText("Checkpoint loaded", 2.5f, color, 2.0f);

	//checkpoint file sanity check
	if(CHECKPOINT_RESAVE_NECESSARY)
	{
		CryWarning(VALIDATOR_MODULE_GAME, VALIDATOR_WARNING, "Checkpoint file contained obsolete or wrong data, trying to re-save checkpoint.");
		//resave checkpoint to fix changed entity Ids
		SaveGame(metaData.m_checkPointId, fileName);
		//make sure the script entity is aware of the activity
		OnCheckpointLoaded(metaData);
	}

	CHECKPOINT_LOAD_XML_NODE = NULL;

	//when a checkpoint was loaded, it becomes the most recent checkpoint
	g_lastSavedCheckpoint = fileName;

	//make sure the scripts are clean
	//CXP : this caused a crash after some reloads, which hints to problems in the gamerules script
	//gEnv->pScriptSystem->ForceGarbageCollection();

	return true;
}