// vote robot
#include <vote.h> 
#include <ansi.h>

inherit F_CONDITION;

int clear_vote(object me);

int vote(object me, object victim)
{
  int reason; // vote for what?
  int vv;	// valid voter numbers
  int vc; 	// vote count;
  int df;
  string *juror, my_id;

  if (me == victim)
  {
	if (random(2)) me->add("vote/abuse", 10);
  	return notify_fail("㲻ǿЦɣıȨ\n");
  }

  if ((reason = (int)victim->query("vote/reason"))>0 && (reason!=V_ROBOT))
  {
  	return notify_fail("ҪѵǰıԺſµĶ顣\n");
  }

  if( victim->query("robot_on") ) 
  {
  	return notify_fail(victim->name()+"Ѿץͥˡ\n");
  }

  if (reason <= 0)
  {
  	victim->set("vote/reason", (int)V_ROBOT); 
  }
  
  my_id = me->query("id");

  // dont allow me to vote twice for the same issue
  juror = victim->query("vote/juror");
  
  if( !pointerp(juror) )
  {
 	victim->set("vote/juror", ({ my_id }) );
  } else if( member_array(my_id, juror) == -1 ) 
  {
 	victim->set("vote/juror", juror+({ my_id }) );
  } else
  {
	me->add("vote/abuse", 10);
  	return notify_fail("һһƱñȨҪܳͷģ\n");
  }

  vv = (int) ("/cmds/std/vote")->valid_voters(me)/6;  
  vc = victim->add("vote/count", 1);

  df = vv - vc;
  if (vv < 4) df = 4 - vc;

  if (df>0)
  { 
        shout( HIG ""+me->name(1)+"ͶƱ"+victim->name(1)+"("+capitalize(victim->query("id"))+")"
			+"лУ"+chinese_number(df)+"Ʊ\n" NOR);
	write( HIG ""+me->name(1)+"ͶƱ" +victim->name(1)
			+"лУ"+chinese_number(df)+"Ʊ\n" NOR);
	victim->apply_condition("vote_clear", 10);
  } else 
  {
        shout( HIG ""+me->name(1)+"ͶƱ" +victim->name(1)+"("+capitalize(victim->query("id"))+")"
			+"лС"+victim->name(1)+"ץзͥˣ\n" NOR);
	write( HIG ""+me->name()+"ͶƱ" +victim->name()
			+"лС"+victim->name(1)+"ץзͥˣ\n" NOR);
			
	victim->apply_condition("vote_clear", -10);
	victim->set("robot_on", 1);
	victim->move("/d/wizard/robot_court");
  } 
  
  return 1;
}