Пример #1
0
bool CSector::CanSleep(bool fCheckAdjacents) const
{
	ADDTOCALLSTACK_INTENSIVE("CSector::CanSleep");
	if ( (g_Cfg._iSectorSleepDelay == 0) || IsFlagSet(SECF_NoSleep) )
		return false;	// never sleep
    if (m_Chars_Active.GetClientsNumber() > 0)
        return false;	// has at least one client, no sleep
	if ( IsFlagSet(SECF_InstaSleep) )
		return true;	// no active client inside, instant sleep
    
    if (fCheckAdjacents)
    {
        for (int i = 0; i < (int)DIR_QTY; ++i)// Check for adjacent's sectors sleeping allowance.
        {
            const CSector *pAdjacent = GetAdjacentSector((DIR_TYPE)i);    // set this as the last sector to avoid this code in the adjacent one and return if it can sleep or not instead of searching its adjacents.
            /*
            * Only check if this sector exist and it's not the last checked (sectors in the edges of the map doesn't have adjacent on those directions)
            * && Only check if the sector isn't sleeping (IsSleeping()) and then check if CanSleep().
            */
            if (!pAdjacent)
            {
                continue;
            }
            if (!pAdjacent->IsSleeping() || !pAdjacent->CanSleep(false))
            {
                return false;   // assume the base sector can't sleep.
            }
        }
    }

	//default behaviour;
	return ((g_World.GetCurrentTime().GetTimeRaw() - GetLastClientTime()) > g_Cfg._iSectorSleepDelay); // Sector Sleep timeout.
}
Пример #2
0
inline bool CSector::IsSectorSleeping() const
{
	ADDTOCALLSTACK_INTENSIVE("CSector::IsSectorSleeping");
	if ( IsFlagSet(SECF_NoSleep) )
		return false;	// never sleep

	if ( IsFlagSet(SECF_InstaSleep) )
	{
		if ( m_Chars_Active.HasClients() > 0 )
			return false;	// has at least one client, no sleep
		else
			return true;	// no active client inside, instant sleep
	}

	//default behaviour
	return (-g_World.GetTimeDiff(GetLastClientTime()) > 10 * 60 * TICK_PER_SEC);
}