Greetings all,

 I'm attempting to add in a basic trophy system.  What I am wanting it to
do is keep track of the last 10 kills made by a PC.  I have a basic
framework for it set up but I'm running into a problem.  I have a function
add_trophy that is called from inside raw_kill that should add the data
from the kill to the PC's trophy data.  Though, when a mob is killed
instead of adding the data to the TROPHY_DATA structure it overwrites the
PC's short/long descriptions and appends the killed mobs short description to the PC's input buffer. I'm not too terribly familiar with attaching
gdb to processes so if anyone could look over my code here and point out
something I'm missing I'd appreciate it.

/* These functions are located in act_info.c */

void add_trophy (CHAR_DATA *ch, CHAR_DATA *victim)
{
  int i = 0;
  TROPHY_DATA * trophy;

  /* If were the first entry, set it up */
  if (ch->pcdata->trophy_list->next == NULL)
  {
      ch->pcdata->trophy = new_trophy_data();
      ch->pcdata->trophy_list->next = ch->pcdata->trophy;
      ch->pcdata->trophy->vnum = victim->pIndexData->vnum;
      ch->pcdata->trophy->killed = 1;
      strcat(ch->pcdata->trophy->short_desc, victim->short_descr);
      ch->pcdata->trophy->next = NULL;
      return;
  }

  /* If were NOT the first entry, lets add us to the list */
  trophy = ch->pcdata->trophy_list->next;
  while (trophy->next)
  {
     trophy = trophy->next;
     i++;
  }
  if (i <= 10)
  {
     trophy->next = new_trophy_data();
     trophy = trophy->next;
     trophy->vnum = victim->pIndexData->vnum;
     trophy->killed = 1;
     strcat (trophy->short_desc, victim->short_descr);
     trophy->next = NULL;
  }

  return;
};

void do_trophy (CHAR_DATA *ch, char *argument)
{
 TROPHY_DATA * trophy;
 char buf[MAX_STRING_LENGTH];

 trophy = ch->pcdata->trophy_list->next;

 sprintf (buf, "{cTrophy Data{x\n\r{C==============={x\n\r");
 send_to_char (buf, ch);

 if (trophy == NULL)
 {
   sprintf (buf, "None\n\r");
   send_to_char (buf, ch);
   return;
 }

 while (trophy)
 {
  sprintf (buf, "%d  %s\n\r", trophy->killed, trophy->short_desc);
  send_to_char (buf, ch);
  trophy = trophy->next;
 }

 return;
};

/* Here is the merc.h info */
typedef struct    trophy_data      TROPHY_DATA;

/* These are located at the bottom of pc_data */
   TROPHY_DATA *       trophy;
   TROPHY_DATA *       trophy_list;

/* And this is defined just beneath pc_data */
struct trophy_data
{
   TROPHY_DATA * next;
   bool          valid;
   char *        short_desc;
   int           vnum;
   int           killed;
};

/* act_info.c */
void     set_title           args( ( CHAR_DATA *ch, char *title ) );
void     add_trophy          args( ( CHAR_DATA *ch, CHAR_DATA *victim ) );

/* And this is located in recycle.c */
/* stuff for recycling trophy data */
TROPHY_DATA *trophy_data_free;

TROPHY_DATA *new_trophy_data (void)
{
   TROPHY_DATA *trophy;

   if (trophy_data_free == NULL)
       trophy = alloc_perm (sizeof (*trophy));
   else
   {
       trophy = trophy_data_free;
       trophy_data_free = trophy_data_free->next;
   }

   trophy->short_desc = &str_empty[0];
   trophy->vnum = 0;
   trophy->killed = 0;
   VALIDATE (trophy);
   return trophy;
}

void free_trophy_data (TROPHY_DATA * trophy)
{
   if (!IS_VALID (trophy))
       return;

   free_string (trophy->short_desc);
   INVALIDATE (trophy);

   trophy->next = trophy_data_free;
   trophy_data_free = trophy;

   return;
}


Now, I have the appropriate definitions in the .h files, and as I mentioned I call add_trophy from raw_kill in fight.c. I'm sure there is
a better way to go about this, but any input would be very helpful.

Thanks,
Brett Phipps
[EMAIL PROTECTED]

_________________________________________________________________
MSN 8 helps eliminate e-mail viruses. Get 2 months FREE* http://join.msn.com/?page=features/virus


Reply via email to