示例#1
0
void VotingSystem::Update()
{
    if( g_app->GetGame()->m_winner != -1 ) 
    {
        return;
    }

    m_updateTimer += SERVER_ADVANCE_PERIOD;
    if( m_updateTimer >= 1 )
    {
        m_updateTimer = 0;

        for( int i = 0; i < m_votes.Size(); ++i )
        {
            if( m_votes.ValidIndex(i) )
            {
                Vote *vote = m_votes[i];
                if( vote->m_result == Vote::VoteUnknown )
                {
                    vote->m_timer -= 1;
                    int required = vote->GetVotesRequired();
                    int yes, no, abstain;
                    vote->GetCurrentVote( &yes, &no, &abstain );
                
                    if( yes >= required )
                    {
                        vote->Finish( Vote::VoteYes );
                    }
                    else if( no >= required || abstain == 0 || vote->m_timer <= 0 )
                    {
                        vote->Finish( Vote::VoteNo );
                    }
                }                
            }
        }
    }
}
示例#2
0
void VotingWindow::Render( bool _hasFocus )
{
    InterfaceWindow::Render( _hasFocus );

    Vote *vote = g_app->GetWorld()->m_votingSystem.LookupVote(m_voteId);
    if( vote )
    {   
        Team *myTeam = g_app->GetWorld()->GetMyTeam();

        switch( vote->m_voteType )
        {
            case Vote::VoteTypeJoinAlliance:
                if( myTeam->m_teamId == vote->m_createTeamId )
                {
                    char *allianceName = g_app->GetWorld()->GetAllianceName(vote->m_voteData);
                    g_renderer->TextCentreSimple( m_x+m_w/2, m_y+30, White, 20, LANGUAGEPHRASE("dialog_you_requested_alliance_1") );
					char caption[512];
					sprintf( caption, LANGUAGEPHRASE("dialog_you_requested_alliance_2") );
					LPREPLACESTRINGFLAG( 'A', allianceName, caption );
                    g_renderer->TextCentreSimple( m_x+m_w/2, m_y+50, White, 20, caption );
                }
                else if( myTeam->m_allianceId == vote->m_voteData )
                {
                    Team *team = g_app->GetWorld()->GetTeam( vote->m_createTeamId );
					char caption[512];
					sprintf( caption, LANGUAGEPHRASE("dialog_requested_alliance_1") );
					LPREPLACESTRINGFLAG( 'T', team->m_name, caption );
					g_renderer->TextCentreSimple( m_x+m_w/2, m_y+30, White, 20, caption );
                    g_renderer->TextCentreSimple( m_x+m_w/2, m_y+50, White, 20, LANGUAGEPHRASE("dialog_requested_alliance_2") );
                }
                break;

            case Vote::VoteTypeKickPlayer:
            {
                Team *kickTeam = g_app->GetWorld()->GetTeam(vote->m_voteData);
                if( myTeam->m_teamId == vote->m_createTeamId )
                {
                    g_renderer->TextCentreSimple( m_x+m_w/2, m_y+30, White, 20, LANGUAGEPHRASE("dialog_you_requested_kick_1") );
					char caption[512];
					sprintf( caption, LANGUAGEPHRASE("dialog_you_requested_kick_2") );
					LPREPLACESTRINGFLAG( 'T', kickTeam->m_name, caption );
                    g_renderer->TextCentreSimple( m_x+m_w/2, m_y+50, White, 20, caption );
                }
                else if( myTeam->m_allianceId == kickTeam->m_allianceId &&
                         myTeam->m_teamId != kickTeam->m_teamId )
                {
                    Team *team = g_app->GetWorld()->GetTeam( vote->m_createTeamId );
					char caption[512];
					sprintf( caption, LANGUAGEPHRASE("dialog_requested_kick_1") );
					LPREPLACESTRINGFLAG( 'T', team->m_name, caption );
                    g_renderer->TextCentreSimple( m_x+m_w/2, m_y+30, White, 20, caption );
					sprintf( caption, LANGUAGEPHRASE("dialog_requested_kick_2") );
					LPREPLACESTRINGFLAG( 'T', kickTeam->m_name, caption );
                    g_renderer->TextCentreSimple( m_x+m_w/2, m_y+50, White, 20, caption );
                }
                break;
            }
        }


        g_renderer->SetFont( "kremlin" );
        g_renderer->TextCentreSimple( m_x + m_w/2, m_y + 90, White, 20, LANGUAGEPHRASE("dialog_vote_yes") );
        g_renderer->TextCentreSimple( m_x + m_w/2, m_y + 120, White, 20, LANGUAGEPHRASE("dialog_vote_no") );
        g_renderer->TextCentreSimple( m_x + m_w/2, m_y + 150, White, 20, LANGUAGEPHRASE("dialog_vote_abstain") );
        g_renderer->SetFont();

        int yes, no, abstain;
        vote->GetCurrentVote( &yes, &no, &abstain );

        g_renderer->Text( m_x + m_w - 40, m_y + 90, White, 20, "%d", yes );
        g_renderer->Text( m_x + m_w - 40, m_y + 120, White, 20, "%d", no );
        g_renderer->Text( m_x + m_w - 40, m_y + 150, White, 20, "%d", abstain );

        if( vote->m_result == Vote::VoteUnknown )
        {
			char caption[512];
			sprintf( caption, LANGUAGEPHRASE("dialog_vote_seconds_to_vote") );
			LPREPLACEINTEGERFLAG( 'S', (int) vote->m_timer, caption );
            g_renderer->TextCentreSimple( m_x + m_w/2, m_y + m_h - 70, White, 15, caption );
            
            int votesRequired = vote->GetVotesRequired();
			sprintf( caption, LANGUAGEPHRASE("dialog_vote_number_votes_required") );
			LPREPLACEINTEGERFLAG( 'V', votesRequired, caption );
            g_renderer->TextCentreSimple( m_x+m_w/2, m_y + m_h - 50, White, 15, caption );
        }
        else if( vote->m_result == Vote::VoteYes )
        {
            g_renderer->SetFont( "kremlin" );
            g_renderer->TextCentreSimple( m_x+m_w/2, m_y + m_h - 70, White, 30, LANGUAGEPHRASE("dialog_vote_succeeded") );
            g_renderer->SetFont();
        }
        else if( vote->m_result == Vote::VoteNo )
        {
            g_renderer->SetFont( "kremlin" );
            g_renderer->TextCentreSimple( m_x+m_w/2, m_y + m_h - 70, White, 30, LANGUAGEPHRASE("dialog_vote_failed") );
            g_renderer->SetFont();
        }
    }       
}