Re: counting inventory

From: George (greerga@CIRCLEMUD.ORG)
Date: 06/04/98


On Wed, 4 Jun 1998, Pheonix Shadowflame wrote:

>What I need to do is count the number of items the person has wearing + in
>the inventory + in containers (some of which the person may wear) and
>there I'm lost.  I can get the first 2 parts done but I can't figure out
>how to count all the items in containers. Any hints?

I'd change 'Crash_save' as follows:

int Crash_save(struct obj_data * obj, FILE * fp)
{
  struct obj_data *tmp;
  int result, objcount = 0;

  if (obj) {
    objcount += Crash_save(obj->contains, fp);
    objcount += Crash_save(obj->next_content, fp);
    result = Obj_to_store(obj, fp);

    for (tmp = obj->in_obj; tmp; tmp = tmp->in_obj)
      GET_OBJ_WEIGHT(tmp) -= GET_OBJ_WEIGHT(obj);

    if (!result)
      return -1;
  }
  return objcount;
}

(Error of -1 would skew result though...not sure if a large problem.)

Than change checks that say this:
  if (!Crash_save(ch->carrying, fp)) {

to actually record the value.

---

Not even sure if that will work due to recursion, but it's a thought.
100% pure Code-written-in-mail-program-and-not-even-feasibility-tested.

--
George Greer, greerga@circlemud.org | Genius may have its limitations, but
http://patches.van.ml.org/          | stupidity is not thus handicapped.
http://www.van.ml.org/CircleMUD/    |                  -- Elbert Hubbard


     +------------------------------------------------------------+
     | Ensure that you have read the CircleMUD Mailing List FAQ:  |
     | http://democracy.queensu.ca/~fletcher/Circle/list-faq.html |
     +------------------------------------------------------------+



This archive was generated by hypermail 2b30 : 12/15/00 PST