bool CProceduralClipFactory::Register( const char* const typeName, const SProceduralClipFactoryRegistrationInfo& registrationInfo )
{
	CRY_ASSERT( typeName );
	CRY_ASSERT( registrationInfo.pProceduralClipCreator != NULL );
	CRY_ASSERT( registrationInfo.pProceduralParamsCreator != NULL );

	const THash typeNameHash( typeName );

	const char* const registeredTypeNameForHash = FindTypeName( typeNameHash );
	const bool alreadyRegistered = ( registeredTypeNameForHash != NULL );
	if ( alreadyRegistered )
	{
		const bool namesMatch = ( strcmp( typeName, registeredTypeNameForHash ) == 0 );
		if ( namesMatch )
		{
			CryWarning( VALIDATOR_MODULE_GAME, VALIDATOR_ERROR, "CProceduralClipFactory::Register: Register called more than once for type with name '%s'.", typeName );
		}
		else
		{
			CryWarning( VALIDATOR_MODULE_GAME, VALIDATOR_ERROR, "CProceduralClipFactory::Register: Trying to register type with name '%s' and hash '%u', but hash collides with already registered type with name '%s'. Choose a different name for the type.", typeName, typeNameHash.ToUInt32(), registeredTypeNameForHash );
			// TODO: FatalError?
		}

		CRY_ASSERT( false );
		return false;
	}

#if defined(_DEBUG)
	CryLogAlways( "CProceduralClipFactory: Registering procedural clip with name '%s'.", typeName );
#endif
	m_typeHashToName[ typeNameHash ] = string( typeName );
	m_typeHashToRegistrationInfo[ typeNameHash ] = registrationInfo;

	return true;
}
Example #2
0
//------------------------------------------------------------------------------------------------------------------------
bool CCustomEventManager::UnregisterEventListener( ICustomEventListener* pListener, const TCustomEventId eventId )
{
	TCustomEventsMap::iterator eventsDataIter = m_customEventsData.find( eventId );
	if (eventsDataIter != m_customEventsData.end())
	{
		SCustomEventData &     eventData = eventsDataIter->second;
		TCustomEventListeners &listeners = eventData.m_listeners;

		if (listeners.Contains( pListener ))
		{
			listeners.Remove( pListener );
			return true;
		}
		else
		{
			CryWarning( VALIDATOR_MODULE_GAME, VALIDATOR_WARNING, "CCustomEventManager::UnregisterEventListener: Listener isn't registered for event id: %u", eventId );
		}
	}
	else
	{
		CryWarning( VALIDATOR_MODULE_GAME, VALIDATOR_WARNING, "CCustomEventManager::UnregisterEventListener: No event data exists for event id: %u", eventId );
	}

	return false;
}
Example #3
0
float CWorldState::GetFloat(const char * entityName, char * valueName)
{
//	CryLog("CWorldState::GetFloat()");
	float result = 0.f;

	if(worldStateXml)
	{

		XmlNodeRef entityNode = worldStateXml->findChild(entityName);

		if(entityNode)
		{
			const uint32 Count = entityNode->getChildCount();
			for (uint32 Index = 0; Index < Count; ++Index)
			{
				const XmlNodeRef currentNode = entityNode->getChild(Index);
				if(strcmp(currentNode->getTag(),valueName)==0)
				{
					currentNode->getAttr("value",result);
					break;
				}
			}
		}
		else
			CryWarning( VALIDATOR_MODULE_GAME, VALIDATOR_ERROR, "CWorldState::Failed to get world state value!");
	}
	else
		CryWarning( VALIDATOR_MODULE_GAME, VALIDATOR_ERROR, "CWorldState::Failed to get world state value!");

	return result;
}
Example #4
0
void CEditorGame::InitDialogBuffersEnum( IGameToEditorInterface* pGTE )
{
	static const char* BUFFERS_FILENAME = "Libs/FlowNodes/DialogFlowNodeBuffers.xml";

	XmlNodeRef xmlNodeRoot = gEnv->pSystem->LoadXmlFromFile( BUFFERS_FILENAME );
	if (xmlNodeRoot==NULL)
	{
		CryWarning( VALIDATOR_MODULE_GAME, VALIDATOR_WARNING, "CEditorGame::InitDialogBuffersEnum() - Failed to load '%s'. flownode dialog buffers drop down list will be empty.", BUFFERS_FILENAME);
		return;
	}

	uint32 count = xmlNodeRoot->getChildCount();

	const char** bufferNames = new const char*[count];
	bool bOk = true;

	for (uint32 i=0; i<count; ++i)
	{
		XmlNodeRef xmlNode = xmlNodeRoot->getChild( i );
		bufferNames[i] = xmlNode->getAttr("name");
		if (!bufferNames[i])
		{
			CryWarning( VALIDATOR_MODULE_GAME, VALIDATOR_WARNING, "CEditorGame::InitDialogBuffersEnum() - file: '%s' child: %d is missing the 'name' field. flownode dialog buffers drop down list will be empty", BUFFERS_FILENAME, i);
			bOk = false;
		}
	}
	if (bOk)
		pGTE->SetUIEnums("dialogBuffers", bufferNames, count);
	delete[] bufferNames;
}
Example #5
0
/// Force running of the defined test case (ignores dependencies)
void CFeatureTestMgr::ForceRun(const char* testNameFilter)
{
	if (!IsRunning())
	{
		// Ensure no other tests run apart from the selected one
		ResetAllTests(eFTS_Disabled);

		size_t firstTestIndex = ~0;

		for (TFeatureTestVec::iterator iter(m_featureTests.begin()); iter != m_featureTests.end(); ++iter)
		{
			FeatureTestState& ftState = *iter;

			const char* testName = ftState.m_pTest->Name();

			// If test name contains the filter string
			if (strstr(testName, testNameFilter) != NULL)
			{
				ftState.m_state = eFTS_Scheduled;
				
				CryLogAlways("Scheduling test: %s", testName);

				// Store the first valid test found as the one to run first
				if (firstTestIndex == ~0)
					firstTestIndex = std::distance(m_featureTests.begin(), iter);
			}
		}

		if (firstTestIndex != ~0)
		{
			FeatureTestState& ftState = m_featureTests[firstTestIndex];
			ftState.m_state = eFTS_Running;
			m_runningTestIndex = firstTestIndex;
			m_pRunningTest = ftState.m_pTest;
			m_running = true;

			CryLogAlways("Forcefully running Map Tests: %s", m_pRunningTest->Name());

			const float currTime = gEnv->pTimer->GetCurrTime();

			// If test doesn't start
			if (!m_pRunningTest->Start())
			{
				// Reset state
				m_running = false;
				ResetAllTests(eFTS_Disabled);
			}
		}
		else
		{
			CryWarning(VALIDATOR_MODULE_GAME, VALIDATOR_ERROR, "Unable to find test(s) to run: %s", testNameFilter);
		}
	}
	else
	{
		CryWarning(VALIDATOR_MODULE_GAME, VALIDATOR_WARNING, "Tests are already running, can't start: %s", testNameFilter);
	}
}
/// Runs all registered tests (if they meet their dependencies)
void CFeatureTestMgr::RunAll()
{
	// Writing the list of the active registered tests. 
	// This can be useful to later check, when a crash occurs, 
	// which tests were executed and which are skipped 
	// (We will have no valid results for them)
	{
		if(m_pAutoTester && !m_testManifestWritten)
		{
			XmlNodeRef testManifest = GetISystem()->CreateXmlNode("testManifest");
			testManifest->setTag("testmanifest");		

			CryLogAlways("About to dump out the testmanifest xml...");

			for (TFeatureTestVec::iterator iter(m_featureTests.begin()); iter != m_featureTests.end(); ++iter)
			{
				FeatureTestState& fTest = *iter;
				XmlNodeRef testDescrNode = fTest.m_pTest->XmlDescription();
				if(testDescrNode)
				{
					testManifest->addChild(testDescrNode);
				}
				
			}

			m_pAutoTester->WriteTestManifest(testManifest);
			m_testManifestWritten = true;
		}
	}



	if (!IsRunning())
	{
		// Ensure all tests are cleaned up and scheduled to run
		ResetAllTests(eFTS_Scheduled);

		if (StartNextTest() || WaitingForScheduledTests())
		{
			CryLog("Running all map feature tests...");
		}
		else
		{
			CryWarning(VALIDATOR_MODULE_GAME, VALIDATOR_WARNING, "No tests available to run!");
		}
	}
	else
	{
		CryWarning(VALIDATOR_MODULE_GAME, VALIDATOR_WARNING, "Tests are already running, can't start more until tests are complete.");
	}
}
bool CCheckpointSystem::SaveExternalEntity(EntityId id)
{
	//this function allows external logic (flowgraph) to save specific entities
	if(!CHECKPOINT_SAVE_XML_NODE)
	{
		CryWarning(VALIDATOR_MODULE_GAME, VALIDATOR_WARNING, "Tried writing external entity %i while savegame was not open.", (int)id);
		return false;
	}

	//find entity and access external section
	IEntity *pEntity = gEnv->pEntitySystem->GetEntity(id);
	if(pEntity)
	{
		XmlNodeRef externalEntities = CHECKPOINT_SAVE_XML_NODE->findChild(EXTERNAL_ENTITIES_SECTION);
		if(!externalEntities)
		{
			externalEntities = GetISystem()->CreateXmlNode(EXTERNAL_ENTITIES_SECTION);
			CHECKPOINT_SAVE_XML_NODE->addChild(externalEntities);
		}

		IActor *pActor = CCryAction::GetCryAction()->GetIActorSystem()->GetActor(pEntity->GetId());
		if(pActor)
		{
			CryWarning(VALIDATOR_MODULE_GAME, VALIDATOR_WARNING, "The actor %s is additionally saved as external entity.", pEntity->GetName());
		}

		//create entity data
		char entityId[16];
		_snprintf(entityId, sizeof(entityId), "%s%i", "id", id);
		XmlNodeRef nextEntity = GetISystem()->CreateXmlNode(entityId);
		if(nextEntity)
		{
			nextEntity->setAttr("id", pEntity->GetId());
			nextEntity->setAttr("name", pEntity->GetName());
			//save active / hidden
			nextEntity->setAttr("active", pEntity->IsActive());
			nextEntity->setAttr("hidden", pEntity->IsHidden());
			//save translation and rotation (complete tm matrix for simplicity)
			SerializeWorldTM(pEntity, nextEntity, true);
			//add new entity to checkpoint
			externalEntities->addChild(nextEntity);

			return true;
		}

		return false;
	}

	return false;
}
void CGameQueryListener::ConnectToServer(const char* server)
{
	//first check the version of the server ...
	char myVersion[32];
	GetISystem()->GetProductVersion().ToShortString(myVersion);
	string version(myVersion);

	SGameServer* targetServer = FindServer(server);
	if(!targetServer)
	{
		CryWarning(VALIDATOR_MODULE_NETWORK, VALIDATOR_WARNING, "Selected server not found in list!");
		return;
	}

	if(version.compare(targetServer->GetServerGameVersion()) != 0)
	{
		CryWarning(VALIDATOR_MODULE_NETWORK, VALIDATOR_WARNING, "Game versions differ - not connecting!");
		return;
	}

	string addr(server);
	string port;
	int pos = addr.find(":");
	if(pos != string::npos)	//space for port
	{
		port = addr.substr(pos+1, addr.size()-pos);
		addr.erase(pos, addr.size()-pos);
	}

	IConsole* pConsole = gEnv->pConsole;

	pConsole->GetCVar("cl_serveraddr")->Set(addr.c_str());
	if(port.size() > 0)
		pConsole->GetCVar("cl_serverport")->Set(port.c_str());

	string tempHost = pConsole->GetCVar("cl_serveraddr")->GetString();

	SGameStartParams params;	//this would connect to a server
	params.flags = eGSF_Client;
	params.hostname = tempHost.c_str();
	params.pContextParams = NULL;
	params.port = pConsole->GetCVar("cl_serverport")->GetIVal();

	CCryAction *action = (CCryAction*) (gEnv->pGame->GetIGameFramework());
	if(action)
	{
		gEnv->pConsole->ExecuteString("net_lanbrowser 0");
		action->StartGameContext(&params);
	}
}
    virtual void ProcessEvent( EFlowEvent event, SActivationInfo *pActInfo )
    {
        switch (event)
        {
        case eFE_Initialize:
            break;
        case eFE_Activate:
        {
            if(!IsPortActive(pActInfo, EIP_Load))
                return;

            // get the file name
            string pathAndfileName;
            const string fileName = GetPortString(pActInfo, EIP_FileName);
            if (fileName.empty())
                return;

            ILevelInfo* pCurrentLevel = gEnv->pGame->GetIGameFramework()->GetILevelSystem()->GetCurrentLevel();
            string path = pCurrentLevel ? pCurrentLevel->GetPath() : "";
            pathAndfileName.Format("%s/%s", path.c_str(), fileName.c_str());

            // try to load it
            XmlNodeRef root = GetISystem()->LoadXmlFromFile( pathAndfileName );
            if (root == NULL)
            {
                CryWarning(VALIDATOR_MODULE_SYSTEM, VALIDATOR_WARNING, "FlowGraph: TimeOfDay Loading Node: Could not load tod file %s. Aborting.", pathAndfileName.c_str());
                ActivateOutput(pActInfo, EOP_Fail, true);
                return;
            }

            // get the TimeofDay interface
            ITimeOfDay *pTimeOfDay = gEnv->p3DEngine->GetTimeOfDay();
            if (pTimeOfDay == NULL)
            {
                CryWarning(VALIDATOR_MODULE_SYSTEM, VALIDATOR_WARNING, "FlowGraph: TimeOfDay Loading Node: Could not obtain ITimeOfDay interface from engine. Aborting.");
                ActivateOutput(pActInfo, EOP_Fail, true);
                return;
            }

            // try to serialize from that file
            pTimeOfDay->Serialize( root,true );
            pTimeOfDay->Update(true, true);

            ActivateOutput(pActInfo, EOP_Success, true);
        }
        break;
        }
    }
