[ScryMUD] SVN Commit Info r733 - branches/version-2-1/mud/grrmud/server

scrymud at wanfear.com scrymud at wanfear.com
Sat Dec 4 14:17:44 PST 2004


Author: eroper
Date: 2004-12-04 14:17:43 -0800 (Sat, 04 Dec 2004)
New Revision: 733

Modified:
   branches/version-2-1/mud/grrmud/server/commands.cc
   branches/version-2-1/mud/grrmud/server/misc.cc
   branches/version-2-1/mud/grrmud/server/misc.h
   branches/version-2-1/mud/grrmud/server/object.h
Log:
Inventory now sorts by type-of-item. Bulletin boards no longer stack (they use
fake onums for postings).
--Khaav


Modified: branches/version-2-1/mud/grrmud/server/commands.cc
===================================================================
--- branches/version-2-1/mud/grrmud/server/commands.cc	2004-12-04 12:21:39 UTC (rev 732)
+++ branches/version-2-1/mud/grrmud/server/commands.cc	2004-12-04 22:17:43 UTC (rev 733)
@@ -386,7 +386,7 @@
          buf.Cap();
          show(buf, pc);
          
-         out_inv(obj_ptr->inv, pc, OBJ_INV);
+         out_inv(obj_ptr->inv, pc, OBJ_INV, obj_ptr->isBulletinBoard());
          
          String cmd = "examine";
          ROOM.checkForProc(cmd, NULL_STRING, pc, obj_ptr->OBJ_NUM);

Modified: branches/version-2-1/mud/grrmud/server/misc.cc
===================================================================
--- branches/version-2-1/mud/grrmud/server/misc.cc	2004-12-04 12:21:39 UTC (rev 732)
+++ branches/version-2-1/mud/grrmud/server/misc.cc	2004-12-04 22:17:43 UTC (rev 733)
@@ -2060,21 +2060,66 @@
 
 
 void out_inv(const List<object*>& lst, critter& pc, 
-             const short type_of_list) {
+             const short type_of_list, int is_board) {
                                //outs the names object*
-   Cell<object*> cell(lst);
 
-   //Can't use lst.head(cell) because of the const definition above.
-   //if there's a workaround, this is horrible. Thought about
-   //un-const'ing it but thought better of it.
-   Cell<object*> cnt_cell(lst);
+   List<object*>* lst_ptr = NULL;
+   int lst_idx;
 
+   List<object*> full_lst(lst);
+   Cell<object*> cell(full_lst);
+
+   List<object*> inv_weapons(NULL);
+   List<object*> inv_armor(NULL);
+   List<object*> inv_consumables(NULL);
+   List<object*> inv_containers(NULL);
+   List<object*> inv_potions(NULL);
+   List<object*> inv_scrolls(NULL);
+   List<object*> inv_wands(NULL);
+   List<object*> inv_ammunition(NULL);
+   List<object*> inv_skins(NULL);
+   List<object*> inv_misc(NULL);
+   List<object*> inv_lights(NULL);
+   
+   //when doing obj/crit inventory, PCs walk these lists.
+   List<object*>* inv_lists[] = {
+      &inv_weapons,
+      &inv_armor,
+      &inv_consumables,
+      &inv_containers,
+      &inv_potions,
+      &inv_scrolls,
+      &inv_wands,
+      &inv_ammunition,
+      &inv_lights,
+      &inv_misc,
+      NULL
+   };
+
+   //when doing obj/crit inventory, MOBs walk these lists.
+   List<object*>* mob_inv_lists[] = {
+      &full_lst,
+      NULL
+   };
+
+   char *inv_names[] = {
+      "[ Weapons ]",
+      "[ Armor ]",
+      "[ Consumables ]",
+      "[ Containers ]",
+      "[ Potions ]",
+      "[ Scrolls ]",
+      "[ Wands ]",
+      "[ Ammunition ]",
+      "[ Lights ]",
+      "[ Misc. ]"
+   };
+
    object*  obj_ptr;
    String buf(100);
    String qty_str = "";//important to set this? so it's not undef (if mob)
    static int item_counts[NUMBER_OF_ITEMS + 1];
    int id_num;
-   
 
    mudlog.log(TRC, "In out_inv.\n");
 
@@ -2082,7 +2127,7 @@
       pc.show("<ITEM_LIST>");
    }
 
