Ejemplo n.º 1
0
int find_first_step(sh_int src, sh_int target, int stay_zone)
{
  int curr_dir;
  sh_int curr_room;
  int src_zone = ((src - (src % 100)) / 100);
  int target_zone = ((target - (target % 100)) / 100);

  if (src < 0 || src > top_of_world || target < 0 || target > top_of_world) {
    stderr_log("Illegal value passed to find_first_step (graph.c)");
    return BFS_ERROR;
  }

  /* dez 19980805
   if ((src_zone != target_zone && stay_zone == 1) || stay_zone == 2) {
   return BFS_NO_PATH;
   }
   */
  if (src_zone != target_zone && stay_zone == 1) {
    return BFS_NO_PATH;
  }

  if (src == target) {
    return BFS_ALREADY_THERE;
  }

  /* clear marks first */
  for (curr_room = 0; curr_room <= top_of_world; curr_room++) {
    UNMARK(curr_room);
  }

  MARK(src);

  /* first, enqueue the first steps, saving which direction we're going. */
  for (curr_dir = 0; curr_dir < NUM_OF_DIRS; curr_dir++) {
    if (VALID_EDGE(src, curr_dir)) {
      MARK(TOROOM(src, curr_dir));
      bfs_enqueue(TOROOM(src, curr_dir), curr_dir);
    }
  }
  /* now, do the classic BFS. */
  while (queue_head) {
    if (queue_head->room == target) {
      curr_dir = queue_head->dir;
      bfs_clear_queue();
      return curr_dir;
    } else {
      for (curr_dir = 0; curr_dir < NUM_OF_DIRS; curr_dir++) {
        if (VALID_EDGE(queue_head->room, curr_dir)) {
          MARK(TOROOM(queue_head->room, curr_dir));
          bfs_enqueue(TOROOM(queue_head->room, curr_dir), queue_head->dir);
        }
      }
      bfs_dequeue();
    }
  }

  return BFS_NO_PATH;
}
Ejemplo n.º 2
0
/* 
 * find_first_step: given a source room and a target room, find the first
 * step on the shortest path from the source to the target.
 *
 * Intended usage: in mobile_activity, give a mob a dir to go if they're
 * tracking another mob or a PC.  Or, a 'track' skill for PCs.
 */
int	find_first_step(room_rnum src, room_rnum target)
{
	int curr_dir;
	room_rnum curr_room;

	if (src == NOWHERE || target == NOWHERE || src > top_of_world || target > top_of_world) {
		extended_mudlog(NRM, SYSL_BUGS, TRUE, "Illegal value %d or %d passed to find_first_step. (%s)", src, target, __FILE__);
		return (BFS_ERROR);
	}
	if (src == target)
		return (BFS_ALREADY_THERE);

	/* clear marks first, some OLC systems will save the mark. */
	for (curr_room = 0; curr_room <= top_of_world; curr_room++)
		UNMARK(curr_room);

	MARK(src);

	/* first, enqueue the first steps, saving which direction we're going. */
	for (curr_dir = 0; curr_dir < NUM_OF_DIRS; curr_dir++)
		if (VALID_EDGE(src, curr_dir)) {
			MARK(TOROOM(src, curr_dir));
			bfs_enqueue(TOROOM(src, curr_dir), curr_dir);
		}

	/* now, do the classic BFS. */
	while (queue_head) {
		if (queue_head->room == target) {
			curr_dir = queue_head->dir;
			bfs_clear_queue();
			return (curr_dir);
		} else {
			for (curr_dir = 0; curr_dir < NUM_OF_DIRS; curr_dir++)
	if (VALID_EDGE(queue_head->room, curr_dir)) {
		MARK(TOROOM(queue_head->room, curr_dir));
		bfs_enqueue(TOROOM(queue_head->room, curr_dir), queue_head->dir);
	}
			bfs_dequeue();
		}
	}

	return (BFS_NO_PATH);
}
Ejemplo n.º 3
0
int find_first_step( ROOM_INDEX_DATA * src, ROOM_INDEX_DATA * target, int maxdist )
{
    int curr_dir, count;
    EXIT_DATA *pexit;

    if( !src || !target )
    {
        bug( "%s", "Illegal value passed to find_first_step (track.c)" );
        return BFS_ERROR;
    }

    if( src == target )
        return BFS_ALREADY_THERE;

    if( src->area != target->area )
        return BFS_NO_PATH;

    room_enqueue( src );
    MARK( src );

    /*
     * first, enqueue the first steps, saving which direction we're going.
     */
    for( pexit = src->first_exit; pexit; pexit = pexit->next )
        if( valid_edge( pexit ) )
        {
            curr_dir = pexit->vdir;
            MARK( pexit->to_room );
            room_enqueue( pexit->to_room );
            bfs_enqueue( pexit->to_room, curr_dir );
        }

    count = 0;
    while( queue_head )
    {
        if( ++count > maxdist )
        {
            bfs_clear_queue(  );
            clean_room_queue(  );
            return BFS_NO_PATH;
        }
        if( queue_head->room == target )
        {
            curr_dir = queue_head->dir;
            bfs_clear_queue(  );
            clean_room_queue(  );
            return curr_dir;
        }
        else
        {
            for( pexit = queue_head->room->first_exit; pexit; pexit = pexit->next )
                if( valid_edge( pexit ) )
                {
                    curr_dir = pexit->vdir;
                    MARK( pexit->to_room );
                    room_enqueue( pexit->to_room );
                    bfs_enqueue( pexit->to_room, queue_head->dir );
                }
            bfs_dequeue(  );
        }
    }
    clean_room_queue(  );

    return BFS_NO_PATH;
}