tfe-1.0/area/
tfe-1.0/files/
tfe-1.0/logs/
tfe-1.0/logs/immortal/
tfe-1.0/logs/mob/
tfe-1.0/logs/object/
tfe-1.0/logs/player/
tfe-1.0/logs/room/
tfe-1.0/notes/clans/
tfe-1.0/player/
tfe-1.0/prev/
tfe-1.0/prev/area/
tfe-1.0/prev/player/
tfe-1.0/prev/rooms/
tfe-1.0/rooms/
tfe-1.0/src-gc/
tfe-1.0/src-msvc/
tfe-1.0/src-unix/
tfe-1.0/www/
tfe-1.0/www/html/
#include "define.h"
#include "struct.h"


void vote_summary( char_data* ch, int i )
{
  int  count_array  [ MAX_PFILE ];
  int    sort_array  [ 20 ];
  int         j, k;

  vzero( count_array, MAX_PFILE );

  for( j = 0; j < 20; j++ )
    sort_array[j] = -1;

  /* COUNT VOTES */

  for( j = 0; j < max_pfile; j++ )
    if( pfile_list[j]->vote[i] != NULL )
      count_array[pfile_list[j]->vote[i]->ident]++;

  /* SORT VOTES */

  for( j = 0; j < max_pfile; j++ ) {
     for( k = 20; k > 0 && ( sort_array[k-1] == -1
       || count_array[pfile_list[j]->ident]
       > count_array[sort_array[k-1]] ); k-- )
       if( k < 20 )
         sort_array[k] = sort_array[k-1];
    if( k < 20 )
      sort_array[k] = pfile_list[j]->ident;
    }

  /* DISPLAY VOTES */

  for( j = 0; j < 20; j++ )
    send( ch, "%d  %s\r\n", 
      sort_array[j] == -1 ? 0 : count_array[sort_array[j]], 
      sort_array[j] == -1 ? "noone" : ident_list[sort_array[j]]->name );
  
  return;
}

void do_vote( char_data* ch, char* argument )
{
  pfile_data*  pfile;
  int              i;

  if( *argument == '\0' ) {
    for( i = 0; i < MAX_VOTE; i++ ) {
      pfile = ch->pcdata->pfile->vote[i];     
      send( ch, "[%d] %s\n", i+1, pfile == NULL ? "noone" : pfile->name );
      }
    return;
    }
  
  if( exact_match( argument, "results" ) ) {
    if( !number_arg( argument, i ) ) {
      send( ch, "What vote number do you want summarized?\r\n" );
      return;
      }
    if( i < 1 || i > MAX_VOTE ) {
      send( ch, "Voting only has %d slots.\r\n", MAX_VOTE );
      return;
      }
    vote_summary( ch, i-1 );
    return;
    }

  if( !number_arg( argument, i ) ) {
    send( ch, "Syntax: Vote # <player>\r\n" );
    return;
    }

  if( i < 1 || i > MAX_VOTE ) {
    send( ch, "Voting only has %d slots.\r\n", MAX_VOTE );
    return;
    }

  if( *argument == '\0' ) {
    send( ch, "You must vote for someone.\r\n" );
    return;
    }

  if( ( pfile = find_pfile( argument, ch ) ) == NULL )  {
    send( ch, "That player does not exist.\r\n" );
    return;
    }

  send( ch, "For slot %d you vote for %s.\r\n",
    i, pfile->name );

  ch->pcdata->pfile->vote[i-1] = pfile;

  return;
}