-   if (IsEmpty(lst) && type_of_list == OBJ_INV) {
+   if (IsEmpty(full_lst) && type_of_list == OBJ_INV) {
       pc.show("        [empty]        \n");
       if (pc.isUsingClient()) {
          pc.show("</ITEM_LIST>");
@@ -2094,12 +2139,41 @@
 
 
    //don't bother if it's not a player... yes mobs do call this function.
-   if (pc.isPc()) {
+   //also dont do this for boards.
+   if ( (pc.isPc()) && (!is_board) ) {
       //set the counts to zero, then update them all.
       memset(item_counts, 0, sizeof(int) * (NUMBER_OF_ITEMS + 1));
-      while ( (obj_ptr = cnt_cell.next()) ) {
+      while ( (obj_ptr = cell.next()) ) {
          item_counts[obj_ptr->getIdNum()]++;
+
+         switch (type_of_list) {
+            case OBJ_INV:
+            case CRIT_INV:
+               if(obj_ptr->isWeapon()) {
+                  inv_weapons.append(obj_ptr);
+               } else if (obj_ptr->isArmor()) {
+                  inv_armor.append(obj_ptr);
+               } else if (obj_ptr->isPotion()) {
+                  inv_consumables.append(obj_ptr);
+               } else if (obj_ptr->isFood()) {
+                  inv_consumables.append(obj_ptr);
+               } else if (obj_ptr->isContainer()) {
+                  inv_containers.append(obj_ptr);
+               } else if (obj_ptr->isWand()) {
+                  inv_wands.append(obj_ptr);
+               } else if (obj_ptr->isScroll()) {
+                  inv_scrolls.append(obj_ptr);
+               } else if (obj_ptr->isAmmo()) {
+                  inv_ammunition.append(obj_ptr);
+               } else if (obj_ptr->isLightSource()) {
+                  inv_lights.append(obj_ptr);
+               } else {
+                  inv_misc.append(obj_ptr);
+               }
+         }//switch
+
       }//while
+      full_lst.head(cell);
    }
 
    switch (type_of_list)
@@ -2112,7 +2186,8 @@
                id_num = obj_ptr->getIdNum();
 
                //don't bother if it's not a player... yes mobs do call this function.
-               if (pc.isPc()) {
+               //don't bother if it's a board
+               if ( (pc.isPc()) && (!is_board) ) {
                   if (//these objects should not stack. 
                         (id_num == config.corpseObject) ||
                         (id_num == config.pcSkinObject) ||
@@ -2168,68 +2243,90 @@
          }//while
          break;
       case OBJ_INV: case CRIT_INV:
-         while ((obj_ptr = cell.next())) {
-            if (detect(pc.SEE_BIT, obj_ptr->OBJ_VIS_BIT)) {
+         
+         //pc's walk sorted inventory, mobs dont.
+         //boards don't get sorted either.
+         if ( (pc.isPc()) && (!is_board) ) {
+            lst_ptr = inv_lists[0];
+         } else {
+            lst_ptr = mob_inv_lists[0];
+         }
+         lst_idx = 0;
 
-               id_num = obj_ptr->getIdNum();
+         while ( lst_ptr ) {
 
-               //don't bother if it's not a player... yes mobs do call this function.
-               if (pc.isPc()) {
-                  if (//these objects should not stack. 
-                        (id_num == config.corpseObject) ||
-                        (id_num == config.pcSkinObject) ||
-                        (id_num == config.HeadObject)
-                     ) {
-                     qty_str = "";
-                  } else {
-                     if ( item_counts[id_num] == -1 ) {
-                        //already done it.
-                        continue;
-                     } else if ( item_counts[id_num] > 1 ) {
-                        Sprintf(qty_str, "(%i%s) ", item_counts[id_num], "x");
+            lst_ptr->head(cell);
+
+            if ( (pc.isPc()) && (!is_board) ) {
+               Sprintf(buf, "%s\n", inv_names[lst_idx]);
+               pc.show(buf, HL_OBJ_LIST);
+            }
+
+            while ((obj_ptr = cell.next())) {
+               if (detect(pc.SEE_BIT, obj_ptr->OBJ_VIS_BIT)) {
+
+                  id_num = obj_ptr->getIdNum();
+
+                  //don't bother if it's not a player... yes mobs do call this function.
+                  if ((pc.isPc()) && (!is_board)) {
+                     if (//these objects should not stack. 
+                           (id_num == config.corpseObject) ||
+                           (id_num == config.pcSkinObject) ||
+                           (id_num == config.HeadObject)
+                        ) {
+                        qty_str = "";
                      } else {
-                        qty_str = "";
-                     }
-                     item_counts[id_num] = -1;
-                  }//okay to stack
-               }
+                        if ( item_counts[id_num] == -1 ) {
+                           //already done it.
+                           continue;
+                        } else if ( item_counts[id_num] > 1 ) {
+                           Sprintf(qty_str, "(%i%s) ", item_counts[id_num], "x");
+                        } else {
+                           qty_str = "";
+                        }
+                        item_counts[id_num] = -1;
+                     }//okay to stack
+                  }
 
-               if (pc.shouldShowVnums()) {
-                  char tmp[50];
-                  sprintf(tmp, "%p: ", obj_ptr);
-                  Sprintf(buf, "   %s [%i] %P11 %S%S", tmp, id_num,
-                          &qty_str, long_name_of_obj(*obj_ptr, ~0));
-               }
-               else {
-                  Sprintf(buf, "\t%S%S", &qty_str,
-                        long_name_of_obj(*obj_ptr, ~0));
-               }
+                  if (pc.shouldShowVnums()) {
+                     char tmp[50];
+                     sprintf(tmp, "%p: ", obj_ptr);
+                     Sprintf(buf, "   %s [%i] %P11 %S%S", tmp, id_num,
+                           &qty_str, long_name_of_obj(*obj_ptr, ~0));
+                  }
+                  else {
+                     Sprintf(buf, "\t%S%S", &qty_str,
+                           long_name_of_obj(*obj_ptr, ~0));
+                  }
 
-               buf.Cap();
+                  buf.Cap();
 
-               if (obj_ptr->isHerb()) {
-                  if (d(1, 100) <= 
-                      d(1, 2 * get_percent_lrnd(HERBALISM_SKILL_NUM, pc))) {
-                     buf.Append("(^Gherb^0)");
+                  if (obj_ptr->isHerb()) {
+                     if (d(1, 100) <= 
+                           d(1, 2 * get_percent_lrnd(HERBALISM_SKILL_NUM, pc))) {
+                        buf.Append("(^Gherb^0)");
+                     }//if
                   }//if
-               }//if
 
-               if  (pc.canDetectMagic() &&
-                    (!IsEmpty(obj_ptr->affected_by) ||
-                     !IsEmpty(obj_ptr->stat_affects))) {
+                  if  (pc.canDetectMagic() &&
+                        (!IsEmpty(obj_ptr->affected_by) ||
+                         !IsEmpty(obj_ptr->stat_affects))) {
                      buf.Append("^B{Blue Glow}^0\n");
-		     
-                 
+
+
+                  }//if
+                  else {
+                     buf.Append("\n");
+                  }
+                  if (obj_ptr->OBJ_VIS_BIT & 2) {
+                     buf.Prepend("*");
+                  }//if
+                  pc.show(buf, HL_OBJ_LIST);
                }//if
-	       else {
-	          buf.Append("\n");
-               }
-               if (obj_ptr->OBJ_VIS_BIT & 2) {
-                  buf.Prepend("*");
-               }//if
-               pc.show(buf, HL_OBJ_LIST);
-            }//if
-         }//while
+            }//while
+            lst_idx++;
+            lst_ptr = inv_lists[lst_idx];
+         }// while lst_ptr
          break;
       default:
          mudlog.log(ERROR, "ERROR:  default called in out_inv.\n");

Modified: branches/version-2-1/mud/grrmud/server/misc.h
===================================================================
--- branches/version-2-1/mud/grrmud/server/misc.h	2004-12-04 12:21:39 UTC (rev 732)
+++ branches/version-2-1/mud/grrmud/server/misc.h	2004-12-04 22:17:43 UTC (rev 733)
@@ -110,7 +110,8 @@
 
 void out_str(const List<String*>& lst, critter& pc); 
 void out_crit(const List<critter*>& lst, critter& pc, int see_all = FALSE);
-void out_inv(const List<object*>& lst, critter& pc, const short l_type); 
+void out_inv(const List<object*>& lst, critter& pc, const short l_type, const
+      int is_board = false); 
          //outs the names object*, formats according to l_type
 
 

Modified: branches/version-2-1/mud/grrmud/server/object.h
===================================================================
--- branches/version-2-1/mud/grrmud/server/object.h	2004-12-04 12:21:39 UTC (rev 732)
+++ branches/version-2-1/mud/grrmud/server/object.h	2004-12-04 22:17:43 UTC (rev 733)
@@ -284,7 +284,16 @@
    int hasScript() const { return obj_flags.get(76); }
    int isLiquid() const;
    int isCanteen() const;
+   int isContainer() const { return obj_flags.get(54); }
    int isTwoHanded() const;
+   int isWeapon() const { return (obj_flags.get(57) && (! obj_flags.get(40))); }
+   int isNotWeapon() const { return (!isWeapon()); }
+   int isWand() const { return obj_flags.get(51); }
+   int isArmor() const { return obj_flags.get(56); }
+   int isDart() const { return obj_flags.get(48); }
+   int isArrow() const { return obj_flags.get(49); }
+   int isAmmo() const { return ( isArrow() || isDart() ); }
+         
    int isBoat() const { return OBJ_FLAGS.get(62); }
 
    void setComplete();




More information about the ScryMUD mailing list