Ok, rewrote the code. Now my problems are far, far worse. I tried compiling the mud.. didn't work, forgot some semicolons and tried to reference a non existent field of a struct. Easy fix. So, it compiled, yay, time to test it out. Place the executable in the area folder, cd'ed over to it, and did a good ol' "./rom"

"Bus error"

And that was on startup.. didn't even send a single message before I received the error.

Doh. Figured it might be because I was initializing the tracking struct fields to NULL, then the struct itself to NULL. Changed some values around, figured maybe int types can't be NULL, changed them to 0, removed the pRoomIndex->tracking = NULL; line.

Compiled, ran. Bus Error. Then, instead of returning to the prompt, it just went to an empty line. So I ctrl+x'ed out of it. All of a sudden, another Bus error came up. They are periodically scrolling my screen.. at the exact moment of this writing, I have -18- bus errors scrolled on my screen. *cough*

This happened to me before with some code I was trying to install OLC on. So, I figured it was a lost cause, deleted the entire thing, and re downloaded stock rom and started my tracking endeavour. I have this awful feeling I am doomed to not be able to have a MUD. Evil *nix gods, EVIL!

My new and updated code (which seems to work much, much worse than before): in "db.c" in "void load_rooms( FILE *fp )" right before the "iHash = vnum % MAX_KEY_HASH;" line:
/* begin: zero out the data */
        pRoomIndex->tracking->player = NULL;
        pRoomIndex->tracking->age = 0; /* was NULL */
        pRoomIndex->tracking->dir_to = 0; /* was NULL */
        pRoomIndex->tracking->dir_from = 0; /* was NULL */
        pRoomIndex->tracking->next = NULL;
        pRoomIndex->tracking = NULL;
/* end */

in "db.c" in "void reset_area( AREA_DATA *pArea )" in case 'R' (I was told this was in the wrong spot.. why? I would like this code executed on every room in every area, and this looks to me like the place to do it.. any other recommendations?) after the d0 = 0 for loop:
            /*
* This is the tracking reset code. Every PULSE_AREA, we update/destroy the tracks
            */
            /* tracks are in room, update them */
            if ( pRoomIndex->tracking ) {
                if ( ( srchTrack = alloc_mem( sizeof
( TRACK_DATA ) ) ) != NULL
                        && ( prevTrack = alloc_mem( sizeof
( TRACK_DATA ) ) ) != NULL
                        && ( tmpTrack = alloc_mem( sizeof
( TRACK_DATA ) ) ) != NULL ) {
                    srchTrack = pRoomIndex->tracking;
                    prevTrack->age = NULL;
                    prevTrack->dir_to = NULL;
                    prevTrack->dir_from = NULL;
                    prevTrack->player = NULL;
                    prevTrack->next = NULL;

                    firstTrack = TRUE;
                /* go through all tracks, update */
                    for ( ; srchTrack; ) {
/* make sure we don't kill tracks we want to keep */
                        killTrack = FALSE;
                        /* age the tracks */
                        srchTrack->age += 1;
                        /* keep the last struct so we don't lose it */
                        prevTrack = srchTrack;

/* this is fun. tracks will "age" based on the sector type. forest tracks * last longer than tracks in the mountains, so we act accordingly
                        */
                        switch ( pRoomIndex->sector_type ) {
                        case 0: case 1:
/* since PULSE_AREA is the amount of beats it takes for the area to age, * we do X * PULSE_AREA so track aging is dynamic. makes it easy to change * the age rate of areas without changing track code
                            */
                            if ( srchTrack->age >= ( 3 * PULSE_AREA ) )
                            {
                                killTrack = TRUE;
                                break;
                            }
                        case 2: case 4: case 5:
                            if ( srchTrack->age >= ( 7 * PULSE_AREA ) )
                            {
                                killTrack = TRUE;
                                break;
                            }
                        case 3:
                            if ( srchTrack->age >= ( 15 * PULSE_AREA ) )
                            {
                                killTrack = TRUE;
                                break;
                            }
                        case 10:
                            if ( srchTrack->age >= ( 10 * PULSE_AREA ) )
                            {
                                killTrack = TRUE;
                                break;
                            }
                        }

                        if ( killTrack ) {
                            if ( firstTrack ) {
                                tmpTrack = srchTrack;
                                free_mem( pRoomIndex->tracking, sizeof
( *pRoomIndex->tracking ) );
                                pRoomIndex->tracking = tmpTrack;
                                srchTrack = tmpTrack;
                            }
                            else {
                                prevTrack->next = srchTrack->next;
                                *tmpTrack = *srchTrack;
                                free_mem( srchTrack, sizeof
( *srchTrack ) );
                                *srchTrack = *prevTrack->next;
                            }
                        }

                        if ( srchTrack != pRoomIndex->tracking ) {
                            firstTrack = FALSE;
                        }
                    /* end for */
                    }
                /* end if */
                }
            /* end if */
            }
/* END */

