예제 #1
0
void do_scan( char_data* ch, char* argument )
{
  char             tmp  [ ONE_LINE ];
  room_data*      room  = ch->in_room;
  room_data*     room1;
  room_data*     room2;
  bool        anything  = FALSE;
  bool         is_auto  = !strcmp( argument, "shrt" );
  int i, j;

  if( !ch->in_room->Seen( ch ) ) {
    if( !is_auto )
      send( ch, "The room is too dark to scan.\r\n" );
    return;
    }

  if( !is_auto ) 
    anything = scan_room( ch, room, "[Here]", FALSE );

  room->distance = 0;

  for( i = 0; i < room->exits; i++ ) {
    if( is_set( &room->exits[i]->exit_info, EX_CLOSED ) )
      continue;
    room1     = room->exits[i]->to_room;
    anything |= scan_room( ch, room1,
      dir_table[room->exits[i]->direction].name,
      !anything && is_auto );
    if( ch->get_skill( SKILL_SCAN ) != 0 ) {
      for( j = 0; j < room1->exits; j++ ) {
        if( is_set( &room1->exits[j]->exit_info, EX_CLOSED ) )
          continue;
        room2 = room1->exits[j]->to_room;
        if( room2->distance != 0 ) {
          sprintf( tmp, "%s %s",
            room->exits[i]->direction == room1->exits[j]->direction
            ? "far" : dir_table[ room->exits[i]->direction ].name,
            dir_table[ room1->exits[j]->direction ].name );
          anything |= scan_room( ch, room2, tmp, !anything
            && is_auto );
          }
        }  
      }
    } 

  if( !anything && !is_auto ) 
    send( ch, "You see nothing in the vicinity.\r\n" );

  /*--  CLEANUP DISTANCE --*/

  room->distance = MAX_INTEGER;

  for( i = 0; i < room->exits; i++ ) { 
    room1 = room->exits[i]->to_room;
    room1->distance = MAX_INTEGER;
    for( j = 0; j < room1->exits; j++ )
      room1->exits[j]->to_room->distance = MAX_INTEGER;
    }
}
// explore the directory tree of rooms for files and directories
// in search of reward patterns.
int explore_world(char *dir)
{
    DIR *dirp;
    struct dirent *de;
    char cwd[512];

    memset(cwd, 0, sizeof(cwd));
    if ((dirp = scan_room(dir, cwd, sizeof(cwd))) == NULL)
        return 0;

    while ((de=readdir(dirp)) != NULL) {
        if (health_status <= 0) {
            printf("the primal organism has died.\n");
            return 0;
        }
        //printf("%s: %lld\n", de->d_name, health_status);
        if (de->d_type == DT_DIR && strncmp(".", de->d_name, 1) != 0) {
            if (explore_world(de->d_name) == 0)
                return 0;
            if (chdir("..") < 0) {
                perror("chdir() failed");
                return 0;
            }
        }
    }
    closedir(dirp);

    return 1;
}
예제 #3
0
int main(void) {
  room r;

  printf("Enter a room (<room name> (\"on\"|\"off\") (\"on\"|\"off\")): ");
  scan_room(&r);
  print_room(r);

  return 0;
}
예제 #4
0
파일: scan.c 프로젝트: blanciq/bq-killer
void do_scan( CHAR_DATA *ch, char *argument )
{
    EXIT_DATA       *pexit;
    ROOM_INDEX_DATA *room;
    ROOM_INDEX_DATA *in_room;
    DESCRIPTOR_DATA * d;
    extern char *const dir_name[];
    char buf[ MAX_STRING_LENGTH ];
    char exitname[ MAX_STRING_LENGTH ];
    int lookdoor, door, iter;
    int distance, max_dist;
    int mob_count, mob_count_new;
    bool darkness = FALSE;
    const char *dir_long_name[] = { "pó³noc", "wschód", "po³udnie", "zachód", "góra", "dó³" };
    lookdoor = -1;
    door = -1;

    if ( !IS_NPC( ch ) && ch->pcdata->mind_in )
    {
        in_room = ch->pcdata->mind_in;
    }
    else
    {
        if ( !check_blind( ch ) )
        {
            return ;
        }
        in_room = ch->in_room;
    }

    if ( argument[0] != '\0' )
    {
        if ( IS_AFFECTED( ch, AFF_MAZE ) )
        {
            send_to_char("Nie bardzo wiesz w która stronê popatrzeæ.\n\r", ch);
            return;
        }

        //wieza obserwacyjna
        if( !str_prefix( argument, "around" ) )
        {
            if ( !EXT_IS_SET( ch->in_room->room_flags, ROOM_WATCH_TOWER ) )
            {
                send_to_char( "Musisz byæ na szczycie wie¿y obserwacyjnej.\n\r", ch );
                return;
            }

            if ( ch->position != POS_STANDING )
            {
                send_to_char( "Najpierw wstañ.\n\r", ch );
                return;
            }

            send_to_char( "Ze szczytu wie¿y ogl±dasz uwa¿nie ca³± okolicê.\n\r", ch );
            act( "Stoj±c na szczycie wie¿y $n uwa¿nie omiata wzrokiem ca³± okolicê.", ch, NULL, NULL, TO_ROOM );

            for ( d = descriptor_list; d != NULL; d = d->next )
            {
                if ( !d->character || d->connected < 0 )
                {
                    continue;
                }
                if( d->connected != CON_PLAYING || d->character == ch || d->character->in_room == NULL )
                {
                    continue;
                }
                if ( !SAME_AREA( d->character->in_room->area, ch->in_room->area ) || !SAME_AREA_PART( d->character, ch ) )
                {
                    continue;
                }
                if ( !can_see( ch, d->character ) )
                {
                    continue;
                }
                if ( EXT_IS_SET( d->character->in_room->room_flags, ROOM_INDOORS ) || IS_SET( sector_table[ d->character->in_room->sector_type ].flag, SECT_NOWEATHER ) )
                {
                    continue;
                }
                if ( ch->in_room == d->character->in_room )
                {
                    continue;
                }
                print_char( ch, "{x%s - Widzisz tam {C%s{x.\n\r", d->character->in_room->name, d->character->name4 );
            }
            return;
        }
        door = get_door( ch, argument );
        if ( door >= 0 && check_vname( ch, door, FALSE ) )
        {
            send_to_char("W ktorym kierunku chcesz siê rozejrzeæ?\n\r", ch);
            return;
        }
        if ( door < 0 )
        {
            door = -1;
            for ( iter = 0; iter <= 5; iter++ )
            {
                if ( ( pexit = in_room->exit[iter] ) != NULL &&   !str_prefix( argument, pexit->vName ) &&  !( (IS_SET(pexit->exit_info, EX_SECRET) || IS_SET(pexit->exit_info, EX_HIDDEN))&& !IS_AFFECTED(ch,AFF_DETECT_HIDDEN) ) )
                {
                    door = iter;
                    break;
                }
            }
        }
        if ( door < 0 || in_room->exit[door] == NULL )
        {
            send_to_char("W ktorym kierunku chcesz siê rozejrzeæ?\n\r", ch);
            return;
        }
        lookdoor = door;
        door = -1;
    }
    if ( lookdoor < 0 )
    {
        if ( IS_NPC( ch ) || !ch->pcdata->mind_in )
        {
            act("$n rozgl±da siê dooko³a.", ch, NULL, NULL, TO_ROOM);
        }
        send_to_char("Rozgl±daj±c siê dooko³a widzisz:\n\r", ch);
        sprintf( buf, "{CTutaj{x\n\r" );
        mob_count = 0;
        mob_count_new = scan_room (ch, in_room, buf, 0);
        if ( mob_count_new < 0 )
        {
            send_to_char( "{CTutaj{x{c - nieprzenikniona ciemno¶æ.{x\n\r", ch );
            darkness = TRUE;
        }
        else
        {
            mob_count += mob_count_new;
        }
        strcat(buf, "{x");
        if ( mob_count > 0 )
        {
            send_to_char ( buf, ch );
        }
        else
        {
            if ( mob_count == 0 && !darkness)
            {
                send_to_char( "{CTutaj{x{c - nikogo nie ma.{x\n\r", ch );
            }
        }
    }
    darkness = FALSE;

    if ( !IS_NPC( ch ) && !EXT_IS_SET( ch->act, PLR_HOLYLIGHT ) )
    {
        if ( room_is_dark(ch, in_room) && !IS_AFFECTED(ch, AFF_INFRARED) )
        {
            send_to_char("Jest tutaj zbyt ciemno aby powiedzieæ co¶ o okolicy.\n\r", ch);
            return;
        }
    }
    for ( door = 0; door < MAX_DIR; door++ )
    {
        room = in_room;
        if ( lookdoor >= 0 && door != lookdoor )
        {
            continue;
        }
        if ( ( pexit = room->exit[door] ) == NULL )
        {
            continue;
        }
        if ( lookdoor >= 0 || !( ( IS_SET(pexit->exit_info, EX_SECRET) && !IS_SET(pexit->exit_info, EX_HIDDEN) ) || ( IS_SET(pexit->exit_info, EX_HIDDEN) && !IS_AFFECTED(ch,AFF_DETECT_HIDDEN) ) ) )
        {
            if ( pexit )
            {
                if ( pexit->vName && pexit->vName[0] != '\0' )
                {
                    sprintf( exitname, "%s", pexit->vName );
                }
                else
                {
                    if ( IS_AFFECTED( ch, AFF_MAZE ) )
                    {
                        sprintf ( exitname, "%s", capitalize( dir_long_name[ number_range( 0, 5 ) ] ) );
                    }
                    else
                    {
                        sprintf( exitname, "%s", capitalize( dir_name[door] ) );
                    }
                }
            }
            else
            {
                exitname[0] = '\0';
            }
            if ( !room_is_dark( ch, in_room ) )
            {
                if ( IS_SET( pexit->exit_info, EX_HIDDEN ) )
                {
                    sprintf( buf, "{C%s{x{c - kto¶ stara³ siê ukryæ to przej¶cie.{x\n\r", exitname );
                    send_to_char( buf, ch );
                    continue;
                }
                else if ( IS_SET( pexit->exit_info, EX_CLOSED ) && !IS_AFFECTED(ch, AFF_PIERCING_SIGHT) )
                {
                    if ( pexit->biernik != NULL && pexit->biernik[ 0 ] != '\0' && pexit->biernik[ 0 ] != ' ' )
                    {
                        if( !pexit->liczba_mnoga )
                        {
                            sprintf( buf, "{C%s{x{c - nic nie widzisz przez zamkniêt± %s.{x\n\r", exitname, pexit->biernik );
                        }
                        else
                        {
                            sprintf( buf, "{C%s{x{c - nic nie widzisz przez zamkniête %s.{x\n\r", exitname, pexit->biernik );
                        }
                        send_to_char( buf, ch );
                    }
                    else
                    {
                        sprintf( buf, "{C%s{x{c - nic nie widzisz przez zamkniête drzwi.{x\n\r", exitname );
                        send_to_char( buf, ch );
                    }
                    continue;
                }
                else if ( IS_SET( pexit->exit_info, EX_WALL_OF_MIST ) && !IS_AFFECTED(ch, AFF_PIERCING_SIGHT) )
                {
                    sprintf( buf, "{C%s{x{c - ¶ciana mg³y zas³ania ci widoczno¶æ.{x\n\r", exitname );
                    send_to_char( buf, ch );
                    continue;
                }
            }

            buf[0] = '\0';
            mob_count = 0;
            max_dist = (lookdoor < 0)? 2:4;

            /**
             * imorovmen range for elfs
             * http://forum.mud.pl/viewtopic.php?t=5457
             */
            if(!str_cmp( race_table[ GET_RACE(ch) ].name, "elf" ))
            {
                max_dist += number_range(0, 2);
            }
            for ( distance = 1 ; distance < max_dist; distance++ )
            {
                pexit = room->exit[door];
                if ( !pexit || !pexit->u1.to_room || ( IS_SET( pexit->exit_info, EX_CLOSED ) && !IS_AFFECTED(ch, AFF_PIERCING_SIGHT) ) || ( IS_SET( pexit->exit_info, EX_WALL_OF_MIST ) && !IS_AFFECTED(ch, AFF_PIERCING_SIGHT) ))
                {
                    break;
                }
                darkness = FALSE;
                mob_count_new = scan_room ( ch, pexit->u1.to_room, buf, distance);
                if (  mob_count_new < 0)
                {
                    printf_to_char( ch, "{C%s{x{c - panuje tam nieprzenikniona ciemno¶æ.{x\n\r", exitname );
                    darkness = TRUE;
                }
                else
                {
                    mob_count += mob_count_new;
                }

                room = pexit->u1.to_room;
            }
            strcat(buf, "{x");

            if ( mob_count > 0 && !darkness )
            {
                if ( room_is_dark( ch, in_room ) )
                {
                    printf_to_char( ch, "{C%s{x{c - widaæ tam chyba kogo¶.{x\n\r", exitname );
                }
                else
                {
                    print_char( ch, "{C%s{x\n\r", exitname );
                    send_to_char ( buf, ch );
                }
            }
            else if ( !room_is_dark( ch, in_room ) && !darkness )
            {
                if ( mob_count == 0 && in_room->exit[door])
                {
                    printf_to_char( ch, "{C%s{x{c - nikogo tam nie widaæ.{x\n\r", exitname );
                }
            }
            darkness = FALSE;
        }
    }

    if ( room_is_dark( ch, in_room ) )
    {
        send_to_char("\n\rJest tutaj zbyt ciemno aby powiedzieæ co¶ dok³adniej o okolicy.\n\r", ch);
        return;
    }
    return;
}