private Star findHighestScoreStar(Sector sector) { double highestScore = 5.0; // scores lower than 5.0 don't count Star highestScoreStar = null; for (BaseStar star : sector.getStars()) { // ignore colonized stars, they're no good if (isColonized(star)) { continue; } // similarly, colonies with fleets are right out boolean hasFleets = false; for (BaseFleet fleet : star.getFleets()) { if (fleet.getEmpireKey() != null) { hasFleets = true; break; } } if (hasFleets) { continue; } double score = scoreStar(sector, star); if (score > highestScore) { highestScore = score; highestScoreStar = (Star) star; } } return highestScoreStar; }
private void onColonizeClick() { MyEmpire empire = EmpireManager.i.getEmpire(); // check that we have a colony ship (the server will check too, but this is // easy) boolean hasColonyShip = false; for (BaseFleet fleet : star.getFleets()) { if (fleet.getEmpireKey() == null) { continue; } if (fleet.getEmpireKey().equals(empire.getKey())) { if (fleet.getDesignID().equals("colonyship")) { // TODO: hardcoded? hasColonyShip = true; } } } if (!hasColonyShip) { // TODO: better errors... StyledDialog dialog = new StyledDialog.Builder(this) .setMessage( "You don't have a colony ship around this star, so you cannot colonize this planet.") .setPositiveButton("OK", null) .create(); dialog.show(); } empire.colonize( planet, new MyEmpire.ColonizeCompleteHandler() { @Override public void onColonizeComplete(Colony colony) { finish(); } }); }