Logical thinking, not a huge prob, just ignorance

Posted by Trom on Sat 10 Apr 2004 03:55 AM — 7 posts, 25,302 views.

#0
I've been approaching a new type of assemble system were items are combined to create another item. This exists on many muds already, but i'm taking a shot at coding it on my own. So far i've got it done and working great, but now i've come across the difficulty of coding it so it can be used for QUEST ASSEMBLES.

Now a quest assemble is a bit more work since all the pieces and the result piece have to be quest pieces, so i've figured out most of it, all the dirty work is done.. the problem i've run into is when the player types 'quest info' it should display what mobs have recieved the quest pieces and what room their in.

I've come up with an idea to add questmob to ch->pcdata which would be of CHAR_DATA * structure.

Now this is the problem, how can i add an unknown amount of mobs to ch->pcdata->questmob.

So when quest info is typed, it would cycle through that list and display all their info (because it would be a pointer to the target mobs).

I don't think this can be anymore descriptive.


BTW:
I have a vague idea of how it works, it would be like assigning mobs to questmob then doing something like questmob = questmob->next, then assigning the mob to questmob again, the only prob with that is getting back to the start and keeping the new mobs at the same time.
Amended on Sat 10 Apr 2004 03:57 AM by Trom
USA #1
Perhaps a linked list would be best. I was thinking of using an array, but I guess thats not really possible.
#2
I plan to use a link list, but don't know how to keep adding to the end of the list without losing the whole list.
Australia Forum Administrator #3
Do you want a different list per player?

You may need a separate structure, something like this:


struct  questmob_type
{
    questmob_type *        next;
    int  vnum;
};


Then in your pcdata you would put the *first* questmob (which might be NULL), and then you add them by putting the first mob as "first" and then next is linked onto the last one in the list.

There are plenty of examples of that in SMAUG, look at the macros LINK, UNLINK etc. in mud.h.


#4
I've download smaug 1.4 and checked mud.h but didn't see much more than what rot/rom had.

Could you give me an example of adding to a link list ( to the start or end, order doesn't matter ).

I plan to have the following variables.

/*
struct pc_data
{
LIST_DATA *list;
}
*/
//Main list - ch->pcdata->list

typedef structure list_data_type LIST_DATA;
struct list_data_type
{
CHAR_DATA *mob;
LIST_DATA *next;
}

The above code is the type of code i want to use to store a temporary list in memory. How would i add like say 5 mobs to the list 'ch->pcdata->list'. I'm hoping the above code is at least a start to the right path.
#5
nevermind, i figured it out. Basically i setup a function which creates a newnode, then assigns the existing list to the newnode->next. Then assigned the new values to newnode itself then in that function returned newnode so the new data would be at the top of the list. Then assigned the new list to the ch->pcdata->list directly.
Australia Forum Administrator #6
Yes, that is about it. The linked-list macros in mud.h do that and more for you, and if you happen to have converted it to C++ you can use STL which greatly simplifies things like keeping lists.