Re: [CODE] Scan snippet

From: Chris Jacobson (fear@ATHENET.NET)
Date: 04/28/98


On 4/28/98 3:41 AM, Mark Gerritsen (m.p.h.gerritsen@STUDENT.UTWENTE.NL)
stated:

>If that is_in wasn't there to reset ch->room to the actual room the char is
>in after every direction, you'd scan around corners, or even in circles.
>For instance, if your skill would grant you a distance of 2, your
>"scan-path" would be this:
>
>              [ ]>[ ]>[ ]
>               ^       v      Followed by a double overview of the
>              [ ]     [ ]     2 rooms above you, since you scan up
>               ^       v      first, then down from there.
>              [x]<[ ]<[ ]
>
>This is provided you can go in those directions and have the 6 stock exits,
>of course. That's what the is_in is there for.

Why move the character to another room?  Also along the same line, in
look_at_room(ch), why not call yet another function, look_at_rnum(ch,
room) ?  It makes for any instance where you want the character to look
at a room, but don't want to move them there (this was necessary for the
vehicles patch, otherwise it would kill the player when they looked out
of the vehicle and it was a DT, or drove into a DT, since it shows the
description - vehicles are supposed to protect chars from DTs), and also
saves just a bit of extra work by not needing to save/restore or even
mess with ch->in_room.

Heres some extra code from my MUD (note it isn't plug-and-play, you'll
have to adapt it - a lot) used for our scanning.

(You'll note some usage of a template here, LList<>, and a lot of class
usage.  I'll be sending LList<> along in another post shortly after this
one.)

*** Begin Snippet ***


void look_in_direction(CharData * ch, int dir) {
        int             distance;
        RNum    room, nextroom, orig_room = IN_ROOM(ch);

void look_in_direction(CharData * ch, SInt32 dir, SInt32 maxDist) {
        int             distance;
        RNum    room, nextroom, orig_room = IN_ROOM(ch);

        if (EXIT(ch, dir)) {
                send_to_char(EXIT(ch, dir)->GetDesc("You see nothing special.\r\n"),
ch);

                if (EXIT(ch, dir)->GetKeyword()) {
                        if (EXIT_FLAGGED(EXIT(ch, dir), EX_CLOSED))
                                act("The $T is closed.\r\n", FALSE, ch, 0, fname(EXIT(ch,
dir)->GetKeyword()), TO_CHAR);
                        else if (EXIT_FLAGGED(EXIT(ch, dir), EX_ISDOOR))
                                act("The $T is open.\r\n", FALSE, ch, 0, fname(EXIT(ch,
dir)->GetKeyword()), TO_CHAR);
                }
                nextroom = CAN_GO2(orig_room, dir) ? EXIT2(orig_room, dir)->to_room :
NOWHERE;

                for (distance = 0; ((nextroom != NOWHERE) && (distance < maxDist));
distance++) {
                        list_scanned_chars(world[nextroom].people, ch, distance, dir);

                        room = nextroom;
                        nextroom = CAN_GO2(room, dir) ? EXIT2(room, dir)->to_room : NOWHERE;
                }
        } else
                send_to_char("Nothing special there...\r\n", ch);
}


void list_scanned_chars(LList<CharData *> &list, CharData * ch, int
distance, int door) {
        const char *    how_far[] = {
                "close by",
                "nearby",
                "to the",
                "far off",
                "far in the distance"
        };
        char                    relation;
        CharData *              i;
        UInt32                  count = 0, one_sent = 0;
        LListIterator<CharData *>       iter(list);

        while((i = iter.Peek())) {
                if (ch->CanSee(i))
                        count++;
        }

        if (!count)
                return;

        iter.Reset();
        while((i = iter.Peek())) {
                if (!ch->CanSee(i))
                        continue;

                relation = relation_colors[ch->GetRelation(i)];

                if (!one_sent)  ch->send("You see `%c%s", relation, i->GetName());
                else ch->send("`%c%s", relation, i->GetName());

                if (--count > 1)        send_to_char("`n, ", ch);
                else if (count == 1) send_to_char(" `nand ", ch);
                else ch->send(" `n%s %s.\r\n", how_far[distance], dirs[door]);
                one_sent++;
        }
}


*** End Snippet ***


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



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