Example #1
1
  void setTileContent(TileEntity entity, int level, boolean undo) {
    if (!isFlat()) {
      return;
    }

    if (entity instanceof Roof) {
      for (TileEntity e : entities.values()) {
        if (e instanceof Roof) {
          return;
        }
      }
    }

    final EntityData entityData = new EntityData(level, EntityType.FLOORROOF);
    if (entity != entities.get(entityData)) {
      Tile oldTile = new Tile(this);

      if (entity != null) {
        entities.put(entityData, entity);
      } else {
        entities.remove(entityData);
      }

      if (undo) {
        map.addUndo(this, oldTile);
      }
    }
  }
Example #2
1
 void setGameObject(GameObjectData data, ObjectLocation location, int floor, boolean undo) {
   Tile oldTile = new Tile(this);
   if (data != null) {
     entities.put(new ObjectEntityData(floor, location), new GameObject(data));
   } else {
     entities.remove(new ObjectEntityData(floor, location));
   }
   if (undo) {
     map.addUndo(this, oldTile);
   }
 }
Example #3
1
  void setVerticalBorder(BorderData border, boolean undo) {
    final EntityData entityData = new EntityData(0, EntityType.VBORDER);
    if (border != entities.get(entityData)) {
      Tile oldTile = new Tile(this);

      if (border != null) {
        entities.put(entityData, border);
      } else {
        entities.remove(entityData);
      }

      if (undo) {
        map.addUndo(this, oldTile);
      }
    }
  }
Example #4
1
  void setVerticalWall(WallData wall, int level, boolean undo) {
    if (wall != null && wall.houseWall) {
      if (!(isFlat() || map.getTile(this, -1, 0).isFlat())) {
        return;
      }
    }

    final EntityData entityData;
    if (wall != null && wall.houseWall) {
      entityData = new EntityData(level, EntityType.VWALL);
    } else if (wall != null) {
      entityData = new EntityData(level, EntityType.VFENCE);
    } else {
      entityData = null;
    }

    final EntityData wallEntity = new EntityData(level, EntityType.VWALL);
    final EntityData fenceEntity = new EntityData(level, EntityType.VFENCE);
    final Wall currentWall = (Wall) entities.get(wallEntity);
    final Wall currentFence = (Wall) entities.get(fenceEntity);

    boolean reversed;
    if (wall != null && wall.houseWall) {
      if (Globals.autoReverseWall) {
        reversed =
            getTileContent(level) == null && map.getTile(this, -1, 0).getTileContent(level) != null;
        if (reversed == false) {
          reversed = Globals.reverseWall;
        }
      } else {
        reversed = Globals.reverseWall;
      }
    } else {
      reversed = false;
    }

    if (!(new Wall(wall, reversed).equals(entities.get(entityData)))) {
      Tile oldTile = new Tile(this);
      if (wall != null) {
        entities.put(entityData, new Wall(wall, reversed));
        if (wall.houseWall
            && !(wall.arch && currentFence != null && currentFence.data.archBuildable)) {
          entities.remove(fenceEntity);
        } else if (!wall.houseWall
            && !(wall.archBuildable && currentWall != null && currentWall.data.arch)) {
          entities.remove(wallEntity);
        }
      } else {
        entities.remove(wallEntity);
        entities.remove(fenceEntity);
      }

      if (undo) {
        map.addUndo(this, oldTile);
      }
    }
  }
Example #5
0
 public void render2d(GL2 g) {
   for (Entry<EntityData, TileEntity> e : entities.entrySet()) {
     EntityData key = e.getKey();
     TileEntity entity = e.getValue();
     g.glPushMatrix();
     switch (key.getType()) {
       case VBORDER:
         g.glRotatef(90, 0, 0, 1);
         BorderData vBorder = (BorderData) entity;
         if (Globals.upCamera) {
           vBorder.render(g, this);
         }
         g.glColor3f(1, 1, 1);
         break;
       case HBORDER:
         BorderData hBorder = (BorderData) entity;
         if (Globals.upCamera) {
           hBorder.render(g, this);
         }
         g.glColor3f(1, 1, 1);
         break;
     }
     g.glPopMatrix();
     g.glColor3f(1, 1, 1);
   }
 }
