private MechSummary generateSalvage(UnitFilter filter){
  while (salvageTotal > 0) {
    int roll=Compute.randomInt(salvageTotal);
    TableEntry salvageEntry=null;
    for (    TableEntry te : salvageTable) {
      if (roll < te.weight) {
        salvageEntry=te;
        break;
      }
      roll-=te.weight;
    }
    if (salvageEntry != null) {
      UnitTable salvage=UnitTable.findTable(salvageEntry.getSalvageFaction(),key.getUnitType(),key.getYear() - 5,key.getRating(),key.getWeightClasses(),key.getNetworkMask(),key.getMovementModes(),key.getRoles(),key.getRoleStrictness(),key.getFaction());
      if (salvage.hasUnits()) {
        return salvage.generateUnit(filter);
      }
 else {
        salvageTotal-=salvageEntry.weight;
        salvageTable.remove(salvageEntry);
      }
    }
  }
  assert (salvageTable.isEmpty() && salvageTotal == 0);
  return null;
}

private MechSummary generateSalvage ( UnitFilter filter ) { while ( salvageTotal > 0 ) { int roll = Compute . randomInt ( salvageTotal ) ; TableEntry salvageEntry = null ; for ( TableEntry te : salvageTable ) { if ( roll < te . weight ) { salvageEntry = te ; break ; } roll -= te . weight ; } if ( salvageEntry != null ) { UnitTable salvage = UnitTable . findTable ( salvageEntry . getSalvageFaction ( ) , key . getUnitType ( ) , key . getYear ( ) - 5 , key . getRating ( ) , key . getWeightClasses ( ) , key . getNetworkMask ( ) , key . getMovementModes ( ) , key . getRoles ( ) , key . getRoleStrictness ( ) , key . getFaction ( ) ) ; if ( salvage . hasUnits ( ) ) { return salvage . generateUnit ( filter ) ; } else { salvageTotal -= salvageEntry . weight ; salvageTable . remove ( salvageEntry ) ; } } } assert ( salvageTable . isEmpty ( ) && salvageTotal == 0 ) ; return null ; }
selects a faction from the salvage list and generates a table using the same parameters as this table , but from five years earlier . generated tables are cached for later use . if the generated table contains no units , it is discarded and the selected entry is deleted . this continues until either a unit is generated or there are no remaining entries .
