Code:
void CHUD::UpdateTeamActionHUD()
{
if (CGameRules *pGameRules=g_pGame->GetGameRules())
{
if (pGameRules->IsRoundTimeLimited() && !stricmp(pGameRules->GetEntity()->GetClass()->GetName(), "TeamAction"))
{
IEntityScriptProxy *pScriptProxy=static_cast<IEntityScriptProxy *>(pGameRules->GetEntity()->GetProxy(ENTITY_PROXY_SCRIPT));
if (pScriptProxy)
{
bool preround=false;
int remainingTime=-1;
if (!stricmp(pScriptProxy->GetState(), "InGame"))
{
remainingTime = (int)(pGameRules->GetRemainingRoundTime());
}
else if (!stricmp(pScriptProxy->GetState(), "PreRound"))
{
preround=true;
remainingTime = (int)(pGameRules->GetRemainingPreRoundTime());
}
if (remainingTime>-1)
{
int minutes = (remainingTime)/60;
int seconds = (remainingTime - minutes*60);
string msg;
msg.Format("%02d:%02d", minutes, seconds);
Vec3 color=Vec3(1.0f, 1.0f, 1.0f);
if (remainingTime<g_pGameCVars->g_suddendeathtime || preround)
{
float t=fabsf(cry_sinf(gEnv->pTimer->GetCurrTime()*2.5f));
Vec3 red=Vec3(0.85f, 0.0f, 0.0f);
color=color*(1.0f-t)+red*t;
}
m_pUIDraw->DrawText(m_pDefaultFont,0,12,22,22,msg.c_str(),0.85f,color.x,color.y,color.z,UIDRAWHORIZONTAL_CENTER,UIDRAWVERTICAL_TOP,UIDRAWHORIZONTAL_CENTER,UIDRAWVERTICAL_TOP);
}
int key0;
int nkScore = 0;
int usScore = 0;
IScriptTable *pGameRulesScript=pGameRules->GetEntity()->GetScriptTable();
if (pGameRulesScript && pGameRulesScript->GetValue("TEAMSCORE_TEAM0_KEY", key0))
{
pGameRules->GetSynchedGlobalValue(key0+1, nkScore);
pGameRules->GetSynchedGlobalValue(key0+2, usScore);
}
if (pGameRules->IsRoundTimeLimited() && !stricmp(pGameRules->GetEntity()->GetClass()->GetName(), "TeamAction"))
{
IActor *pClientActor=g_pGame->GetIGameFramework()->GetClientActor();
if(!pClientActor)
return;
int clientTeam = pGameRules->GetTeam(pClientActor->GetEntityId());
CGameRules::TPlayers nkPlayers, usPlayers;
pGameRules->GetTeamPlayers(1, nkPlayers);
pGameRules->GetTeamPlayers(2, usPlayers);
int numNK = 0;
int numUS = 0;
for(int i=0; i<nkPlayers.size(); ++i)
{
IActor* pActor = g_pGame->GetIGameFramework()->GetIActorSystem()->GetActor(nkPlayers[i]);
if(pActor && pActor->GetHealth() > 0)
++numNK;
}
for(int i=0; i<usPlayers.size(); ++i)
{
IActor* pActor = g_pGame->GetIGameFramework()->GetIActorSystem()->GetActor(usPlayers[i]);
if(pActor && pActor->GetHealth() > 0)
++numUS;
}
if(clientTeam != 0)
{
string nkPlayers;
string usPlayers;
string nkScoreText;
string usScoreText;
for(int i=0; i<nkScore; ++i)
nkScoreText += "*";
for(int i=0; i<usScore; ++i)
usScoreText += "*";
if(clientTeam == 1)
{
nkPlayers.Format("NK: %d", numNK);
usPlayers.Format("%d :US", numUS);
m_pUIDraw->DrawText(m_pDefaultFont, -40, 5, 22, 22, nkScoreText.c_str(), 0.85f, 1.0f, 1.0f, 1.0f, UIDRAWHORIZONTAL_CENTER, UIDRAWVERTICAL_TOP, UIDRAWHORIZONTAL_RIGHT,UIDRAWVERTICAL_TOP);
m_pUIDraw->DrawText(m_pDefaultFont, 40, 5, 22, 22, usScoreText.c_str(), 0.85f, 1.0f, 1.0f, 1.0f, UIDRAWHORIZONTAL_CENTER, UIDRAWVERTICAL_TOP, UIDRAWHORIZONTAL_LEFT,UIDRAWVERTICAL_TOP);
m_pUIDraw->DrawText(m_pDefaultFont, -40, 12, 22, 22, nkPlayers.c_str(), 0.85f, 1.0f, 1.0f, 1.0f, UIDRAWHORIZONTAL_CENTER, UIDRAWVERTICAL_TOP, UIDRAWHORIZONTAL_RIGHT,UIDRAWVERTICAL_TOP);
m_pUIDraw->DrawText(m_pDefaultFont, 40, 12, 22, 22, usPlayers.c_str(), 0.85f, 1.0f, 1.0f, 1.0f, UIDRAWHORIZONTAL_CENTER, UIDRAWVERTICAL_TOP, UIDRAWHORIZONTAL_LEFT,UIDRAWVERTICAL_TOP);
}
else
{
nkPlayers.Format("%d :NK", numNK);
usPlayers.Format("US: %d", numUS);
m_pUIDraw->DrawText(m_pDefaultFont, -40, 5, 22, 22, usScoreText.c_str(), 0.85f, 1.0f, 1.0f, 1.0f, UIDRAWHORIZONTAL_CENTER, UIDRAWVERTICAL_TOP, UIDRAWHORIZONTAL_RIGHT,UIDRAWVERTICAL_TOP);
m_pUIDraw->DrawText(m_pDefaultFont, 40, 5, 22, 22, nkScoreText.c_str(), 0.85f, 1.0f, 1.0f, 1.0f, UIDRAWHORIZONTAL_CENTER, UIDRAWVERTICAL_TOP, UIDRAWHORIZONTAL_LEFT,UIDRAWVERTICAL_TOP);
m_pUIDraw->DrawText(m_pDefaultFont, -40, 12, 22, 22, usPlayers.c_str(), 0.85f, 1.0f, 1.0f, 1.0f, UIDRAWHORIZONTAL_CENTER, UIDRAWVERTICAL_TOP, UIDRAWHORIZONTAL_RIGHT,UIDRAWVERTICAL_TOP);
m_pUIDraw->DrawText(m_pDefaultFont, 40, 12, 22, 22, nkPlayers.c_str(), 0.85f, 1.0f, 1.0f, 1.0f, UIDRAWHORIZONTAL_CENTER, UIDRAWVERTICAL_TOP, UIDRAWHORIZONTAL_LEFT,UIDRAWVERTICAL_TOP);
}
}
}
}
}
}
}
//-----------------------------------------------------------------------------------------------------
void CHUD::RequestRevive()
{
CPlayer *pPlayer = static_cast<CPlayer*>(gEnv->pGame->GetIGameFramework()->GetClientActor());
if(pPlayer && pPlayer->GetHealth()<=0)
pPlayer->GetPlayerInput()->OnAction(g_pGame->Actions().attack1, eAAM_OnPress, 1.0f);
}
//-----------------------------------------------------------------------------------------------------
void CHUD::UpdatePlayerAmmo()
{
if(!m_animPlayerStats.GetVisible())
{
m_playerAmmo = m_playerRestAmmo = -1; //forces update next time loaded
return;
}
if(!(m_pHUDVehicleInterface && m_pHUDVehicleInterface->GetHUDType() != CHUDVehicleInterface::EHUD_NONE))
{
int ammo = 0;
int clipSize = 0;
int restAmmo = 0;
CryFixedStringT<128> grenadeType;
int grenades = 0;
bool TACLauncherMode = false;
CPlayer *pPlayer = static_cast<CPlayer*>(gEnv->pGame->GetIGameFramework()->GetClientActor());
if(pPlayer)
{
IItem *pItem = pPlayer->GetCurrentItem(false);
if(pItem)
{
if(CWeapon *pWeapon = static_cast<CWeapon*>(pItem->GetIWeapon()))
{
IEntityClass *tacgun = gEnv->pEntitySystem->GetClassRegistry()->FindClass("TACGun");
if(pItem->GetEntity() && pItem->GetEntity()->GetClass()==tacgun)
{
TACLauncherMode = true;
}
int fm = pWeapon->GetCurrentFireMode();
if(IFireMode *pFM = pWeapon->GetFireMode(fm))
{
ammo = pFM->GetAmmoCount();
if(IItem *pSlave = pWeapon->GetDualWieldSlave())
{
if(IWeapon *pSlaveWeapon = pSlave->GetIWeapon())
if(IFireMode *pSlaveFM = pSlaveWeapon->GetFireMode(pSlaveWeapon->GetCurrentFireMode()))
ammo += pSlaveFM->GetAmmoCount();
}
clipSize = pFM->GetClipSize();
restAmmo = pPlayer->GetInventory()->GetAmmoCount(pFM->GetAmmoType());
if(pFM->CanOverheat())
{
int heat = int(pFM->GetHeat()*100.0f);
m_animPlayerStats.Invoke("setOverheatBar", heat);
}
}
}
}
IItem *pOffhand = g_pGame->GetIGameFramework()->GetIItemSystem()->GetItem(pPlayer->GetInventory()->GetItemByClass(CItem::sOffHandClass));
if(pOffhand)
{
int firemode = pOffhand->GetIWeapon()->GetCurrentFireMode();
if(IFireMode *pFm = pOffhand->GetIWeapon()->GetFireMode(firemode))
{
if(pFm->GetAmmoType())
{
grenadeType = pFm->GetAmmoType()->GetName();
if(pPlayer)
grenades = pPlayer->GetInventory()->GetAmmoCount(pFm->GetAmmoType());
}
else //can happen during object pickup/throw
{
grenadeType.assign(m_sGrenadeType, m_sGrenadeType.length());
grenades = m_iGrenadeAmmo;
}
}
}
}
if(m_playerAmmo == -1) //probably good to update fireMode
{
SetFireMode(NULL, NULL);
m_animPlayerStats.Invoke("setAmmoMode", 0);
}
m_animPlayerStats.GetFlashPlayer()->SetVariable("TACLauncherMode", SFlashVarValue(TACLauncherMode));
if(m_playerAmmo != ammo || m_playerClipSize != clipSize || m_playerRestAmmo != restAmmo ||
m_iGrenadeAmmo != grenades || grenadeType.compare(m_sGrenadeType) != 0)
{
SFlashVarValue args[7] = {0, ammo, clipSize, restAmmo, grenades, grenadeType.c_str(), true};
m_animPlayerStats.Invoke("setAmmo", args, 7);
m_playerAmmo = ammo;
m_playerClipSize = clipSize;
m_playerRestAmmo = restAmmo;
m_iGrenadeAmmo = grenades;
m_sGrenadeType.assign(grenadeType.c_str()); // will alloc
}
}
else
m_playerAmmo = m_playerRestAmmo = -1; //forces update next time outside vehicle
}