Example #10
0
	virtual void ProcessEvent( EFlowEvent event, SActivationInfo *pActInfo )
	{
		switch (event)
		{
		case eFE_Initialize:
			break;
		case eFE_Activate:
			IGameFramework* const pGameFramework = gEnv->pGame->GetIGameFramework();
			IGameObject* const pGameObject = pGameFramework->GetGameObject(pActInfo->pEntity->GetId());

			if(IsPortActive(pActInfo, EIP_Enslave) || IsPortActive(pActInfo, EIP_UnEnslave) )
			{
				IAnimatedCharacter* const pAnimChar = pGameObject ? (IAnimatedCharacter*) pGameObject->QueryExtension("AnimatedCharacter") : NULL;
				if(pAnimChar && pAnimChar->GetActionController())
				{
					const EntityId slaveChar = GetPortEntityId(pActInfo, EIP_Slave);
					IGameObject* pSlaveGameObject = pGameFramework->GetGameObject(slaveChar);
					IAnimatedCharacter* pSlaveAnimChar = pSlaveGameObject ? (IAnimatedCharacter*) pSlaveGameObject->QueryExtension("AnimatedCharacter") : NULL;

					if(pSlaveAnimChar && pSlaveAnimChar->GetActionController())
					{
						IAnimationDatabaseManager &dbManager = gEnv->pGame->GetIGameFramework()->GetMannequinInterface().GetAnimationDatabaseManager();
						uint32 db_crc32 = CCrc32::ComputeLowercase(GetPortString(pActInfo, EIP_DB));
						const IAnimationDatabase* db = dbManager .FindDatabase(db_crc32);

						const string& scopeContextName = GetPortString(pActInfo, EIP_ScopeContext);
						const string& requestedScopeContext = scopeContextName.empty() ? "SlaveChar" : scopeContextName;
						const TagID scopeContext = pAnimChar->GetActionController()->GetContext().controllerDef.m_scopeContexts.Find(scopeContextName.c_str());

						pAnimChar->GetActionController()->SetSlaveController(*pSlaveAnimChar->GetActionController(), scopeContext, IsPortActive(pActInfo, EIP_Enslave) ? true : false, db);
						ActivateOutput(pActInfo, EOP_Success, 1 );
					}
					else
					{
						CryWarning( VALIDATOR_MODULE_GAME, VALIDATOR_ERROR, "No GameObject or Animated character found for the slave");
						ActivateOutput(pActInfo, EOP_Fail, 1 );
					}
				}
				else
				{
					CryWarning( VALIDATOR_MODULE_GAME, VALIDATOR_ERROR, "No GameObject or AnimatedCharacter found");
					ActivateOutput(pActInfo, EOP_Fail, 1 );
				}
			}

			break;
		}
	}
