[Circle][Code] Multiple items contrib

From: John (witpens@optushome.com.au)
Date: 12/14/01


Just did a simple thing so that you can list multiple objects like
this:-
A bag is here. [3]
A bag is here. [2] <invisible>
etc

Sorry, I dont know how to use the diff commands to add into the contrib
section - besides, my base code is already modified too much to do so
anyways.

So, for those that want it, here are the easy steps:-

1. Near the top:-
Change
void show_obj_to_char(struct obj_data *obj, struct char_data *ch, int
mode);  TO
void show_obj_to_char(struct obj_data *obj, struct char_data *ch, int
mode, int list_view);

Add:
struct list_view_type {
 struct obj_data *obj;
 int count;
 struct list_view_type *next;
};

2. Change all calls of show_obj_to_char in act.informative so that
list_view = 0;
eg. original is show_obj_to_char(obj, ch, mode);
change to show_obj_to_char(obj, ch, mode, 0);
This needs to be applied to approx 4-6 calls.

3. Now in show_obj_to_char() function, add in the int list_view
parameter.
Then, right at the bottom of the function, add:-
RIGHT ABOVE show_obj_modifiers(obj, ch);
if (list_view > 1) {
   sprintf(buf, " [%d] ", list_view);
   send_to_char(buf, ch);
  }

4. Copy the functions below and replace the original list_obj_to_char to
the one done below. And thats it. Have fun

void create_list_view(struct obj_data *obj)
{
  struct list_view_type *tmp;
  CREATE(tmp, struct list_view_type, 1);
  tmp->obj = obj;
  tmp->count = 1;
  if (list_view_top)
   tmp->next = list_view_top;
  else
   tmp->next = NULL;
  list_view_top = tmp;
}

void find_list_view(struct obj_data *obj)
{
 struct list_view_type *tmp, *tmp_next;
 int found = 0, i =0;

 for (tmp = list_view_top; tmp; tmp = tmp_next) {
  i++;
  tmp_next = tmp->next;
  if ((tmp->obj->item_number == obj->item_number) &&
!strcmp(tmp->obj->name, obj->name) && !strcmp(tmp->obj->description,
obj->description) && (GET_OBJ_EXTRA(tmp->obj) == GET_OBJ_EXTRA(obj))) {
   tmp->count++;
   found = 1;
  }
 }
 if (!found)
  create_list_view(obj);
}


void list_obj_to_char(struct obj_data *list, struct char_data *ch, int
mode, int show)
{
  struct obj_data *i;
  bool found = FALSE;
  struct list_view_type *tmp, *tmp_next, *tmp1;

  list_view_top = NULL;
  list_view_reverse = NULL;

  for (i = list; i; i = i->next_content)
   if (CAN_SEE_OBJ(ch, i))
    find_list_view(i);

  for (tmp = list_view_top; tmp; tmp = tmp_next) {
 tmp_next = tmp->next;
 CREATE(tmp1, struct list_view_type, 1);
 if (list_view_reverse)
  tmp1->next = list_view_reverse;
 else
  tmp1->next = NULL;
 tmp1->count = tmp->count;
 tmp1->obj = tmp->obj;
 list_view_reverse = tmp1;
 free(tmp);
  }

  /* now reverse the orders to original order */
  for (tmp = list_view_reverse; tmp; tmp = tmp_next) {
 tmp_next = tmp->next;
 show_obj_to_char(tmp->obj, ch, mode, tmp->count);
 found = TRUE;
 free(tmp);
  }

  if (!found && show)
    send_to_char(" Nothing.\r\n", ch);
}

--
   +---------------------------------------------------------------+
   | FAQ: http://qsilver.queensu.ca/~fletchra/Circle/list-faq.html |
   | Archives: http://post.queensu.ca/listserv/wwwarch/circle.html |
   | Newbie List:  http://groups.yahoo.com/group/circle-newbies/   |
   +---------------------------------------------------------------+



This archive was generated by hypermail 2b30 : 06/24/03 PDT