/* base - activate the uninvolved */
void activate(void)
{
   vector<Creature *> temppool = activatable_liberals();

   if(temppool.size()==0)return;

   sortliberals(temppool,activesortingchoice[SORTINGCHOICE_ACTIVATE]);

   int page=0;

   char str[80];
   char num[20];

   do
   {
      erase();

      set_color(COLOR_WHITE,COLOR_BLACK,0);     
      printfunds(0,1,"Money: ");


      move(0,0);
      addstr("Activate Uninvolved Liberals");
      move(1,0);
      addstr("----CODE NAME------------SKILL---HEALTH---LOCATION------------------------------");
      move(1,57);
      addstr("ACTIVITY");

      int y=2;
      for(int p=page*19;p<temppool.size()&&p<page*19+19;p++)
      {
         set_color(COLOR_WHITE,COLOR_BLACK,0);
         move(y,0);
         addch(y+'A'-2);addstr(" - ");
         addstr(temppool[p]->name);

         char bright=0;
         int skill=0;
         for(int sk=0;sk<SKILLNUM;sk++)
         {
            skill+=temppool[p]->get_skill(sk);
            if(temppool[p]->get_skill_ip(sk)>=100+(10*temppool[p]->get_skill(sk))&&
               temppool[p]->get_skill(sk)<temppool[p]->skill_cap(sk,true))bright=1;
         }

         set_color(COLOR_WHITE,COLOR_BLACK,bright);

         move(y,25);
         itoa(skill,num,10);
         addstr(num);

         printhealthstat(*temppool[p],y,33,TRUE);

         if(mode==REVIEWMODE_JUSTICE)set_color(COLOR_YELLOW,COLOR_BLACK,1);
         else set_color(COLOR_WHITE,COLOR_BLACK,0);
         move(y,42);
         addstr(location[temppool[p]->location]->getname(true));

         move(y,57);
         // Let's add some color here...
         set_activity_color(temppool[p]->activity.type);
         getactivity(str,temppool[p]->activity);
         addstr(str);

         y++;
      }

      set_color(COLOR_WHITE,COLOR_BLACK,0);
      move(22,0);
      addstr("Press a Letter to Assign an Activity.");
      move(23,0);
      addpagestr();
      addstr(" T to sort people.");
      move(24,0);
      addstr("Press Z to assign simple tasks in bulk.");

      refresh();

      int c=getch();
      translategetch(c);

      //PAGE UP
      if((c==interface_pgup||c==KEY_UP||c==KEY_LEFT)&&page>0)page--;
      //PAGE DOWN
      if((c==interface_pgdn||c==KEY_DOWN||c==KEY_RIGHT)&&(page+1)*19<temppool.size())page++;

      if(c>='a'&&c<='s')
      {
         int p=page*19+(int)(c-'a');
         if(p<temppool.size())
         {
            activate(temppool[p]);
         }
      }

      if(c=='t')
      {
         sorting_prompt(SORTINGCHOICE_ACTIVATE);
         sortliberals(temppool,activesortingchoice[SORTINGCHOICE_ACTIVATE],true);
      }

      if(c=='z')
      {
         activatebulk();
      }

      if(c==10||c==ESC)break;
   }while(1);
}
void activatebulk(void)
{
   vector<Creature *> temppool = activatable_liberals();

   if(temppool.size()==0)return;

   int page=0;

   char str[80];

   int selectedactivity=0;

   do
   {
      erase();

      set_color(COLOR_WHITE,COLOR_BLACK,0);
      printfunds(0,1,"Money: ");

      set_color(COLOR_WHITE,COLOR_BLACK,0);
      move(0,0);
      addstr("Activate Uninvolved Liberals");
      move(1,0);
      addstr("----CODE NAME------------CURRENT ACTIVITY---------------------------------------");
      move(1,51);
      addstr("BULK ACTIVITY");

      if(selectedactivity==0)set_color(COLOR_WHITE,COLOR_BLACK,1);
      else set_color(COLOR_WHITE,COLOR_BLACK,0);
      move(2,51);
      addstr("1 - Engaging in Liberal Activism");
      if(selectedactivity==1)set_color(COLOR_WHITE,COLOR_BLACK,1);
      else set_color(COLOR_WHITE,COLOR_BLACK,0);
      move(3,51);
      addstr("2 - Legal Fundraising");
      if(selectedactivity==2)set_color(COLOR_WHITE,COLOR_BLACK,1);
      else set_color(COLOR_WHITE,COLOR_BLACK,0);
      move(4,51);
      addstr("3 - Illegal Fundraising");
      if(selectedactivity==3)set_color(COLOR_WHITE,COLOR_BLACK,1);
      else set_color(COLOR_WHITE,COLOR_BLACK,0);
      move(5,51);
      addstr("4 - Checking Polls");
      if(selectedactivity==4)set_color(COLOR_WHITE,COLOR_BLACK,1);
      else set_color(COLOR_WHITE,COLOR_BLACK,0);
      move(6,51);
      addstr("5 - Stealing Cars");
      if(selectedactivity==5)set_color(COLOR_WHITE,COLOR_BLACK,1);
      else set_color(COLOR_WHITE,COLOR_BLACK,0);
      move(7,51);
      addstr("6 - Community Service");

      int y=2;
      for(int p=page*19;p<temppool.size()&&p<page*19+19;p++)
      {
         set_color(COLOR_WHITE,COLOR_BLACK,0);
         move(y,0);
         addch(y+'A'-2);addstr(" - ");
         addstr(temppool[p]->name);

         move(y,25);
         set_activity_color(temppool[p]->activity.type);
         getactivity(str,temppool[p]->activity);
         addstr(str);
         /*if(temppool[p]->activity.type==ACTIVITY_TROUBLE)
         {
         addstr(" ($");
         itoa(temppool[p]->activity.arg,num,10);
         addstr(num);
         addstr(")");
         }*/

         y++;
      }

      set_color(COLOR_WHITE,COLOR_BLACK,0);
      move(22,0);
      addstr("Press a Letter to Assign an Activity.  Press a Number to select an Activity.");
      move(23,0);
      addpagestr();

      refresh();

      int c=getch();
      translategetch(c);

      //PAGE UP
      if((c==interface_pgup||c==KEY_UP||c==KEY_LEFT)&&page>0)page--;
      //PAGE DOWN
      if((c==interface_pgdn||c==KEY_DOWN||c==KEY_RIGHT)&&(page+1)*19<temppool.size())page++;

      if(c>='a'&&c<='s')
      {
         int p=page*19+(int)(c-'a');
         if(p<temppool.size())
         {
            switch(selectedactivity)
            {
            case 0: //Activism
               if(temppool[p]->get_attribute(ATTRIBUTE_WISDOM,true)>7)
                  temppool[p]->activity.type=ACTIVITY_COMMUNITYSERVICE;
               else if(temppool[p]->get_attribute(ATTRIBUTE_WISDOM,true)>4)
                  temppool[p]->activity.type=ACTIVITY_TROUBLE;
               else
               {
                  if(temppool[p]->get_skill(SKILL_COMPUTERS)>2)
                     temppool[p]->activity.type=ACTIVITY_HACKING;
                  else if(temppool[p]->get_skill(SKILL_ART)>1)
                  {
                     temppool[p]->activity.type=ACTIVITY_GRAFFITI;
                     temppool[p]->activity.arg=-1;
                  }
                  else temppool[p]->activity.type=ACTIVITY_TROUBLE;
               }
               break;
            case 1: //Fundraising
               if(temppool[p]->get_skill(SKILL_ART)>1)
                  temppool[p]->activity.type=ACTIVITY_SELL_ART;
               else if(temppool[p]->get_skill(SKILL_MUSIC)>1)
                  temppool[p]->activity.type=ACTIVITY_SELL_MUSIC;
               else if(temppool[p]->get_skill(SKILL_TAILORING)>1)
                  temppool[p]->activity.type=ACTIVITY_SELL_TSHIRTS;
               else temppool[p]->activity.type=ACTIVITY_DONATIONS;
               break;
            case 2: //Illegal Fundraising
               if(temppool[p]->get_skill(SKILL_COMPUTERS)>1)
                  temppool[p]->activity.type=ACTIVITY_CCFRAUD;
#ifndef ZEROMORAL
                else if(temppool[p]->get_skill(SKILL_SEDUCTION)>1 && temppool[p]->age >=18)
#else
               else if(temppool[p]->get_skill(SKILL_SEDUCTION)>1)
#endif
                  temppool[p]->activity.type=ACTIVITY_PROSTITUTION;
               else
                  temppool[p]->activity.type=ACTIVITY_SELL_DRUGS;
               break;
            case 3: //Check polls
               temppool[p]->activity.type=ACTIVITY_POLLS;
               break;
            case 4: //Steal cars
               temppool[p]->activity.type=ACTIVITY_STEALCARS;
               break;
            case 5: //Volunteer
               temppool[p]->activity.type=ACTIVITY_COMMUNITYSERVICE;
               break;
            }
         }
      }
      if(c>='1'&&c<='6')
      {
         selectedactivity=c-'1';
      }

      if(c==10||c==ESC)break;
   }while(1);
/* base - activate sleepers */
void activate_sleepers(void)
{
    vector<Creature *> temppool;
    // Comb the pool of Liberals for sleeper agents
    for(int p=0; p<pool.size(); p++)
    {
        // Select only sleepers that can work
        if(pool[p]->alive==true&&
                pool[p]->flag & CREATUREFLAG_SLEEPER&&
                pool[p]->align==ALIGN_LIBERAL&&
                pool[p]->hiding==false&&
                pool[p]->clinic==false&&
                pool[p]->dating==false)
        {
            temppool.push_back(pool[p]);
        }
    }

    if(temppool.size()==0)return;

    sortliberals(temppool,activesortingchoice[SORTINGCHOICE_ACTIVATESLEEPERS]);

    int page=0;

    char str[80];

    do
    {
        erase();

        set_color(COLOR_WHITE,COLOR_BLACK,0);
        printfunds(0,1,"Money: ");


        move(0,0);
        addstr("Activate Sleeper Agents");
        makedelimiter(1,0);
        move(1,4);
        addstr("CODE NAME");
        move(1,25);
        addstr("JOB");
        move(1,42);
        addstr("SITE");
        move(1,57);
        addstr("ACTIVITY");

        int y=2;
        for(int p=page*9; p<temppool.size()&&p<page*9+9; p++)
        {
            set_color(COLOR_WHITE,COLOR_BLACK,0);
            move(y,0);
            addch((y-2)/2+'A');
            addstr(" - ");
            addstr(temppool[p]->name);

            move(y,25);
            getrecruitcreature(str,temppool[p]->type);
            addstr(str);

            move(y+1,6);
            addstr("Effectiveness: ");

            if(temppool[p]->infiltration > 0.8f)
            {
                set_color(COLOR_RED,COLOR_BLACK,1);
            }
            else if(temppool[p]->infiltration > 0.6f)
            {
                set_color(COLOR_MAGENTA,COLOR_BLACK,1);
            }
            else if(temppool[p]->infiltration > 0.4f)
            {
                set_color(COLOR_YELLOW,COLOR_BLACK,1);
            }
            else if(temppool[p]->infiltration > 0.2f)
            {
                set_color(COLOR_WHITE,COLOR_BLACK,1);
            }
            else if(temppool[p]->infiltration > 0.1f)
            {
                set_color(COLOR_WHITE,COLOR_BLACK,0);
            }
            else
            {
                set_color(COLOR_GREEN,COLOR_BLACK,0);
            }
            char num[10];
            itoa(static_cast<int>(temppool[p]->infiltration*100),num,10);
            addstr(num);
            addstr("%");

            move(y,42);
            set_color(COLOR_WHITE,COLOR_BLACK,0);
            addshortname(location[temppool[p]->worklocation]);

            move(y,57);
            // Let's add some color here...
            set_activity_color(temppool[p]->activity.type);
            getactivity(str,temppool[p]->activity);
            addstr(str);

            y+=2;
        }

        set_color(COLOR_WHITE,COLOR_BLACK,0);
        move(22,0);
        addstr("Press a Letter to Assign an Activity.");
        move(23,0);
        addpagestr();
        addstr(" T to sort people.");

        set_color(COLOR_WHITE,COLOR_BLACK,0);

        refresh();

        int c=getch();
        translategetch(c);

        //PAGE UP
        if((c==interface_pgup||c==KEY_UP||c==KEY_LEFT)&&page>0)page--;
        //PAGE DOWN
        if((c==interface_pgdn||c==KEY_DOWN||c==KEY_RIGHT)&&(page+1)*9<temppool.size())page++;

        if(c>='a'&&c<='s')
        {
            int p=page*9+(int)(c-'a');
            if(p<temppool.size())
            {
                activate_sleeper(temppool[p]);
            }
        }

        if(c=='t')
        {
            sorting_prompt(SORTINGCHOICE_ACTIVATESLEEPERS);
            sortliberals(temppool,activesortingchoice[SORTINGCHOICE_ACTIVATESLEEPERS],true);
        }

        if(c==10)break;
    } while(1);
}