// Path: src/main/java/org/terasology/cities/common/Edges.java
// public final class Edges {
// 
//     private Edges() {
//         // no instances
//     }
// 
//     public static Vector2i getCorner(BlockAreac rc, Orientation o) {
// 
//         int dx = o.direction().x() + 1; //  [0..2]
//         int dy = o.direction().y() + 1; //  [0..2]
// 
//         int x = rc.minX() + (rc.getSizeX() - 1) * dx / 2;
//         int y = rc.minY() + (rc.getSizeY() - 1) * dy / 2;
// 
//         return new Vector2i(x, y);
//     }
// 
//     public static int getDistanceToBorder(BlockAreac rc, int x, int z) {
//         int rx = x - rc.minX();
//         int rz = z - rc.minY();
// 
//         // distance to border along both axes
//         int borderDistX = Math.min(rx, rc.getSizeX() - 1 - rx);
//         int borderDistZ = Math.min(rz, rc.getSizeY() - 1 - rz);
// 
//         int dist = Math.min(borderDistX, borderDistZ);
//         return dist;
//     }
// 
//     public static float getDistanceToCorner(BlockAreac rc, int x, int y) {
//         return (float) Math.sqrt(getDistanceToCorner(rc, x, y));
//     }
// 
//     public static int getDistanceToCornerSq(BlockAreac rc, int x, int y) {
//         int dx = Math.min(x - rc.minX(), rc.maxX() - x);
//         int dy = Math.min(y - rc.minY(), rc.maxY() - y);
//         return dx * dx + dy * dy;
//     }
// 
//     public static Line2f getEdge(BlockAreac rc, Orientation o) {
// 
//         Vector2i p0 = getCorner(rc, o.getRotated(-45));
//         Vector2i p1 = getCorner(rc, o.getRotated(45));
//         return new Line2f(p0.x(), p0.y(), p1.x(), p1.y());
//     }
// }
// 
// Path: src/main/java/org/terasology/cities/door/SimpleDoor.java
// public class SimpleDoor implements Door {
// 
//     private final Orientation orientation;
//     private final int baseHeight;
//     private final int topHeight;
//     private final Vector2i pos = new Vector2i();
// 
//     /**
//      * @param orientation the orientation
//      * @param pos the position in the XZ plane
//      * @param baseHeight the height at the bottom
//      * @param topHeight the height at the top
//      */
//     public SimpleDoor(Orientation orientation, Vector2ic pos, int baseHeight, int topHeight) {
//         this.orientation = orientation;
//         this.pos.set(pos);
//         this.baseHeight = baseHeight;
//         this.topHeight = topHeight;
//     }
// 
//     /**
//      * @return the orientation
//      */
//     public Orientation getOrientation() {
//         return this.orientation;
//     }
// 
//     /**
//      * @return the door position
//      */
//     public Vector2ic getPos() {
//         return this.pos;
//     }
// 
//     /**
//      * @return the baseHeight
//      */
//     public int getBaseHeight() {
//         return this.baseHeight;
//     }
// 
//     /**
//      * @return the topHeight
//      */
//     public int getTopHeight() {
//         return this.topHeight;
//     }
// }
// 
// Path: src/main/java/org/terasology/cities/model/roof/BattlementRoof.java
// public class BattlementRoof extends FlatRoof {
// 
//     /**
//      * @param baseRect the building rectangle (must be fully inside <code>withEaves</code>).
//      * @param withEaves the roof area including eaves (=overhang)
//      * @param baseHeight the base height of the roof
//      * @param merlonHeight the height of the border
//      */
//     public BattlementRoof(BlockAreac baseRect, BlockAreac withEaves, int baseHeight, int merlonHeight) {
//         super(baseRect, withEaves, baseHeight, merlonHeight);
//     }
// 
//     /**
//      * @param lx x in local (roof area) coordinates
//      * @param lz z in local (roof area) coordinates
//      * @return the borderHeight
//      */
//     @Override
//     public int getBorderHeight(int lx, int lz) {
//         if (lx % 2 == 1) {
//             return 0;
//         }
// 
//         if (lz % 2 == 1) {
//             return 0;
//         }
// 
//         return super.getBorderHeight(lx, lz);
//     }
// }
// 
// Path: src/main/java/org/terasology/cities/model/roof/Roof.java
// public interface Roof {
// 
// 
// }


import org.joml.Vector2i;
import org.terasology.cities.common.Edges;
import org.terasology.cities.door.SimpleDoor;
import org.terasology.cities.model.roof.BattlementRoof;
import org.terasology.cities.model.roof.Roof;
import org.terasology.commonworld.Orientation;
import org.terasology.engine.world.block.BlockArea;
import org.terasology.engine.world.block.BlockAreac;
/*
 * Copyright 2015 MovingBlocks
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.terasology.cities.bldg;


/**
 * A simple tower
 */
public class SimpleTower extends DefaultBuilding implements Tower {

    private BlockArea shape = new BlockArea(BlockArea.INVALID);
    private RectBuildingPart room;

