Package com.drakulo.games.ais.core.delayed

Examples of com.drakulo.games.ais.core.delayed.BuildingAction


    Building b = BuildingHelper.create(t);
    b.setUnderConstruction(true);
    final int duration = 5; // TODO externalize this
    final int robots = 1; // TODO externalize this

    BuildingAction ba = new BuildingAction(c, cost, b, duration, robots);
    return ba;
  }
View Full Code Here


    PreparationAction pa02 = createCleaningAction(c, x - 1, y + 1);
    PreparationAction pa12 = createCleaningAction(c, x, y + 1);
    PreparationAction pa22 = createCleaningAction(c, x + 1, y + 1);

    // Road construction
    BuildingAction n = createBuildingAction(c, x, y - 1, BuildingType.ROAD);
    BuildingAction e = createBuildingAction(c, x + 1, y, BuildingType.ROAD);
    BuildingAction w = createBuildingAction(c, x - 1, y, BuildingType.ROAD);
    BuildingAction s = createBuildingAction(c, x, y + 1, BuildingType.ROAD);

    // Buildings construction
    BuildingAction nw = createBuildingAction(c, x - 1, y - 1,
        BuildingType.SOLAR_PLANT);
    BuildingAction ne = createBuildingAction(c, x + 1, y - 1,
        BuildingType.GAS_REFINERY);
    BuildingAction sw = createBuildingAction(c, x - 1, y + 1,
        BuildingType.CRISTAL_MINE);
    BuildingAction se = createBuildingAction(c, x + 1, y + 1,
        BuildingType.BIO_FARM);
    se.setCallback(new Runnable() {

      @Override
      public void run() {
        c.setCommandCenterBuilt(true);
      }
View Full Code Here

    return pa;
  }

  private static BuildingAction createBuildingAction(Colony c, int x, int y,
      BuildingType type) {
    return new BuildingAction(c, null, new Building(type, x, y), 5, 1);
  }
View Full Code Here

        for (DelayedAction da : children) {
          if (da instanceof PreparationAction) {
            PreparationAction pa = (PreparationAction) da;
            c.addPreparationAction(pa);
          } else if (da instanceof BuildingAction) {
            BuildingAction ba = (BuildingAction) da;
            c.addBuildingAction(ba);

          }
        }
      }
View Full Code Here

    ImageButton button = new ImageButton(type.toString());
    button.setActionHandler(new ActionHandler() {

      @Override
      public void run() {
        BuildingAction ba = BuildingHelper.createAction(GameData.getSelectedColony(), type,
            BuildWindowOld.this.cost);
        BuildWindowOld.this.parent.setSelectedAction(ba);
        hide();
      }
    });
View Full Code Here

    // Set the build action
    button.setActionHandler(new ActionHandler() {

      @Override
      public void run() {
        BuildingAction ba = BuildingHelper.createAction(
            GameData.getSelectedColony(), type, costMap);
        parent.setSelectedAction(ba);
        hide();
      }
    });
