On Sun, 12 Jan 2003, Brett Phipps wrote:
> 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)
Where are you initializing ch->pcdata->trophy_list?
You neglected to show that code.
You seem to be a bit confused on linked lists.
Either you use an empty head node, like you seem to be doing here,
or you treat the case of adding to an empty list specially, also
like you seem to be doing. Not both. If you're initializing
ch->pcdata->trophy_list somewhere to an empty value, the whole
first part of this function (everything inside this if) is
unnecessary. The code below takes care of it.
> {
> ch->pcdata->trophy = new_trophy_data();
What are you using ch->pcdata->trophy for?
It looks to me like you're using it instead of using the
local variable trophy in this function?
> 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);
^^^^^^
Big no no. Don't ever do this unless you have a large character
buffer (you don't here. All you have is a pointer)
> 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);
Don't do this. It isn't good for your health.
> trophy->next = NULL;
> }
>
> return;
> };
[snipped]
> /* Here is the merc.h info */
> typedef struct trophy_data TROPHY_DATA;
>
> /* These are located at the bottom of pc_data */
> TROPHY_DATA * trophy;