Example #11
0
bool CFlowGraphDebugger::RemoveAllBreakpointsForNode(IFlowGraphPtr pFlowgraph, TFlowNodeId nodeID)
{
	CRY_ASSERT(nodeID != InvalidFlowNodeId);

	if (nodeID == InvalidFlowNodeId)
		return false;

	TDebugInfo::iterator iterDebugInfo = m_DebugInfo.find(pFlowgraph);
	if (iterDebugInfo != m_DebugInfo.end())
	{
		TFlowNodesDebugInfo* flownodesDebugInfo = &(*iterDebugInfo).second;
		TFlowNodesDebugInfo::iterator iterNode = flownodesDebugInfo->find(nodeID);

		if (iterNode != flownodesDebugInfo->end())
		{
			flownodesDebugInfo->erase(iterNode);

			for (CListenerSet<IFlowGraphDebugListener*>::Notifier notifier(m_Listeners); notifier.IsValid(); notifier.Next())
			{
				notifier->OnAllBreakpointsRemovedForNode(pFlowgraph, nodeID);
			}

			return true;
		}
	}
	else
	{
		CryWarning(VALIDATOR_MODULE_FLOWGRAPH, VALIDATOR_WARNING, "Flownode %d is not in debug list [CFlowgraphDebugger::RemoveBreakPointsForNode]", nodeID);
		return false;
	}

	return false;
}
void CFlowNode_AISequenceAction_WeaponHolster::HandleSequenceEvent(AIActionSequence::SequenceEvent sequenceEvent)
{
	switch(sequenceEvent)
	{
	case AIActionSequence::StartAction:
		{
			CRY_ASSERT_MESSAGE(m_actInfo.pEntity, "entity has magically gone");
			if (!m_actInfo.pEntity)
			{
				// the entity has gone for some reason, at least make sure the action gets finished properly and the FG continues
				CancelSequenceAndActivateOutputPort(OutputPort_Done);
				return;
			}

			assert(gEnv && gEnv->pGame && gEnv->pGame->GetIGameFramework() && gEnv->pGame->GetIGameFramework()->GetIActorSystem());
			IActor* pActor = gEnv->pGame->GetIGameFramework()->GetIActorSystem()->GetActor(m_actInfo.pEntity->GetId());
			if (!pActor)
			{
				CRY_ASSERT_MESSAGE(0, "Provided entity must be an IActor");
				CryWarning(VALIDATOR_MODULE_AI, VALIDATOR_WARNING, "Provided entity %s must be an IActor", m_actInfo.pEntity->GetName());
				CancelSequenceAndActivateOutputPort(OutputPort_Done);
				return;
			}

			const bool skipHolsterAnimation = GetPortBool(&m_actInfo, InputPort_SkipHolsterAnimation);
			pActor->HolsterItem(true, !skipHolsterAnimation);
			FinishSequenceActionAndActivateOutputPort(OutputPort_Done);
		}
		break;
	}
}
bool CWriter::FinishWritingFile()
{
	// if this happens, most likely is an overflow of some of the hard coded limits ( which usually is caused by an error in game side ).
	if (m_hasInternalError)
		CryWarning( VALIDATOR_MODULE_SYSTEM, VALIDATOR_ERROR, "XMLCPB: ERROR in binary save generation. The savegame is corrupted." );

	if (!m_compressor->m_errorWritingIntoFile)	
	{
		if (!m_rootAddr.IsValid())
			Done();

		assert( m_rootAddr.IsValid() );


		m_mainBuffer.WriteToFile(); // this actually writes only the last data remains, because it has been writing all along the process.
		m_tableTags.WriteToFile();
		m_tableAttrNames.WriteToFile();
		m_tableStrData.WriteToFile();
		m_tableAttrSets.WriteToFile();

		CreateFileHeader(m_compressor->GetFileHeader());

		m_compressor->FlushZLibBuffer();
	}	
	
		
	return !m_compressor->m_errorWritingIntoFile;
}
bool CWriter::WriteAllIntoMemory( uint8* &rpData, uint32& outSize )
{
	if (!m_rootAddr.IsValid())
		Done();

	SFileHeader fileHeader;
	CreateFileHeader(fileHeader);

	outSize = sizeof(fileHeader);
	outSize += m_tableTags.GetDataSize();
	outSize += m_tableAttrNames.GetDataSize();
	outSize += m_tableStrData.GetDataSize();
	outSize += m_tableAttrSets.GetDataSize();
	outSize += m_mainBuffer.GetDataSize();

	if (outSize > 0)
	{
		rpData = (uint8*)realloc((void*)rpData, outSize*sizeof(uint8));

		uint32 uWriteLoc = 0;
		WriteDataIntoMemory( rpData, &fileHeader, sizeof(fileHeader), uWriteLoc);
		m_mainBuffer.WriteToMemory( rpData, uWriteLoc );
		m_tableTags.WriteToMemory( rpData, uWriteLoc );
		m_tableAttrNames.WriteToMemory( rpData, uWriteLoc );
		m_tableStrData.WriteToMemory( rpData, uWriteLoc );
		m_tableAttrSets.WriteToMemory( rpData, uWriteLoc );
	}

	if (m_hasInternalError)
		CryWarning( VALIDATOR_MODULE_SYSTEM, VALIDATOR_ERROR, "XMLCPB: ERROR in binary save-into-memory generation. (probably something wrong in a pooled entity). The data will be corrupted" );

	return (outSize > 0);
}
Example #15
0
void CProfileOptions::Init()
{
	XmlNodeRef root = GetISystem()->LoadXmlFromFile("libs/config/profiles/default/attributes.xml");
	if(!root)
	{
		CryWarning(VALIDATOR_MODULE_GAME, VALIDATOR_WARNING, "Failed loading attributes.xml");
		return;
	}

	CGameXmlParamReader reader(root);
	const int childCount = reader.GetUnfilteredChildCount();
	m_allOptions.reserve(childCount);


	for (int i = 0; i < childCount; ++i)
	{
		XmlNodeRef node = reader.GetFilteredChildAt(i);
		if(node)
		{
			AddOption(node);
		}
	}

	IPlayerProfileManager* const profileManager = g_pGame->GetIGameFramework()->GetIPlayerProfileManager();
	CRY_ASSERT_MESSAGE(profileManager != NULL, "IPlayerProfileManager doesn't exist - profile options will not be updated");
	if(profileManager)
		profileManager->AddListener(this, false);
}
Example #16
0
	virtual void OnHUDEvent(const SHUDEvent& event)
	{
		int eventID = GetPortInt(&m_pActInfo, 0);
		if(event.eventType == eventID)
		{
			ActivateOutput(&m_pActInfo, eOP_EventFired, 1);
			for(unsigned int i = 0; i < event.GetDataSize(); i++)
			{
				switch(event.GetData(i).m_type)
				{
				case SHUDEventData::eSEDT_voidptr:
					break;
				case SHUDEventData::eSEDT_bool:				
					break;
				case SHUDEventData::eSEDT_int:
					break;
				case SHUDEventData::eSEDT_float:	
					{
						if(eventID == eHUDEvent_LeavingBattleArea)
						{
							float fDeathTimer = event.GetData(i).GetFloat();
							ActivateOutput(&m_pActInfo, eOP_DeathTimer, fDeathTimer);
						}
					}
					break;
				case SHUDEventData::eSEDT_undef:
				default:
					CryWarning(VALIDATOR_MODULE_FLOWGRAPH, VALIDATOR_WARNING, "[CFlowNode_BattleAreaListener] HudEvent data unknown.");
					break;
				}
			}
		}
	}
