/* /inherit/basic_object.c - basic variables and functions * This file contains basic code that almost all objects * should be able to inherit: name, aliases, short and long * descriptions, articles, etc. * Latest change to this file: September 8, 1992 by Padrone */ #pragma strict_types inherit "players/padrone/inherit/smartwrite"; /* #define ERROR(str) 0 */ #define ERROR(str) write("Error in " + file_name(this_object()) + ": " + str + "\n") /*---------------------------------------------------------------------------*/ string name, /* Name, with desired capitals - example: "Polly-Anna" * Actually, not only a name, but the string with * which this object will refer to iself, * for example "metal helmet". */ original_name, /* The name, exactly as it was set in set_name */ lower_name, /* The same name, but in all lowercase */ *aliases, /* Array of (lowercase) alias names (except name) */ plural; /* Pluralis form ("orcs", "oxen", "spies") */ string short_desc, /* One line, without any newlines - or 0! */ long_desc, /* Usually several lines, should end with a newline */ long_file; /* If this is set, cat this file as long description */ int weight, value; status can_get; /*---------------------------------------------------------------------------*/ void set_short(string sh) { short_desc = sh; } void set_long(string long) { long_desc = long; } void set_long_file(string filename) { long_file = filename; } void set_can_get(status n) { can_get = n; } void set_weight(int w) { weight = w; } void set_value(int v) { value = v; } string query_indefinite_form(); string query_long(string str) { if (long_file) return read_file(long_file); else if (long_desc) return long_desc; else return "It's just " + query_indefinite_form() + ".\n"; } /* query_long */ string query_short() { return short_desc; } void long(string str) { write(query_long(str)); } string short() { return query_short(); } int query_weight() { return weight; } int query_value() { return value; } /*---------------------------------------------------------------------------*/ /* "set_name" also sets the short description */ void set_name(string str) { original_name = str; name = str; lower_name = lower_case(str); /* The "name" should always be capitalized: */ if (name == lower_name) name = capitalize(name); set_short("a " + lower_name); } /* set_name */ string query_name() { if (name != 0) return name; else if (aliases != 0 && sizeof(aliases) > 0) return capitalize(aliases[0]); else return 0; } /* query_name */ string query_lower_name() { if (lower_name != 0) return lower_name; else if (aliases != 0 && sizeof(aliases) > 0) return aliases[0]; else return 0; } /* query_lower_name */ #if 0 static string query_set_name() { if (original_name != 0) return original_name; else if (aliases != 0 && sizeof(aliases) > 0) return aliases[0]; else return 0; } /* query_set_name */ #endif #define query_set_name() ((original_name) ? (original_name) : ((aliases) && sizeof(aliases) ? aliases[0] : 0)) /*---------------------------------------------------------------------------*/ void set_plural(string str) { plural = str; } string query_plural() { return plural; } /*---------------------------------------------------------------------------*/ void add_alias(string str) { if (aliases == 0) aliases = ({ }); aliases += ({ lower_case(str) }); } /* add_alias */ void set_aliases(string *all_aliases) { aliases = all_aliases; } /* set_aliases */ string *query_aliases() { return aliases; } void set_alias(string n) { add_alias(n); } /* For campatibility */ /*---------------------------------------------------------------------------*/ /* All these different sscanf's and stuff in "id" should really be * done in "smartpresent", so we can do it just once for each search, * instead of once for each object that we look at during the search. * However, only some objects use "smartpresent", so we'll have * to do it here too, for maximum compatibility with everything. */ status id(string str) { string lstr, junk; if (!str) return 0; lstr = lower_case(str); if ( lstr == lower_name || (aliases && member_array(lstr, aliases) != -1) || (short_desc && lstr == lower_case(short_desc))) return 1; while ( sscanf(lstr, "the %s", lstr) == 1 || sscanf(lstr, "a %s", lstr) == 1 || sscanf(lstr, "an %s", lstr) == 1 || sscanf(lstr, "%s.", lstr) == 1 || sscanf(lstr, "%s, %s", lstr, junk) == 2 || sscanf(lstr, "%s - %s", lstr, junk) == 2 || sscanf(lstr, "%s %s", lstr, junk) == 2) { if ( lstr == lower_name || (aliases && member_array(lstr, aliases) != -1) || (short_desc && lstr == lower_case(short_desc))) return 1; } return 0; } /* id */ /*---------------------------------------------------------------------------*/ void reset(int arg) { if (arg) return; /* set_name("object"); */ /* set_short("an uninitialized object"); */ aliases = 0; long_desc = 0; long_file = 0; } /* reset */ int get() { return can_get; } /*---------------------------------------------------------------------------*/ /* Article codes: * 0 = no article ("Gandalf") * 1 = "a"/"the" ("a bird"/"the bird") * 2 = "an"/"the" ("an orc"/"the orc") * 3 = "the" ("the Beatles") */ int article_code; void set_no_article() { article_code = 0; } void set_article_a() { article_code = 1; } void set_article_an() { article_code = 2; } void set_article_the() { article_code = 3; } int query_no_article() { return article_code == 0; } int query_article_a() { return article_code == 1; } int query_article_an() { return article_code == 2; } int query_article_the() { return article_code == 3; } void set_article(mixed a) { if (a == 0 || a == "" || a == " ") article_code = 0; else if (a == 1 || a == "a" || a == "a ") article_code = 1; else if (a == 2 || a == "an" || a == "an ") article_code = 2; else if (a == 3 || a == "the" || a == "the ") article_code = 3; else { ERROR("Illegal article " + a + " in set_article in basic_object"); } } /* set_article */ string query_indefinite_article() { return ({ 0, "a", "an", "the" }) [ article_code ]; } /* query_indefinite_article */ string query_definite_article() { return ({ 0, "the", "the", "the" }) [ article_code ]; } /* query_definite_article */ string query_definite_form() { if (article_code) return "the " + query_set_name(); else return query_name(); } /* query_definite_form */ string query_indefinite_form() { if (article_code == 0) return query_name(); else if (article_code == 1) return "a " + query_set_name(); else if (article_code == 2) return "an " + query_set_name(); else /* article_code == 3 */ return "the " + query_set_name(); } /* query_indefinite_form */ /* "Low-level" article handling. Use the functions above instead, * except for things like * thing2->set_article_code(thing1->query_article_code()); */ void set_article_code(int ac) { if (ac == 0 || ac == 1 || ac == 2 || ac == 3) article_code = ac; else ERROR("Illegal article code " + ac + " in set_article_code in basic_object"); } int query_article_code() { return article_code; } /*---------------------------------------------------------------------------*/ void show_stats() { write("name = "); smartwrite(name); if (name == 0) { write(", query_name() = "); smartwrite(query_name()); } write("\n"); write("article_code = " + article_code + " ("); smartwrite(query_indefinite_form()); write(", "); smartwrite(query_definite_form()); write(")\n"); write("aliases = "); smartwrite(aliases); write("\n"); write("short_desc = '" + short_desc + "'\n"); write("long_desc = "); smartwrite(long_desc); write("\n"); write("value = " + value + ", weight = " + weight + ", can_get = " + can_get + "\n"); } /* show_stats */ /*---------------------------------------------------------------------------*/