Commit 946ede3b authored by Florian Grabowski's avatar Florian Grabowski
Browse files

Updated Buildings to be able to be not square.

parent bad6607d
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="DataSourceManagerImpl" format="xml" multifile-model="true">
<data-source source="LOCAL" name="@localhost" uuid="7964bdec-e778-4768-bdf5-f18b5b7f77b6">
<driver-ref>mariadb</driver-ref>
<synchronize>true</synchronize>
<jdbc-driver>org.mariadb.jdbc.Driver</jdbc-driver>
<jdbc-url>jdbc:mariadb://localhost:3306</jdbc-url>
<working-dir>$ProjectFileDir$</working-dir>
</data-source>
</component>
</project>
\ No newline at end of file
......@@ -41,11 +41,11 @@ public class SetPreset implements CommandExecutor{
public void run() {
DataHolder.foundation.setLocation(location);
DataHolder.generateSimpleData(Integer.parseInt(args[0]));
fillPlane(server, location, DataHolder.foundation.getWidth(), DataHolder.foundation.getWidth(), DataHolder.foundation.getMaterial());
fillPlane(server, location, DataHolder.foundation.getWidth().x, DataHolder.foundation.getWidth().y, DataHolder.foundation.getMaterial());
for (Structure structure : DataHolder.foundation.getChildren()) {
Building building = (Building) structure;
sender.sendMessage("bau" + building.toString());
fillQube(server, building.getLocation(), building.getWidth(), building.getHeight(), building.getWidth(), building.getMaterial());//Not yet ready to print foundations
fillQube(server, building.getLocation(), building.getWidth().x, building.getHeight(), building.getWidth().y, building.getMaterial());//Not yet ready to print foundations
}
}
};
......
......@@ -31,7 +31,7 @@ public class generateLayout implements CommandExecutor {
DataHolder.foundation.setLocation(location);
DataHolder.foundation.organizeFoundation();
DataHolder.foundation.correctAllLocations(location);
setFoundation(server, DataHolder.foundation.getLocation().clone().add(0, DataHolder.foundation.getDepth(), 0), DataHolder.foundation.getWidth(), DataHolder.foundation.getWidth(), DataHolder.foundation.getMaterial());
setFoundation(server, DataHolder.foundation.getLocation().clone().add(0, DataHolder.foundation.getDepth(), 0), DataHolder.foundation.getWidth().x, DataHolder.foundation.getWidth().x, DataHolder.foundation.getMaterial());
setAllChildren(server, DataHolder.foundation);
}
};
......@@ -49,33 +49,33 @@ public class generateLayout implements CommandExecutor {
}
private void buildBuilding(Server server, Location startLocation, int x, int y, Material material) {
setWalls(server, startLocation.clone().add(0, 1, 0), x, y);
setWalls(server, startLocation.clone().add(0, 1, 0), x, y, material);
}
private void setWalls(Server server, Location startLocation, int x, int y) {
private void setWalls(Server server, Location startLocation, int x, int y,Material material) {
Location save = startLocation.clone();
Location temp = startLocation.clone();
for (int cx = 0; cx < x - 1; cx++) {// x+x Wall
for (int cy = 0; cy < y; cy++) {
server.getWorlds().get(0).getBlockAt(temp.clone().add(cx,cy,1)).setType(Material.RED_CONCRETE);
server.getWorlds().get(0).getBlockAt(temp.clone().add(cx,cy,1)).setType(material);
}
}
temp = save.clone();
for (int cz = 0; cz < x - 1; cz++) {// z+x Wall
for (int cy = 0; cy < y; cy++) {
server.getWorlds().get(0).getBlockAt(temp.clone().add(1, cy, cz)).setType(Material.RED_CONCRETE);
server.getWorlds().get(0).getBlockAt(temp.clone().add(1, cy, cz)).setType(material);
}
}
temp = save.clone().add(0, 0, x - 1);
for (int cx = 0; cx < x; cx++) {// x+x z+x Wall from x+x
for (int cy = 0; cy < y; cy++) {
server.getWorlds().get(0).getBlockAt(temp.clone().add(cx, cy, -1)).setType(Material.RED_CONCRETE);
server.getWorlds().get(0).getBlockAt(temp.clone().add(cx, cy, -1)).setType(material);
}
}
temp = save.clone().add(x - 1, 0, 0);
for (int cz = 0; cz < x - 1; cz++) {// x+x z+x Wall from x+z
for (int cy = 0; cy < y; cy++) {
server.getWorlds().get(0).getBlockAt(temp.clone().add(-1, cy, cz)).setType(Material.RED_CONCRETE);
server.getWorlds().get(0).getBlockAt(temp.clone().add(-1, cy, cz)).setType(material);
}
}
......@@ -127,11 +127,11 @@ public class generateLayout implements CommandExecutor {
private void setAllChildren(Server server, Foundation foundation) {
for (Structure s : foundation.getChildren()) {
if (s.getClass() == Foundation.class) {
setFoundation(server, s.getLocation().clone().add(0, s.getDepth(), 0), s.getWidth(), s.getWidth(), s.getMaterial());
if (s.getClass() == Foundation.class) {//TODO must be revisited to draw rectangular Foundations
setFoundation(server, s.getLocation().clone().add(0, s.getDepth(), 0), s.getWidth().x, s.getWidth().x, s.getMaterial());
setAllChildren(server, (Foundation) s);
} else {
buildBuilding(server, s.getLocation().clone().add(1, s.getDepth(), 1), s.getWidth() - 2, ((Building) s).getHeight(), s.getMaterial());
} else {//TODO must be revisited to draw rectangular Buildings
buildBuilding(server, s.getLocation().clone().add(1, s.getDepth(), 1), s.getWidth().x - 2, ((Building) s).getHeight(), s.getMaterial());
}
}
}
......
......@@ -24,46 +24,46 @@ public class DataHolder {
public static void ComplexData(){
Foundation foundation3 = new Foundation(3,Material.BLACK_CONCRETE);
ArrayList<Structure> buildins3 = new ArrayList<>();
ArrayList<Structure> buildings3 = new ArrayList<>();
for (int i = 0; i < 5; i++) {
buildins3.add(generateBuilding());
buildings3.add(generateBuilding());
}
foundation3.addChildren(buildins3);
foundation3.addChildren(buildings3);
ArrayList<Structure> buildins2_1 = new ArrayList<>();
ArrayList<Structure> buildings2_1 = new ArrayList<>();
Foundation foundation2_1 = new Foundation(2,Material.BROWN_CONCRETE);
for (int i = 0; i < 5; i++) {
buildins2_1.add(generateBuilding());
buildings2_1.add(generateBuilding());
}
buildins2_1.add(foundation3);
foundation2_1.addChildren(buildins2_1);
buildings2_1.add(foundation3);
foundation2_1.addChildren(buildings2_1);
ArrayList<Structure> buildins2_2 = new ArrayList<>();
ArrayList<Structure> buildings2_2 = new ArrayList<>();
Foundation foundation2_2 = new Foundation(2,Material.LIGHT_GRAY_CONCRETE);
for (int i = 0; i < 5; i++) {
buildins2_2.add(generateBuilding());
buildings2_2.add(generateBuilding());
}
foundation2_2.addChildren(buildins2_2);
foundation2_2.addChildren(buildings2_2);
ArrayList<Structure> buildins1 = new ArrayList<>();
ArrayList<Structure> buildings1 = new ArrayList<>();
Foundation foundation1 = new Foundation(1,Material.GRAY_CONCRETE);
for (int i = 0; i < 5; i++) {
buildins1.add(generateBuilding());
buildings1.add(generateBuilding());
}
buildins1.add(foundation2_1);
buildins1.add(foundation2_2);
foundation1.addChildren(buildins1);
buildings1.add(foundation2_1);
buildings1.add(foundation2_2);
foundation1.addChildren(buildings1);
ArrayList<Structure> buildins0 = new ArrayList<>();
ArrayList<Structure> buildings0 = new ArrayList<>();
for (int i = 0; i < 5; i++) {
buildins1.add(generateBuilding());
buildings1.add(generateBuilding());
}
buildins0.add(foundation1);
buildings0.add(foundation1);
foundation = new Foundation(0,Material.COBBLESTONE);
foundation.addChildren(buildins0);
foundation.addChildren(buildings0);
foundation.setDepth(0);
}
......
......@@ -27,7 +27,7 @@ public class Layout {
@Override
public int compare(Quadrat o1, Quadrat o2) {
return Integer.compare(o1.getWidth(), o2.getWidth());
return Integer.compare(o1.getWidth().x, o2.getWidth().x);
}
}
private static class CoordinateXComparator implements Comparator<Quadrat>{
......@@ -48,8 +48,8 @@ public class Layout {
for (Structure s:structures) {
if(first){
first = false;
this.size = s.getWidth();
layout.add(new Quadrat(new Point(0,0),s.getWidth()));
this.size = s.getWidth().x;
layout.add(new Quadrat(new Point(0,0),s.getWidth().x));
layout.addAll(layout.get(0).setBelegt(s));
}else{
layout.sort(new CoordinateYComparator());
......@@ -57,7 +57,7 @@ public class Layout {
layout.sort(new WidthComparator());
boolean noneFoundFlag = true;
for (int i = 0;i < layout.size();i++) {
if((s.getWidth() <= layout.get(i).getWidth())&&(!layout.get(i).getBelegt())&&(noneFoundFlag)){
if((s.getWidth().x <= layout.get(i).getWidth().x)&&(!layout.get(i).getBelegt())&&(noneFoundFlag)){
noneFoundFlag = false;
layout.addAll(layout.get(i).setBelegt(s));
}
......@@ -70,16 +70,16 @@ public class Layout {
}
private void appendQuad(Structure structure){
Quadrat q = new Quadrat(new Point(this.size,0),structure.getWidth());
Quadrat q = new Quadrat(new Point(this.size,0),structure.getWidth().x);
q.setBelegt(structure);
this.size += structure.getWidth();
this.size += structure.getWidth().x;
layout.add(q);
layout.add(new Quadrat(new Point(q.bottomLeftCorner.y,q.bottomLeftCorner.x),new Point(q.topRightCorner.y,q.topRightCorner.x))); // gespiegeltes Quadrat
layout.add(new Quadrat(new Point(q.bottomLeftCorner.x,q.bottomLeftCorner.x),structure.getWidth())); // Oberes rechtes Quadrat
if((this.size-(2*structure.getWidth())) > 0){ //falls Abstand zwischen den Quadraten ist.
Rectangle rTop = new Rectangle(structure.getWidth(),(this.size-2*structure.getWidth()),new Point(q .topRightCorner.y,q.bottomLeftCorner.x));
layout.add(new Quadrat(new Point(q.bottomLeftCorner.x,q.bottomLeftCorner.x),structure.getWidth().x)); // Oberes rechtes Quadrat
if((this.size-(2*structure.getWidth().x)) > 0){ //falls Abstand zwischen den Quadraten ist.
Rectangle rTop = new Rectangle(structure.getWidth().x,(this.size-2*structure.getWidth().x),new Point(q .topRightCorner.y,q.bottomLeftCorner.x));
layout.addAll(rTop.splittToQuads(rTop));
Rectangle rRight = new Rectangle((this.size-2*structure.getWidth()),structure.getWidth(),new Point(q.bottomLeftCorner.x,q.topRightCorner.y));
Rectangle rRight = new Rectangle((this.size-2*structure.getWidth().x),structure.getWidth().x,new Point(q.bottomLeftCorner.x,q.topRightCorner.y));
layout.addAll(rRight.splittToQuads(rRight));
}
}
......
......@@ -32,7 +32,7 @@ public class Quadrat extends Shape{
this.bottomLeftCorner = bottomLeftCorner;
this.topRightCorner = new Point(bottomLeftCorner.x+xEdgeLength,bottomLeftCorner.y+xEdgeLength);
this.belegt = false;
if(xEdgeLength < 3){
if(xEdgeLength < 3 || topRightCorner.x-bottomLeftCorner.x <3){
throw new IllegalArgumentException("keine Quadrate < 3 erlaubt " + xEdgeLength);
}
}
......@@ -41,15 +41,15 @@ public class Quadrat extends Shape{
this.belegt = true;
this.structure = structure;
ArrayList<Quadrat> result = new ArrayList<>();
if(this.xEdgeLength > structure.getWidth()+3){//if you can splitt rest into more quads
int scrapLength = this.xEdgeLength-structure.getWidth();
result.add(new Quadrat(new Point(this.bottomLeftCorner.x+structure.getWidth(),this.bottomLeftCorner.y),scrapLength));
result.add(new Quadrat(new Point(this.bottomLeftCorner.x,this.bottomLeftCorner.y+structure.getWidth()),scrapLength));
result.add(new Quadrat(new Point(this.bottomLeftCorner.x+structure.getWidth(),this.bottomLeftCorner.y+structure.getWidth()),scrapLength));
if(this.xEdgeLength > structure.getWidth().x+3){//if you can splitt rest into more quads
int scrapLength = this.xEdgeLength-structure.getWidth().x;
result.add(new Quadrat(new Point(this.bottomLeftCorner.x+structure.getWidth().x,this.bottomLeftCorner.y),scrapLength));
result.add(new Quadrat(new Point(this.bottomLeftCorner.x,this.bottomLeftCorner.y+structure.getWidth().x),scrapLength));
result.add(new Quadrat(new Point(this.bottomLeftCorner.x+structure.getWidth().x,this.bottomLeftCorner.y+structure.getWidth().x),scrapLength));
if(this.xEdgeLength%scrapLength != 0){
Rectangle temp = new Rectangle(scrapLength,this.xEdgeLength-2*scrapLength,new Point(this.bottomLeftCorner.x+scrapLength,this.bottomLeftCorner.y+structure.getWidth()));
Rectangle temp = new Rectangle(scrapLength,this.xEdgeLength-2*scrapLength,new Point(this.bottomLeftCorner.x+scrapLength,this.bottomLeftCorner.y+structure.getWidth().x));
result.addAll(temp.splittToQuads(temp));
temp = new Rectangle(this.xEdgeLength-2*scrapLength,scrapLength,new Point(this.bottomLeftCorner.x+structure.getWidth(),this.bottomLeftCorner.y+scrapLength));
temp = new Rectangle(this.xEdgeLength-2*scrapLength,scrapLength,new Point(this.bottomLeftCorner.x+structure.getWidth().x,this.bottomLeftCorner.y+scrapLength));
result.addAll(temp.splittToQuads(temp));
}
}
......@@ -60,8 +60,8 @@ public class Quadrat extends Shape{
return belegt;
}
public int getWidth(){
return this.xEdgeLength;
public Point getWidth(){
return new Point(topRightCorner.x-bottomLeftCorner.x,topRightCorner.y-bottomLeftCorner.y);
}
public void applyCoordinates(){
......
......@@ -3,17 +3,28 @@ package de._82grfl1bif.KPI_Visualizer.structures;
import org.bukkit.Material;
import javax.persistence.Column;
import java.awt.*;
public class Building extends Structure{
@Column(name = "height")
private final int height;
public Building(int width, int height, Material material){ //Buildings are Square -> no depth
this.width.x = width;
this.width.y = width;
this.height = height;
this.material = material;
if(this.width.x < 3){
throw new IllegalArgumentException("keine Gebäude kleiner 3 wegen 2 Gehweg");
}
}
public Building(Point width, int height, Material material){ //Buildings are Square -> no depth
this.width = width;
this.height = height;
this.material = material;
if(this.width < 3){
throw new IllegalArgumentException("keine Gebäude kleiner 3 wegen 2 gehweg");
if(this.width.x < 3 || this.width.y < 3){
throw new IllegalArgumentException("keine Gebäude kleiner 3 wegen 2 Gehweg");
}
}
......
......@@ -17,7 +17,7 @@ public class Foundation extends Structure{
private Layout layout;
public Foundation(int depth, Material material){ //Foundations are uniform Height
this.width = 0;
this.width.x = 0;
this.depth = depth;
this.material = material;
}
......@@ -38,13 +38,12 @@ public class Foundation extends Structure{
}
public void optimizeLayout(){
//TODO: find cool Algorithms to do this scientifically and optimal.
int cWith = 0;
for (Structure s : children) {
s.setLocation(location.clone().add(new Vector(1,depth,((cWith)+1))));
cWith += (s.getWidth() + 2);
cWith += (s.getWidth().x + 2);
}
this.width = cWith;
this.width.x = cWith;
}
private static class DepthComparator implements Comparator<Foundation>{
......@@ -58,7 +57,7 @@ public class Foundation extends Structure{
@Override
public int compare(Structure o1, Structure o2) {
return Integer.compare(o1.getWidth(), o2.getWidth());
return Integer.compare(o1.getWidth().x, o2.getWidth().x);
}
}
......@@ -79,7 +78,7 @@ public class Foundation extends Structure{
Collections.reverse(this.children); //Widest Building or Foundation first
this.layout = new Layout(this.children);
this.layout.createLayout();
this.width = layout.getSize();
this.width.x = layout.getSize();
}
}
......
......@@ -6,12 +6,13 @@ import org.bukkit.util.Vector;
import javax.persistence.Column;
import javax.persistence.Entity;
import java.awt.*;
@Entity
public class Structure{
@Column(name ="width")
protected int width;
protected Point width = new Point(0,0);
@Column(name ="material")
protected Material material;
protected Location location;
......@@ -33,7 +34,7 @@ public class Structure{
this.location.add(vector);
}
public int getWidth() {
public Point getWidth() {
return width;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment