engine/items/source/InitialItemEquipper.cpp
// Equip an initial equipment map, whether from the class, the creature's
// definition, or something else.
Equip an initial equipment map, whether from the class, the creature's
definition, or something else.
Equip an initial equipment map whether from the class the creature ' s definition or something else .
void InitialItemEquipper::process_initial_equipment(CreaturePtr creature, const map<EquipmentWornLocation, InitialItem>& initial_equipment_map, ActionManager& am)
{
  if (creature != nullptr)
  {
    InitialItemSelector iis;
    string creature_race = creature->get_race_id();
    for (const InitialEquipmentMap::value_type& ii_i : initial_equipment_map)
    {
      InitialItem ii = ii_i.second;
      pair<string, uint> item_details = iis.get_item_details(creature_race, ii);
      string item_id = item_details.first;
      uint item_quantity = item_details.second;
      if (!item_id.empty())
      {
        ItemPtr item = ItemManager::create_item(item_id, item_quantity);
        if (item != nullptr)
        {
          item->set_quantity(item_quantity);
          Equipment& eq = creature->get_equipment();
          if (item->get_quantity() > 1 && !eq.can_equip_multiple_items(ii_i.first))
          {
            item->set_quantity(1);
          }
          am.handle_item(creature, ItemAction::ITEM_ACTION_EQUIP, item, ii_i.first);
        }
        else
        {
          Log::instance().error("Could not instantiate item with id " + item_id);
        }
      }
    }
  }
}
void InitialItemEquipper :: process_initial_equipment ( CreaturePtr creature , const map < EquipmentWornLocation , InitialItem > & initial_equipment_map , ActionManager & am ) { if ( creature != nullptr ) { InitialItemSelector iis ; string creature_race = creature -> get_race_id ( ) ; for ( const InitialEquipmentMap :: value_type & ii_i : initial_equipment_map ) { InitialItem ii = ii_i . second ; pair < string , uint > item_details = iis . get_item_details ( creature_race , ii ) ; string item_id = item_details . first ; uint item_quantity = item_details . second ; if ( ! item_id . empty ( ) ) { ItemPtr item = ItemManager :: create_item ( item_id , item_quantity ) ; if ( item != nullptr ) { item -> set_quantity ( item_quantity ) ; Equipment & eq = creature -> get_equipment ( ) ; if ( item -> get_quantity ( ) > 1 && ! eq . can_equip_multiple_items ( ii_i . first ) ) { item -> set_quantity ( 1 ) ; } am . handle_item ( creature , ItemAction :: ITEM_ACTION_EQUIP , item , ii_i . first ) ; } else { Log :: instance ( ) . error ( " " + item_id ) ; } } } } }
Equip an initial equipment map, whether from the class, the creature's
definition, or something else.
Equip an initial equipment map whether from the class the creature ' s definition or something else .
// Sanity check: only allow multiple items for slots that allow this.