BOOL CUser::CheckWeight(int itemid, short count) { _ITEM_TABLE* pTable = NULL; pTable = m_pMain->m_ItemtableArray.GetData( itemid ); if (!pTable) return FALSE; if (!pTable->m_bCountable) { if ((m_sItemWeight + pTable->m_sWeight ) <= m_sMaxWeight) { // Check weight first! if (GetEmptySlot(itemid, 0) != 0xFF) { // Now check empty slots :P return TRUE; } else { return FALSE; } } else { return FALSE; } } else { if (((pTable->m_sWeight * count) + m_sItemWeight) <= m_sMaxWeight) { // Check weight first! if (GetEmptySlot(itemid, pTable->m_bCountable) != 0xFF) { // Now check empty slots :P return TRUE; } else { return FALSE; } } else { return FALSE; } } return FALSE; }
//------------------------------------------------------------------ // HeapPage::InsertRecord // // Input : Pointer to the record and the record's length // Output : Record ID of the record inserted. // Purpose : Insert a record into the page // Return : OK if everything went OK, DONE if sufficient space is not available. //------------------------------------------------------------------ Status HeapPage::InsertRecord(const char *recPtr, int length, RecordID& rid) { if (length<=0) return FAIL; if (AvailableSpace()>=length) { // there is enough space on the page for a new slot (if needed) and the record short index; Slot* newslot=GetEmptySlot(index); if (newslot == NULL) { // slot directory is full if (GetContiguousFreeSpaceSize()<sizeof(Slot)+length) { // not enough space for a slot and the record in the contiguous free space area Status cs=CompressPage(); if (cs==FAIL) return FAIL; } newslot = AppendNewSlot(); } //if (newslot == NULL) return DONE; if (GetContiguousFreeSpaceSize()<length) { // slot directory not full, but not enough space for a record at the end Status cs=CompressPage(); if (cs==FAIL) return FAIL; } freePtr = freePtr-length; freeSpace= freeSpace-length; FillSlot(newslot,freePtr+1,length); if (memcpy(data + freePtr+1,recPtr,length) != data+freePtr+1) { return FAIL; } rid.slotNo=index; rid.pageNo=pid; return OK; } else return DONE; }
int Append( T* data ) { int newslot = GetEmptySlot( ); m_Data[ newslot ] = data; m_UsedCnt++; return newslot; };
// must wait for state to be written because it must know if all slots are taken void SaveFirstSaved() { std::map<double, int> savedStates = GetSavedStates(); // save to an empty slot if (savedStates.size() < NUM_STATES) Save(GetEmptySlot(savedStates), true); // overwrite the oldest state else { std::map<double, int>::iterator it = savedStates.begin(); std::advance(it, savedStates.size() - 1); Save(it->second, true); } }
CItem* CItemSlot::AddItem( tagITEM& Item ) { t_InvTYPE type = CInventory::m_InvTYPE[ Item.GetTYPE() ]; int iStartIdx,iEndIdx; iStartIdx = MAX_EQUIP_IDX + type * INVENTORY_PAGE_SIZE; iEndIdx = iStartIdx + INVENTORY_PAGE_SIZE - 1; int iEmptySlotIdx = GetEmptySlot( iStartIdx, iEndIdx ); assert( iEmptySlotIdx >= 0 ); /// TODO::리턴값이 없었는데 일단 임시로 넣었음 원래 리턴값을 넣도록.. return AddItem( iEmptySlotIdx, Item ); }
void Message::AddMessage(DWORD tshow, int type, TCHAR* Text) { Lock(); int i; DWORD fpsTime = ::GetTickCount() - startTime; i = GetEmptySlot(); messages[i].type = type; messages[i].tshow = tshow; messages[i].tstart = fpsTime; messages[i].texpiry = fpsTime; _tcscpy(messages[i].text, Text); Unlock(); // Render(); // NO this causes crashes (don't know why..) }
int32 URInventoryComponent::AddItem(ARItem* Item) { // find an empty inventory slot int32 EmptySlot = GetEmptySlot(); if(EmptySlot == -1) { // failed // blow up return -1; } FRInventorySlot Slot; Slot.DisplayInfo.ItemName = Item->DisplayInfo.ItemName; Slot.SlotIndex = EmptySlot; Slot.DisplayInfo.ItemIcon = Item->DisplayInfo.ItemIcon; Inventory[EmptySlot] = Slot; // add item to Items array return EmptySlot; }
BOOL CUser::GiveItem(int itemid, short count, bool send_packet /*= true*/) { int pos = 255; int send_index = 0 ; char send_buff[128]; _ITEM_TABLE* pTable = NULL; // This checks if such an item exists. pTable = m_pMain->m_ItemtableArray.GetData( itemid ); if( !pTable ) return FALSE; pos = GetEmptySlot( itemid, pTable->m_bCountable ); if( pos != 0xFF ) { // Common Item if( pos >= HAVE_MAX ) return FALSE; if( m_pUserData->m_sItemArray[SLOT_MAX+pos].nNum != 0 ) { if( pTable->m_bCountable != 1) return FALSE; else if( m_pUserData->m_sItemArray[SLOT_MAX+pos].nNum != itemid ) return FALSE; } /* if (pTable->m_bCountable) { // Check weight of countable item. if (((pTable->m_sWeight * count) + m_sItemWeight) > m_sMaxWeight) { return FALSE; } } else { // Check weight of non-countable item. if ((pTable->m_sWeight + m_sItemWeight) > m_sMaxWeight) { return FALSE; } } */ m_pUserData->m_sItemArray[SLOT_MAX+pos].nNum = itemid; // Add item to inventory. if( pTable->m_bCountable) { // Apply number of items to a countable item. m_pUserData->m_sItemArray[SLOT_MAX+pos].sCount += count; if( m_pUserData->m_sItemArray[SLOT_MAX+pos].sCount > MAX_ITEM_COUNT ) { m_pUserData->m_sItemArray[SLOT_MAX+pos].sCount = MAX_ITEM_COUNT; } } else { // Just add uncountable item to inventory. m_pUserData->m_sItemArray[SLOT_MAX+pos].sCount = 1; } m_pUserData->m_sItemArray[SLOT_MAX+pos].sDuration = pTable->m_sDuration; // Apply duration to item. } else { return FALSE; // No empty slots. } SendItemWeight(); // Change weight first -- do this regardless. if (send_packet) { SetByte( send_buff, WIZ_ITEM_COUNT_CHANGE, send_index ); SetShort( send_buff, 0x01, send_index ); // The number of for-loops SetByte( send_buff, 0x01, send_index ); SetByte( send_buff, pos, send_index ); SetDWORD( send_buff, itemid, send_index ); // The ID of item. SetDWORD( send_buff, m_pUserData->m_sItemArray[SLOT_MAX+pos].sCount, send_index ); Send( send_buff, send_index ); } return TRUE; }