Esempio n. 1
0
//---------------------------------------------------------------
void CWeaponSystem::CreateEnvironmentGameTokens(bool frozenEnvironment, bool wetEnvironment)
{
	if(gEnv->bMultiplayer)
		return;

	IGameTokenSystem *pGameTokenSystem = gEnv->pGame->GetIGameFramework()->GetIGameTokenSystem();

	// create the game tokens if not present
	if(pGameTokenSystem)
	{
		pGameTokenSystem->SetOrCreateToken("weapon.effects.ice", TFlowInputData(frozenEnvironment));
		pGameTokenSystem->SetOrCreateToken("weapon.effects.wet", TFlowInputData(wetEnvironment));
	}
}
Esempio n. 2
0
//------------------------------------------------------------------------
bool CPlayerProfile::LoadAttributes(const XmlNodeRef& root, int requiredVersion)
{
	int version = 0;
	const bool bHaveVersion = root->getAttr(VERSION_TAG, version);
	
	if (requiredVersion > 0)
	{
		if (bHaveVersion && version < requiredVersion)
		{
			GameWarning("CPlayerProfile::LoadAttributes: Attributes of profile '%s' have different version (%d != %d). Updated.", GetName(), version, requiredVersion);
			return false;
		}
		else if (!bHaveVersion)
		{
			GameWarning("CPlayerProfile::LoadAttributes: Attributes of legacy profile '%s' has no version (req=%d). Loading anyway.", GetName(), requiredVersion);
		}
		m_attributesVersion = requiredVersion;
	}
	else
		// for default profile we set the version we found in the rootNode
		m_attributesVersion = version;

	int nChilds = root->getChildCount();
	for (int i=0; i<nChilds; ++i)
	{
		XmlNodeRef child = root->getChild(i);
		if (child && strcmp(child->getTag(), "Attr") == 0)
		{
			const char* name = child->getAttr("name");
			const char* value = child->getAttr("value");
			const char* platform = child->getAttr("platform");

			bool platformValid = true;
			if(platform != NULL && platform[0])
			{
#if defined(DURANGO)
				platformValid = (strstr(platform, "xbox")!=0);
#elif defined(ORBIS)
				platformValid = (strstr(platform, "ps4")!=0);
#else
				platformValid = (strstr(platform, "pc")!=0);
#endif
			}

			if (name && value && platformValid)
			{
				m_attributeMap[name] = TFlowInputData(string(value));
			}
		}
	}

	if(m_pManager->HasEnabledOnlineAttributes() && m_pManager->CanProcessOnlineAttributes() && !IsDefault())
	{
		m_pManager->LoadOnlineAttributes(this);
	}

	return true;
}
void CGeomEntity::OnFlowgraphActivation(EntityId entityId, IFlowNode::SActivationInfo* pActInfo, const class CFlowGameEntityNode* pNode)
{
	if (CGeomEntity* pGeomEntity = QueryExtension(entityId))
	{
		if (IsPortActive(pActInfo, eInputPorts_LoadGeometry))
		{
			pGeomEntity->GetEntity()->LoadGeometry(0, GetPortString(pActInfo, eInputPorts_LoadGeometry));
			ActivateOutputPort(entityId, eOutputPorts_Done, TFlowInputData(true));
		}
	}
}
Esempio n. 4
0
//------------------------------------------------------------------------
CSingleTG::CSingleTG()
{
	m_iSerializeIgnoreUpdate = 0;
	m_fSerializeProgress = 0.0f;
	m_idSerializeTarget = 0;

	// create the game tokens if not present
	IGameTokenSystem *pGameTokenSystem = gEnv->pGame->GetIGameFramework()->GetIGameTokenSystem();
	if(pGameTokenSystem)
	{
		for(int i=0; i<SINGLETG_MAX_TARGETS; i++)
		{
			EntityId entityId = 0;
			if (pGameTokenSystem->FindToken(g_TokenTable[i]) == 0)
				pGameTokenSystem->SetOrCreateToken(g_TokenTable[i], TFlowInputData(entityId));
		}
	}
}
void CGameTokenSystem::RegisterListener( const char *sGameToken,IGameTokenEventListener *pListener,bool bForceCreate,bool bImmediateCallback )
{
	CGameToken *pToken = GetToken(sGameToken);

	if(!pToken && bForceCreate)
	{
		pToken = new CGameToken;
		pToken->m_name = sGameToken;
		pToken->m_value = TFlowInputData(0.0f);
		(*m_pGameTokensMap)[pToken->m_name.c_str()] = pToken;
	}

	if(pToken)
	{
		pToken->AddListener( pListener );

		if(bImmediateCallback)
		{
			pListener->OnGameTokenEvent(EGAMETOKEN_EVENT_CHANGE,pToken);
		}
	}
}
	virtual void OnPostUpdate(float fDeltaTime)
	{
		// Get it once, then unregister to prevent unnescessary updates
		if(!m_get)
		{
			gEnv->pGame->GetIGameFramework()->UnregisterListener(this);
			return;
		}
		m_get = false;

		// Grab the container, and make sure its valid (user has to create it for us and pass the valid ID)
		IFlowSystemContainerPtr pContainer = gEnv->pFlowSystem->GetContainer(GetPortInt(&m_actInfo, EIP_ContainerId));
		
		if(!pContainer)
			return;
		
		IEntityItPtr pIt = gEnv->pEntitySystem->GetEntityIterator();

		while (!pIt->IsEnd())
		{
			if (IEntity *pEntity = pIt->Next())
			{
				//skip Local player
				if (IPhysicalEntity *physEnt = pEntity->GetPhysics())
				{
					IActor *pClientActor = gEnv->pGame->GetIGameFramework()->GetClientActor();

					if (!pClientActor)
						return;

					//skip the client actor entity
					if (physEnt == pClientActor->GetEntity()->GetPhysics())
						continue;

					AABB worldBounds;
					pEntity->GetWorldBounds(worldBounds);

					//skip further calculations if the entity is not visible at all...
					if (gEnv->pSystem->GetViewCamera().IsAABBVisible_F(worldBounds) == CULL_EXCLUSION)
						continue;

					Vec3 wpos = pEntity->GetWorldPos();
					Quat rot = pEntity->GetWorldRotation();
					AABB localBounds;

					pEntity->GetLocalBounds(localBounds);

					//get min and max values of the entity bounding box (local positions)
					Vec3 points[2];
					points[0] = wpos + rot * localBounds.min;
					points[1] = wpos + rot * localBounds.max;

					Vec3 pointsProjected[2];

					//project the bounding box min max values to screen positions
					for (int i=0; i<2; ++i)
					{
						gEnv->pRenderer->ProjectToScreen(points[i].x, points[i].y, points[i].z, &pointsProjected[i].x, &pointsProjected[i].y, &pointsProjected[i].z); 
						const float fWidth = (float)gEnv->pRenderer->GetWidth();
						const float fHeight = (float)gEnv->pRenderer->GetHeight();

						//scale projected values to the actual screen resolution
						pointsProjected[i].x *= 0.01f * fWidth;
						pointsProjected[i].y *= 0.01f * fHeight;
					}	

					//check if the projected bounding box min max values are fully or partly inside the screen selection 
					if ((m_screenX <= pointsProjected[0].x && pointsProjected[0].x <= m_screenX2) || 
						(m_screenX >= pointsProjected[0].x && m_screenX2 <= pointsProjected[1].x) || 
						(m_screenX <= pointsProjected[1].x && m_screenX2 >= pointsProjected[1].x) ||
						(m_screenX <= pointsProjected[0].x && m_screenX2 >= pointsProjected[1].x))
					{
						if ((m_screenY <= pointsProjected[0].y && m_screenY2 >= pointsProjected[0].y) ||
							(m_screenY <= pointsProjected[1].y && m_screenY2 >= pointsProjected[0].y) ||
							(m_screenY <= pointsProjected[1].y && m_screenY2 >= pointsProjected[1].y))
						{
							// Add entity to container
							pContainer->AddItem(TFlowInputData(pEntity->GetId()));
						}
					}
				}

			}
		}
	}
