Package org.freerealm.tile

Examples of org.freerealm.tile.Tile


        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);
View Full Code Here


        Tile[][] mapItems = new Tile[widthValue][heightValue];
        int abscissa = 0;
        int ordinate = 0;
        for (Node tileNode = tilesNode.getFirstChild(); tileNode != null; tileNode = tileNode.getNextSibling()) {
            if (tileNode.getNodeType() == Node.ELEMENT_NODE) {
                Tile tile = new TileXMLConverter().initializeFromNode(realm, tileNode);
                mapItems[abscissa][ordinate] = tile;
                ordinate = ordinate + 1;
                if (ordinate >= heightValue) {
                    ordinate = 0;
                    abscissa = abscissa + 1;
View Full Code Here

        xml.append("</Tile>");
        return xml.toString();
    }

    public Tile initializeFromNode(Realm realm, Node node) {
        Tile tile = new Tile();
        for (Node subNode = node.getFirstChild(); subNode != null; subNode = subNode.getNextSibling()) {
            if (subNode.getNodeType() == Node.ELEMENT_NODE) {
                if (subNode.getNodeName().equals("type")) {
                    int tileTypeId = Integer.parseInt(subNode.getFirstChild().getNodeValue());
                    TileType tileType = realm.getTileTypeManager().getTileType(tileTypeId);
                    tile.setType(tileType);
                } else if (subNode.getNodeName().equals("improvements")) {
                    tile.clearImprovements();
                    for (Node improvementNode = subNode.getFirstChild(); improvementNode != null; improvementNode = improvementNode.getNextSibling()) {
                        if (improvementNode.getNodeType() == Node.ELEMENT_NODE) {
                            int improvementId = Integer.parseInt(improvementNode.getFirstChild().getNodeValue());
                            TileImprovementType improvement = realm.getTileImprovementTypeManager().getImprovement(improvementId);
                            tile.addImprovement(improvement);
                        }
                    }
                } else if (subNode.getNodeName().equals("vegetation")) {
                    int vegetationId = Integer.parseInt(subNode.getFirstChild().getNodeValue());
                    tile.setVegetation(realm.getVegetationManager().getVegetation(vegetationId));
                } else if (subNode.getNodeName().equals("bonusResource")) {
                    int bonusResourceId = Integer.parseInt(subNode.getFirstChild().getNodeValue());
                    tile.setBonusResource(realm.getBonusResourceManager().getBonusResource(bonusResourceId));
                }
            }
        }
        return tile;
    }
View Full Code Here

    @Override
    public void execute(Realm realm) {
        BuildTileImprovement buildTileImprovement = (BuildTileImprovement) getUnit().getType().getAbility("BuildTileImprovement");
        if (buildTileImprovement != null) {
            Tile tile = realm.getTile(getUnit().getCoordinate());
            if (buildTileImprovement.canBuildTileImprovement(tileImprovementType, tile)) {
                int productionCost = tileImprovementType.getProductionCost();
                int productionPoints = buildTileImprovement.getProductionPoints();
                int turnsNeeded = (productionCost / productionPoints);
                int turnsSpent = realm.getNumberOfTurns() - getTurnGiven();
View Full Code Here

    }

    private void manageDiplomacy(Realm realm) {
        Vector<Coordinate> circleCoordinates = realm.normalizeCoordinates(Utility.getCircleCoordinates(coordinate, realm, 1));
        for (Coordinate checkCoordinate : circleCoordinates) {
            Tile checkTile = realm.getTile(checkCoordinate);
            if (checkTile.getSettlement() != null) {
                Player movingUnitsPlayer = unit.getPlayer();
                Player neighborTileCityPlayer = checkTile.getSettlement().getPlayer();
                setDiplomaticStatusToPeaceIfNeeded(realm, movingUnitsPlayer, neighborTileCityPlayer);
            }
            Iterator<Unit> unitIterator = checkTile.getUnitsIterator();
            while (unitIterator.hasNext()) {
                Unit checkUnit = unitIterator.next();
                Player movingUnitsPlayer = unit.getPlayer();
                Player neighborTileUnitPlayer = checkUnit.getPlayer();
                setDiplomaticStatusToPeaceIfNeeded(realm, movingUnitsPlayer, neighborTileUnitPlayer);
View Full Code Here

     */
    public CommandResult execute(Realm realm) {
        Iterator<Settlement> settlementIterator = player.getSettlementsIterator();
        while (settlementIterator.hasNext()) {
            Settlement settlement = settlementIterator.next();
            Tile tile = settlement.getTile();
            tile.setSettlement(null);
            //player.removeSettlement(settlement);
        }
        Vector<Unit> unitsToRemove = new Vector<Unit>();
        Iterator<Unit> unitIterator = player.getUnitsIterator();
        while (unitIterator.hasNext()) {
View Full Code Here

            return new CommandResult(CommandResult.RESULT_ERROR, "Unit can not move");
        }
        if (tile.getNumberOfUnits() > 0) {
            Unit defendingUnit = tile.getUnits().get(tile.getUnits().firstKey());
            if (!unit.getPlayer().equals(defendingUnit.getPlayer())) {
                Tile defenceTile = realm.getTile(defendingUnit.getCoordinate());
                int defencePercentage = defenceTile.getType().getDefencePercentage();
                if ((tile.getSettlement() != null) && tile.getSettlement().getDefenceModifier() > 0) {
                    defencePercentage = (defencePercentage * tile.getSettlement().getDefenceModifier()) / 100;
                }
                Executor.getInstance().execute(new AttackUnitCommand(unit, defendingUnit));
            }
View Full Code Here

            return new CommandResult(CommandResult.RESULT_ERROR, errorMessage);
        }
        int i = 0;
        while ((unit.getMovementPoints() > 0) && (i < path.getLength())) {
            Coordinate pathCoordinate = path.getStep(i);
            Tile tile = realm.getTile(pathCoordinate);
            ICommand command = null;
            if (tile.getNumberOfUnits() > 0) {
                Unit tileUnit = tile.getUnits().get(tile.getUnits().firstKey());
                if (!unit.getPlayer().equals(tileUnit.getPlayer())) {
                    command = new AttackTileCommand(unit, tile);
                } else {
                    command = new MoveUnitCommand(unit, pathCoordinate);
                }
            } else {
                if (tile.getSettlement() != null) {
                    Settlement settlement = tile.getSettlement();
                    if (!unit.getPlayer().equals(settlement.getPlayer())) {
                        command = new CaptureSettlementCommand(unit, settlement);
                    } else {
                        command = new MoveUnitCommand(unit, pathCoordinate);
                    }
View Full Code Here

        boolean tileHasAllowMovement = false;
        Move moveAbility = (Move) unit.getType().getAbility("Move");
        if (moveAbility == null) {
            return new CommandResult(CommandResult.RESULT_ERROR, "");
        }
        Tile toTile = realm.getTile(coordinate);
        Iterator<TileImprovementType> iterator = toTile.getImprovementsIterator();
        while (iterator.hasNext()) {
            TileImprovementType tileImprovement = iterator.next();
            if (tileImprovement.hasPropertyNamed("AllowMovement")) {
                tileHasAllowMovement = true;
                break;
            }
        }
        if (!moveAbility.hasTileType(toTile.getType()) && !tileHasAllowMovement) {
            return new CommandResult(CommandResult.RESULT_ERROR, "");
        }
        Vector<Coordinate> adjacentTiles = Utility.getNeighborCoordinates(realm, unit.getCoordinate());
        if (!adjacentTiles.contains(coordinate)) {
            return new CommandResult(CommandResult.RESULT_ERROR, "");
        }
        if (unit.getMovementPoints() <= 0) {
            return new CommandResult(CommandResult.RESULT_ERROR, "");
        }
        if (unit.getMovementPoints() > 0 && unit.getMovementPoints() < 1 && toTile.getMovementCost() >= 1) {
            return new CommandResult(CommandResult.RESULT_ERROR, "");
        }
        if (toTile.getNumberOfUnits() > 0) {
            Unit defendingUnit = toTile.getUnits().get(toTile.getUnits().firstKey());
            if (!unit.getPlayer().equals(defendingUnit.getPlayer())) {
                return new CommandResult(CommandResult.RESULT_ERROR, "Tile contains a unit that does not belong to player. Use AttackTileCommand.");
            }
        }

        if ((toTile.getSettlement() != null) && (!unit.getPlayer().equals((toTile.getSettlement().getPlayer())))) {
            return new CommandResult(CommandResult.RESULT_ERROR, "Tile contains a settlement that does not belong to player. Use InvadeCityCommand.");
        }

        Coordinate oldCoordinate = unit.getCoordinate();
        realm.getWorldMap().removeUnit(unit);
        unit.setCoordinate(coordinate);
        realm.getWorldMap().addUnit(unit);
        float movementCost = toTile.getMovementCost();
        float newMovementPoints = (unit.getMovementPoints() >= movementCost ? unit.getMovementPoints() - movementCost : 0);
        unit.setMovementPoints(newMovementPoints);
        manageExploration(realm);
        manageDiplomacy(realm);
        CommandResult commandResult = new CommandResult(CommandResult.RESULT_OK, "", CommandResult.UNIT_MOVEMENT_UPDATE);
View Full Code Here

                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);
View Full Code Here

TOP

Related Classes of org.freerealm.tile.Tile

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.