public Bay getBayById(int bayNumber) { //TODO: Change transports to a map or other indexed data structure to avoid // linear-time algorithm. for (Transporter next : transports) { if (next instanceof Bay) { if (((Bay) next).getBayNumber() == bayNumber) { return (Bay) next; } } } return null; }
public double getCargoCapacity() { double capacity = 0; for (Bay bay : entity.getTransportBays()) { if (bay instanceof CargoBay) { capacity += bay.getCapacity(); } if (bay instanceof PillionSeatCargoBay) { capacity += bay.getCapacity(); } if (bay instanceof StandardSeatCargoBay) { capacity += bay.getCapacity(); } } return capacity; }
/** * Damages a randomly determined bay door on the entity, if one exists */ public String damageBayDoor() { String bayType = "none"; Vector<Bay> potential; potential = new Vector<Bay>(); Enumeration<Transporter> iter = transports.elements(); while (iter.hasMoreElements()) { Transporter next = iter.nextElement(); if (next instanceof Bay) { Bay nextBay = (Bay) next; if (nextBay.getCurrentDoors() > 0) { potential.add(nextBay); } } } if (potential.size() > 0) { Bay chosenBay = potential.elementAt(Compute.randomInt(potential .size())); chosenBay.destroyDoor(); chosenBay.resetDoors(); chosenBay.setCurrentDoors(chosenBay.getCurrentDoors() - 1); bayType = chosenBay.getType(); } return bayType; }
public void restoreDoor() { if (getCurrentDoors() < getDoors()) { setCurrentDoors(getCurrentDoors() + 1); } }
public void destroyDoor() { if (getCurrentDoors() > 0) setCurrentDoors(getCurrentDoors() - 1); }
public void restoreAllDoors() { setCurrentDoors(getDoors()); }
gridBagConstraints.gridy++; gridBagConstraints.weightx = 0.0; panSystem.add(new JLabel("<html><b>" + nextbay.getType() + " Bay # " + nextbay.getBayNumber() + "</b><br></html>"), gridBagConstraints); bayCrit = new JSpinner(new SpinnerNumberModel(nextbay.getCapacity() - nextbay.getBayDamage(), 0, nextbay.getCapacity(), nextbay.isCargo()? 0.5: 1.0)); bayDamage[b] = bayCrit; gridBagConstraints.gridx = 1; gridBagConstraints.gridy++; gridBagConstraints.weightx = 0.0; panSystem.add(new JLabel("<html><b>" + "Bay # " + nextbay.getBayNumber() + " Doors" + "</b><br></html>"), gridBagConstraints); CheckCritPanel doorCrit = new CheckCritPanel(nextbay.getDoors(), (nextbay.getDoors() - nextbay.getCurrentDoors())); bayDoorCrit[b] = doorCrit; gridBagConstraints.gridx = 1;
if (next.getBayDamage() > 0) { if (!first) { toReturn += ", "; toReturn += next.getType() + " Bay # " + next.getBayNumber(); first = false; if (next.getCurrentDoors() < next.getDoors()) { if (!first) { toReturn += ", "; toReturn += next.getType() + " Bay #" + next.getBayNumber() + " Doors (" + (next.getDoors() - next.getCurrentDoors()) + ")"; first = false;
continue; bay.setBayDamage(bay.getCapacity() - (Double) bayCrit.getModel().getValue()); CheckCritPanel doorCrit = bayDoorCrit[b]; if (null == doorCrit) { continue; if ((bay.getCurrentDoors() > 0) && (doorCrit.getHits() > 0)) { bay.setCurrentDoors(bay.getDoors() - doorCrit.getHits()); bay.setCurrentDoors(bay.getDoors());
protected void addTransportBays(Entity entity) { final List<Map<String, Object>> bays = new ArrayList<>(); for (final Bay bay : entity.getTransportBays()) { if (bay.isQuarters()) { continue; } final BayData bayData = BayData.getBayType(bay); if (null != bayData) { final Map<String, Object> bayRow = new HashMap<>(); bayRow.put("name", bayData.getDisplayName()); if (bayData.isCargoBay()) { bayRow.put("size", bay.getCapacity() + Messages.getString("TROView.tons")); } else { bayRow.put("size", (int) bay.getCapacity()); } bayRow.put("doors", bay.getDoors()); bays.add(bayRow); } else { DefaultMmLogger.getInstance().warning(getClass(), "addBays()", "Could not determine bay type for " + bay.toString()); } } setModelData("bays", bays); }
if (bay.isQuarters()) { continue; bay.getBayNumber(), bay.getCapacity(), campaign); oldUnit.addPart(bayPart); oldUnit.campaign.addPart(bayPart, 0); for (int i = 0; i < bay.getDoors(); i++) { Part door; if (doors.size() > 0) { for (int i = 0; i < bay.getCapacity(); i++) { Part cubicle; if (cubicles.containsKey(btype) && (cubicles.get(btype).size() > 0)) {
@Override public boolean isClan() { return getTechAdvancement().isClan(); }
public double getWeightQuarters() { double quartersWeight = 0; for (Bay bay : getEntity().getTransportBays()) { if (bay.isQuarters()) { quartersWeight += bay.getWeight(); } } return quartersWeight; }
if (null != bay) { int prevHits = hits; hits = (int) bay.getBayDamage(); int prevDoorHits = 0; for (int id : childPartIds) { if (prevDoorHits < bay.getDoors() - bay.getCurrentDoors()) { if (prevDoorHits >= bay.getDoors() - bay.getCurrentDoors()) { break;
output.write(indentStr(indentLvl+1) + "<transportBay index=\"" + nextbay.getBayNumber() + "\">"); output.write(CommonConstants.NL); output.write(indentStr(indentLvl + 2) + "<damage>" + nextbay.getBayDamage() + "</damage>"); output.write(CommonConstants.NL); output.write(indentStr(indentLvl + 2) + "<doors>" + nextbay.getCurrentDoors() + "</doors>"); output.write(CommonConstants.NL); output.write(indentStr(indentLvl+1) + "</transportBay>");
.filter(b -> !b.isQuarters()).collect(Collectors.toList()); List<Bay> newUnitBays = newEntity.getTransportBays().stream() .filter(b -> !b.isQuarters()).collect(Collectors.toList()); for (Iterator<Bay> newbays = newUnitBays.iterator(); newbays.hasNext(); ) { final Bay newbay = newbays.next(); if ((oldbay.getCapacity() == newbay.getCapacity()) && (oldbay.getDoors() == newbay.getDoors())) { oldbays.remove(); newbays.remove(); for (Iterator<Bay> newbays = newUnitBays.iterator(); newbays.hasNext(); ) { final Bay newbay = newbays.next(); if (oldbay.getCapacity() == newbay.getCapacity()) { if (oldbay.getDoors() > newbay.getDoors()) { doorsRemoved += oldbay.getDoors() - newbay.getDoors(); } else { doorsAdded += newbay.getDoors() - oldbay.getDoors();
bayPartsToAdd.put(bay.getBayNumber(), new ArrayList<>()); BayType btype = BayType.getTypeForBay(bay); Part bayPart = bays.get(bay.getBayNumber()); if (null == bayPart) { bayPart = new TransportBayPart((int) entity.getWeight(), bay.getBayNumber(), bay.getCapacity(), campaign); addPart(bayPart); partsToAdd.add(bayPart); for (int i = 0; i < bay.getDoors(); i++) { Part door = new BayDoor((int) entity.getWeight(), campaign); bayPartsToAdd.get(bay.getBayNumber()).add(door); addPart(door); partsToAdd.add(door); for (int i = 0; i < bay.getCapacity(); i++) { Part cubicle = new Cubicle((int) entity.getWeight(), btype, campaign); bayPartsToAdd.get(bay.getBayNumber()).add(cubicle); addPart(cubicle); partsToAdd.add(cubicle); || (p instanceof MissingBayDoor))) .collect(Collectors.toList()); while (bay.getDoors() > doors.size()) { Part door = new MissingBayDoor((int) entity.getWeight(), campaign); bayPartsToAdd.get(bay.getBayNumber()).add(door); addPart(door); partsToAdd.add(door); || (p instanceof MissingCubicle)))
@Override public void updateConditionFromPart() { Bay bay = getBay(); if (null != bay) { int goodDoors = 0; int badCubicles = 0; for (int id : childPartIds) { final Part p = campaign.getPart(id); if (null != p) { if ((p instanceof BayDoor) && !p.needsFixing()) { goodDoors++; } else if (p instanceof MissingCubicle) { badCubicles++; } } } bay.setCurrentDoors(goodDoors); // Even if the bay is repaired, it still has reduced capacity until the cubicles are replaced. bay.setBayDamage(Math.max(hits, badCubicles)); } }
currentBay = Bays.elementAt(i); Vector<Integer> bayChoices = new Vector<Integer>(); currentUnits = currentBay.getDroppableUnits().stream() .filter(e -> !alreadyDropped.contains(e.getId())) .collect(Collectors.toList()); doors = currentBay.getCurrentDoors(); if ((currentUnits.size() > 0) && (doors > 0)) { String[] names = new String[currentUnits.size()]; Messages.getString( "MovementDisplay.DropUnitDialog.title", new Object[]{ //$NON-NLS-1$ currentBay.getType(), bayNum}), question, names, false, doors); choiceDialog.setVisible(true);
currentBay = FighterBays.elementAt(i); Vector<Integer> bayChoices = new Vector<Integer>(); currentFighters = currentBay.getLaunchableUnits(); doors = currentBay.getCurrentDoors(); if (currentFighters.size() == 0) { bayNum++; Messages.getString( "MovementDisplay.LaunchFighterDialog.title", new Object[]{ //$NON-NLS-1$ currentBay.getType(), bayNum}), question, names); choiceDialog.setVisible(true);