Spoken Language Code

From: Zizazat Lazuras (zizazat@hotmail.com)
Date: 03/31/02


I have made a few minor changes to the spoken language snippet credited to
Frollo (mudaholic@aol.com). Props to anyone else who helped with this code
but is not credited.

The main change in my snippet is that the garble function gets passed the
actual spoken language, which is used to determine the garble letters.

Why would you want that? So that different languages look differently
spoken. I also had a particular need for my MUD to have a binary language,
so the garble letters could only be 0 and 1. Code follows.

Please give me props in your credits file (and Frollo too!)

Zizazat Lazuras (zizazat@hotmail.com)

--Ziz

---act.comm.c---

char *languages[] =
{
  "common",
  "elven",
  "demon",
  "binary",
  "\n"
};

void list_languages(struct char_data *ch)
{
  int a = 0, i;

  if (SPEAKING(ch) <= MIN_LANGUAGES) {
    SET_SKILL(ch, MIN_LANGUAGES, 100);
    SPEAKING(ch) = MIN_LANGUAGES;
  }
  /* Slight hack to avoid core dumping cause no one speaks the
   * language after implementation. */

  sprintf(buf, "Languages:\r\n");
  for (i = MIN_LANGUAGES; i < MAX_LANGUAGES; i++) {
    if (GET_SKILL(ch, i) > 60) {
      sprintf( buf, "%s%s", buf, a++ != 0 ? "&n, " : "[ " );
      strcat( buf, SPEAKING(ch) == i ? "&r" : "&n" );
      strcat( buf, languages[i-MIN_LANGUAGES]);
    }
  }
  sprintf(buf, "%s &w]&n\r\n", buf);
  send_to_char(buf, ch);
}

ACMD(do_languages)
{
  int i, found = FALSE;

  one_argument(argument, arg);
  if (!*arg)
    list_languages(ch);
  else {
    for (i = MIN_LANGUAGES; i < MAX_SKILLS; i++) {
      if (is_abbrev(arg, languages[i-MIN_LANGUAGES]) && GET_SKILL(ch, i) >
60) {
        SPEAKING(ch) = i;
        sprintf(buf, "You now speak %s.\r\n", languages[i-MIN_LANGUAGES]);
        send_to_char(buf, ch);
        found = TRUE;
        break;
      }
    }
    if (!found)
      list_languages(ch);
  }
}

void garble_text(char *string, int percent, int lang)
{
  char letters[12] = "";
  /* Always up letters[12] to the largest size for letters you wish to
* use below. */
  int i,s;

  switch (lang) {
  case SKILL_LANG_BINARY:
    strcpy (letters, "01");
    s=1;
    break;
  case SKILL_LANG_DEMON:
    strcpy (letters, "hprstwxyz");
    s=8;
    break;
  default:
    strcpy (letters, "aeiousthpwxyz");
    s=12;
    break;
  }

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

/* Replace original do_say with this */

ACMD(do_say)
{
  char ibuf[MAX_INPUT_LENGTH];
  char obuf[MAX_INPUT_LENGTH];
  struct char_data *tch;

  skip_spaces(&argument);

  if(!*argument) {
    send_to_char("Yes, but WHAT do you want to say?\r\n", ch);
    return;
  }

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

  if (!IS_NPC(ch))
    garble_text(ibuf, GET_SKILL(ch, SPEAKING(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 */
      if (!IS_NPC(ch) && !IS_NPC(tch))
        garble_text(obuf, GET_SKILL(tch, SPEAKING(ch)), SPEAKING(ch));
      if (GET_SKILL(tch, SPEAKING(ch)) < 1)
       sprintf(buf, "$n says, in an unfamiliar tongue, '%s'",  obuf);
      else
       sprintf(buf, "$n says '%s'", obuf);
      act(buf, TRUE, ch, 0, tch, TO_VICT);
    }
  }

  sprintf(buf, "&cYou say, '%s&c'&n", argument);
  act(buf, TRUE, ch, 0, 0, TO_CHAR);
}


---spells.h---
#define SKILL_LANG_COMMON   141
#define SKILL_LANG_ELVEN    142
#define SKILL_LANG_DEMON    143
#define SKILL_LANG_BINARY   144

/* Stock Circle 141 is the next open skill, season to taste. */

#define MIN_LANGUAGES       141
#define MAX_LANGUAGES       145

/* Min must be same value as 1st Language. Max should be one more than
* the last lang. */

---utils.h---
#define SPEAKING(ch)     ((ch)->player_specials->saved.speaking)

---structs.h---
You'll need to add speaking to the player_specials->saved.

int spare8; is a good place replace with
int speaking;

If you are using ascii player files, it might also be a good idea to make
mods to db.c and pfdefaults.h so you can save and load the value of
speaking.





_________________________________________________________________
Chat with friends online, try MSN Messenger: http://messenger.msn.com

--
   +---------------------------------------------------------------+
   | FAQ: http://qsilver.queensu.ca/~fletchra/Circle/list-faq.html |
   | Archives: http://post.queensu.ca/listserv/wwwarch/circle.html |
   | Newbie List:  http://groups.yahoo.com/group/circle-newbies/   |
   +---------------------------------------------------------------+



This archive was generated by hypermail 2b30 : 06/25/03 PDT