    /**
     * @param orient the orientation of the building
     * @param layout the building layout
     * @param baseHeight the height of the floor level
     * @param wallHeight the building height above the floor level
     */
    public SimpleTower(Orientation orient, BlockAreac layout, int baseHeight, int wallHeight) {
        super(orient);
        this.shape.set(layout);

        BlockArea roofArea = layout.expand(1, 1,new BlockArea(BlockArea.INVALID));
// Path: src/main/java/org/terasology/cities/common/Edges.java
// public final class Edges {
// 
//     private Edges() {
//         // no instances
//     }
// 
//     public static Vector2i getCorner(BlockAreac rc, Orientation o) {
// 
//         int dx = o.direction().x() + 1; //  [0..2]
//         int dy = o.direction().y() + 1; //  [0..2]
// 
//         int x = rc.minX() + (rc.getSizeX() - 1) * dx / 2;
//         int y = rc.minY() + (rc.getSizeY() - 1) * dy / 2;
// 
//         return new Vector2i(x, y);
//     }
// 
//     public static int getDistanceToBorder(BlockAreac rc, int x, int z) {
//         int rx = x - rc.minX();
//         int rz = z - rc.minY();
// 
//         // distance to border along both axes
//         int borderDistX = Math.min(rx, rc.getSizeX() - 1 - rx);
//         int borderDistZ = Math.min(rz, rc.getSizeY() - 1 - rz);
// 
//         int dist = Math.min(borderDistX, borderDistZ);
//         return dist;
//     }
// 
//     public static float getDistanceToCorner(BlockAreac rc, int x, int y) {
//         return (float) Math.sqrt(getDistanceToCorner(rc, x, y));
//     }
// 
//     public static int getDistanceToCornerSq(BlockAreac rc, int x, int y) {
//         int dx = Math.min(x - rc.minX(), rc.maxX() - x);
//         int dy = Math.min(y - rc.minY(), rc.maxY() - y);
//         return dx * dx + dy * dy;
//     }
// 
//     public static Line2f getEdge(BlockAreac rc, Orientation o) {
// 
//         Vector2i p0 = getCorner(rc, o.getRotated(-45));
//         Vector2i p1 = getCorner(rc, o.getRotated(45));
//         return new Line2f(p0.x(), p0.y(), p1.x(), p1.y());
//     }
// }
// 
// Path: src/main/java/org/terasology/cities/door/SimpleDoor.java
// public class SimpleDoor implements Door {
// 
//     private final Orientation orientation;
//     private final int baseHeight;
//     private final int topHeight;
//     private final Vector2i pos = new Vector2i();
// 
//     /**
//      * @param orientation the orientation
//      * @param pos the position in the XZ plane
//      * @param baseHeight the height at the bottom
//      * @param topHeight the height at the top
//      */
//     public SimpleDoor(Orientation orientation, Vector2ic pos, int baseHeight, int topHeight) {
//         this.orientation = orientation;
//         this.pos.set(pos);
//         this.baseHeight = baseHeight;
//         this.topHeight = topHeight;
//     }
// 
//     /**
//      * @return the orientation
//      */
//     public Orientation getOrientation() {
//         return this.orientation;
//     }
// 
//     /**
//      * @return the door position
//      */
//     public Vector2ic getPos() {
//         return this.pos;
//     }
// 
//     /**
//      * @return the baseHeight
//      */
//     public int getBaseHeight() {
//         return this.baseHeight;
//     }
// 
//     /**
//      * @return the topHeight
//      */
//     public int getTopHeight() {
//         return this.topHeight;
//     }
// }
// 
// Path: src/main/java/org/terasology/cities/model/roof/BattlementRoof.java
// public class BattlementRoof extends FlatRoof {
// 
//     /**
//      * @param baseRect the building rectangle (must be fully inside <code>withEaves</code>).
//      * @param withEaves the roof area including eaves (=overhang)
//      * @param baseHeight the base height of the roof
//      * @param merlonHeight the height of the border
//      */
//     public BattlementRoof(BlockAreac baseRect, BlockAreac withEaves, int baseHeight, int merlonHeight) {
//         super(baseRect, withEaves, baseHeight, merlonHeight);
//     }
// 
//     /**
//      * @param lx x in local (roof area) coordinates
//      * @param lz z in local (roof area) coordinates
//      * @return the borderHeight
//      */
//     @Override
//     public int getBorderHeight(int lx, int lz) {
//         if (lx % 2 == 1) {
//             return 0;
//         }
// 
//         if (lz % 2 == 1) {
//             return 0;
//         }
// 
//         return super.getBorderHeight(lx, lz);
//     }
// }
// 
// Path: src/main/java/org/terasology/cities/model/roof/Roof.java
// public interface Roof {
// 
// 
// }


// Path: src/main/java/org/terasology/cities/bldg/SimpleTower.java
import org.joml.Vector2i;
import org.terasology.cities.common.Edges;
import org.terasology.cities.door.SimpleDoor;
import org.terasology.cities.model.roof.BattlementRoof;
import org.terasology.cities.model.roof.Roof;
import org.terasology.commonworld.Orientation;
import org.terasology.engine.world.block.BlockArea;
import org.terasology.engine.world.block.BlockAreac;

/*
 * Copyright 2015 MovingBlocks
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.terasology.cities.bldg;


/**
 * A simple tower
 */
public class SimpleTower extends DefaultBuilding implements Tower {

    private BlockArea shape = new BlockArea(BlockArea.INVALID);
    private RectBuildingPart room;

    /**
     * @param orient the orientation of the building
     * @param layout the building layout
     * @param baseHeight the height of the floor level
     * @param wallHeight the building height above the floor level
     */
    public SimpleTower(Orientation orient, BlockAreac layout, int baseHeight, int wallHeight) {
        super(orient);
        this.shape.set(layout);

        BlockArea roofArea = layout.expand(1, 1,new BlockArea(BlockArea.INVALID));
        Roof roof = new BattlementRoof(layout, roofArea, baseHeight + wallHeight, 1);