예제 #1
0
bool Weapon::reload(Clip& clip)
{
   if (acceptable_ammo(clip) && !clip.empty())
   {
      loaded_cliptype_ = clip.get_itemtypename();
      ammo_ = clip.get_ammoamount();
      clip.decrease_number(1);
      return true;
   }
   else
      return false;
}
예제 #2
0
void Shop::ShopItem::choose(squadst& customers, int& buyer) const
{
   if (is_available())
   {
      ledger.subtract_funds(adjusted_price(), EXPENSE_SHOPPING);
      switch (itemclass_)
      {
         case WEAPON:
         {
            Weapon* i = new Weapon(*weapontype[getweapontype(itemtypename_)]);
            customers.squad[buyer]->give_weapon(*i, &location[customers.squad[0]->base]->loot);
            if (i->empty())
               delete i;
            else
               location[customers.squad[0]->base]->loot.push_back(i);
            break;
         }
         case CLIP:
         {
            Clip* i = new Clip(*cliptype[getcliptype(itemtypename_)]);
            customers.squad[buyer]->take_clips(*i, 1);
            if (i->empty())
               delete i;
            else
               location[customers.squad[0]->base]->loot.push_back(i);
            break;
         }
         case ARMOR:
         {
            Armor* i = new Armor(*armortype[getarmortype(itemtypename_)]);
            customers.squad[buyer]->give_armor(*i, &location[customers.squad[0]->base]->loot);
            if (i->empty())
               delete i;
            else
               location[customers.squad[0]->base]->loot.push_back(i);
            break;
         }
         case LOOT:
         {
            Loot* i = new Loot(*loottype[getloottype(itemtypename_)]);
            location[customers.squad[0]->base]->loot.push_back(i);
            break;
         }
      }
   }
}