Re: [CODE] Rooms moving around...

From: Daniel Wickes (circle@wormsoft.demon.co.uk)
Date: 04/06/99


Hi,

> I have tried to make a flying fortress that changes room 2617's (The
> entrance to the fort)  link south from none to something each season.
> The code look like this and is called every tick in comm.c

First of all I don't like the look of those 'magic' numbers, especially not if
they're real numbers, not virtual ones.   Are these there as an example for
us, or is this actually how it appears?  If it's how it appears, maybe you
want to do something like;

        int nRealFrom, nRealTo;

        nRealFrom = real_room(766);
        nRealTo = real_room(2617);

and then replace every instance of "766" in your current snippet with
nRealFrom, and "2617" to nRealTo.  Also, you're CREATE()ing these directions
everytime your function gets called; allocating new memory each time, and not
freeing it, as far as I can see.  Without seeing the rest of it, this is the
simplest fix for what you've written.  I'm going totally from memory here, but
I think it should work;

void move_fort(void)
{
        extern struct time_info_data time_info;
        int nRealFrom, nRealTo;

        if (time_info.month > 4 && time_info.month < 8)
        {
                nRealFrom = real_room(766);
                nRealTo = real_room(2617);

                /* Only allocate the memory if we need to */
                if (!world[nRealTo].dir_option[0])
                        CREATE(world[nRealTo].dir_option[0], struct room_direction_data, 1);

                world[nRealTo].dir_option[0]->general_description = NULL;
                world[nRealTo].dir_option[0]->keyword = NULL;
                world[nRealTo].dir_option[0]->to_room = nRealFrom;

                /* Only allocate the memory if we need to*/
                if (!world[nRealFrom].dir_option[2])
                        CREATE(world[nRealFrom].dir_option[2], struct room_direction_data, 1);

                world[nRealFrom].dir_option[2]->general_description = NULL;
                world[nRealFrom].dir_option[2]->keyword = NULL;
                world[nRealFrom].dir_option[2]->to_room = nRealTo;

        } else if (time_info.month > 7 && time_info.month < 12)
        {

This code assumes your two rooms have _virtual_ numbers of 2617 and 766.
Also, if you might want to use a long instead of an int for the real rooms,
depending on your setup.  Another one to watch out for is if your
"world[<room>].dir_option[<dir>]->general_description" wasn't NULL and it
wasn't created by you in this function, you might be losing your pointer to
allocated memory.

Anyway, that's enough to give you a good start, I think! :)

-- Dan

> {
>   extern struct time_info_data time_info;
>
>   if (time_info.month > 4 && time_info.month < 8) {
>     CREATE(world[766].dir_option[0], struct room_direction_data, 1);
>     world[766].dir_option[0]->general_description = NULL;
>     world[766].dir_option[0]->keyword = NULL;
>     world[766].dir_option[0]->to_room = 2617;
>
>     CREATE(world[2617].dir_option[2], struct room_direction_data, 1);
>     world[2617].dir_option[2]->general_description = NULL;
>     world[2617].dir_option[2]->keyword = NULL;
>     world[2617].dir_option[2]->to_room = 766;
>
>   } else if (time_info.month > 7 && time_info.month < 12) {
>   ...
>   ..
>   .
>
> But, it won't set the link south. I have logged the whole function, and
> all logs go through. What can be wrong?


     +------------------------------------------------------------+
     | Ensure that you have read the CircleMUD Mailing List FAQ:  |
     |  http://qsilver.queensu.ca/~fletchra/Circle/list-faq.html  |
     +------------------------------------------------------------+



This archive was generated by hypermail 2b30 : 12/15/00 PST