Author Topic: /equip and /dequip a tiny bit differently  (Read 196 times)

Denes

  • Traveller
  • *
  • Posts: 32
    • View Profile
/equip and /dequip a tiny bit differently
« on: December 07, 2013, 05:26:22 pm »
Little changes that might make ’reload arrows’ or ’hammer closed ring’ shortcuts work smoother:
Code: [Select]
Index: client/cmdusers.cpp
===================================================================
--- client/cmdusers.cpp (revision 9059)
+++ client/cmdusers.cpp (working copy)
@@ -362,13 +362,22 @@
 
     else if ( words[0] == "/dequip" )
     {
-        if ( words.GetCount() < 2 )
-            return "Usage: /dequip [item name|slot name]";
+        if ( words.GetCount() < 2 || (words[1] == "stack" && words.GetCount() < 3))
+            return "Usage: /dequip [stack] [item name|slot name]";
 
         pawsInventoryWindow* window = (pawsInventoryWindow*)PawsManager::GetSingleton().FindWidget("InventoryWindow");
-        csString itemName( words.GetTail(1) );
+        csString itemName;
+ if (words[1] == "stack")
+ {
+ itemName=( words.GetTail(2) );
+ window->Dequip( itemName, true );
+ }
+ else
+ {
+ itemName=( words.GetTail(1) );
         window->Dequip( itemName );
     }
+    }
 
     else if ( words[0] == "/write" )
     {
Index: client/gui/inventorywindow.cpp
===================================================================
--- client/gui/inventorywindow.cpp (revision 9059)
+++ client/gui/inventorywindow.cpp (working copy)
@@ -288,8 +288,15 @@
     return NULL;
 }
 
+pawsSlot* pawsInventoryWindow::GetStackingSlot(const char* itemName, int stackCount)
+{
+    for ( size_t n = 0; n < bulkSlots.GetSize(); n++ ) //Iterate for first fit stacking slot
+ if ( (bulkSlots[n]) && (!bulkSlots[n]->IsEmpty()) && (bulkSlots[n]->GetToolTip().CompareNoCase(itemName)) && (bulkSlots[n]->StackCount()+stackCount<=65) ) //magical 65 used hardcoded in many places but also declared in psiem.h. include? MAX_STACK_COUNT?
+ return bulkSlots[n];
+    return NULL;
+}
 
-void pawsInventoryWindow::Dequip( const char* itemName )
+void pawsInventoryWindow::Dequip( const char* itemName, bool stack)
 {
     pawsListBox* bulkList = dynamic_cast <pawsListBox*> (FindWidget("BulkList"));
     if ( (itemName != NULL) && (bulkList) )
@@ -318,7 +325,15 @@
             int slot        = fromSlot->ID();
             int stackCount  = fromSlot->StackCount();
 
-            pawsSlot* freeSlot = GetFreeSlot();
+ pawsSlot* freeSlot = NULL;
+ if (stack)//Find a stacking slot
+ {
+ freeSlot = GetStackingSlot(fromSlot->GetToolTip(), fromSlot->StackCount());
+ }
+ if (freeSlot == NULL) //Need to look for an empty slot
+ {
+ freeSlot = GetFreeSlot();
+ }
             if ( freeSlot )
             {
 
@@ -353,12 +368,20 @@
                 // We found an item with a matching name.
                 // If the stack count matches the desired amount, we are done.
                 // Otherwise, keep looking for a better match.
+                if (slotDesc->stackCount == stackCount)
+ {
                 from = slotDesc;
-                if (slotDesc->stackCount == stackCount)
                     break;
             }
+ else if (from==NULL // if its first match
+ || ((from->stackCount<stackCount)&&(from->stackCount < slotDesc->stackCount)) // if storedslot stackcount (from) is smaller than what we wanted (stackCount), take the larger stack. '/equip 65 iron arrow' will take 45 over 35
+ || ((from->stackCount > slotDesc->stackCount)&&(slotDesc->stackCount>stackCount))) // if storedslot stackcount (from) is greater the examined (slotDesc) is greater than what we wanted (stackCount), take the smaller stack. '/equip 1 open steel ring' will take 10 over 65
+ {
+ from = slotDesc;
         }
     }
+        }
+    }
 
     if (from)
     {
Index: client/gui/inventorywindow.h
===================================================================
--- client/gui/inventorywindow.h (revision 9059)
+++ client/gui/inventorywindow.h (working copy)
@@ -66,6 +66,8 @@
 
     /// Get a free slot
     pawsSlot* GetFreeSlot();
+ /// Get a stacking slot returns NULL if no suitable found
+ pawsSlot* GetStackingSlot(const char* itemName, int stackCount);
 
     /** Equips an item into it's closest available slot.
      *  Will pick the first item of the given name in the bulk slots to try
@@ -84,7 +86,7 @@
      *
      *  @param itemName The name of the item in the inventory.     
      */   
-    void Dequip(const char* itemName);
+    void Dequip(const char* itemName, bool stack = false);
     
     /** Finds an item with the given name and attempts to open it as a book
      *  to write on.

So a ’/dequip stack iron arrow; /equip 65 iron arrow’ could first try to stack the ones you are holding with another in the inventory and then grab the stack which is closest to 65, so you don’t end up with several smaller stacks clogging the invo;
The same way ’/dequip stack dozen closed steel; /equip 1 dozen open steel rings; /use’ could stack the products and use up the smaller stack of materials first.