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; }
/** * Load the given unit. * * @param unit - the <code>Entity</code> to be loaded. * @throws IllegalArgumentException If the unit can't be loaded */ public void load(Entity unit, boolean checkElev, int bayNumber) { // Walk through this entity's transport components; // find the one that can load the unit. // Stop looking after the first match. Enumeration<Transporter> iter = transports.elements(); while (iter.hasMoreElements()) { Transporter next = iter.nextElement(); if (next.canLoad(unit) && (!checkElev || (unit.getElevation() == getElevation())) && ((bayNumber == -1) || (((Bay) next).getBayNumber() == bayNumber))) { next.load(unit); unit.setTargetBay(-1); // Reset the target bay for later. return; } } // If we got to this point, then we can't load the unit. throw new IllegalArgumentException(getShortName() + " can not load " + unit.getShortName()); }
gridBagConstraints.gridy++; gridBagConstraints.weightx = 0.0; panSystem.add(new JLabel("<html><b>" + nextbay.getType() + " Bay # " + nextbay.getBayNumber() + "</b><br></html>"), gridBagConstraints); gridBagConstraints.gridy++; gridBagConstraints.weightx = 0.0; panSystem.add(new JLabel("<html><b>" + "Bay # " + nextbay.getBayNumber() + " Doors" + "</b><br></html>"), gridBagConstraints);
bay.getBayNumber(), bay.getCapacity(), campaign); oldUnit.addPart(bayPart); oldUnit.campaign.addPart(bayPart, 0);
output.write(indentStr(indentLvl+1) + "<transportBay index=\"" + nextbay.getBayNumber() + "\">"); output.write(CommonConstants.NL); output.write(indentStr(indentLvl + 2) + "<damage>" + nextbay.getBayDamage() + "</damage>");
for (Transporter t : choice.getTransports()) { if (t.canLoad(ce) && (t instanceof Bay)) { bayChoices.add(((Bay) t).getBayNumber());
if (t instanceof Bay) { Bay bay = (Bay) t; menuItem = new JMenuItem("Into Bay #" + bay.getBayNumber() + " (Free " + "Slots: " + (int) loader.getBayById(bay.getBayNumber()).getUnusedSlots() + loader.getBayById(bay.getBayNumber()).getDefaultSlotDescription() + ")"); menuItem.setActionCommand( "LOAD|" + loader.getId() + ":" + bay.getBayNumber()); if (bay.getLoadedUnits().size() > 0) { menuItem = new JMenuItem( "Bay # " + bay.getBayNumber() + " (" + bay.getLoadedUnits().size() + " units)"); menuItem.setActionCommand("UNLOADALLFROMBAY|" + bay.getBayNumber()); menuItem.addActionListener(this); menuItem.setEnabled((isOwner || isBot));
for (Transporter t : ce().getTransports()) { if (t.canLoad(choice) && (t instanceof Bay)) { bayChoices.add(((Bay) t).getBayNumber());
toReturn += ", "; toReturn += next.getType() + " Bay # " + next.getBayNumber(); first = false; toReturn += ", "; toReturn += next.getType() + " Bay #" + next.getBayNumber() + " Doors (" + (next.getDoors() - next.getCurrentDoors()) + ")"; first = false;
for (Transporter t : ce().getTransports()) { if (t.canLoad(other) && (t instanceof Bay)) { bayChoices.add(((Bay) t).getBayNumber());
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); while (bay.getDoors() > doors.size()) { Part door = new MissingBayDoor((int) entity.getWeight(), campaign); bayPartsToAdd.get(bay.getBayNumber()).add(door); addPart(door); partsToAdd.add(door); while (bay.getCapacity() > cubicles.size()) { Part cubicle = new MissingCubicle((int) entity.getWeight(), btype, campaign); bayPartsToAdd.get(bay.getBayNumber()).add(cubicle);