* Executes command to create resize map for realm.
* @param realm Realm to execute the command
* @return CommandResult
*/
public CommandResult execute(Realm realm) {
WorldMap currentMap = realm.getWorldMap();
int probabilityTotal = 0;
Iterator<TileType> tileIterator = realm.getTileTypeManager().getTileTypesIterator();
while (tileIterator.hasNext()) {
TileType tileType = tileIterator.next();
probabilityTotal = probabilityTotal + tileType.getProbability();
}
int newColumnsToAdd = width - currentMap.getWidth();
int newRowsToAdd = height - currentMap.getHeight();
int columnSegmentSize = currentMap.getWidth() / newColumnsToAdd;
int rowSegmentSize = currentMap.getHeight() / newRowsToAdd;
Tile[][] mapItems = new Tile[width][height];
for (int i = 0; i < width; i++) {
for (int j = 0; j < height; j++) {
Tile newTile;
if ((i != 0 && i % (columnSegmentSize + 1) == 0) || (j != 0 && j % (rowSegmentSize + 1) == 0)) {
newTile = new Tile(generateTileType(realm, probabilityTotal));
} else {
int targetX = i - i / columnSegmentSize;
int targetY = j - j / rowSegmentSize;
Coordinate coordinate = new Coordinate(targetX, targetY);
newTile = currentMap.getTile(coordinate);
}
mapItems[i][j] = newTile;
}
}
currentMap.setMapItems(mapItems);
realm.setWorldMap(currentMap);
return new CommandResult(CommandResult.RESULT_OK, "");
}