/* ********************************************************************
   This is the find familiar skill.
   April 4 1998 by Gothar
   
   This skill allows your players to
   have a companion like those loveable 
   pets in the pet shops.
   
   Email me if you use it. Leave this header
   to say Gothar had a great idea there.
   gothar@magma.ca
   mcco0055@algonquinc.on.ca
 * ******************************************************************** */
/*
1. Add the entry in the interp.c and .h
2. Add to merc.h:
  #define MOB_VNUM_FAMILIAR 	1
  Here it is the 1st mob in limbo.are
3. Add the follow entry in limbo.are:


	#MOBILES
	#1
	familiar~
	(no short description)~
	(no long description)
	~
	~
	human~
	A 0 0 0
	0 0 0d0+0 0d0+0 5d7+5 pound
	0 0 0 0
	0 0 0 0
	stand stand none 0
	0 0 medium unknown
	F for AHMV
	F par ABCDEFGHIJK
	#0
4. In const.c insert into the skill table
   {
      "find familiar",	{ 15, 42, 0, 40 },	{3, 5, 0, 8 },
      spell_null,	TAR_IGNORE,		POS_RESTING,
      &gsn_familiar,	SLOT(0),	0,	0,
      "",		"!Find Familiar",	""
   }
5. Increment MAX_SKILL by 1 in merc.h
6. In merc.h add:
	extern   sh_int &gsn_familiar;
7. In db.c add:
        sh_int	&gsn_familiar;
8. Add to the groups of your choice.
*/

/* command procedures needed */
DECLARE_DO_FUN(do_sit		);
DECLARE_DO_FUN(do_stand		);

void familiar (CHAR_DATA *ch, char *argument)
{
    MOB_INDEX_DATA *pMobIndex;
    CHAR_DATA *mount;
    int i, chance;

   if ( chance = get_skill(ch,gsn_familiar)) == 0
   || (!IS_NPC(ch) 
   && ch->level < skill_table[gsn_familiar].skill_level[ch->clas])
   {
      send_to_char("You don't know where to start.\n\r",ch);
      return;
   }
   if ( ch->pet != NULL )
   {
       send_to_char("You already a companion.\n\r",ch);
       return;
   }
   if(ch->position == POS_FIGHTING)
   {
      send_to_char("You can't study the ritual while in combat!\n\r",ch);
      return;
   }
    
   if ( ( pMobIndex = get_mob_index(MOB_VNUM_FAMILIAR) ) == NULL )
   {
       send_to_char( "The familiar mob doesn't exist.\n\r", ch );
       return;
   }
    /* can't cast the spell in these sectors */
    if(ch->in_room->sector_type == SECT_INSIDE
    || ch->in_room->sector_type == SECT_WATER_SWIM 
    || ch->in_room->sector_type == SECT_WATER_NOSWIM
    || ch->in_room->sector_type == SECT_AIR )
    {
       send_to_char("You are feeling too sick to concentrate.\n\r",ch);
       return;
    }
     	
    mount = create_mobile( pMobIndex );
    
    mount->level = number_fuzzy(ch->level / 2);
    mount->mana = mount->max_mana = 0;
    mount->hit = mount->max_hit = number_fuzzy(ch->max_hit / 2);
    for(i = 0; i < 4; i++)
       mount->armor[i] = number_fuzzy(ch->armor[i] - 10);
    mount->hitroll = number_fuzzy(ch->level / 30);
    mount->damroll = number_fuzzy(ch->level / 30);
    
    /* free up the old mob names */ 
    free_string(mount->description);
    free_string(mount->name);
    free_string(mount->short_descr);
    free_string(mount->long_descr);
    
    /* terrain */
    switch(ch->in_room->sector_type)
    {
	case(SECT_CITY): /* rat */
	case(SECT_FIELD):
	    mount->description = 
	          str_dup("You see a large furry rat.  Long whiskers hang down from it's nose.\n\r"
	                  "You can feel the dirt and disease crawling off this beast.\n\r");
	    mount->short_descr = str_dup("large rat");
	    mount->long_descr = str_dup("A large furry rodent is here.\n\r");
	    mount->name = str_dup("familiar rat");
	    mount->dam_type = 22; /* scratch */
	    break;
	case(SECT_FOREST):  /* falcon */
	case(SECT_HILLS):
	    mount->description = 
	          str_dup("You see a large falcon.  Golden brown feathers frame powerful\n\r"
	                  "wings.  Long talons grasp at nothingness in vain attempts at\n\r"
	                  "getting some rabbit or rodent for dinner.\n\r");
	    mount->short_descr = str_dup("large falcon");
	    mount->long_descr = str_dup("A large falcon screams here.\n\r");
	    mount->name = str_dup("familiar falcon");
	    mount->dam_type = 5; /* claw */
	    break;
	case(SECT_MOUNTAIN): /* mountain lion */
	    mount->description = 
	          str_dup("You see a very large mountain lion.  One wrong look and it could\n\r"
	                  "have your head lying at your feet.  You should think better than\n\r"
	                  "cross this beast especial if you have a weapon in your hand.\n\r");
	    mount->short_descr = str_dup("large mountain lion");
	    mount->long_descr = str_dup("A large mountain lion claws the ground here.\n\r");
	    mount->name = str_dup("familiar mountain lion");
	    mount->dam_type = 10; /* bite */
	    break;
	case(SECT_DESERT): /* sandworm */
	    mount->description = 
	          str_dup("You see a large white sandworm wiggling in the light.\n\r"
	                  "A red spot on one end makes you guess it is a mouth.\n\r"
	                  "A loud moan comes from the direction of that red spot.\n\r");
	    mount->short_descr = str_dup("sandworm");
	    mount->long_descr = str_dup("A white sandworm wiggles on the ground here.\n\r");
	    mount->name = str_dup("familiar sandworm");
	    mount->dam_type = 12; /* suction */
	    break;
    }
    /* player seen stuff here */
    do_sit(ch,"");
    char_to_room( mount, ch->in_room );
    act( "You begin to chant and call to a $N!.",ch,NULL,mount,TO_CHAR);
    act( "$n begins to chant and calls to a $N!", ch, NULL, mount, TO_ROOM );
    WAIT_STATE(ch, 2 * PULSE_MOBILE);
    add_follower( mount, ch );
    mount->leader = ch;
    ch->pet = mount;
    do_stand(ch,"");

    SET_BIT(mount->act, ACT_PET);
    SET_BIT(mount->affected_by, AFF_CHARM);
    ch->move -= (mount->level / 2);  /* physically draining lose of move */
    check_improve(ch,gsn_familiar,TRUE,6);
    return;
}