// handle fighter launching
if (step.getType() == MovePath.STEP_LAUNCH) {
TreeMap<Integer, Vector<Integer>> launched = step.getLaunched();
Set<Integer> bays = launched.keySet();
Iterator<Integer> bayIter = bays.iterator();
Bay currentBay;
while(bayIter.hasNext()) {
int bayId = bayIter.next();
currentBay = entity.getFighterBays().elementAt(bayId);
Vector<Integer> launches = launched.get(bayId);
int nLaunched = launches.size();
//need to make some decisions about how to handle the distribution
//of fighters to doors beyond the launch rate. The most sensible thing
//is probably to distribut them evenly.
int doors = currentBay.getDoors();
int[] distribution = new int[doors];
for(int l = 0; l < nLaunched; l++) {
distribution[l % doors] = distribution[l % doors] + 1;
}
//ok, now lets launch them
r = new Report(9380);
r.add(entity.getDisplayName());
r.subject = entity.getId();
r.newlines = 0;
r.add(nLaunched);
addReport(r);
int currentDoor = 0;
int fighterCount = 0;
boolean doorDamage = false;
for(int fighterId : launches) {
//check to see if we are in the same door
fighterCount++;
if(fighterCount > distribution[currentDoor]) {
//move to a new door
currentDoor++;
fighterCount = 0;
doorDamage = false;
}
int bonus = Math.max(0, distribution[currentDoor] - 2);
//check for door damage
if(!doorDamage && (distribution[currentDoor] > 2) && (Compute.d6(2) == 2)) {
doorDamage = true;
r = new Report(9390);
r.subject = entity.getId();
r.indent(1);
r.newlines = 0;
r.add(currentBay.getType());
addReport(r);
currentBay.destroyDoorNext();
}
Entity fighter = game.getEntity(fighterId);
if (!launchUnit(entity, fighter, curPos, curFacing, step.getVelocity(), step.getElevation(), step.getVectors(), bonus)) {
System.err.println("Error! Server was told to unload " + fighter.getDisplayName() + " from " + entity.getDisplayName() + " into " + curPos.getBoardNum());
}