Languages

From: system operator (root@net26.intserv.com)
Date: 08/26/95


How many people out there have implemented languages?  I just put them
in today, and was wondering if anyone has any suggestions for my code.
I'm a little shakey on text manipulation, so if anyone notices some real
gaffs I made here, I'd apprectiate being set straight.

I'll include everything you need to "make it go" in case anyone wants
to test it, or actually use it... it does work, I'm just not sure if
I've gone about it in the most efficient way, thus I'm posting it here
to see what others have to say...

Some notes: I use skill slots to hold language ability, this coincides
very nicely with my learn_by_use code (stripped out of this example).
If you try to use this, you'll need to make the appropriate entries
in spells.h (I use 190+ for langs), also, you'll need to change one of
the spares in the player structure to be "speaking".
Oh, you'll also need some way to toggle what language you're speaking,
you could use a simple do_speak command or something, I'm not finished
putting this all in yet, so I just made an entry in do_set to toggle
the person's current lang like: "SPEAKING(vict) = value"



--snip--

/* spells.h */
#define LANG_COMMON     190
#define LANG_ELVEN      191
#define LANG_DWARVEN    192
#define LANG_TROLLISH   193
#define LANG_HALFLING   194


/* this would fit best in utils.h */
#define SPEAKING(ch)     ((ch)->player_specials->saved.speaking)


/* this would fit best in constants.c */
const char *languages[] =
{
  "common",
  "elven",
  "dwarven",
  "trollish",
  "halfling",
  "\n"
};


/* the rest would fit best in act.comm.c i guess */

void garble_text(char *string, int percent)
{
  char letters[] = "aeiousthpwxyz";
  int i;

  for (i = 0; i < strlen(string); ++i)
    if (isalpha(string[i]) && number(0, 1) && number(0, 100) > percent)  
      string[i] = letters[number(0, 12)];
}


ACMD(do_lang_say)
{

  char ibuf[MAX_INPUT_LENGTH];
  char obuf[MAX_INPUT_LENGTH];
  int ofs = 190;              /* offset - should be first language */
  struct char_data *tch;      

  skip_spaces(&argument);

  if(!*argument) {
    send_to_char("Say what?\r\n", ch);
    return;
  }

  strcpy(ibuf, argument);     /* preserve original text */

  garble_text(ibuf, GET_SKILL(ch, SPEAKING(ch)));

  for (tch = world[ch->in_room].people; tch; tch = tch->next_in_room) {
    if (tch != ch && AWAKE(tch) && tch->desc) {

      strcpy(obuf, ibuf);     /* preserve the first garble */

      garble_text(obuf, GET_SKILL(tch, SPEAKING(ch)));

      if (GET_SKILL(tch, SPEAKING(ch)) < 1)
        sprintf(buf, "$n says, in an unfamiliar tongue,\r\n     '%s'",  obuf);
      else
        sprintf(buf, "$n says, in the %s tongue,\r\n     '%s'", languages[(SPEAKING(ch) - ofs)], obuf);
      act(buf, TRUE, ch, 0, tch, TO_VICT);
    }
  }  

  sprintf(buf, "You say, in the %s tongue,\r\n     '%s'", languages[(SPEAKING(ch)- ofs)], argument);
  act(buf, TRUE, ch, 0, 0, TO_CHAR);

}


--snip--



This archive was generated by hypermail 2b30 : 12/18/00 PST