Re: Recall Command

From: George Greer (greerga@circlemud.org)
Date: 01/10/02


On Thu, 10 Jan 2002, Bejhan Jetha wrote:

>ACMD(do_recall)
>{
>  extern sh_int r_mortal_start_room;
>
>  if (IS_NPC(ch)) {
>    send_to_char("Monsters can't recall!!\r\n", ch);
>    return;
>  }
>  if (GET_LEVEL(ch) <= 10) {
>    send_to_char("Recalling for FREE, courtesy of Newbie
>Transportation...\r\n", ch);
>    act("$n concentrates and disappears.", TRUE, ch, 0, 0, TO_ROOM);
>    char_from_room(ch);
>    char_to_room(ch, r_mortal_start_room);
>    act("$n appears suddenly.", TRUE, ch, 0, 0, TO_ROOM);
>    look_at_room(ch, 0);
>    return;
>  }
>   else if (GET_LEVEL(ch) >== 91) {
>    send_to_char("Recalling for FREE, courtesy of Immortal
>Transportation...\r\n", ch);
>    act("$n concentrates and disappears.", TRUE, ch, 0, 0, TO_ROOM);
>    char_from_room(ch);
>    char_to_room(ch, r_immortal_start_room);
>    act("$n appears suddenly.", TRUE, ch, 0, 0, TO_ROOM);
>    look_at_room(ch, 0);
>    return;
>  }
>   else if (GET_LEVEL(ch) == 99) {
>    send_to_char("Recalling for FREE, courtesy of Chaos...\r\n", ch);
>    act("$n concentrates and disappears.", TRUE, ch, 0, 0, TO_ROOM);
>    char_from_room(ch);
>    char_to_room(ch, r_chaos_start_room);
>    act("$n appears suddenly.", TRUE, ch, 0, 0, TO_ROOM);
>    look_at_room(ch, 0);
>    return;
>  }
>  else {
>    send_to_char("Recalling for 200 gold per level...\r\n", ch);
>    if (GET_GOLD(ch) < (GET_LEVEL(ch) * 200))
>{
>      send_to_char("You don't have enough gold!\r\n", ch);
>      act("$n tries to recall, but fails\r\n", FALSE, ch, 0, 0, TO_ROOM);
>      return;
>      }
>    else {
>    GET_GOLD(ch) -= (GET_LEVEL(ch) * 200);
>    act("$n concentrates and disappears.", TRUE, ch, 0, 0, TO_ROOM);
>    char_from_room(ch);
>    char_to_room(ch, r_mortal_start_room);
>    act("$n appears suddenly.", TRUE, ch, 0, 0, TO_ROOM);
>    look_at_room(ch, 0);
>    return;
>    }
>  }
>}

Lots of duplication. Try:

ACMD(do_recall)
{
  int lk, cost;

  struct {
    int low;
    int high;
    int costperlevel;
    room_rnum target;
    const char *message;
  } recallinfo[] = {
    {  1,  10,   0, r_mortal_start_room,
        "Recalling for FREE, courtesy of Newbie Transportation...\r\n" },
    { 11,  90, 200, r_mortal_start_room,
        "Recalling for 200 gold per level...\r\n" },
    { 91,  91,   0, r_chaos_start_room,
        "Recalling for FREE, courtesy of Chaos...\r\n" },
    { 92, 100,   0, r_immortal_start_room,
        "Recalling for FREE, courtesy of Immortal Transportation...\r\n" },
    { -1, -1, -1, 0, NULL },
  };

  for (lk = 0; recallinfo[lk].low >= 0; lk++)
    if (GET_LEVEL(ch) >= recallinfo[lk].low &&
                GET_LEVEL(ch) <= recallinfo[lk].high)
      break;

  if (IS_NPC(ch) || recallinfo[lk].low < 0) {
    send_to_char("Sorry, you can't do that.\r\n", ch);
    return;
  }

  cost = recallinfo[lk].costperlevel * GET_LEVEL(ch);
  if (cost > GET_GOLD(ch)) {
    send_to_char("You don't have enough gold.\r\n", ch);
    act("$n tries to recall, but fails.\r\n", FALSE, ch, 0, 0, TO_ROOM);
    return;
  }

  GET_GOLD(ch) -= cost;
  send_to_char(recallinfo[lk].message, ch);
  act("$n concentrates and disappears.", TRUE, ch, 0, 0, TO_ROOM);
  char_from_room(ch);
  char_to_room(ch, recallinfo[lk].target);
  act("$n appears suddenly.", TRUE, ch, 0, 0, TO_ROOM);
  look_at_room(ch, 0);
}

MailerCode(tm)

--
George Greer
greerga@circlemud.org

--
   +---------------------------------------------------------------+
   | 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