Exemplo n.º 1
0
void
mr_center_room (int room)
{
  mr.room = room;

  int x, y, lc = 0, c = 0, ld = INT_MAX;
  int lx = mr.x;
  int ly = mr.y;
  for (y = mr.h - 1; y >= 0; y--)
    for (x = 0; x < mr.w; x++) {
      mr.x = x;
      mr.y = y;
      mr_map_rooms ();
      c = mr_count_rooms ();
      int cx, cy;
      mr_topmost_cell (&cx, &cy);
      int ca = cy;
      mr_bottommost_cell (&cx, &cy);
      int cb = (mr.h - 1) - cy;
      int d = abs (ca - cb);
      if (c >= lc && (c > lc || d < ld)) {
        lx = x;
        ly = y;
        lc = c;
        ld = d;
      }
    }

  mr.x = lx;
  mr.y = ly;

  mr.select_cycles = SELECT_CYCLES;
}
Exemplo n.º 2
0
void
mr_center_room (int room)
{
  int x, y, lc = 0, c = 0, ld = INT_MAX;
  float ldc = INFINITY;
  int lx = mr.x;
  int ly = mr.y;
  for (y = mr.h - 1; y >= 0; y--)
    for (x = 0; x < mr.w; x++) {
      mr_set_origin (room, x, y);
      c = mr_count_rooms ();
      int cx, cy;
      mr_topmost_cell (&cx, &cy);
      int ca = cy;
      mr_bottommost_cell (&cx, &cy);
      int cb = (mr.h - 1) - cy;
      mr_leftmost_cell (&cx, &cy);
      int cl = cx;
      mr_rightmost_cell (&cx, &cy);
      int cr = (mr.w - 1) - cx;;
      int d = abs (ca - cb) + abs (cl - cr);
      float dc = dist_cart (x, y, (mr.w - 1) / 2, (mr.h - 1) / 2);
      if (c > lc
          || (c == lc && d < ld)
          || (c == lc && d == ld && dc < ldc)) {
        lx = x;
        ly = y;
        lc = c;
        ld = d;
        ldc = dc;
      }
    }

  mr_set_origin (room, lx, ly);
  mr.select_cycles = SELECT_CYCLES;
}