Synopsis: Extending act: one act fits them all. July 96 Date: Wed, 17 Jul 1996 19:10:45 +0200 (MET DST) From: erwin@pip.dknet.dk To: MERC/Envy Mailing List Subject: Extending act() The following is based on an idea that someone suggested on rec.games.mud.diku. Alas, I cannot recall the person's name. If you look at the calls to act(), you will notice that in many cases, act is called several times, with slightly different texts. E.g.: act ("You poke $N's eyes out!", ch, NULL, vic, TO_CHAR); act ("$n pokes $N's eyes out!", ch, NULL, vic, TO_NOTVICT); act ("$n pokes your eyes out!", ch, NULL, vic, TO_VICT); Much of the text is repeated. With the below code, this can be condensed in a single message: act ("$n poke$% $O eyes out!", ch, NULL, vic, TO_ALL); TO_ALL sends the text to everyone in room. When act creates the string to be seen by ch, it replaces $n with "you" rather than the name of ch. Similarly, when creating the text for vic, it replaces $N with "you". $% is a hack to show verbs correctly in 3rd person; to ch, it shows as an empty string, but to anyone else it shows as "s" (so, it will be "poke" when send to ch, but "pokes" when sent to anyone else.) $o/$O are much like $n/$N, but with 's afterwards. E.g. $o will be replaced by "Joe's". However, when Joe sees $o, it will be replaced by "yours" instead. This cannot be done with $n's, as Joe would then see "your's". There are many places in the code where these new features can replace three calls to act() with only one. The changes are simple: In merc.h, #define TO_ALL as 5. In act(), replace the big switch with this: PS: Note that $n is not replaced with "your" when sending to ch when the to-type is TO_CHAR. This is mainly because of emote: you want to see what the others see in that case. PPS: Note that no special provision for TO_ALL is necessary, and it could as well be defined as any value except the existing TO_XXX defines. If you're in doubt, check the code that selects which characters are to see a message. switch (*str) { default: bug ("Act: bad code %d.", *str); sprintf (buf1, "Bad act string: %s", format); bug (buf1, 0); i = " <@@@> "; break; /* Thx alex for 't' idea */ case 't': i = (char *) arg1; break; case 'T': i = (char *) arg2; break; case 'n': i = PERS (ch, to); if (ch == to && type != TO_CHAR) i = "you"; break; case 'N': i = PERS (vch, to); if (vch == to && type != TO_VICT) i = "you"; break; case 'o': sprintf (buf1, "%s's", PERS (ch, to)); if (ch == to) i = "your"; else i = buf1; break; case 'O': sprintf (buf1, "%s's", PERS (vch, to)); if (vch == to) i = "your"; else i = buf1; break; case 'e': i = he_she[URANGE (0, ch->sex, 2)]; if (ch == to) i = "you"; break; case 'E': i = he_she[URANGE (0, vch->sex, 2)]; if (vch == to) i = "you"; break; case 'm': i = him_her[URANGE (0, ch->sex, 2)]; if (ch == to) i = "you"; break; case 'M': i = him_her[URANGE (0, vch->sex, 2)]; if (vch == to) i = "you"; break; case 's': i = his_her[URANGE (0, ch->sex, 2)]; if (ch == to) i = "your"; break; case 'S': i = his_her[URANGE (0, vch->sex, 2)]; if (vch == to) i = "your"; break; /* Third person */ case '%': if (ch == to) i = ""; else i = "s"; break; case 'p': i = can_see_obj (to, obj1) ? obj1->short_descr : "something"; break; case 'P': i = can_see_obj (to, obj2) ? obj2->short_descr : "something"; break; case 'd': if (!arg2 || ((char *) arg2)[0] == '\0') { i = "door"; } else { one_argument ((char *) arg2, fname); i = fname; } break; } ============================================================================== Erwin Andreasen Viby J, Denmark Computer Science Student at Aarhus Business 4u2@aabc.dk Click here! College ============================================================================== [I believe the person with the original idea on merc-l was Adam Wiggins - I need to ask him. Also, a you-your problem was corrected with m/M/s/S. I have since added a y/Y code, which expands to yourself/name.]