Example #6
0
 public Materials getMaterials(boolean withRight, boolean withTop) {
   Materials materials = new Materials();
   entities
       .values()
       .stream()
       .forEach(
           (entity) -> {
             materials.put(entity.getMaterials());
           });
   if (withRight) {
     for (int i = 0; i < Constants.FLOORS_LIMIT; i++) {
       Wall wall = map.getTile(this, 1, 0).getVerticalWall(i);
       Wall fence = map.getTile(this, 1, 0).getVerticalFence(i);
       if (wall != null) {
         materials.put(wall.getMaterials());
       }
       if (fence != null) {
         materials.put(fence.getMaterials());
       }
     }
   }
   if (withTop) {
     for (int i = 0; i < Constants.FLOORS_LIMIT; i++) {
       Wall wall = map.getTile(this, 0, 1).getHorizontalWall(i);
       Wall fence = map.getTile(this, 0, 1).getHorizontalFence(i);
       if (wall != null) {
         materials.put(wall.getMaterials());
       }
       if (fence != null) {
         materials.put(fence.getMaterials());
       }
     }
   }
   return materials;
 }
Example #7
0
  public Tile(Map map, Tile tile, int x, int y) {
    this.map = map;
    this.x = x;
    this.y = y;

    this.height = tile.height;
    this.ground = tile.ground;
    this.cave = tile.cave;
    this.label = tile.label;
    HashMap<EntityData, TileEntity> entities = new HashMap<>();
    for (Entry<EntityData, TileEntity> entrySet : tile.entities.entrySet()) {
      EntityData key = entrySet.getKey();
      TileEntity value = entrySet.getValue();
      entities.put(key, value.deepCopy());
    }
    this.entities = new HashMap(tile.entities);
  }
Example #8
0
  public Tile(Map map, int x, int y, Element tile) {
    this.map = map;
    this.x = x;
    this.y = y;
    height = (int) Float.parseFloat(tile.getAttribute("height"));
    if (!tile.getAttribute("caveHeight").equals("")) {
      caveHeight = (int) Float.parseFloat(tile.getAttribute("caveHeight"));
    }
    if (!tile.getAttribute("caveSize").equals("")) {
      caveSize = (int) Float.parseFloat(tile.getAttribute("caveSize"));
    }
    ground = new Ground((Element) tile.getElementsByTagName("ground").item(0));
    if (tile.getElementsByTagName("cave").getLength() != 0) {
      cave = CaveData.get((Element) tile.getElementsByTagName("cave").item(0));
    }

    NodeList labels = tile.getElementsByTagName("label");
    if (labels.getLength() != 0) {
      label = new Label((Element) labels.item(0));
    }
    NodeList caveLabels = tile.getElementsByTagName("caveLabel");
    if (caveLabels.getLength() != 0) {
      caveLabel = new Label((Element) caveLabels.item(0));
    }

    entities = new HashMap<>();

    NodeList list = tile.getElementsByTagName("level");
    for (int i = 0; i < list.getLength(); i++) {
      Element level = (Element) list.item(i);
      int floor = Integer.parseInt(level.getAttribute("value"));
      NodeList childNodes = level.getElementsByTagName("*");
      for (int i2 = 0; i2 < childNodes.getLength(); i2++) {
        Element entity = (Element) childNodes.item(i2);
        switch (entity.getNodeName().toLowerCase()) {
          case "floor":
            entities.put(new EntityData(floor, EntityType.FLOORROOF), new Floor(entity));
            break;
          case "hwall":
            Wall hwall = new Wall(entity);
            if (hwall.data.houseWall) {
              entities.put(new EntityData(floor, EntityType.HWALL), hwall);
            } else {
              entities.put(new EntityData(floor, EntityType.HFENCE), hwall);
            }
            break;
          case "vwall":
            Wall vwall = new Wall(entity);
            if (vwall.data.houseWall) {
              entities.put(new EntityData(floor, EntityType.VWALL), vwall);
            } else {
              entities.put(new EntityData(floor, EntityType.VFENCE), vwall);
            }
            break;
          case "hborder":
            entities.put(new EntityData(0, EntityType.HBORDER), BorderData.get(entity));
            break;
          case "vborder":
            entities.put(new EntityData(0, EntityType.VBORDER), BorderData.get(entity));
            break;
          case "roof":
            entities.put(new EntityData(floor, EntityType.FLOORROOF), new Roof(entity));
            break;
          case "object":
            ObjectLocation loc = ObjectLocation.parse(entity.getAttribute("position"));
            entities.put(new ObjectEntityData(floor, loc), new GameObject(entity));
            break;
          case "cave":
            cave = CaveData.get(entity);
            break;
        }
      }
    }
  }
