#define WHISTLE_MOVE_COST 30
#define WHISTLE_WOLF 8094
#define WHISTLE_TIMBER 7502
#define WHISTLE_VISCIOUS 7502

int bob(int num)
{
    if (number(1,100) <= num) return 1;
    else return 0;
}

ACMD(do_whistle) {

  struct obj_data *obj;
  struct char_data *pet;
  struct follow_type *f;
  int chance;
  int penalty=0;

  if (!GET_SKILL(ch, SKILL_WHISTLE)) {
    send_to_char("You have no idea how.\r\n", ch);
    return;
  }

  if (GET_MOVE(ch) <= WHISTLE_MOVE_COST) {
    send_to_char("You are too tired.\r\n", ch);
    return;
  }

  obj = get_obj_in_list_vis(ch, "whistle", ch->carrying);

  if (!obj) {
      send_to_char("But you need something to whistle with!\r\n", ch); 
      return;
  }

  GET_MOVE(ch) -= WHISTLE_MOVE_COST;

  for (f = ch->followers; f; f = f->next)
    if (IN_ROOM(ch) == IN_ROOM(f->follower)) {
      if (IS_MOB(f->follower))
        penalty += 5;
      else
        penalty += 2;
    }

  if (GET_CHA(ch) < (penalty + 5)) {
    send_to_char("You can not attract any more followers now.\r\n", ch);
    return;
  }

  chance = number(0, GET_SKILL(ch, SKILL_WHISTLE) + GET_LEVEL(ch));

  if (chance < 50) {
    act("Your whistle fails.  No wolves were attracted.", FALSE, ch,
        0, 0, TO_CHAR);
    act("$n lets out one hell of a whistle, but nothing seems interested.", FALSE, ch, 0, 0, TO_NOTVICT);
    return;

  } else if (chance  < 100)
    pet = read_mobile(WHISTLE_TIMBER, VIRTUAL);
  else if (chance  < 120)
    pet = read_mobile(WHISTLE_VISCIOUS, VIRTUAL);
  else
    pet = read_mobile(WHISTLE_WOLF, VIRTUAL);

  act("Your whistle is answered by $N.", FALSE, ch, 0, pet, TO_CHAR);
  act("$ns whistle is answered by $N.", FALSE, ch, 0, pet, TO_ROOM);

  IS_CARRYING_W(pet) = 1000;
  IS_CARRYING_N(pet) = 100;
  SET_BIT(AFF_FLAGS(pet), AFF_CHARM);  

  char_to_room(pet, IN_ROOM(ch));
  add_follower(pet, ch);

  if (number(1, 10) >= 5) {

        if (chance < 70) {
	   return;
	}
        if (chance  < 100)
           pet = read_mobile(WHISTLE_TIMBER, VIRTUAL);
        else if (chance  < 120)
           pet = read_mobile(WHISTLE_VISCIOUS, VIRTUAL);
        else
          pet = read_mobile(WHISTLE_WOLF, VIRTUAL);

     act("Your whistle is answered by $N.", FALSE, ch, 0, pet, TO_CHAR);
     act("$ns whistle is answered by $N.", FALSE, ch, 0, pet, TO_ROOM);
     char_to_room(pet, IN_ROOM(ch));
     add_follower(pet, ch);
  } 
  else if (number(1, 10) >= 8) {

        if (chance < 90) {
	   return;
	}
        if (chance  < 100)
           pet = read_mobile(WHISTLE_WOLF, VIRTUAL);
        else if (chance  < 120)
           pet = read_mobile(WHISTLE_VISCIOUS, VIRTUAL);
        if (bob(50))         
           pet = read_mobile(WHISTLE_TIMBER, VIRTUAL);

     act("Your whistle is answered by $N.", FALSE, ch, 0, pet, TO_CHAR);
     act("$ns whistle is answered by $N.", FALSE, ch, 0, pet, TO_ROOM);
     char_to_room(pet, IN_ROOM(ch));
     add_follower(pet, ch);
  } 

}
