Esempio n. 1
0
User& Battle::OnUserAdded( User& user )
{
		user = IBattle::OnUserAdded( user );
		if ( &user == &GetMe() && (m_timer == NULL) )
		{
			 m_timer = new wxTimer(this,TIMER_ID);
			 m_timer->Start( TIMER_INTERVAL );
		}
    user.SetBattle( this );
    user.BattleStatus().isfromdemo = false;

    if ( IsFounderMe() )
    {
        if ( CheckBan( user ) ) return user;

		if ( ( &user != &GetMe() ) && !user.BattleStatus().IsBot() && ( m_opts.rankneeded != UserStatus::RANK_1 ) && !user.BattleStatus().spectator )
        {
			 if ( m_opts.rankneeded > UserStatus::RANK_1 && user.GetStatus().rank < m_opts.rankneeded )
			 {
				DoAction("Rank limit autospec: " + user.GetNick());
				ForceSpectator( user, true );
			 }
			 else if ( m_opts.rankneeded < UserStatus::RANK_1 && user.GetStatus().rank > ( -m_opts.rankneeded - 1 ) )
			 {
				 DoAction("Rank limit autospec: " + user.GetNick());
				 ForceSpectator( user, true );
			 }
        }

        m_ah.OnUserAdded( user );
        if ( !user.BattleStatus().IsBot() && sett().GetBattleLastAutoAnnounceDescription() ) DoAction( m_opts.description);
    }
    // any code here may be skipped if the user was autokicked
    return user;
}
Esempio n. 2
0
void Battle::OnUserBattleStatusUpdated( User &user, UserBattleStatus status )
{
    if ( IsFounderMe() )
    {
			if ( ( &user != &GetMe() ) && !status.IsBot() && ( m_opts.rankneeded != UserStatus::RANK_1 ) && !status.spectator )
			{
				if ( m_opts.rankneeded > UserStatus::RANK_1 && user.GetStatus().rank < m_opts.rankneeded )
				{
					DoAction( _T("Rank limit autospec: ") + user.GetNick() );
					ForceSpectator( user, true );
				}
				else if ( m_opts.rankneeded < UserStatus::RANK_1 && user.GetStatus().rank > ( -m_opts.rankneeded - 1 ) )
				{
					DoAction( _T("Rank limit autospec: ") + user.GetNick() );
					ForceSpectator( user, true );
				}
			}
			UserBattleStatus previousstatus = user.BattleStatus();
			if ( m_opts.lockexternalbalancechanges )
			{
				if ( previousstatus.team != status.team )
				{
					 ForceTeam( user, previousstatus.team );
					 status.team = previousstatus.team;
				}
				if ( previousstatus.ally != status.ally )
				{
					ForceAlly( user, previousstatus.ally );
					status.ally = previousstatus.ally;
				}
			}
    }
		IBattle::OnUserBattleStatusUpdated( user, status );
    if ( status.handicap != 0 )
    {
		UiEvents::GetUiEventSender( UiEvents::OnBattleActionEvent ).SendEvent(
				UiEvents::OnBattleActionData( wxString(_T(" ")) , ( _T("Warning: user ") + user.GetNick() + _T(" got bonus ") ) << status.handicap )
			);
    }
		if ( IsFounderMe() )
		{
			if ( ShouldAutoStart() )
			{
				if ( sett().GetBattleLastAutoStartState() )
				{
					if ( !spring().IsRunning() ) StartHostedBattle();
				}
			}
		}
	if ( !GetMe().BattleStatus().spectator ) SetAutoUnspec(false); // we don't need auto unspec anymore
	ShouldAutoUnspec();
#ifndef SL_QT_MODE
	ui().OnUserBattleStatus( *this, user );
#endif
}
Esempio n. 3
0
void Battle::ShouldAutoUnspec()
{
	if ( m_auto_unspec && !IsLocked() && GetMe().BattleStatus().spectator )
	{
		if ( GetNumActivePlayers() < m_opts.maxplayers )
		{
			ForceSpectator(GetMe(),false);
		}
	}
}
Esempio n. 4
0
void Battle::ForceUnsyncedAndUnreadyToSpectate()
{
    size_t numusers = GetNumUsers();
    for ( size_t i = 0; i < numusers; ++i )
    {
        User &user = GetUser(i);
        UserBattleStatus& bs = user.BattleStatus();
        if ( bs.IsBot() ) continue;
				if ( !bs.spectator && ( !bs.sync || !bs.ready ) ) ForceSpectator( user, true );
    }
}
Esempio n. 5
0
void Battle::ShouldAutoUnspec()
{
	if ( m_auto_unspec && !IsLocked() && GetMe().BattleStatus().spectator )
	{
		unsigned int numplayers = 0;
		std::map<int, int> allysizes = GetAllySizes();
		for ( std::map<int, int>::const_iterator itor = allysizes.begin(); itor != allysizes.end(); ++itor )
		{
			numplayers += itor->second;
		}
		if ( numplayers < m_auto_unspec_num_players )
		{
			ForceSpectator(GetMe(),false);
		}
	}
}
Esempio n. 6
0
void Battle::OnTimer( wxTimerEvent&  )
{
	if ( !IsFounderMe() ) return;
	if ( m_ingame ) return;
	int autospect_trigger_time = sett().GetBattleLastAutoSpectTime();
	if ( autospect_trigger_time == 0 ) return;
	time_t now = time(0);
	for ( unsigned int i = 0; i < GetNumUsers(); i++)
	{
		User& usr = GetUser( i );
		UserBattleStatus& status = usr.BattleStatus();
		if ( status.IsBot() || status.spectator ) continue;
		if ( status.sync && status.ready ) continue;
		if ( &usr == &GetMe() ) continue;
		std::map<wxString, time_t>::iterator itor = m_ready_up_map.find( usr.GetNick() );
		if ( itor != m_ready_up_map.end() )
		{
			if ( ( now - itor->second ) > autospect_trigger_time )
			{
				ForceSpectator( usr, true );
			}
		}
	}
}