/* /inherit/smartpresent.c - a "smarter" present function * Latest change to this file: September 4, 1992, by Padrone */ #pragma strict_types /* Maybe we should put "smartpresent" in 'obj/simul_efun.c' or somewhere? */ /*---------------------------------------------------------------------------*/ static object smartpresent2(mixed what, mixed where) { object obj, foundobj, *all_inv; string lwhat, lwhat2, junk; int i, n, the_number; if (what == 0) return 0; obj = present(what, where); if (obj || !stringp(what)) return obj; lwhat = lower_case(what); obj = present(lwhat, where); if (obj) return obj; while ( sscanf(lwhat, "the %s", lwhat) == 1 || sscanf(lwhat, "a %s", lwhat) == 1 || sscanf(lwhat, "an %s", lwhat) == 1 || sscanf(lwhat, "%s.", lwhat) == 1) { obj = present(lwhat, where); if (obj) return obj; } while (sscanf(lwhat, "%s %d", lwhat2, the_number) == 2) { if (where == 0) where = environment(this_object()); all_inv = all_inventory(where); if (pointerp(all_inv)) { n = sizeof(all_inv); foundobj = 0; for (i = 0; i < n && the_number > 0; ++i) { if (all_inv[i]->id(lwhat2)) { if (--the_number == 0) return obj; else if (!foundobj) foundobj = all_inv[i]; } } if (foundobj) return foundobj; } lwhat = lwhat2; } while ( sscanf(lwhat, "%s, %s", lwhat2, junk) == 2 || sscanf(lwhat, "%s - %s", lwhat2, junk) == 2 || sscanf(lwhat, "%s %s", lwhat2, junk) == 2) { obj = present(lwhat2, where); if (obj) return obj; lwhat = lwhat2; } return 0; } /* smartpresent2 */ /*---------------------------------------------------------------------------*/ object smartpresent(mixed what, mixed where) { object foundobj; if (where == 0) { foundobj = smartpresent2(what, environment(this_object())); if (foundobj) return foundobj; foundobj = smartpresent2(what, this_object()); if (foundobj) return foundobj; foundobj = smartpresent2(what, this_player()); if (foundobj) return foundobj; foundobj = smartpresent2(what, environment(this_player())); if (foundobj) return foundobj; if (stringp(what) && environment(this_player())->id(what)) return environment(this_player()); return 0; } else return smartpresent2(what, where); } /* smartpresent */