in "act_move.c" in "void move_char( CHAR_DATA *ch, int door, bool follow )" between "char_from_room( ch );" and "char_to_room( ch, to_room );":
/*      TRACKING CODE. COMPLETE(?). */
    if ( do_track ) {
        send_to_char( "DO_TRACK IS TRUE\n\r", ch );

if ( ( srchTrack = alloc_mem( sizeof( TRACK_DATA ) ) ) != NULL ) {
            /* initialize the struct */
            srchTrack->player = NULL;
            srchTrack->dir_to = NULL;
            srchTrack->dir_from = NULL;
            srchTrack->age = NULL;
            srchTrack->next = NULL;

/* Tracking is already in room, so we modify/possibly add to it */
            if ( in_room->tracking ) {
                /* Iterate through the list */
                for ( srchTrack = in_room->tracking; srchTrack; ) {
                    /* If the tracks are ch's, update them */
                    if ( strcmp( srchTrack->player, ch->name ) == 0 ) {
                        srchTrack->dir_to = door;
                        srchTrack->age = 0;
                    }
                    else {
/* If we're at end of list, and no one's been found, we add a new entry */
                        if ( !srchTrack->next ) {
                            if ( ( inTrack = alloc_mem( sizeof
( TRACK_DATA ) ) ) != NULL ) {
                                inTrack->player = str_dup( ch->name );
                                inTrack->age = 0;
                                inTrack->dir_to = door;
                                inTrack->dir_from = NULL;
                                inTrack->next = NULL;
                                srchTrack->next = inTrack;
send_to_char( "Allocated. First block.\n\r", ch );
                                /* get us out of loop ;) */
                                break;
                            }
                        }
                        else {
                            srchTrack = srchTrack->next;
                        }
                    }
                }
            }
            /* no tracking in room, let's make some! */
            else {
if ( ( inTrack = alloc_mem( sizeof( TRACK_DATA ) ) ) != NULL ) {
                    inTrack->player = str_dup( ch->name );
                    inTrack->age = 0;
                    inTrack->dir_to = door;
                    inTrack->dir_from = NULL;
                    inTrack->next = NULL;
                    in_room->tracking = inTrack;
                    send_to_char( "Allocated. Second block.\n\r", ch );
                }
            }

            /* gotta allocate the to_room also */
            if ( to_room->tracking ) {
                /* iterate through the to_room tracks */
                for ( srchTrack = to_room->tracking; srchTrack; ) {
if ( strcmp( to_room->tracking->player, ch->name ) == 0 ) {
                        to_room->tracking->dir_from = rev_dir[door];
                        to_room->tracking->age = 0;
                    }
                    else {
                        if ( !srchTrack->next ) {
                            if ( ( toTrack = alloc_mem( sizeof
( TRACK_DATA ) ) ) != NULL ) {
                                toTrack->player = str_dup( ch->name );
                                toTrack->age = 0;
                                toTrack->dir_to = NULL;
                                toTrack->dir_from = rev_dir[door];
                                toTrack->next = NULL;
                                srchTrack->next = toTrack;
send_to_char( "Allocated. Third block.\n\r", ch );
                                break;
                            }
                        }
                        else {
                            srchTrack = srchTrack->next;
                        }
                    }
                }
            }
            else {
                /* no tracking in room, make tracks */
if ( ( toTrack = alloc_mem( sizeof( TRACK_DATA ) ) ) != NULL ) {
                    toTrack->player = str_dup( ch->name );
                    toTrack->age = 0;
                    toTrack->dir_to = NULL;
                    toTrack->dir_from = rev_dir[door];
                    toTrack->next = NULL;
                    to_room->tracking = toTrack;
                    send_to_char( "Allocated. Fourth block.\n\r", ch );
                }
            }

        }
    }
/* END TRACKING CODE */

A note of comment. I switched the "player" field if TRACK_DATA to a char * instead of CHAR_DATA * so we can just use the player's name. This way, I can actually keep tracks around when the player logs off, piece of cake. In fact, that's the way it's currently set up.. I'd have to make changes in order to prevent the tracks from being permanent (blah :P).

Well, let me know what your comments are this time.. by the way, I -really- appreciate all your help. I'm at least gaining good programming experience destroying my operating system ;)

Oh, and I just stumbled across the reset commends. No wonder 'R' is a bad place to put it. Would 'D' be better? I'm sure some of these little issues, like where it's placed, is probably making all the difference right now.. i'm fairly confident my tracking code is decently stable ;)

And for the heck of it:
struct  track_data
{
    char *              player;         /* player to pass through exit */
    sh_int              age;            /* age of tracks */
    sh_int              dir_to;         /* direction tracks go to */
    sh_int              dir_from;       /* direction tracks come from */
TRACK_DATA * next; /* next tracking data, say, if another player passes through exit */
};

Another note about the bus error.. it happens, seriously, before I receive ANY feedback the mud startup normally gives (resets, mobs, etc). It's like, something completely different is going wrong. Because it won't even start trying to work. Who knows, maybe that's the way it DOES work.. *hopes so*

--Daniel, the long winded.


Reply via email to