/* active squad visits the hospital */
void hospital(int loc)
{
   music.play(MUSIC_SHOPPING);
   locatesquad(activesquad,loc);

   int partysize=squadsize(activesquad);

   while(true)
   {
      erase();

      locheader();
      printparty();

      set_color(COLOR_WHITE,COLOR_BLACK,0);
      move(10,1);
      addstr("F - Go in and fix up Conservative wounds");

      set_color(COLOR_WHITE,COLOR_BLACK,0);
      move(12,1);
      addstr("Enter - Leave");

      if(partysize>0&&(party_status==-1||partysize>1)) set_color(COLOR_WHITE,COLOR_BLACK,0);
      else set_color(COLOR_BLACK,COLOR_BLACK,1);
      move(13,1);
      addstr("# - Check the status of a squad Liberal");
      if(party_status!=-1) set_color(COLOR_WHITE,COLOR_BLACK,0);
      else set_color(COLOR_BLACK,COLOR_BLACK,1);
      move(14,1);
      addstr("0 - Show the squad's Liberal status");

      int c=getkey();

      if(c=='x'||c==ENTER||c==ESC||c==SPACEBAR) break;

      if(c=='0') party_status=-1;

      if(c>='1'&&c<='6'&&activesquad!=NULL)
         if(activesquad->squad[c-'1']!=NULL)
         {
            if(party_status==c-'1')fullstatus(party_status);
            else party_status=c-'1';
         }

      if(c=='f')
      {
         for(int p=5;p>=0;p--)
         {
            if(activesquad->squad[p]==NULL)continue;
            hospitalize(loc,*activesquad->squad[p]);
         }
         break;
      }
   }
}
/* active squad visits the car dealership */
void dealership(int loc)
{
   music.play(MUSIC_SHOPPING);
   short buyer=0;

   locatesquad(activesquad,loc);

   int partysize=squadsize(activesquad);

   while(true)
   {
      erase();

      locheader();
      printparty();

      Creature *sleepercarsalesman=NULL;
      for(int p=0;p<len(pool);p++)
         if(pool[p]->alive&&(pool[p]->flag & CREATUREFLAG_SLEEPER)&&
            pool[p]->type==CREATURE_CARSALESMAN&&location[pool[p]->location]->city==location[loc]->city)
            sleepercarsalesman=pool[p];

      Vehicle* car_to_sell=0;
      int price=0;

      for(int v=len(vehicle)-1;v>=0;v--)
         if(vehicle[v]->id()==activesquad->squad[buyer]->carid)
            car_to_sell = vehicle[v];

      if(!car_to_sell) set_color(COLOR_WHITE,COLOR_BLACK,0);
      else set_color(COLOR_BLACK,COLOR_BLACK,1);
      move(10,1);
      addstr("G - Get a Liberal car");

      move(11,1);
      if(car_to_sell)
      {
         price = static_cast<int>(0.8*car_to_sell->price());

         if(car_to_sell->get_heat())
            price/=10;
         set_color(COLOR_WHITE,COLOR_BLACK,0);
         addstr("S - Sell the "+car_to_sell->fullname()+" ($"+tostring(price)+")");
      }
      else
      {
         set_color(COLOR_BLACK,COLOR_BLACK,1);
         addstr("S - Sell a car");
      }

      /*if(car_to_sell && car_to_sell->heat>1 && ledger.get_funds()>=500)
         set_color(COLOR_WHITE,COLOR_BLACK,0);
      else
         set_color(COLOR_BLACK,COLOR_BLACK,1);
      move(12,1);
      addstr("P - Repaint car, replace plates and tags ($500)");*/

      if(partysize>=2)set_color(COLOR_WHITE,COLOR_BLACK,0);
      else set_color(COLOR_BLACK,COLOR_BLACK,1);
      move(16,1);
      addstr("B - Choose a buyer");

      set_color(COLOR_WHITE,COLOR_BLACK,0);
      move(16,40);
      addstr("Enter - Leave");

      if(party_status!=-1)set_color(COLOR_WHITE,COLOR_BLACK,0);
      else set_color(COLOR_BLACK,COLOR_BLACK,1);
      move(15,1);
      addstr("0 - Show the squad's Liberal status");
      if(partysize>0&&(party_status==-1||partysize>1))set_color(COLOR_WHITE,COLOR_BLACK,0);
      else set_color(COLOR_BLACK,COLOR_BLACK,1);
      move(15,40);
      addstr("# - Check the status of a squad Liberal");

      int c=getkey();

      // Leave
      if(c=='x'||c==ENTER||c==ESC||c==SPACEBAR)break;

      //Sell the car
      if(c=='s' && car_to_sell)
      {
         ledger.add_funds(price,INCOME_CARS);
         for(int v=len(vehicle)-1;v>=0;v--)
            if(vehicle[v]==car_to_sell)
            {
            	delete_and_remove(vehicle,v);
               break;
            }
      }

      // Get a car
      if(c=='g' && !car_to_sell)
      {
         int carchoice;

         vector<int> availablevehicle;
         vector<string> vehicleoption;
         for(int i=0;i<len(vehicletype);i++)
            if (vehicletype[i]->availableatshop())
            {
               availablevehicle.push_back(i);
               vehicleoption.push_back(vehicletype[i]->longname()+" ($"+
                  tostring(sleepercarsalesman?vehicletype[i]->sleeperprice():vehicletype[i]->price())+")");
            }
         while(true)
         {
            carchoice = choiceprompt("Choose a vehicle","",vehicleoption,"Vehicle",
                                     true,"We don't need a Conservative car");
            if (carchoice!=-1 && (sleepercarsalesman?vehicletype[availablevehicle[carchoice]]->sleeperprice():
                                  vehicletype[availablevehicle[carchoice]]->price()) > ledger.get_funds())
            {
               set_color(COLOR_RED,COLOR_BLACK,0);
               move(1,1);
               addstr("You don't have enough money!");

               getkey();
            }
            else break;
         }

         if(carchoice==-1) continue;

         //Picked a car, pick color
         int colorchoice;
         //if(len(vehicletype[availablevehicle[choice]]->color())>1) //Allow to back out if you don't like single colour? -XML
         //{
         colorchoice = choiceprompt("Choose a color","",vehicletype[availablevehicle[carchoice]]->color(),
                                    "Color",true,"These colors are Conservative");
         //}
         //else
         //   colorchoice = 0;

         if(colorchoice==-1) continue;

         Vehicle *v=new Vehicle(*vehicletype[availablevehicle[carchoice]],
                                vehicletype[availablevehicle[carchoice]]->color()[colorchoice],year);
         activesquad->squad[buyer]->pref_carid = v->id();
         vehicle.push_back(v);

         ledger.subtract_funds((sleepercarsalesman?v->sleeperprice():v->price()),EXPENSE_CARS);
      }

      // Reduce heat
      /*if(c=='p' && car_to_sell && car_to_sell->heat>1 && ledger.get_funds()>=500)
      {
         funds-=500;
         moneylost_goods+=500;
         car_to_sell->heat=1;
      }*/

      if(c=='b')choose_buyer(buyer);

      if(c=='0')party_status=-1;

      if(c>='1'&&c<='6'&&activesquad!=NULL)
         if(activesquad->squad[c-'1']!=NULL)
         {
            if(party_status==c-'1')fullstatus(party_status);
            else party_status=c-'1';
         }

   }
}
示例#3
0
void Shop::browse_halfscreen(squadst& customers, int& buyer) const
{
   unsigned page = 0;
   const unsigned max_entries_per_page = 20;

   std::vector<ShopOption*> available_options = options_;

   available_options.erase (remove_if (available_options.begin(),
				       available_options.end(),
				       not1 (mem_fun (&ShopOption::display))),
			    available_options.end());

   int partysize = 0;
   for (int p = 0; p < 6; ++p)
   {
      if(customers.squad[p] != NULL)
      {
         partysize++;
      }
   }

   do
   {
      erase();
      set_color(COLOR_WHITE,COLOR_BLACK,0);

      locheader();
      printparty();

      move(8,45);
      addstr("Buyer: ");
      addstr(customers.squad[buyer]->name);

      //Write wares and prices
      int yline = 10;
      int column = 1;
      int taken_letters = 0;
      for (unsigned p = page * (max_entries_per_page - 1);
           p < available_options.size() && p < page * (max_entries_per_page - 1) + max_entries_per_page;
           ++p)
      {
         if (available_options[p]->is_available())
            set_color(COLOR_WHITE,COLOR_BLACK,0);
         else
            set_color(COLOR_BLACK,COLOR_BLACK,1);
         if (column == 1)
            move(yline,1);
         else
            move(yline,40);

         if (available_options[p]->letter_defined_)
            addch(available_options[p]->showletter());
         else
         {
            // Find an available letter to use for this ware.
            bool done = false;
            while (taken_letters < 27 && !done)
            {
               done = true;
               if ('a' + taken_letters == 'b' || // Letters used by the shop UI are disallowed.
                   'a' + taken_letters == 'e' ||
                   ('a' + taken_letters == 's' && allow_selling_) ||
                   ('a' + taken_letters == 'm' && sell_masks_))
               {
                  ++taken_letters;
                  done = false;
                  continue;
               }
               for (unsigned i = 0; i < available_options.size(); ++i)
               {
                  if (available_options[i]->letter_defined_ &&
                      'a' + taken_letters == available_options[i]->letter_)
                  {
                     ++taken_letters;
                     done = false;
                     break;
                  }
               }
            }
            available_options[p]->letter_ = 'a' + taken_letters;
            addch('A' + taken_letters);
            ++taken_letters;
         }

         addstr(" - ");
         addstr(available_options[p]->get_description_halfscreen().c_str());
         if (column == 1)
            column = 2;
         else
         {
            ++yline;
            column = 1;
         }
      }
      if (sell_masks_)
      {
         move(yline,1+(column-1)*39);
         if (ledger.get_funds() >= 15)
            set_color(COLOR_WHITE,COLOR_BLACK,0);
         else
            set_color(COLOR_BLACK,COLOR_BLACK,1);
         addstr("M - Buy a Mask                ($15)");
      }
      if (column == 2)
         ++yline;

      set_color(COLOR_WHITE,COLOR_BLACK,0);
      move(yline,1);
      addstr("E - Look over Equipment");
      ++yline;

      if (allow_selling_)
      {
         move(yline,1);
         if (location[customers.squad[0]->base]->loot.size() > 0)
            set_color(COLOR_WHITE,COLOR_BLACK,0);
         else
            set_color(COLOR_BLACK,COLOR_BLACK,1);
         addstr("S - Sell something");
         ++yline;
      }

      ++yline;

      if (party_status != -1)
         set_color(COLOR_WHITE,COLOR_BLACK,0);
      else
         set_color(COLOR_BLACK,COLOR_BLACK,1);
      move(yline,1);
      addstr("0 - Show the squad's Liberal status");

      if (partysize > 0 && (party_status == -1 || partysize > 1))
         set_color(COLOR_WHITE,COLOR_BLACK,0);
      else
         set_color(COLOR_BLACK,COLOR_BLACK,1);
      move(yline++,40);
      addstr("# - Check the status of a squad Liberal");

      if (partysize >= 2)
         set_color(COLOR_WHITE,COLOR_BLACK,0);
      else
         set_color(COLOR_BLACK,COLOR_BLACK,1);
      move(yline,1);
      addstr("B - Choose a buyer");

      set_color(COLOR_WHITE,COLOR_BLACK,0);
      move(yline,40);
      addstr("Enter - ");
      addstr(exit_.c_str());



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

      for (unsigned i = 0; i < available_options.size(); ++i)
      {
         if (c == available_options[i]->letter_)
         {
            available_options[i]->choose(customers, buyer);
            break;
         }
      }

      if(c == 'e' && customers.squad[0]->base != -1)
         equip(location[customers.squad[0]->base]->loot, -1);
      else if (c == 's' && allow_selling_
               && location[customers.squad[0]->base]->loot.size() > 0)
         sell_loot(customers);
      else if (c == 'm' && sell_masks_ && ledger.get_funds() >= 15)
      {
         maskselect(*customers.squad[buyer]);
      }
      else if (c == 'b')
         choose_buyer(customers, buyer);
      else if (c == '0')
         party_status=-1;
      else if ( c >= '1' && c <= '6')
      {
         if (customers.squad[c-'1'] != NULL)
         {
            if (party_status == c - '1')
               fullstatus(party_status);
            else
               party_status = c - '1';
         }
      }
      else if (c == 10)
         break;

   } while (true);
}