#ifndef FORMAT_H #define FORMAT_H #include <unistd.h> #define PRONOUNS 8 int columns(const MudObject *who); int rows(const MudObject *who); //! grab the name of /what/. pluralises it if /plural/, grabs the longname if /islong/, ignores state if /dontstate/. const char *name(const MudObject *what, int plural=0, bool islong=0, bool dontstate=0); //! return has or have depending upon plurality static inline const char *has_have(MudObject *m) { return m->get_flag(FL_PLURAL)?"has":"have"; } //! return was or were depending upon plurality const char *was_or_were(MudObject *); //! return is or are depending upon plurality const char *is_are(MudObject*); //! return it or them depending upon plurality const char *it_them(MudObject*); //! return it or they depending upon plurality const char *it_they(MudObject*); //! return yourself or yourselves depending upon plurality static inline const char *yourself_yourselves(MudObject*m) { if (m->get_flag(FL_PLURAL)) return "yourselves"; return "yourself"; } enum gender_t { GENDER_MALE, GENDER_FEMALE, GENDER_PLURAL, GENDER_NEUTRAL, GENDER_ANDRO, GENDER_UNKNOWN, GENDER_YOU_S, GENDER_YOU_P, GENDERS, }; enum pron_t { PRON_THEY, PRON_THEM, PRON_THEIR, PRON_THEIRS, PRON_THEMSELF, PRON_PERSON, }; extern char *pronoun[PRONOUNS][GENDERS]; //! obtain the gender of an object extern gender_t get_gender(const MudObject *); //! his or her, depending upon gender static inline const char *his_or_her(MudObject *who) { return pronoun[2][get_gender(who)]; } //! he or she, depending upon gender static inline const char *he_or_she(MudObject *who) { return pronoun[0][get_gender(who)]; } //! him or her, depending upon gender static inline const char *him_or_her(MudObject *who) { return pronoun[1][get_gender(who)]; } //! himself or herself, depending upon gender static inline const char *himself_or_herself(MudObject *who) { return pronoun[PRON_THEMSELF][get_gender(who)]; } //! format an action string extern string sprinta(MudObject *consumer, const char *format, MudObject *sender, MudObject *target, const char *text=0, int aber=0, MudObject *prop=0); //! pluralise n's name and give it a number. possibly insert an adjective. string give_number(MudObject *n, int i, const char *adj=0, int islong=0, bool donstate=0); //! describe playing card /which/. if /ln/ it will be in long format string describe_card(int which, int ln=0); //! return title with the embedded string /a/, wide enough to fit on /who/'s screen snugly. you can override the colour. string title_for(string a, const MudObject *who, const char *col="^B", const char *chr=NULL); //! return a footer wide enough to fit on /who/'s screen. string footer_for(MudObject *who, const char *col="^B", const char *chr=NULL); //! return the job that /who/ has. string role(MudObject *who); //! describe the appearance of the mobile /obj/ string descmob(MudObject *obj, bool col=1); //! format a roomname with a preposition in front of it string format_roomname(MudObject *room, MudObject *o, const char *ic="", const char *oc="", const char *notin="in", const char *myprep=0); string format_roomname(MudObject *room, MudObject *o, const char *ic, const char *oc, const char *notin, int yesid); string build_setin(MudObject *whose, const char *fmt, const char *name, const char *dir, const char *vic); enum setin_t { setmin, setmout, setvin, setvout, setqin, setqout, setsit, setstand, setsleep, }; const char *get_message(MudObject *, setin_t); inline string build_setin(MudObject *whose, setin_t s, const char *nam=0, const char *dir=0, const char *vic=0) { return build_setin(whose, get_message(whose, s), nam?nam:name(whose), dir, vic); } //! return a description of the position of /who/ string owhere(MudObject *who, MudObject *room=0); //! temporarily divert the output sent to a player to a file, then pager it back at them later. class Divert { Player *who; FILE *f; string fn; public: //! divert q's output to a file named a Divert(MudObject *q, string a) { if (!is_player(q)) { who = 0; f = 0; fn = ""; return; } who = (Player *)q; fn = "autotmp."; fn += a; fn += "."; fn += who->id; f = xopen("tmp", fn.c_str(), "w+"); if (!f) return; who->file_divert(f); } //! set q to page a and then unlink a ~Divert() { if (!who) return; who->file_undivert(); if (f) { fclose(f); who->spewfile("tmp", fn.c_str()); } unlink(("tmp/"+fn).c_str()); } operator FILE *() { return f; } }; typedef string (*displayname_t)(MudObject *); //! describe the contents of /what/. set further to 0 to not do 'items of clothing'-style collapsing string magiclist(const World<MudObject> &what, displayname_t r=0, int further=1); //! mangle the string given to be spoken by /who/. for example, add drunk effects, add farmyard noises, correct spelling if appropiate flag set. string possibly_drunkify(MudObject *who, string what2); //! when is an absolute time. describe how far in the future this is. /seconds/ is whether to include seconds in this or not. char *howsoon(time_t when, bool seconds=true); //! secs is a number of seconds. convert this to h/m/s in words. string nicetime(int secs); class Header { MudObject *who; int pad; public: Header(MudObject *who, const char *a, int pad=0) : who(who), pad(pad) { who->printf("%s\n", title_for(a, who).c_str()); for (int i=0;i<pad;i++) who->printf("\n"); } ~Header() { for (int i=0;i<pad;i++) who->printf("\n"); who->printf("%s\n", footer_for(who).c_str()); } }; #endif