Package org.freerealm.map

Examples of org.freerealm.map.WorldMap


     * 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, "");
    }
View Full Code Here


        realm.setUnitTypeManager(new UnitTypeManager());
        realm.setNationManager(new NationManager());
        realm.setPlayerManager(new PlayerManager());
        realm.setDiplomacy(new Diplomacy());
        realm.setHistory(new FreeRealmHistory());
        realm.setWorldMap(new WorldMap());
        realm.setPathFinder(null);
        realm.setNumberOfTurns(0);
        realm.setManagedObjectCount(0);
        return new CommandResult(CommandResult.NO_UPDATE, "");
    }
View Full Code Here

        Node historyNode = XMLConverterUtility.findNode(node, "history");
        History history = (new FreeRealmHistoryXMLConverter()).initializeFromNode(realm, historyNode);
        realm.setHistory(history);

        Node worldMapNode = XMLConverterUtility.findNode(node, "WorldMap");
        WorldMap worldMap = new WorldMap();
        (new WorldMapXMLWrapper(worldMap)).initializeFromNode(realm, worldMapNode);

        Iterator<Player> playerIterator = realm.getPlayerManager().getPlayersIterator();
        while (playerIterator.hasNext()) {
            Player player = playerIterator.next();
            Iterator<Settlement> settlementsIterator = player.getSettlementsIterator();
            while (settlementsIterator.hasNext()) {
                Settlement settlement = settlementsIterator.next();
                worldMap.addSettlement(settlement);
            }
            Iterator<Unit> unitsIterator = player.getUnitsIterator();
            while (unitsIterator.hasNext()) {
                Unit unit = unitsIterator.next();
                if (unit.getCoordinate() != null) {
                    worldMap.addUnit(unit);
                }
            }
        }
        realm.setWorldMap(worldMap);
    }
View Full Code Here

        } catch (IOException exception) {
            return new CommandResult(CommandResult.RESULT_ERROR, "IOException : " + exception.getMessage());
        }
        NodeList nodeList = builder.getDocument().getElementsByTagName("WorldMap");
        Node worldMapNode = nodeList.item(0);
        WorldMap worldMap = new WorldMap();
        (new WorldMapXMLWrapper(worldMap)).initializeFromNode(realm, worldMapNode);
        realm.setWorldMap(worldMap);
        realm.setPathFinder(new AStarPathFinder(realm, 100));
        return new CommandResult(CommandResult.RESULT_OK, "");
    }
View Full Code Here

     * @param realm Realm to execute the command
     * @return CommandResult
     */
    public CommandResult execute(Realm realm) {
        Tile[][] mapItems = new Tile[width][height];
        WorldMap worldMap = new WorldMap();
        if (useTileType == null) {
            int probabilityTotal = 0;
            Iterator<TileType> tileIterator = realm.getTileTypeManager().getTileTypesIterator();
            while (tileIterator.hasNext()) {
                TileType tileType = tileIterator.next();
                probabilityTotal = probabilityTotal + tileType.getProbability();
            }
            for (int i = 0; i < width; i++) {
                for (int j = 0; j < height; j++) {
                    mapItems[i][j] = new Tile(generateTileType(realm, probabilityTotal));
                }
            }
        } else {
            for (int i = 0; i < width; i++) {
                for (int j = 0; j < height; j++) {
                    mapItems[i][j] = new Tile(useTileType);
                }
            }
        }
        worldMap.setMapItems(mapItems);
        realm.setWorldMap(worldMap);
        realm.setPathFinder(new AStarPathFinder(realm, 100));
        return new CommandResult(CommandResult.RESULT_OK, "");
    }
View Full Code Here

TOP

Related Classes of org.freerealm.map.WorldMap

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.