Beispiel #1
0
// Moves an item from one slot to another
bool _Inventory::MoveInventory(_Buffer &Data, size_t OldSlot, size_t NewSlot) {
	if(!CanSwap(OldSlot, NewSlot))
		return false;

	// Add to stack
	if(Slots[NewSlot].Item == Slots[OldSlot].Item) {
		Slots[NewSlot].Count += Slots[OldSlot].Count;

		// Group stacks
		if(Slots[NewSlot].Count > INVENTORY_MAX_STACK) {
			Slots[OldSlot].Count = Slots[NewSlot].Count - INVENTORY_MAX_STACK;
			Slots[NewSlot].Count = INVENTORY_MAX_STACK;
		}
		else
			Slots[OldSlot].Item = nullptr;

	}
	else {

		// Check for reverse swap
		if(!CanSwap(NewSlot, OldSlot))
			return false;

		SwapItem(NewSlot, OldSlot);
	}

	// Build packet
	SerializeSlot(Data, NewSlot);
	SerializeSlot(Data, OldSlot);

	return true;
}
Beispiel #2
0
// 퀵 소트
void CRankDlg::QuickSort(int first, int last)
{
    int pivot, left, right ;

     if (first < last) {
         pivot =(last +first) /2 ; 
		 left =first ; right =last ;
         while (left < right) {
			 while (_ttoi (rankList.GetItemText (left, 0)) <= _ttoi (rankList.GetItemText (pivot, 0)) && left < last) left++ ;
             while (_ttoi (rankList.GetItemText (right, 0)) > _ttoi (rankList.GetItemText (pivot, 0))) right-- ;
             if (left < right) SwapItem (left, right) ;	// 교환 
         }
		 SwapItem (pivot, right) ;
     
         QuickSort (first, right -1) ;
         QuickSort (right +1, last) ;
    }
}