XmlNodeRef CCheckpointSystem::LoadXMLNode(const char *identifier)
{
	if(!identifier)
		return NULL;
	//check whether a checkpoint is currently open
	if(!CHECKPOINT_LOAD_XML_NODE)
	{
		CryWarning(VALIDATOR_MODULE_GAME, VALIDATOR_WARNING, "Tried reading checkpoint section %s while checkpoint was not open.", identifier);
		return NULL;
	}

	int numChildren = CHECKPOINT_LOAD_XML_NODE->getChildCount();
	for(int i = 0; i < numChildren; ++i)
	{
		XmlNodeRef child = CHECKPOINT_LOAD_XML_NODE->getChild(i);
		//return external section if name matches
		const char *key = "external";
		const char *attribName = child->getAttr(key);
		if(attribName)
		{
			//check name
			if(!stricmp(identifier, attribName))
				return child;
		}
	}

	return NULL;
}
XmlNodeRef CCheckpointSystem::ReadXML(const char *fileName)
{
	IPlayerProfileManager *pPlayerProfMan = CCryAction::GetCryAction()->GetIPlayerProfileManager();;

	string path;
	if(!pPlayerProfMan)	
	{
		//on consoles there is no profile manager
		path = CONSOLE_SAVEGAME_DIRECTORY;
	}
	else
	{
		const char* sharedSaveGameFolder = pPlayerProfMan->GetSharedSaveGameFolder();
		path = sharedSaveGameFolder;
	}

	path = PathUtil::AddSlash(path);
	path.append(fileName);

	//read XML data from given checkpoint file
	_smart_ptr<IXmlParser> xmlParser;
	xmlParser.reset(GetISystem()->GetXmlUtils()->CreateXmlParser());
	XmlNodeRef data = xmlParser->ParseFile(path.c_str(), true);

	if(!data)
		CryWarning(VALIDATOR_MODULE_GAME, VALIDATOR_ERROR, "Failed reading checkpoint at %s", path.c_str());

	return data;
}
void CGameTokenSystem::SerializeSaveLevelToLevel( const char** ppGameTokensList, uint32 numTokensToSave )
{
	{
		ScopedSwitchToGlobalHeap globalHeap;
		m_levelToLevelSave = gEnv->pSystem->CreateXmlNode( "GameTokensLevelToLevel" );
	}

	IXmlSerializer* pSerializer = gEnv->pSystem->GetXmlUtils()->CreateXmlSerializer();
	ISerialize* pSer = pSerializer->GetWriter(m_levelToLevelSave);
	TSerialize ser = TSerialize(pSer);

	{
		ScopedSwitchToGlobalHeap globalHeap;
		uint32 numTokensSaved = 0;
		for (uint32 i=0; i<numTokensToSave; ++i)
		{
			const char* pName = ppGameTokensList[i];
			CGameToken* pToken = GetToken( pName );
			if (pToken)
			{
				numTokensSaved++;
				ser.BeginGroup("Token");
				ser.Value( "name",pToken->m_name );
				pToken->m_value.Serialize(ser);
				ser.EndGroup();
			}
			else
				CryWarning(VALIDATOR_MODULE_GAME, VALIDATOR_ERROR, "GameTokenSystem. GameToken %s was not found when trying to serialize (save) level to level", pName ? pName : "<NULL>");
		}
		ser.Value( "numTokens", numTokensSaved );
	}
	pSerializer->Release();
}
Example #20
0
bool CActionScope::InstallAnimation(const SAnimationEntry &animEntry, int layer, const SAnimBlend &animBlend)
{
    if (animEntry.animRef.IsEmpty())
    {
        StopAnimationOnLayer(layer, animBlend.duration);
        return true;
    }
    else
    {
        int animID = m_scopeContext.charInst->GetIAnimationSet()->GetAnimIDByCRC(animEntry.animRef.crc);

        if (animID >= 0)
        {
            //--- Cleared for install, install across scopes
            CryCharAnimationParams animParams;
            InitAnimationParams(animEntry, layer, animBlend, animParams);
            return InstallAnimation(animID, animParams);
        }
        else
        {
            CryWarning(VALIDATOR_MODULE_GAME, VALIDATOR_WARNING, "Invalid anim ref %s on scope %s in database %s", animEntry.animRef.GetString(), m_name.c_str(), m_scopeContext.database->GetFilename());

            StopAnimationOnLayer(layer, animBlend.duration);
            return false;
        }
    }
}
void CCheckpointSystem::WriteXML(XmlNodeRef data, const char *fileName)
{
	IPlayerProfileManager *pPlayerProfMan = CCryAction::GetCryAction()->GetIPlayerProfileManager();;

	string path;
	if(!pPlayerProfMan)
	{
		path = CONSOLE_SAVEGAME_DIRECTORY;
	}
	else
	{
		const char* sharedSaveGameFolder = pPlayerProfMan->GetSharedSaveGameFolder();
		path = sharedSaveGameFolder;
	}

	path = PathUtil::AddSlash(path);
	path.append(fileName);
	if(data)
	{
		//write checkpoint data to xml file with given name
		const string xmlHeader("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n");

		bool bSuccess = data->saveToFile(path.c_str(), 32767/2, NULL);
		if (bSuccess)
		{
			//remember last saved checkpoint for "quickload"
			g_lastSavedCheckpoint = fileName;
		}
		else
			CryWarning(VALIDATOR_MODULE_GAME, VALIDATOR_ERROR, "Failed writing checkpoint file at %s", path.c_str());
	}
}
void CGameTokenSystem::SerializeReadLevelToLevel()
{
	if (!m_levelToLevelSave)
		return;

	IXmlSerializer* pSerializer = gEnv->pSystem->GetXmlUtils()->CreateXmlSerializer();
	ISerialize* pSer = pSerializer->GetReader( m_levelToLevelSave );
	TSerialize ser = TSerialize(pSer);

	{
		ScopedSwitchToGlobalHeap globalHeap;
		uint32 numTokens = 0;
		ser.Value( "numTokens", numTokens );
		for (uint32 i=0; i<numTokens; i++)
		{
			ser.BeginGroup("Token");
			string tokenName;
			ser.Value( "name", tokenName );
			CGameToken* pToken = GetToken( tokenName.c_str() );
			if (pToken)
				pToken->m_value.Serialize(ser);
			else
				CryWarning(VALIDATOR_MODULE_GAME, VALIDATOR_ERROR, "GameTokenSystem. GameToken '%s' was not found when trying to serialize (read) level to level", tokenName.c_str() );
			ser.EndGroup();
		}
	}
	pSerializer->Release();
	m_levelToLevelSave = NULL; // this frees it
}
Example #23
0
void CEditorGame::InitActionMapsEnums(IGameToEditorInterface* pGTE)
{
	IActionMapManager* pAM = m_pGame->GetIGameFramework()->GetIActionMapManager();
	IActionMapIteratorPtr iter = pAM->CreateActionMapIterator();

	const int numActionMaps = pAM->GetActionMapsCount();

	if(numActionMaps == 0)
		return;

	const char** nameValueStrings = new const char*[numActionMaps];
	int curEntryIndex = 0;
	while (IActionMap* pMap = iter->Next())
	{
		assert(curEntryIndex < numActionMaps);
		PREFAST_ASSUME(curEntryIndex < numActionMaps);
		nameValueStrings[curEntryIndex++] = pMap->GetName();

		if (curEntryIndex > numActionMaps)
		{
			CryWarning(VALIDATOR_MODULE_GAME, VALIDATOR_WARNING, "[InitActionMapsEnums] Wrong number of Action Maps.");
			break;
		}
	}

	pGTE->SetUIEnums("action_maps", nameValueStrings, numActionMaps);

	delete[] nameValueStrings;
}
Example #24
0
void CDLCManager::OnDLCMountFailed(IPlatformOS::EDLCMountFail reason)
{
	CryWarning(VALIDATOR_MODULE_GAME, VALIDATOR_WARNING, "Unable to load DLC, error code: %d", reason);
	const char* sWarning = NULL;
	switch (reason)
	{
	case IPlatformOS::eDMF_FileCorrupt:
		sWarning = "DLCFileCorrupt";
		break;
	case IPlatformOS::eDMF_DiskCorrupt:
		sWarning = "DLCDiskCorrupt";
		break;
	case IPlatformOS::eDMF_XmlError:
		sWarning = "DLCXmlError";
		break;
	}
	if (sWarning)
	{
		RequestDLCWarning(sWarning, 4, true);
	}
	else
	{
		CRY_ASSERT_MESSAGE(false, "Unrecognised DLC error");
	}
}
bool CCheckpointSystem::LoadLastCheckpoint()
{
	if(!g_lastSavedCheckpoint.empty())
		return LoadGame(g_lastSavedCheckpoint.c_str());
	CryWarning(VALIDATOR_MODULE_GAME, VALIDATOR_WARNING, "Can't load latest checkpoint : no recent checkpoint found!");
	return false;
}
Example #26
0
// Console commands
void CFeatureTestMgr::CmdMapRunAll(IConsoleCmdArgs *pArgs)
{
#if ENABLE_FEATURE_TESTER
	CFeatureTester* pFTester = CFeatureTester::GetInstance();

	bool reloadLevel = false;
	bool quickload = false;

	int argCount = pArgs->GetArgCount();
	for (int argIndex = 0; argIndex < argCount; ++argIndex)
	{
		const char* arg = pArgs->GetArg(argIndex);
		if (!stricmp("reloadlevel", arg))
		{
			reloadLevel = true;
		}
		if (!stricmp("quickload", arg))
		{
			quickload = true;
		}
	}

	if (pFTester)
		pFTester->GetMapFeatureTestMgr().ScheduleRunAll(reloadLevel, quickload, 0.0f);
#else
	CryWarning(VALIDATOR_MODULE_GAME, VALIDATOR_ERROR, "Feature testing not enabled in this build.");
#endif
}
bool CCheckpointSystem::RepairEntityId(EntityId &id, const char *pEntityName)
{
	//EntityId's may change on level export -> fix id
	if(pEntityName)
	{
		//test the original entity id
		IEntity *pOriginalEntity = gEnv->pEntitySystem->GetEntity(id);
		if(pOriginalEntity && !stricmp(pOriginalEntity->GetName(), pEntityName))
			return true; //seems correct

		IEntity *pNewEntity = gEnv->pEntitySystem->FindEntityByName(pEntityName);
		if(!pNewEntity)
			CryWarning(VALIDATOR_MODULE_GAME, VALIDATOR_WARNING, "Entity %s in loaded checkpoint could not be found. This means the checkpoint file is not compatible with this level version.", pEntityName);
		else if(!stricmp(pNewEntity->GetName(), pEntityName))
		{
			//if the level was re-exported, the entity id might differ
			CHECKPOINT_RESAVE_NECESSARY = true;
			//this is a weakness of our entity system/editor and might be fixed in future
			id = pNewEntity->GetId();
			return true;
		}
		return false;
	}

	return false;
}
	virtual void ProcessEvent(EFlowEvent event, SActivationInfo* pActInfo)
	{
		switch (event)
		{
		case eFE_Initialize:
			{
				break;
			}
		case eFE_Activate:
			{
				const string& variableName = GetPortString(pActInfo, eIn_VariableName);

				if (variableName.empty())
				{
					CryWarning(VALIDATOR_MODULE_GAME, VALIDATOR_WARNING, "CAction:DRS_SetVariable: Cannot be executed without a Variable Name.");
					break;
				}

				const string& collectionName = GetPortString(pActInfo, eIn_VariableCollectionName);
				EntityId entityID = GetPortEntityId(pActInfo, eIn_EntityID);

				DRS::IVariableCollection* variableCollection = GetVariableCollection(entityID, collectionName);

				if (variableCollection)
				{					
					const string& newVariableValue = GetPortString(pActInfo, eIn_StringValue);
					variableCollection->SetVariableValue(variableName, newVariableValue.c_str(), true, GetPortFloat(pActInfo, eIn_ResetTime));
					ActivateOutput(pActInfo, eOut_VariableCollectionName, variableCollection->GetName().GetText());
				}

				break;
			}
		}
	}
