engine/maps/source/MapUtils.cpp
// Get the dimensions for a new map based on the current map, the coords, and the size.
// If it's a large map and the coordinates are in the centre, the dimensions will likely
// be size x size.  In other cases, the dimensions will be smaller, particularly if the
// coordinates fall near the map's borders.
Get the dimensions for a new map based on the current map, the coords, and the size.
If it's a large map and the coordinates are in the centre, the dimensions will likely
be size x size.  In other cases, the dimensions will be smaller, particularly if the
coordinates fall near the map's borders.
Get the dimensions for a new map based on the current map the coords and the size . If it ' s a large map and the coordinates are in the centre the dimensions will likely be size x size . In other cases the dimensions will be smaller particularly if the coordinates fall near the map ' s borders .
Dimensions MapUtils::get_dimensions(MapPtr map, const Coordinate& coords, const int size)
{
  Dimensions new_dimensions(0, 0);
  Dimensions original_dimensions = map->size();
  int rows_orig = original_dimensions.get_y();
  int cols_orig = original_dimensions.get_x();
  int coord_row = coords.first;
  int coord_col = coords.second;
  int num_rows = 0;
  int num_cols = 0;
  for(int row = (coord_row - size); row <= (coord_row + size); row++)
  {
    if ((row >= 0) && (row <= rows_orig - 1))
    {
      if (num_cols == 0)
      {
        for (int col = (coord_col - size); col <= (coord_col + size); col++)
        {
          if ((col >= 0) && (col <= cols_orig - 1))
          {
            num_cols++;
          }
        }
      }
      num_rows++;
    }
  }
  new_dimensions.set_y(num_rows);
  new_dimensions.set_x(num_cols);
  return new_dimensions;
}
Dimensions MapUtils :: get_dimensions ( MapPtr map , const Coordinate & coords , const int size ) { Dimensions new_dimensions ( 0 , 0 ) ; Dimensions original_dimensions = map -> size ( ) ; int rows_orig = original_dimensions . get_y ( ) ; int cols_orig = original_dimensions . get_x ( ) ; int coord_row = coords . first ; int coord_col = coords . second ; int num_rows = 0 ; int num_cols = 0 ; for ( int row = ( coord_row - size ) ; row <= ( coord_row + size ) ; row ++ ) { if ( ( row >= 0 ) && ( row <= rows_orig - 1 ) ) { if ( num_cols == 0 ) { for ( int col = ( coord_col - size ) ; col <= ( coord_col + size ) ; col ++ ) { if ( ( col >= 0 ) && ( col <= cols_orig - 1 ) ) { num_cols ++ ; } } } num_rows ++ ; } } new_dimensions . set_y ( num_rows ) ; new_dimensions . set_x ( num_cols ) ; return new_dimensions ; }
Get the dimensions for a new map based on the current map, the coords, and the size.
Get the dimensions for a new map based on the current map the coords and the size .