present.c~

MudOSa4DGD/mudlib/dgd/lib/sys/efun/present.c~ · 1.3 KB

From the archive MudOSa4DGD-30.06.98.tar.gz

Download the archive   « Back to the archive contents

/*
 * present.c
 *
 * The present efuns
 *
 * (C) Frank Schmidt, Jesus@NorseMUD
 *
 */


#ifdef MUDOS_PRESENT

static varargs object present(mixed str, object ob) {
  object *obs, res;
  int i, num;

  /* check our sfun-emulation of present first */
  if (res=this_object()->sfun_present(str, ob))
    return res;

  /* default to this_object() */
  if (!objectp(ob)) {
    object res, env;
    if (!(res=present(str, this_object())))
      if (env=environment(this_object()))
	return present(str, env);
    /* return result */
    return res;
  }

  if (objectp(str))
    /* easy check */
    return (environment(str) == ob) ? str : 0;

  /* check if we have a number at end of our string */
  if ((i = strsrch(str, " ", -1)) != -1) {
    /* get the number if any */
    string s;
    s = str[i..];
    str = str[..i-1];
    if (strlen(s))
      num = (int)s;
  }

  if (strlen(str)) {
    obs = all_inventory(ob);
    for (i=::sizeof(obs); --i >=0; ) {
      if (call_other(obs[i], __ID_FUNC, str) && (--num <= 0)) {
	/* found it! */
	return obs[i];
      }
    }
  }
  return 0;
}

#endif


#ifdef MUDOS_ALL_PRESENT

/* return array of all matching <id> in <env> */
static varargs object *all_present(string id, object env) {
  if (!env) env = this_object();
  return GLOBAL->filter_all_present(id, env);
}

#endif

Site Stats

Snippets: 1791
Codebases: 571