/* 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);
}
/* 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);
}