package ei.game.scene.buildings; import java.util.LinkedList; import ei.engine.math.Vector2i; import ei.engine.scene.Node; import ei.game.gamestate.InGameState; import ei.game.player.Player; import ei.game.scene.GameEntity; import ei.game.scene.Map; import ei.game.scene.units.Unit; /** * The Building class, handles buildings, this case CommandCenter class. * @author Jesper Lundin * */ public abstract class Building extends GameEntity{ private LinkedList buildQueue; private int buildTime; private Node unitNode; private Vector2i oldPos; private int size; public Building(int l, Vector2i pos, Player p, int size) { super(l, p); this.size = size; buildQueue = new LinkedList(); unitNode = new Node("UnitNode"); unitNode.setLocation(Map.getPixelByPos(pos.getX(), pos.getY(), this.size)); setPos(pos.getX(), pos.getY(), this.size); } public void setSelected(boolean b) { if(b) { unitNode.add(getSelection().getSelectNode()); } else{ unitNode.remove(getSelection().getSelectNode()); } } public void setMouseOver(boolean b) { if(b) { unitNode.add(getSelection().getMouseOverNode()); } else{ unitNode.remove(getSelection().getMouseOverNode()); } } /** * Sets the size of the building. * @param size */ public void setSize(int size) { this.size = size; } /** * Returns the sprite for the unit * * @return The sprite for the unit */ public Node getNode(){ return unitNode; } /** * Changes the pos of the unit in the map * * @param x The x pos to move to * @param y The y pos to move to */ public void setPos(int x, int y, int size) { if(oldPos!=null) { InGameState.getMap().removeBuildPos(oldPos.getX(), oldPos.getY(), size); } oldPos = new Vector2i(x, y); InGameState.getMap().setBuildPos(this, x, y, size); } /** * Adds a unit to the build queue * @param u The unit to build */ public void buildUnit(Unit u){ buildQueue.addLast(u); } /** * Returns the size of the build queue * @return The size of the build queue */ public int getBuildQueueSize(){ return buildQueue.size(); } /** * Removes the last unit in the build queue * */ public void removeLast(){ if(!buildQueue.isEmpty()){ buildQueue.removeLast(); } } /** * Returns the procentage of completion of the unit * */ public int getBuildProgress(){ // TODO return the procentage of completion of the unit return 50; } /** * Removes this building from the game. * */ public void removeBuilding(){ unitNode.remove(getSprite()); getPlayer().removeUnit(this); InGameState.getMap().removeBuildPos(oldPos.getX(), oldPos.getY(), this.size); } /** * Updating the unit */ public void update() { if(getLife()<=0) { removeBuilding(); } } }