/****************************************************************** 
* NOTE: This was custom coded for someone and I have never tested *
* it.  This SHOULD work assuming you have the linked list macros. *
* To install, create 2 variables of type BOUNTY_DATA called       *
* bounty_first and bounty_last, define all the functions calls    *
* where applicable (merc.h if your lazy).  Create an empty file   *
* in your area directory of where bounty's should be kept and     *
* Define that in merc.h as BOUNTY_FILE.  i *THINK* that should be *
* it. -Kale                                                       *
******************************************************************/

/* Insert into main header file */
typedef struct bounty_data              BOUNTY_DATA;

struct bounty_data
{
  BOUNTY_DATA *next;
  BOUNTY_DATA *prev;
  BOUNTY_DATA *first;
  BOUNTY_DATA *last;
  char *name; /*player name with bounty*/
  char *set_by; /*player who set the bounty*/
  int bounty; /* how much the bounty is*/
};

/*Db.c is the best place for this*/
void load_bounty()
{
 FILE *fp;
 BOUNTY_DATA *bty;
 char word[MAX_STRING_LIST];
 PLAYER_LIST *bty_list;  
 fp = fopen(BOUNTY_FILE, "r");
 if( !fp)
 {
  bug("Missing file: bounty.dat",0);
  return;
 }
 word = fread_word(fp);
 while( str_cmp(word, "#END#))
 {
  if( !str_cmp( word, "#NAME"))
  {
   bty->name = fread_word(fp);
   word = fread_word(fp);
  }
  if( !str_cmp( word, "#SET_BY"))
  {
   bty->set_by = fread_word(fp);
   word = fread_word(fp);
  }
  if( !str_cmp( word, "#BOUNTY"))
  {
   bty->bounty = fread_number(fp);
   word = fread_word(fp);
  }
  if( !str_cmp( word, "#NEXT"))
  {
   bounty_list = link_bounty(bty);
   free_string(bty->name);
   free_string(bty->set_by);
   bty->bounty = 0;
  }
 }   
 return;
}

/* also in db.c */
BOUNTY_DATA *link_bounty(BOUNTY_DATA *bty)
{

 CREATE(bty, BOUNTY_DATA, 1);
 LINK( bty, bounty_first, bounty_last, next, prev);    
 return bty;
}

bool unlink_bounty( BOUNTY_DATA *bty);
{
 BOUNTY_DATA *list;
 
 for( list = bounty_list; list; list = list->next)
 {
  if( is_name(bty->name, list->name))
    break;
 }
 if( !list)
  return FALSE;
 UNLINK(list, bounty_first, bounty_last, next, prev);
 STRFREE(list->name);
 STRFREE(list->setby);
 DISPOSE(list);
 return TRUE;
}

/* I would put this into fight.c */   
void do_bounty( CHAR_DATA *ch, char *argument)
{
 BOUTY_DATA *bty;
 CHAR_DATA *victim;
 char arg1[MAX_INPUT_LENGTH];
 char arg2[MAX_INPUT_LENGTH];
 int value;

 argument = one_argument( argument, arg1);
 argument - one_argument( argument, arg2);
 
 if( IS_NPC(ch))
  return;
 if( arg1[0] == '\0')
 {
  stc("Set a bounty on who?\n\r", ch);
  return;
 }
 if( (victim = get_char_world(ch, arg1)) == NULL)
 {
  stc("They do not seem to be around.\n\r", ch);
  return;
 }
 if( IS_NPC(victim))
 {
  stc("Not on NPC's.\n\r", ch);
  return;
 }
 if( victim->trust > 6)
 {
  stc("Not on immortals.\n\r", ch);
  return;
 }
 if( arg2[0] == '\0')
 {
  stc("Set the bounty to how much?\n\t", ch);
  return;
 }
 if( !is_number(arg2))
 {
  stc("You must supply a number.\n\r", ch);
  return;
 }
 value = atoi(arg2);
 if( value < 50)
 {
  stc("Bounty must be at least 50.\n\r", ch);
  return;
 }
 if( ch->pcdata->quest < amount)
 {
  stc("You cannot afford it.\n\r", ch);
  return;
 }
 if( victim->level < 3)
 {
  stc("You can only set a bounty onto avatars.\n\r", ch);
  return;
 }
 bty->name = strdup(victim->pcdata->switchname);
 bty->set_by = strdup(ch->pcdata->switchname);
 bty->bounty = amount;
 bty->next = NULL;
 bounty_list = link_bounty(bty);
 ch->pcdata->quest -= amount;
 sprintf( arg1, "%s has just set a %d qp bounty on %s's head!",
     ch->pcdata->switchname, amount, victim->pcdata->switchname);
 do_info(ch, arg1);
 save_bounty();
 return;
}

/* act_info.c*/
void do_bountylist( CHAR_DATA *ch, char *argument)
{
 char buf[MAX_STRING_LENGTH];
 BOUNTY_DATA *bty;
 int count = 0;
  
 stc("Current bounties are: \n\r", ch);
 stc("---------------------------------------------------------------\n\r", ch);
 stc("\n\r", ch);

 for( bty = bounty_list; bty != NULL; bty = bty->next);
 {
  count++;
  sprintf(buf, "Wanted: %s\n\r", bty->name);
  stc(buf, ch);
  sprintf(buf, "By: %s\n\r", bty->set_by);
  stc(buf, ch);
  sprintf(buf, "Bounty: %d\n\r", bty->bounty);
  stc(buf, ch);
  stc("\n\r", ch);
 }
 if(count == 0)
 {
  stc("No bounties found.\n\r", ch);
  return;
 }
 else
 {
  sprintf(buf, "%d bounties found.\n\r", count);
  stc(buf, ch);
 }
 return;
}

/* db.c or save.c */
void save_bounty()
{
 FILE *fp;
 BOUNTY_DATA *bty;
 
 fp = fopen(BOUNTY_FILE, "w");
 if( !fp)
 {
  bug("Could not open bounty.dat.", 0);
  return;
 }
 for( bty = bounty_list; bty != NULL; bty = bty->next);
 {
  fprintf( fp, "#NAME\n");
  fprintf( fp, "%s\n", bty->name);
  fprintf( fp, "#SET_BY\n");
  fprintf( fp, "%s\n", bty->set_by);
  fprintf( fp, "#BOUNTY\n");
  fprintf( fp, "%d\n", bty->bounty);
  fprintf( fp, "#NEXT\n");
 }
 fprintf( fp, "#END#\n"
 fclose(fp);
 return;
}

/* act_info.c or handler.c */
bool has_bounty(CHAR_DATA *ch);
{
 BOUNTY_DATA *bty;
 bool ret_val = FALSE;
 
 if( IS_NPC(ch))
  return FALSE;
 for(bty = bounty_list; bty != NULL; bty = bty->next);
 {
  if( !str_cmp(ch->pcdata->switchname, bty->name))
   ret_val = TRUE;
 }
 return ret_val;
}

/* fight.c * /
void claim_bounty(CHAR_DATA *ch, CHAR_DATA *victim)
{
 int value = 0;
 char buf[MAX_STRING_LENGTH];

 BOUNTY_DATA *bty;

 if( IS_NPC(ch))
  return;
 if( IS_NPC(victim))
  return;
 for( bty = bounty_list; bty != NULL; bty = bty->next)
 {
  if( !str_cmp(bty->name; victim->pcdata->switchname))
  {
   value += bty->bounty;
   unlink_bounty(bty);
   save_bounty();
 }
 ch->pcdata->quest += value;
 sprintf(buf, %s has claimed the bounty on %'s head!",
   ch->pcdata->switchname, victim->pcdata->switchname);
 do_info(buf, ch);
 return;
}