Example #9
0
 public GameObject getGameObject(int level, ObjectLocation location) {
   // assumption - ObjectEntityData key always have GameObject value.
   return (GameObject) entities.get(new ObjectEntityData(level, location));
 }
Example #10
0
  public void serialize(Document doc, Element root) {
    Element tile = doc.createElement("tile");
    tile.setAttribute("x", Integer.toString(x));
    tile.setAttribute("y", Integer.toString(y));
    tile.setAttribute("height", Float.toString(height));
    tile.setAttribute("caveHeight", Float.toString(caveHeight));
    tile.setAttribute("caveSize", Float.toString(caveSize));
    root.appendChild(tile);

    ground.serialize(doc, tile);
    cave.serialize(doc, tile);
    if (label != null) {
      label.serialize(doc, tile, false);
    }
    if (caveLabel != null) {
      caveLabel.serialize(doc, tile, true);
    }

    final HashMap<Integer, Element> levels = new HashMap<>();

    for (Entry<EntityData, TileEntity> e : entities.entrySet()) {
      final EntityData key = e.getKey();
      final TileEntity entity = e.getValue();
      final int floor = key.getFloor();

      Element level = levels.get(floor);
      if (level == null) {
        level = doc.createElement("level");
        level.setAttribute("value", Integer.toString(key.getFloor()));
        levels.put(key.getFloor(), level);
        tile.appendChild(level);
      }

      switch (key.getType()) {
        case FLOORROOF:
          entity.serialize(doc, level);
          break;
        case HWALL:
        case HFENCE:
          Element hWall = doc.createElement("hWall");
          entity.serialize(doc, hWall);
          level.appendChild(hWall);
          break;
        case VWALL:
        case VFENCE:
          Element vWall = doc.createElement("vWall");
          entity.serialize(doc, vWall);
          level.appendChild(vWall);
          break;
        case HBORDER:
          Element hDeco = doc.createElement("hBorder");
          entity.serialize(doc, hDeco);
          level.appendChild(hDeco);
          break;
        case VBORDER:
          Element vDeco = doc.createElement("vBorder");
          entity.serialize(doc, vDeco);
          level.appendChild(vDeco);
          break;
        case OBJECT:
          ObjectEntityData objectData = (ObjectEntityData) key;
          Element objectElement = doc.createElement("object");
          objectElement.setAttribute("position", objectData.getLocation().toString());
          entity.serialize(doc, objectElement);
          level.appendChild(objectElement);
          break;
      }
    }
  }
Example #11
0
 public BorderData getVerticalBorder() {
   return (BorderData) entities.get(new EntityData(0, EntityType.VBORDER));
 }
Example #12
0
 public void clearVerticalWalls(int level) {
   entities.remove(new EntityData(level, EntityType.VWALL));
   entities.remove(new EntityData(level, EntityType.VFENCE));
 }
