bool CInventory::Ruck(PIItem pIItem, bool strict_placement) { if(!strict_placement && !CanPutInRuck(pIItem)) return false; if (!IsGameTypeSingle()) { u16 real_parent = pIItem->object().H_Parent() ? pIItem->object().H_Parent()->ID() : u16(-1); if (GetOwner()->object_id() != real_parent) { Msg("! WARNING: CL: actor [%d] tries to place to ruck not own item [%d], that has parent [%d]", GetOwner()->object_id(), pIItem->object_id(), real_parent); return false; } } bool in_slot = InSlot(pIItem); //вещь была в слоте if(in_slot) { if(GetActiveSlot() == pIItem->CurrSlot()) Activate(NO_ACTIVE_SLOT); m_slots[pIItem->CurrSlot()].m_pIItem = NULL; }else { //вещь была на поясе или вообще только поднята с земли TIItemContainer::iterator it = std::find(m_belt.begin(), m_belt.end(), pIItem); if(m_belt.end() != it) m_belt.erase(it); if (!IsGameTypeSingle()) { u16 item_parent_id = pIItem->object().H_Parent() ? pIItem->object().H_Parent()->ID() : u16(-1) ; u16 inventory_owner_id = GetOwner()->object_id(); R_ASSERT2(item_parent_id == inventory_owner_id, make_string("! ERROR: CL: Actor[%d] tries to place to ruck not own item [%d], real item owner is [%d]", inventory_owner_id, pIItem->object_id(), item_parent_id).c_str() ); #ifdef MP_LOGGING Msg("--- Actor [%d] place to ruck item [%d]", inventory_owner_id, pIItem->object_id()); #endif } } m_ruck.insert (m_ruck.end(), pIItem); CalcTotalWeight (); InvalidateState (); m_pOwner->OnItemRuck (pIItem, pIItem->m_ItemCurrPlace); SInvItemPlace prev_place = pIItem->m_ItemCurrPlace; pIItem->m_ItemCurrPlace.type = eItemPlaceRuck; pIItem->OnMoveToRuck (prev_place); if(in_slot) pIItem->object().processing_deactivate(); return true; }
bool CUIActorMenu::ToDeadBodyBag(CUICellItem* itm, bool b_use_cursor_pos) { CUIDragDropListEx* old_owner = itm->OwnerList(); CUIDragDropListEx* new_owner = NULL; if(b_use_cursor_pos) { new_owner = CUIDragDropListEx::m_drag_item->BackList(); VERIFY (new_owner==m_pDeadBodyBagList); }else new_owner = m_pDeadBodyBagList; CUICellItem* i = old_owner->RemoveItem(itm, (old_owner==new_owner) ); if(b_use_cursor_pos) new_owner->SetItem (i,old_owner->GetDragItemPosition()); else new_owner->SetItem (i); PIItem iitem = (PIItem)i->m_pData; if ( m_pPartnerInvOwner ) { move_item_from_to (m_pActorInvOwner->object_id(), m_pPartnerInvOwner->object_id(), iitem->object_id()); } else // box { move_item_from_to (m_pActorInvOwner->object_id(), m_pInvBox->ID(), iitem->object_id()); } UpdateDeadBodyBag(); return true; }
bool move_item_check( PIItem itm, CInventoryOwner* from, CInventoryOwner* to, bool weight_check ) { if ( weight_check ) { float invWeight = to->inventory().CalcTotalWeight(); float maxWeight = to->MaxCarryWeight(); float itmWeight = itm->Weight(); if ( invWeight + itmWeight >= maxWeight ) { return false; } } move_item_from_to( from->object_id(), to->object_id(), itm->object_id() ); return true; }
void CUIActorMenu::TakeAllFromInventoryBox() { u16 actor_id = m_pActorInvOwner->object_id(); u32 const cnt = m_pDeadBodyBagList->ItemsCount(); for ( u32 i = 0; i < cnt; ++i ) { CUICellItem* ci = m_pDeadBodyBagList->GetItemIdx(i); for ( u32 j = 0; j < ci->ChildsCount(); ++j ) { PIItem j_item = (PIItem)(ci->Child(j)->m_pData); move_item_from_to( m_pInvBox->ID(), actor_id, j_item->object_id() ); } PIItem item = (PIItem)(ci->m_pData); move_item_from_to( m_pInvBox->ID(), actor_id, item->object_id() ); }//for i m_pDeadBodyBagList->ClearAll( true ); // false }
//положить вещь в слот bool CInventory::Slot(u16 slot_id, PIItem pIItem, bool bNotActivate, bool strict_placement) { VERIFY(pIItem); if(ItemFromSlot(slot_id) == pIItem) return false; if (!IsGameTypeSingle()) { u16 real_parent = pIItem->object().H_Parent() ? pIItem->object().H_Parent()->ID() : u16(-1); if (GetOwner()->object_id() != real_parent) { Msg("! WARNING: CL: actor [%d] tries to place to slot not own item [%d], that has parent [%d]", GetOwner()->object_id(), pIItem->object_id(), real_parent); return false; } } //. Msg("To Slot %s[%d]", *pIItem->object().cName(), pIItem->object().ID()); if(!strict_placement && !CanPutInSlot(pIItem,slot_id)) { #ifdef _DEBUG Msg("there is item %s[%d,%x] in slot %d[%d,%x]", ItemFromSlot(pIItem->GetSlot())->object().cName().c_str(), ItemFromSlot(pIItem->GetSlot())->object().ID(), ItemFromSlot(pIItem->GetSlot()), pIItem->GetSlot(), pIItem->object().ID(), pIItem); #endif //. if(m_slots[pIItem->GetSlot()].m_pIItem == pIItem && !bNotActivate ) //. Activate(pIItem->GetSlot()); return false; } m_slots[slot_id].m_pIItem = pIItem; //удалить из рюкзака или пояса TIItemContainer::iterator it_ruck = std::find(m_ruck.begin(), m_ruck.end(), pIItem); TIItemContainer::iterator it_belt = std::find(m_belt.begin(), m_belt.end(), pIItem); if (!IsGameTypeSingle()) { if (it_ruck != m_ruck.end()) { m_ruck.erase(it_ruck); R_ASSERT(it_belt == m_belt.end()); } else if(it_belt != m_belt.end()) { m_belt.erase(it_belt); R_ASSERT(it_ruck == m_ruck.end()); } else { u16 real_parent = pIItem->object().H_Parent() ? pIItem->object().H_Parent()->ID() : u16(-1); R_ASSERT2(GetOwner()->object_id() == real_parent, make_string("! ERROR: CL: actor [%d] doesn't contain [%d], real parent is [%d]", GetOwner()->object_id(), pIItem->object_id(), real_parent).c_str() ); } #ifdef MP_LOGGING Msg("--- Actor [%d] places to slot item [%d]", GetOwner()->object_id(), pIItem->object_id()); #endif //#ifdef MP_LOGGING } else { if (it_ruck != m_ruck.end()) m_ruck.erase(it_ruck); if (it_belt != m_belt.end()) m_belt.erase(it_belt); } bool in_slot = InSlot(pIItem); if(in_slot && (pIItem->CurrSlot()!=slot_id)) { if(GetActiveSlot() == pIItem->CurrSlot()) Activate(NO_ACTIVE_SLOT); m_slots[pIItem->CurrSlot()].m_pIItem = NULL; } if (((m_iActiveSlot==slot_id) ||(m_iActiveSlot==NO_ACTIVE_SLOT) && m_iNextActiveSlot==NO_ACTIVE_SLOT) && (!bNotActivate)) { #ifdef DEBUG Msg("---To Slot: activating slot [%d], Frame[%d]", slot_id, Device.dwFrame); #endif // #ifdef DEBUG Activate (slot_id); } SInvItemPlace p = pIItem->m_ItemCurrPlace; m_pOwner->OnItemSlot (pIItem, pIItem->m_ItemCurrPlace); pIItem->m_ItemCurrPlace.type = eItemPlaceSlot; pIItem->m_ItemCurrPlace.slot_id = slot_id; pIItem->OnMoveToSlot (p); pIItem->object().processing_activate(); return true; }