gt:         case -1: {
context: package org.openRealmOfStars.player.combat;
  
  import org.openRealmOfStars.player.PlayerInfo;
  import org.openRealmOfStars.player.leader.Leader;
  import org.openRealmOfStars.player.leader.Perk;
  import org.openRealmOfStars.player.ship.Ship;
  import org.openRealmOfStars.player.ship.ShipComponent;
  import org.openRealmOfStars.player.ship.ShipComponentType;
  import org.openRealmOfStars.player.tech.TechType;
  import org.openRealmOfStars.utilities.DiceGenerator;
  
  /**
   *
   * Open Realm of Stars game project
   * Copyright (C) 2016,2017,2020,2021 Tuomo Untinen
   *
   * This program is free software; you can redistribute it and/or
   * modify it under the terms of the GNU General Public License
   * as published by the Free Software Foundation; either version 2
   * of the License, or (at your option) any later version.
   *
   * This program is distributed in the hope that it will be useful,
   * but WITHOUT ANY WARRANTY; without even the implied warranty of
   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   * GNU General Public License for more details.
   *
   * You should have received a copy of the GNU General Public License
   * along with this program; if not, see http://www.gnu.org/licenses/
   *
   *
   * Single ship in combat
   *
   */
  
  public class CombatShip implements Comparable<CombatShip> {
  
    /**
     * Ship information
     */
    private Ship ship;
  
    /**
     * Is component used or not for this round
     */
    private boolean[] componentUsed;
  
    /**
     * Ship's X coordinate in combat
     */
    private int x;
  
    /**
     * Ship's Y coordinate in combat
     */
    private int y;
  
    /**
     * Player whom owns the ship
     */
    private PlayerInfo player;
  
    /**
     * Flip Y axel on ship image
     */
    private boolean flipY;
  
    /**
     * How many moves left for this round
     */
    private int movesLeft;
  
    /**
     * Used only for AI to calculate how many times AI can shoot
     */
    private int aiShotsLeft;
  
    /**
     * Bonus accuracy from defending
     */
    private int bonusAccuracy;
    /**
     * Bonus from overloaded Jammer.
     */
    private int overloadedJammer;
    /**
     * Bonus from overloaded targeting computer
     */
    private int overloadedComputer;
  
    /**
     * Was ship damaged. Really damage not just some shield hit.
     */
    private boolean damaged;
  
    /**
     * Number of credits ship has privateered
     */
    private int privateeredCredits;
  
  
    /**
     * Fleet's commander.
     */
    private Leader commander;
  
    /**
     * Overload failure chance.
     */
    private int overloadFailure;
  
    /**
     * Ship's current energy level.
     */
    private int energyLevel;
    /**
     * Ship has been overloaded.
     */
    private boolean isOverloaded;
    /**
     * Cloaking device is overloaded.
     */
    private boolean cloakOverloaded;
    /**
     * Constructor for Combat ship
     * @param ship Ship to put in combat
     * @param player Player who owns the ship
     * @param x Ship's X coordinate in combat map
     * @param y Ship's Y coordinate in combat map
     * @param flip Ship's image on Y axel
     * @param commander Fleet's commander
     */
    public CombatShip(final Ship ship, final PlayerInfo player, final int x,
        final int y, final boolean flip, final Leader commander) {
      this.ship = ship;
      this.x = x;
      this.y = y;
      this.player = player;
      this.flipY = flip;
      this.commander = commander;
      this.movesLeft = ship.getTacticSpeed();
      this.setBonusAccuracy(0);
      this.setPrivateeredCredits(0);
      this.setOverloadFailure(0);
      this.setEnergyLevel(ship.getTotalEnergy());
      this.setOverloadedJammer(0);
      this.setCloakOverloaded(false);
      this.setOverloadedComputer(0);
      reInitShipForRound();
    }
  
    /**
     * Get ship component for use.
     * @param type Component Type for use.
     * @return component index or -1 if not available.
     */
    public int getComponentForUse(final ShipComponentType type) {
      for (int i = 0; i < ship.getNumberOfComponents(); i++) {
        ShipComponent component = ship.getComponent(i);
        if (component.getType() == type && ship.componentIsWorking(i)) {
          return i;
        }
      }
      return -1;
    }
  
    /**
     * Get Component for overloading movement.
     * @return component index or -1 if not available.
     */
    public int getOverloadMove() {
      int index = getComponentForUse(ShipComponentType.THRUSTERS);
      if (index == -1) {
        index = getComponentForUse(ShipComponentType.ENGINE);
      }
      if (index == -1) {
        index = getComponentForUse(ShipComponentType.SPACE_FIN);
      }
      return index;
    }
  
    /**
     * Get the actual ship
     * @return get Ship
     */
    public Ship getShip() {
      return ship;
    }
  
    /**
     * Get combat ship X coordinate in combat
     * @return X coordinate
     */
    public int getX() {
      return x;
    }
  
    /**
     * Set combat ship's X coordinate
     * @param x X coordinate
     */
    public void setX(final int x) {
      this.x = x;
    }
  
    /**
     * Get combat ship Y coordinate in combat
     * @return Y coordinate
     */
    public int getY() {
      return y;
    }
  
    /**
     * Set combat ship's Y coordinate
     * @param y Y coordinate
     */
    public void setY(final int y) {
      this.y = y;
    }
  
    /**
     * Get Player info for combat ship
     * @return Player info for combat ship
     */
    public PlayerInfo getPlayer() {
      return player;
    }
  
    /**
     * Set Player info for combat ship
     * @param player New player info for combat ship.
     */
    public void setPlayer(final PlayerInfo player) {
      this.player = player;
    }
    @Override
    public int compareTo(final CombatShip o) {
      int thisInit = this.ship.getInitiative();
      int otherInit = o.getShip().getInitiative();
      if (this.getCommander() != null
          && this.getCommander().hasPerk(Perk.COMBAT_TACTICIAN)) {
        thisInit++;
      }
      if (this.getCommander() != null
          && this.getCommander().hasPerk(Perk.AGGRESSIVE)) {
        thisInit++;
      }
      if (this.getCommander() != null
          && this.getCommander().hasPerk(Perk.PEACEFUL)) {
        thisInit--;
      }
      if (o.getCommander() != null
          && o.getCommander().hasPerk(Perk.COMBAT_TACTICIAN)) {
        otherInit++;
      }
      if (o.getCommander() != null
          && o.getCommander().hasPerk(Perk.AGGRESSIVE)) {
        otherInit++;
      }
      if (o.getCommander() != null
          && o.getCommander().hasPerk(Perk.PEACEFUL)) {
        otherInit--;
      }
      return thisInit - otherInit;
    }
  
    /**
     * Does ship image needs to be fliped on Y axel
     * @return True if image needs flipping on Y axel
     */
    public boolean isFlipY() {
      return flipY;
    }
  
    @Override
    public String toString() {
      StringBuilder sb = new StringBuilder();
      sb.append(ship.getName());
      sb.append(" - ");
      sb.append(ship.getHull().getName());
      sb.append("\n");
      sb.append("X: ");
      sb.append(x);
      sb.append(" Y: ");
      sb.append(y);
      sb.append("\n");
      sb.append("Initiative: ");
      sb.append(ship.getInitiative());
      sb.append("\n");
      sb.append("Moves: ");
      sb.append(movesLeft);
      sb.append("\n");
      sb.append("Hull points: ");
      sb.append(ship.getHullPoints());
      sb.append("/");
      sb.append(ship.getMaxHullPoints());
      sb.append("\n");
      if (ship.getTacticSpeed() == 0) {
        sb.append("Immobilized\n");
      }
      if (!ship.hasWeapons()) {
        sb.append("No weapons\n");
      }
      if (ship.getShield() == 0 && ship.getTotalShield() > 0) {
        sb.append("shields down\n");
      }
      if (ship.getShield() == 0 && ship.getTotalShield() == 0) {
        sb.append("No shields\n");
      }
      if (isCloaked()) {
        sb.append("Cloaked\n");
      }
      sb.append("\n");
      sb.append(getOverloadInformation());
      return sb.toString();
    }
  
    /**
     * Get overload information of the combat ship.
     * @return Overload information as string.
     */
    public String getOverloadInformation() {
      StringBuilder sb = new StringBuilder();
      sb.append("Energy reserves: ");
      if (getEnergyReserve() > 0) {
        sb.append("+");
      }
      sb.append(getEnergyReserve());
      sb.append("\n");
      sb.append("Overload failure: ");
      sb.append(getOverloadFailure());
      sb.append("/100\n");
      return sb.toString();
    }
    /**
     * Get Combat ship description
     * @return String for description
     */
    public String getDescription() {
      StringBuilder sb = new StringBuilder();
      sb.append(ship.getName());
      sb.append(" - ");
      sb.append(ship.getHull().getName());
      sb.append("\n");
      sb.append("\n");
      sb.append("Initiative: ");
      sb.append(ship.getInitiative());
      sb.append("\n");
      sb.append("Moves: ");
      sb.append(movesLeft);
      sb.append("\n");
      sb.append("Shield: ");
      sb.append(ship.getShield());
      sb.append("/");
      sb.append(ship.getTotalShield());
      sb.append(" Armor: ");
      sb.append(ship.getArmor());
      sb.append("/");
      sb.append(ship.getTotalArmor());
      sb.append("\n");
      sb.append("Hull points: ");
      sb.append(ship.getHullPoints());
      sb.append("/");
      sb.append(ship.getMaxHullPoints());
      sb.append("\n");
      if (ship.getTacticSpeed() == 0) {
        sb.append("Immobilized\n");
      }
      if (!ship.hasWeapons()) {
        sb.append("No weapons\n");
      }
      if (ship.getShield() == 0 && ship.getTotalShield() > 0) {
        sb.append("shields down\n");
      }
      if (ship.getShield() == 0 && ship.getTotalShield() == 0) {
        sb.append("No shields\n");
      }
      if (isCloaked()) {
        sb.append("Cloaked\n");
      }
      sb.append("\n");
      sb.append(getOverloadInformation());
      return sb.toString();
    }
  
    /**
     * How many moves left for this combat round
     * @return Moves left
     */
    public int getMovesLeft() {
      return movesLeft;
    }
  
    /**
     * Reinitialize ship for next round
     * @return CombatAnimation or null
     */
    public CombatAnimation reInitShipForRound() {
      int weapons = 0;
      setOverloadedJammer(0);
      setCloakOverloaded(false);
      setOverloadedComputer(0);
      if (getEnergyLevel() > ship.getTotalEnergy()) {
        setEnergyLevel(ship.getTotalEnergy());
      }
      if (getEnergyReserve() < 0) {
        int chance = 0;
        switch (getEnergyReserve()) {
  