Exemplo n.º 1
0
void CGameStats::Connected()
{
	//should not be called
	if(gEnv->IsClient() && !gEnv->bServer)//pure clients
	{
		if(IGameRulesSystem* pGR = gEnv->pGame->GetIGameFramework()->GetIGameRulesSystem())
		{
			IGameRules *pR = pGR->GetCurrentGameRules();
			if(pR)
			{
				IEntityScriptProxy *pScriptProxy=static_cast<IEntityScriptProxy *>(pR->GetEntity()->GetProxy(ENTITY_PROXY_SCRIPT));
				if (pScriptProxy)
				{
					string gameState = pScriptProxy->GetState();
					if(gameState=="InGame")
					{
						m_playing=true;
						m_gameMode = pR->GetEntity()->GetClass()->GetName();
					}
				}		
			}		
		}
		if(m_statsTrack)
			m_statsTrack->Reset();
	}
}
Exemplo n.º 2
0
const char *CHUDTagNames::GetPlayerRank(EntityId uiEntityId)
{
	const char *szRank = NULL;

	IGameRules *pGameRules = g_pGame->GetGameRules();

	int iPlayerRank = 0;
	if(IScriptTable *pGameRulesTable=pGameRules->GetEntity()->GetScriptTable())
	{
		HSCRIPTFUNCTION pfnGetPlayerRank = NULL;
		if(pGameRulesTable->GetValue("GetPlayerRank",pfnGetPlayerRank) && pfnGetPlayerRank)
		{
			Script::CallReturn(gEnv->pScriptSystem,pfnGetPlayerRank,pGameRulesTable,ScriptHandle(uiEntityId),iPlayerRank);
			gEnv->pScriptSystem->ReleaseFunc(pfnGetPlayerRank);
		}
	}
  
	if(iPlayerRank)
	{
		static string strRank;
		static wstring wRank;
		strRank.Format("@ui_short_rank_%d",iPlayerRank);
		if(gEnv->pSystem->GetLocalizationManager()->LocalizeLabel(strRank,wRank))
		{
			ConvertWString(wRank,strRank);
		}
		szRank = strRank.c_str();
	}

	return szRank;
}
Exemplo n.º 3
0
void CUIHUD3D::SpawnHudEntities()
{
    RemoveHudEntities();

    if (gEnv->IsEditor() && gEnv->IsEditing())
        return;

    const char* hudprefab = NULL;
    IGameRules* pGameRules = gEnv->pGame->GetIGameFramework()->GetIGameRulesSystem()->GetCurrentGameRules();
    if (pGameRules)
    {
        IScriptTable* pTable = pGameRules->GetEntity()->GetScriptTable();
        if (pTable)
        {
            if (!pTable->GetValue("hud_prefab", hudprefab))
                hudprefab = NULL;
        }
    }
    hudprefab = hudprefab ? hudprefab : HUD3D_PREFAB_LIB;

    XmlNodeRef node = gEnv->pSystem->LoadXmlFromFile(hudprefab);
    if (node)
    {
        // get the prefab with the name defined in HUD3D_PREFAB_NAME
        XmlNodeRef prefab = NULL;
        for (int i = 0; i < node->getChildCount(); ++i)
        {
            const char* name = node->getChild(i)->getAttr("Name");
            if (name && strcmp(name, HUD3D_PREFAB_NAME) == 0)
            {
                prefab = node->getChild(i);
                prefab = prefab ? prefab->findChild("Objects") : XmlNodeRef();
                break;
            }
        }

        if (prefab)
        {
            // get the PIVOT entity and collect childs
            XmlNodeRef pivotNode = NULL;
            std::vector<XmlNodeRef> childs;
            const int count = prefab->getChildCount();
            childs.reserve(count-1);

            for (int i = 0; i < count; ++i)
            {
                const char* name = prefab->getChild(i)->getAttr("Name");
                if (strcmp("PIVOT", name) == 0)
                {
                    assert(pivotNode == NULL);
                    pivotNode = prefab->getChild(i);
                }
                else
                {
                    childs.push_back(prefab->getChild(i));
                }
            }

            if (pivotNode)
            {
                // spawn pivot entity
                IEntityClass* pEntClass = gEnv->pEntitySystem->GetClassRegistry()->FindClass( pivotNode->getAttr("EntityClass") );
                if (pEntClass)
                {
                    SEntitySpawnParams params;
                    params.nFlags = ENTITY_FLAG_CLIENT_ONLY;
                    params.pClass = pEntClass;
                    m_pHUDRootEntity = gEnv->pEntitySystem->SpawnEntity(params);
                }

                if (!m_pHUDRootEntity) return;

                m_HUDRootEntityId = m_pHUDRootEntity->GetId();

                // spawn the childs and link to the pivot enity
                for (std::vector<XmlNodeRef>::iterator it = childs.begin(); it != childs.end(); ++it)
                {
                    XmlNodeRef child = *it;
                    pEntClass = gEnv->pEntitySystem->GetClassRegistry()->FindClass( child->getAttr("EntityClass") );
                    if (pEntClass)
                    {
                        const char* material = child->getAttr("Material");
                        Vec3 pos;
                        Vec3 scale;
                        Quat rot;
                        child->getAttr("Pos", pos);
                        child->getAttr("Rotate", rot);
                        child->getAttr("Scale", scale);

                        SEntitySpawnParams params;
                        params.nFlags = ENTITY_FLAG_CLIENT_ONLY;
                        params.pClass = pEntClass;
                        params.vPosition = pos;
                        params.qRotation = rot;
                        params.vScale = scale;
                        IEntity* pEntity = gEnv->pEntitySystem->SpawnEntity(params);
                        if (pEntity)
                        {
                            IScriptTable* pScriptTable = pEntity->GetScriptTable();
                            if (pScriptTable)
                            {
                                SmartScriptTable probs;
                                pScriptTable->GetValue("Properties", probs);

                                XmlNodeRef properties = child->findChild("Properties");
                                if (probs && properties)
                                {
                                    for (int k = 0; k < properties->getNumAttributes(); ++k)
                                    {
                                        const char* sKey;
                                        const char* sVal;
                                        properties->getAttributeByIndex(k, &sKey, &sVal);
                                        probs->SetValue(sKey, sVal);
                                    }
                                }
                                Script::CallMethod(pScriptTable,"OnPropertyChange");
                            }

                            if (material)
                            {
                                IMaterial* pMat = gEnv->p3DEngine->GetMaterialManager()->LoadMaterial(material);
                                if (pMat)
                                    pEntity->SetMaterial(pMat);
                            }
                            m_pHUDRootEntity->AttachChild(pEntity);
                            m_HUDEnties.push_back( pEntity->GetId() );
                        }
                    }
                }
            }
        }
    }

    OnVisCVarChange( NULL );
}
Exemplo n.º 4
0
void CGameStats::StartGame(bool server)
{
	if(!server && gEnv->bServer)//we simply ignore client events on server
		return;

	if(IGameRulesSystem* pGR = gEnv->pGame->GetIGameFramework()->GetIGameRulesSystem())
	{
		IGameRules *pR = pGR->GetCurrentGameRules();
		if(pR)
		{
			IEntityScriptProxy *pScriptProxy=static_cast<IEntityScriptProxy *>(pR->GetEntity()->GetProxy(ENTITY_PROXY_SCRIPT));
			if (pScriptProxy)
			{
				string gameState = pScriptProxy->GetState();
				if(gameState=="InGame")
				{
					m_playing=true;
					m_gameMode = pR->GetEntity()->GetClass()->GetName();
				}
			}		
		}		
	}

	if(!m_statsTrack || !m_serverReport) 
		Init();
  
	if(m_serverReport)
	{
		ReportGame();
		m_serverReport->Update();
	}
	
	if(m_playing)
	{
		if (ILevelInfo* pLevelInfo = gEnv->pGame->GetIGameFramework()->GetILevelSystem()->GetCurrentLevel())
		{
			m_mapName = pLevelInfo->GetName();//we only need pure level name here
			const char* p = strrchr(m_mapName.c_str(),'/');
			if(p != 0 && strlen(p) > 1)
			{
				m_mapName = p + 1;
				char* pStr = const_cast<char*>(m_mapName.data());
				pStr[0] = toupper(m_mapName[0]);
				for(int i = 1; i < m_mapName.size(); ++i)
					pStr[i] = tolower(m_mapName[i]);
			}
		}
	}
	

	if(m_statsTrack && m_playing  && gEnv->bServer)
		m_statsTrack->StartGame();

	if(gEnv->bServer && m_playing)
	{
		m_roundStart = gEnv->pTimer->GetFrameStartTime();
		m_lastPosUpdate = 0.0f;
		ResetStats();
		m_roundStats->Start(m_mapName, m_roundStart);
	}
}