Example #29
0
bool CActionScope::InstallAnimation(const SAnimationEntry &animEntry, int layer, const SAnimBlend &animBlend)
{
	if ((BIT(layer) & m_mutedAnimLayerMask) == BIT(layer))
	{
		return false;
	}

	if (animEntry.animRef.IsEmpty())
	{
		StopAnimationOnLayer(layer, animBlend.duration);
		return true;
	}
	else
	{
		int animID = m_scopeContext.pCharInst->GetIAnimationSet()->GetAnimIDByCRC(animEntry.animRef.crc);

		if (animID >= 0)
		{
			//--- Cleared for install, install across scopes
			CryCharAnimationParams animParams;
			InitAnimationParams(animEntry, layer, animBlend, animParams);
			return InstallAnimation(animID, animParams);
		}
		else
		{
			CryWarning(VALIDATOR_MODULE_GAME, VALIDATOR_WARNING, "Invalid anim ref '%s' on scope '%s' in database '%s'. Skeleton '%s'", animEntry.animRef.c_str(), m_name.c_str(), m_scopeContext.pDatabase->GetFilename(), m_scopeContext.pCharInst->GetIDefaultSkeleton().GetModelFilePath());

			StopAnimationOnLayer(layer, animBlend.duration);
			return false;
		}
	}
}
void CFlowNode_AISequenceAction_WeaponDrawFromInventory::HandleSequenceEvent(AIActionSequence::SequenceEvent sequenceEvent)
{
	switch(sequenceEvent)
	{
	case AIActionSequence::StartAction:
		{
			CRY_ASSERT_MESSAGE(m_actInfo.pEntity, "entity has magically gone");
			if (!m_actInfo.pEntity)
			{
				// the entity has gone for some reason, at least make sure the action gets finished properly and the FG continues
				CancelSequenceAndActivateOutputPort(OutputPort_Done);
				return;
			}

			assert(gEnv && gEnv->pGame && gEnv->pGame->GetIGameFramework() && gEnv->pGame->GetIGameFramework()->GetIActorSystem());
			IActor* pActor = gEnv->pGame->GetIGameFramework()->GetIActorSystem()->GetActor(m_actInfo.pEntity->GetId());
			if (!pActor)
			{
				CRY_ASSERT_MESSAGE(0, "Provided entity must be an IActor");
				CryWarning(VALIDATOR_MODULE_AI, VALIDATOR_WARNING, "Provided entity %s must be an IActor", m_actInfo.pEntity->GetName());
				CancelSequenceAndActivateOutputPort(OutputPort_Done);
				return;
			}

			assert(gEnv && gEnv->pGame && gEnv->pGame->GetIGameFramework() && gEnv->pGame->GetIGameFramework()->GetIItemSystem());
			IItemSystem* pItemSystem = gEnv->pGame->GetIGameFramework()->GetIItemSystem();

			IInventory* pInventory = pActor->GetInventory();
			if (!pInventory)
			{
				CRY_ASSERT_MESSAGE(0, "Actor has no inventory");
				CryWarning(VALIDATOR_MODULE_AI, VALIDATOR_WARNING, "Actor %s has no inventory", m_actInfo.pEntity->GetName());
				CancelSequenceAndActivateOutputPort(OutputPort_Done);
				return;
			}

			pInventory->SetHolsteredItem(EntityId(0));	// otherwise trying to holster the new weapon later on will not work (i. e. will do nothing)

			// draw the weapon
			const string& weaponName = GetPortString(&m_actInfo, InputPort_WeaponName);
			pItemSystem->SetActorItem(pActor, weaponName.c_str(), false);

			FinishSequenceActionAndActivateOutputPort(OutputPort_Done);
		}
		break;
	}
}