bool CGameTokenSystem::_InternalLoadLibrary( const char *filename, const char* tag )
{
	XmlNodeRef root = GetISystem()->LoadXmlFromFile( filename );
	if (!root)
	{
		GameWarning( _HELP("Unable to load game token database: %s"), filename );
		return false;
	}

	if (0 != strcmp( tag, root->getTag() ))
	{
		GameWarning( _HELP("Not a game tokens library : %s"), filename );
		return false;
	}

	// GameTokens are (currently) not saved with their full path
	// we expand it here to LibName.TokenName
	string libName;
	{
		const char *sLibName = root->getAttr("Name");
		if (sLibName == 0) {
			GameWarning( "GameTokensLibrary::LoadLibrary: Unable to find LibName in file '%s'", filename);
			return false;
		}
		libName = sLibName;
	}
 
	// we dont skip already loaded libraries anymore. We need to reload them to be sure that all necessary gametokens are present even if some level has not up-to-date libraries.
	if (!stl::find(m_libraries, libName)) //return true;
		m_libraries.push_back(libName);

	libName+= ".";

	int numChildren = root->getChildCount();
	for (int i=0; i<numChildren; i++)
	{
		XmlNodeRef node = root->getChild(i);

		const char *sName = node->getAttr("Name");
		const char *sType = node->getAttr("Type");
		const char *sValue = node->getAttr("Value");
		const char *sLocalOnly = node->getAttr("LocalOnly");
		int localOnly=atoi(sLocalOnly);

		EFlowDataTypes tokenType = eFDT_Any;
		if (0 == strcmp(sType,"Int"))
			tokenType = eFDT_Int;
		else if (0 == strcmp(sType,"Float"))
			tokenType = eFDT_Float;
		else if (0 == strcmp(sType,"EntityId"))
			tokenType = eFDT_EntityId;
		else if (0 == strcmp(sType,"Vec3"))
			tokenType = eFDT_Vec3;
		else if (0 == strcmp(sType,"String"))
			tokenType = eFDT_String;
		else if (0 == strcmp(sType,"Bool"))
			tokenType = eFDT_Bool;

		if (tokenType == eFDT_Any)
		{
			GameWarning(_HELP("Unknown game token type %s in token %s (%s:%d)"),sType,sName,node->getTag(),node->getLine());
			continue;
		}

		TFlowInputData initialValue = TFlowInputData(string(sValue));

		string fullName (libName);
		fullName+=sName;
		
		IGameToken *pToken = stl::find_in_map(*m_pGameTokensMap,fullName,NULL);
		if (!pToken)
		{
			pToken = SetOrCreateToken( fullName,initialValue );
			if (pToken && localOnly)
				pToken->SetFlags(pToken->GetFlags()|EGAME_TOKEN_LOCALONLY);
		}
	}
	return true;
}