/*
* present.c
*
* The present efuns
*
* (C) Frank Schmidt, Jesus@NorseMUD
*
*/
#ifdef MUDOS_PRESENT
static varargs object present(mixed str, object ob) {
object *obs, res;
string s;
int num;
/* 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;
#if 1
/* check if we have a number at end of our string */
if (sscanf(str, "%s %d", s, num) >= 2) {
str = s;
}
#else
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;
}
#endif
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