[CODE] Abbrevations

From: Nocturnal Occulto (ronnyi@ifi.uio.no)
Date: 03/22/99


Add these two functions to handler.c and players who are flagged with
PRF_ABBREV will be
able to use abbrevations on characters and mobs in the room. Like if
they type look noc
and a char named nocturnal is in the room they will be able to look at
him. Add the abbrev flag
in structs.h etc, and make a command called abbrevate whch allows
players to toggle abbrevation on and off.
This will make pking fair for everbody, and make sure that ppl with
names like twatasphyich wont win fights
because you cant type their name fast enough.  There is one catch
though,
if for example a two players named lafay and lafayii is in the room. If
you type l lafay the abbrevation code sometimes
picks out lafayii instead of lafay. What you need to do then is look
2.lafay.  Im not sure how to fix this
in a clever way, and if anybody does plz do mail me.

Regards Nocturnal Occulto


struct char_data *get_char_room_vis(struct char_data * ch, char *name)
{
  struct char_data *i;
  int j = 0, number;
  char tmpname[MAX_INPUT_LENGTH];
  char *tmp = tmpname;
  int shortest_name_length = 10000000;

  if (!str_cmp(name, "self") || !str_cmp(name, "me"))
    return ch;

  /* 0.<name> means PC with name */
  strcpy(tmp, name);
  if ( !(number = get_number(&tmp)))
    return get_player_vis(ch, tmp, 1);

  if (!PRF_FLAGGED(ch, PRF_ABBREV)) {
    for (i = world[ch->in_room]->people; i && j <= number; i =
i->next_in_room)
      if (isname(tmp, i->player.name))
 if (CAN_SEE(ch, i))
   if (++j == number)
     return i;
  } else {
    for (i = world[ch->in_room]->people; i && j <= number; i =
i->next_in_room)
      if (isname_abbrev(tmp, i->player.name))
 if (CAN_SEE(ch, i))
   if (++j == number)
     return i;
  }

  return NULL;
}


int isname_abbrev(const char *str, const char *namelist)
{
  const char *curname, *curstr;
  int i = 0;

  curname = namelist;

  for (;;) {
    for (curstr = str;; curstr++, curname++, i++) {
      if (!*curstr) {
 fprintf(stderr, "isname length i: %d\n", i);
 return (i);
      }

      if (!*curname)
 return (0);

      if (!*curstr || *curname == ' ')
 break;

      if (LOWER(*curstr) != LOWER(*curname))
 break;
    }
    /* skip to next name */
    for (; isalpha(*curname); curname++);
    if (!*curname)
      return (0);
    curname++;   /* first char of new name */
  }
}


--
--------------- Codito, ergo sum - "I code, therefore I am" --------------------

http://birk113.studby.uio.no/~ronnyi                           ronnyi@ifi.uio.no

---------------- In a world without fences, who need gates? --------------------


     +------------------------------------------------------------+
     | Ensure that you have read the CircleMUD Mailing List FAQ:  |
     |  http://qsilver.queensu.ca/~fletchra/Circle/list-faq.html  |
     +------------------------------------------------------------+



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