scan snippet

An archive of older topics.
Post Reply
Aj
Posts: 809
Joined: Sun Dec 19, 2004 8:49 am

scan snippet

Post by Aj »

I am assuming our current version of scan is the buggy one that creates errors when dealing with hidden doors, so here's a basic scan snippet, should work circle since circle, merc, and godwars are all in the diku tree.


Note that function prototypes are not included in this code - remember to add them to merc.h yourself.

Code: Select all

/* 
 * returns everything the character can see at that location in buf
 * returns number of creatures seen 
 */

int scan_room (CHAR_DATA *ch, const ROOM_INDEX_DATA *room,char *buf)
{
    CHAR_DATA *target = room->people;
    int number_found = 0;

    while (target != NULL) /* repeat as long more peple in the room */
    {
        if (can_see(ch,target)) /* show only if the character can see the target */
        {
            strcat (buf, " - ");
            strcat (buf, IS_NPC(target) ? target->short_descr : target->name);
            strcat (buf, "\n\r");
            number_found++;
        }
        target = target->next_in_room;
    }

    return number_found;
}

void do_scan (CHAR_DATA *ch, char *argument)
{
    EXIT_DATA * pexit;
    ROOM_INDEX_DATA * room;
    extern char * const dir_name[];
    char buf[MAX_STRING_LENGTH];
    int dir;
    int distance;

    sprintf (buf, "Right here you see:\n\r");
    if (scan_room(ch,ch->in_room,buf) == 0)
        strcat (buf, "Noone\n\r");
    send_to_char (buf,ch);

    for (dir = 0; dir < 6; dir++) /* look in every direction */
    {
        room = ch->in_room; /* starting point */

        for (distance = 1 ; distance < 4; distance++)
        {
            pexit = room->exit[dir]; /* find the door to the next room */
            if ((pexit == NULL) || (pexit->to_room == NULL) || (IS_SET(pexit->exit_info, EX_CLOSED)))
                break; /* exit not there OR points to nothing OR is closed */

            /* char can see the room */
            sprintf (buf, "%d %s from here you see:\n\r", distance, dir_name[dir]);
            if (scan_room(ch,pexit->to_room,buf)) /* if there is something there */
                send_to_char (buf,ch);

            room = pexit->to_room; /* go to the next room */
        } /* for distance */
    } /* for dir */
}
User avatar
Galnor
Site Admin
Posts: 3023
Joined: Wed Oct 23, 2002 12:37 pm
Location: On The Run
Contact:

Post by Galnor »

I'm not really sure what this is suppose to do. Scan is actually disabled, not because it is buggy, but because it was going to have a different use that I just never got around to working out.
Aj
Posts: 809
Joined: Sun Dec 19, 2004 8:49 am

Post by Aj »

I just downloaded the latest version of circle, seems circle has strayed quite a bit from merc and god wars codebase. God wars is less bloated, much more straight forward and easier to tear apart in my opinion.
Post Reply