View Full Code Here

              Color.red);
        }

      } else if (this.selectedAction instanceof BuildingAction) {
        // Building action
        BuildingAction ba = (BuildingAction) this.selectedAction;
        if (BuildingType.COMMAND_CENTER.equals(ba.getBuilding()
            .getType())) {
          // Render the effect zone around the command center
          if (TileHelper.isValidCommandCenterTile(tileX, tileY)) {
            g.setColor(Style.FILTER_GREEN);
          } else {
            // The zone is not correct for Command Center
            // construction.
            g.setColor(Style.FILTER_RED);
          }

          int x = getScreenX(tileX - 1);
          int y = getScreenY(tileY - 1);
          g.fillRect(x, y, Settings.TILE_SIZE * 3,
              Settings.TILE_SIZE * 3);
          gfx.draw(this.squareXOnScreen, this.squareYOnScreen);
          // The command center construction is an exception
        } else if (TileHelper.tileIsBuildable(tileX, tileY, ba
            .getBuilding().getType())) {
          // Can build here
          gfx.draw(this.squareXOnScreen, this.squareYOnScreen);
        } else {
          // Cannot build here
View Full Code Here

      if (GameData.getSelectedColony().isCommandCenterUnderConstruction()) {
        this.developButton.enable();
      }
      if(selectedAction != null){
        if(selectedAction instanceof BuildingAction){
          BuildingAction ba = (BuildingAction) selectedAction;
          if(!BuildingType.COMMAND_CENTER.equals(ba.getBuilding().getType())){
            // The selected action is not a command center construction
            selectedAction = null;
          }
        }else{
          // The action is not allowed yet
          selectedAction = null;
        }
      }
      this.buildWindow.setCommandCenterBuilt(false);
    }

    this.buildWindow.update(input);

    // Handle action drop
    if (this.selectedAction != null) {
      if (input.isMousePressed(Input.MOUSE_LEFT_BUTTON)
          && this.mouseY > TOP_BAR_HEIGHT
          && this.mouseY < Settings.HEIGHT - BOTTOM_BAR_HEIGHT) {
        final int tileX = this.squareXOnMap;
        final int tileY = this.squareYOnMap;
        if (this.selectedAction instanceof PreparationAction) {
          // Preparation action
          PreparationAction pa = (PreparationAction) this.selectedAction;
          boolean canBuild = false;
          if (TileHelper.tileIsPreparable(tileX, tileY)) {
            // Tile is OK
            if (ResourceHelper
                .enoughResourcesFor(SectorState.this.selectedAction
                    .getCostMap())) {
              // Resources are OK
              if (GameData.getSelectedColony()
                  .getAvailableRobots() > 0) {
                canBuild = true;
              }
            }
          }
          if (canBuild) {
            // Preparation can be done
            pa.setX(tileX);
            pa.setY(tileY);
            Map<Resource, BigDecimal> map = pa.getCostMap();
            for (Resource r : resources) {
              if (map.get(r) == null) {
                // No value defined for this resource
                continue;
              }
              GameData.getSelectedColony().updateResource(r,
                  map.get(r).negate());
            }

            GameData.getSelectedColony().addPreparationAction(
                pa.clone());
          } else {
            // TODO play an error sound
          }

        } else if (this.selectedAction instanceof BuildingAction) {
          BuildingAction ba = (BuildingAction) this.selectedAction;
          if (BuildingType.COMMAND_CENTER.equals(ba.getBuilding()
              .getType())) {
            // Command center construction is handled in a submethod
            handleCommandCenterConstruction(ba, tileX, tileY);
          } else if (TileHelper.tileIsBuildable(tileX, tileY, ba
              .getBuilding().getType())) {
            // Is there already a building there?
            List<Building> buildings = GameData.getSelectedColony()
                .getBuildings();
            boolean canBuild = true;
            for (Building b : buildings) {
              if (b.getX() == tileX && b.getY() == tileY) {
                // Oops, there is already a building here.
                // Construction is impossible
                canBuild = false;
                break;
              }
            }
            // No building, but is there a building under
            // construction?
            List<BuildingAction> bactions = GameData
                .getSelectedColony().getBuildingActions();
            for (BuildingAction cba : bactions) {
              Building cb = cba.getBuilding();
              if (cb.getX() == tileX && cb.getY() == tileY) {
                // Construction is impossible
                canBuild = false;
                break;
              }
            }
            if (!ResourceHelper
                .enoughResourcesFor(SectorState.this.selectedAction
                    .getCostMap())) {
              canBuild = false;
            }
            if (canBuild) {
              ba.getBuilding().setX(tileX);
              ba.getBuilding().setY(tileY);
              final BuildingAction nba = ba.clone();
              if (!BuildingType.ROAD.equals(nba.getBuilding()
                  .getType())) {
                nba.setCallback(new Runnable() {

                  @Override
                  public void run() {
                    if (nba.getBuilding()
                        .equals(SectorState.this.selectedBuilding)) {
                      SectorState.this.selectBuilding(nba
                          .getBuilding());
                    }
                  }
                });
              }
              GameData.getSelectedColony().addBuildingAction(nba);
              // Remove from the stock the building cost
              BuildingData data = BuildingIO.getBuildingData(nba
                  .getBuilding().getType());
              Map<Resource, BigDecimal> map = data
                  .getLevelData(0).getUpgradeCost();
              for (Resource r : resources) {
                GameData.getSelectedColony().updateResource(r,
View Full Code Here

        for (BuildingType t : BuildingType.values()) {
          if (t.getShortcut() != -1
              && input.isKeyPressed(t.getShortcut())) {
            // Building selected
            BuildingData data = BuildingIO.getBuildingData(t);
            BuildingAction ba = BuildingHelper.createAction(
                GameData.getSelectedColony(), t, data
                    .getLevelData(0).getUpgradeCost());
            setSelectedAction(ba);
            showBuildWindow(false);
            break;
View Full Code Here

    BigDecimal maxValue = null;
    BigDecimal value = null;
    DelayedAction a = getSelectedBuildingAction();
    this.selectedBuildingPB.setFilledColor(Color.red);
    if (a instanceof BuildingAction) {
      BuildingAction ba = (BuildingAction) a;
      if (ba.isUpgrade()) {
        // Upgrade process
        title = FontHelper.firstToUpper(I18n.get("global.upgrading"))
            + "...";
        this.selectedBuildingPB.setFilledColor(Color.magenta);
      } else if (!ba.isUpgrade()) {
        // Building process
        title = FontHelper.firstToUpper(I18n.get("global.building"))
            + "...";
      }
      maxValue = BigDecimal.valueOf(ba.getDuration());
      value = BigDecimal.valueOf(ba.getCurrentValue());
    } else if (a instanceof ColonyAction) {
      ColonyAction sa = (ColonyAction) a;
      title = FontHelper.firstToUpper(I18n.get(sa.getI18nKey())) + "...";
      this.selectedBuildingPB.setFilledColor(Color.red);
      maxValue = BigDecimal.valueOf(sa.getDuration());
View Full Code Here

TOP

Related Classes of com.drakulo.games.ais.core.delayed.BuildingAction

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.