quest->next = ch->quests;
ch->quests = quest;
quest->next = ch->quests;
ch->quests = quest;
ch->quest_last->next = quest;
ch->quest_last = quest;
if(!ch->quest_first )
ch->quest_first = quest;
if( ch->quest_last )
ch->quest_last->next = quest;
ch->quest_last = quest;
#define LINK(link, first, last, next, prev) \
do { \
if ( (link)->is_free == TRUE ) hang("LINK: link is FREE!"); \
if ( (link)->is_free != FALSE ) hang("LINK: link is corrupted!"); \
if ( (link)->prev || (link)->next ) hang("LINK: link already in list?");$
if ( (last) && (last)->next ) hang("LINK: last->next NON-NULL!"); \
if ( !(first) ) \
(first) = (link); \
else \
(last)->next = (link); \
(link)->next = NULL; \
(link)->prev = (last); \
(last) = (link); \
} while(0)
/* Link at the head of the list rather than the tail. Double linked */
#define TOPLINK(link, first, last, next, prev) \
do { \
if ( (link)->is_free == TRUE ) hang("TOPLINK: link is FREE!"); \
if ( (link)->is_free != FALSE ) hang("TOPLINK: link is corrupted!"); \
if ( (link)->prev || (link)->next ) hang("TOPLINK: link already in list?$
if ( (first) && (first)->prev ) hang("TOPLINK: first->prev NON-NULL!"); \
if ( !(last) ) \
(last) = (link); \
else \
(first)->prev = (link); \
(link)->prev = NULL; \
(link)->next = (first); \
(first) = (link); \
} while(0)
for(q = ch->quest_first ; q ; q = q->next )
…
ch->quest_head
ch->quest_tail
or
ch->quest->head
ch->quest->tail
if(!ch->quests )
ch->quests = quest;
if( ch->quest_last )
ch->quest_last->next = quest;
ch->quest_last = quest;
I am writing player quests to the Pfile using a similar approach to player objects.
Basically, I save the Vnum as index, and anything that isn't read-only to save the state of the quest, including its linked list of 'objectives'. When the player quest-list is loaded, it and the objective list displays in backwards order.
Obviously this is due to the fact that the list writes top-bottom, yet reads bottom-top. I've noticed some routines use recursion to write the lists backwards,
so that it initializes correctly.
I was wondering if there is a better approach to this?
PS. I do know that I could use sorting algorithms associated with std::list, but I
am not yet using std::list.