Example #13
0
 public BorderData getHorizontalBorder() {
   return (BorderData) entities.get(new EntityData(0, EntityType.HBORDER));
 }
Example #14
0
 public Wall getVerticalWall(int level) {
   return (Wall) entities.get(new EntityData(level, EntityType.VWALL));
 }
Example #15
0
 public Wall getVerticalFence(int level) {
   return (Wall) entities.get(new EntityData(level, EntityType.VFENCE));
 }
Example #16
0
  private void renderEntities(GL2 g) {
    for (Entry<EntityData, TileEntity> e : entities.entrySet()) {
      EntityData key = e.getKey();
      final int floor = key.getFloor();
      float colorMod = 1;
      if (Globals.upCamera) {
        switch (Globals.floor - floor) {
          case 0:
            colorMod = 1;
            break;
          case 1:
            colorMod = 0.6f;
            break;
          case 2:
            colorMod = 0.25f;
            break;
          default:
            continue;
        }
      }
      TileEntity entity = e.getValue();
      g.glPushMatrix();
      switch (key.getType()) {
        case FLOORROOF:
          g.glTranslatef(4, 0, 3 * floor + getFloorHeight() / Constants.HEIGHT_MOD);
          g.glColor3f(colorMod, colorMod, colorMod);
          entity.render(g, this);
          break;
        case VWALL:
        case VFENCE:
          g.glTranslatef(0, 0, 3 * floor + getVerticalWallHeight() / Constants.HEIGHT_MOD);
          g.glRotatef(90, 0, 0, 1);
          float vdiff = getVerticalWallHeightDiff() / 47f;
          if (vdiff < 0) {
            g.glTranslatef(0, 0, -vdiff * 4f);
          }
          deform(g, vdiff);

          Wall vwall = (Wall) entity;
          if (Globals.upCamera) {
            vwall.data.color.use(g, colorMod);
          } else {
            g.glColor3f(1, 1, 1);
          }
          vwall.render(g, this);
          g.glColor3f(1, 1, 1);
          break;
        case HWALL:
        case HFENCE:
          g.glTranslatef(0, 0, 3 * floor + getHorizontalWallHeight() / Constants.HEIGHT_MOD);
          float hdiff = getHorizontalWallHeightDiff() / 47f;
          if (hdiff < 0) {
            g.glTranslatef(0, 0, -hdiff * 4f);
          }
          deform(g, hdiff);
          Wall hwall = (Wall) entity;
          if (Globals.upCamera) {
            hwall.data.color.use(g, colorMod);
          } else {
            g.glColor3f(1, 1, 1);
          }
          hwall.render(g, this);
          g.glColor3f(1, 1, 1);
          break;
        case OBJECT:
          ObjectEntityData objData = (ObjectEntityData) key;
          ObjectLocation loc = objData.getLocation();
          GameObject obj = (GameObject) entity;
          g.glColor3f(colorMod, colorMod, colorMod);
          g.glTranslatef(
              loc.getHorizontalAlign(),
              loc.getVerticalAlign(),
              3 * floor
                  + getHeight(loc.getHorizontalAlign() / 4f, loc.getVerticalAlign() / 4f)
                      / Constants.HEIGHT_MOD);
          obj.render(g, this);
          break;
      }
      g.glPopMatrix();
      g.glColor3f(1, 1, 1);
    }
  }
Example #17
0
 public void clearHorizontalWalls(int level) {
   entities.remove(new EntityData(level, EntityType.HWALL));
   entities.remove(new EntityData(level, EntityType.HFENCE));
 }
Example #18
0
 public Wall getHorizontalFence(int level) {
   return (Wall) entities.get(new EntityData(level, EntityType.HFENCE));
 }
Example #19
0
 public Wall getHorizontalWall(int level) {
   return (Wall) entities.get(new EntityData(level, EntityType.HWALL));
 }
Example #20
0
 public TileEntity getTileContent(int level) {
   return entities.get(new EntityData(level, EntityType.FLOORROOF));
 }