Program: 79862
Project: 79862
Buggy source:
public int randomize(final String filename,final PrintStream log,long seed){
  final long startTime=System.currentTimeMillis();
  RandomSource.seed(seed);
  final boolean raceMode=settings.isRaceMode();
  int checkValue=0;
  if (settings.isLimitPokemon()) {
    romHandler.setPokemonPool(settings.getCurrentRestrictions());
    romHandler.removeEvosForPokemonPool();
  }
 else {
    romHandler.setPokemonPool(null);
  }
  if (settings.isUpdateMoves()) {
    romHandler.initMoveUpdates();
    if (!(romHandler instanceof Gen5RomHandler)) {
      romHandler.updateMovesToGen5();
    }
    if (!settings.isUpdateMovesLegacy()) {
      romHandler.updateMovesToGen6();
    }
    romHandler.printMoveUpdates();
  }
  if (settings.isRandomizeMovePowers()) {
    romHandler.randomizeMovePowers();
  }
  if (settings.isRandomizeMoveAccuracies()) {
    romHandler.randomizeMoveAccuracies();
  }
  if (settings.isRandomizeMovePPs()) {
    romHandler.randomizeMovePPs();
  }
  if (settings.isRandomizeMoveTypes()) {
    romHandler.randomizeMoveTypes();
  }
  if (settings.isRandomizeMoveCategory() && romHandler.hasPhysicalSpecialSplit()) {
    romHandler.randomizeMoveCategory();
  }
  List<Move> moves=romHandler.getMoves();
  int currentMiscTweaks=settings.getCurrentMiscTweaks();
  if (romHandler.miscTweaksAvailable() != 0) {
    int codeTweaksAvailable=romHandler.miscTweaksAvailable();
    List<MiscTweak> tweaksToApply=new ArrayList<MiscTweak>();
    for (    MiscTweak mt : MiscTweak.allTweaks) {
      if ((codeTweaksAvailable & mt.getValue()) > 0 && (currentMiscTweaks & mt.getValue()) > 0) {
        tweaksToApply.add(mt);
      }
    }
    Collections.sort(tweaksToApply);
    for (    MiscTweak mt : tweaksToApply) {
      romHandler.applyMiscTweak(mt);
    }
  }
  if (settings.isUpdateBaseStats()) {
    romHandler.updatePokemonStats();
  }
switch (settings.getBaseStatisticsMod()) {
case SHUFFLE:
    romHandler.shufflePokemonStats(settings.isBaseStatsFollowEvolutions());
  break;
case RANDOM:
romHandler.randomizePokemonStats(settings.isBaseStatsFollowEvolutions());
break;
default :
break;
}
if (settings.isStandardizeEXPCurves()) {
romHandler.standardizeEXPCurves();
}
if (romHandler.abilitiesPerPokemon() > 0 && settings.getAbilitiesMod() == Settings.AbilitiesMod.RANDOMIZE) {
romHandler.randomizeAbilities(settings.isAbilitiesFollowEvolutions(),settings.isAllowWonderGuard(),settings.isBanTrappingAbilities(),settings.isBanNegativeAbilities());
}
switch (settings.getTypesMod()) {
case RANDOM_FOLLOW_EVOLUTIONS:
romHandler.randomizePokemonTypes(true);
break;
case COMPLETELY_RANDOM:
romHandler.randomizePokemonTypes(false);
break;
default :
break;
}
if (settings.isRandomizeWildPokemonHeldItems()) {
romHandler.randomizeWildHeldItems(settings.isBanBadRandomWildPokemonHeldItems());
}
maybeLogBaseStatAndTypeChanges(log,romHandler);
for (Pokemon pkmn : romHandler.getPokemon()) {
if (pkmn != null) {
checkValue=addToCV(checkValue,pkmn.hp,pkmn.attack,pkmn.defense,pkmn.speed,pkmn.spatk,pkmn.spdef,pkmn.ability1,pkmn.ability2,pkmn.ability3);
}
}
if (settings.getEvolutionsMod() == Settings.EvolutionsMod.RANDOM) {
romHandler.randomizeEvolutions(settings.isEvosSimilarStrength(),settings.isEvosSameTyping(),settings.isEvosMaxThreeStages(),settings.isEvosForceChange());
log.println("String_Node_Str");
List<Pokemon> allPokes=romHandler.getPokemon();
for (Pokemon pk : allPokes) {
if (pk != null) {
int numEvos=pk.evolutionsFrom.size();
if (numEvos > 0) {
StringBuilder evoStr=new StringBuilder(pk.evolutionsFrom.get(0).to.name);
for (int i=1; i < numEvos; i++) {
if (i == numEvos - 1) {
evoStr.append("String_Node_Str" + pk.evolutionsFrom.get(i).to.name);
}
 else {
evoStr.append("String_Node_Str" + pk.evolutionsFrom.get(i).to.name);
}
}
log.println(pk.name + "String_Node_Str" + evoStr.toString());
}
}
}
log.println();
}
if (settings.isChangeImpossibleEvolutions()) {
romHandler.removeTradeEvolutions(!(settings.getMovesetsMod() == Settings.MovesetsMod.UNCHANGED));
}
if (settings.isMakeEvolutionsEasier()) {
romHandler.condenseLevelEvolutions(40,30);
}
maybeChangeAndLogStarters(log,romHandler);
maybeLogMoveChanges(log,romHandler);
boolean noBrokenMoves=settings.doBlockBrokenMoves();
boolean forceFourLv1s=romHandler.supportsFourStartingMoves() && settings.isStartWithFourMoves();
double msGoodDamagingProb=settings.isMovesetsForceGoodDamaging() ? settings.getMovesetsGoodDamagingPercent() / 100.0 : 0;
if (settings.getMovesetsMod() == Settings.MovesetsMod.RANDOM_PREFER_SAME_TYPE) {
romHandler.randomizeMovesLearnt(true,noBrokenMoves,forceFourLv1s,msGoodDamagingProb);
}
 else if (settings.getMovesetsMod() == Settings.MovesetsMod.COMPLETELY_RANDOM) {
romHandler.randomizeMovesLearnt(false,noBrokenMoves,forceFourLv1s,msGoodDamagingProb);
}
if (settings.isReorderDamagingMoves()) {
romHandler.orderDamagingMovesByDamage();
}
if (settings.getMovesetsMod() == Settings.MovesetsMod.UNCHANGED) {
log.println("String_Node_Str" + NEWLINE);
}
 else if (settings.getMovesetsMod() == Settings.MovesetsMod.METRONOME_ONLY) {
log.println("String_Node_Str" + NEWLINE);
}
 else {
log.println("String_Node_Str");
List<String> movesets=new ArrayList<String>();
Map<Pokemon,List<MoveLearnt>> moveData=romHandler.getMovesLearnt();
for (Pokemon pkmn : moveData.keySet()) {
StringBuilder sb=new StringBuilder();
sb.append(String.format("String_Node_Str",pkmn.number,pkmn.name));
List<MoveLearnt> data=moveData.get(pkmn);
boolean first=true;
for (MoveLearnt ml : data) {
if (!first) {
sb.append("String_Node_Str");
}
try {
sb.append(moves.get(ml.move).name).append("String_Node_Str").append(ml.level);
}
 catch (NullPointerException ex) {
sb.append("String_Node_Str" + ml.level);
}
first=false;
}
movesets.add(sb.toString());
}
Collections.sort(movesets);
for (String moveset : movesets) {
log.println(moveset);
}
log.println();
}
if (settings.getTrainersMod() == Settings.TrainersMod.RANDOM) {
romHandler.randomizeTrainerPokes(settings.isTrainersUsePokemonOfSimilarStrength(),settings.isTrainersBlockLegendaries(),settings.isTrainersBlockEarlyWonderGuard());
}
 else if (settings.getTrainersMod() == Settings.TrainersMod.TYPE_THEMED) {
romHandler.typeThemeTrainerPokes(settings.isTrainersUsePokemonOfSimilarStrength(),settings.isTrainersMatchTypingDistribution(),settings.isTrainersBlockLegendaries(),settings.isTrainersBlockEarlyWonderGuard());
}
if ((settings.getTrainersMod() != Settings.TrainersMod.UNCHANGED || settings.getStartersMod() != Settings.StartersMod.UNCHANGED) && settings.isRivalCarriesStarterThroughout()) {
romHandler.rivalCarriesStarter();
}
if (settings.isTrainersForceFullyEvolved()) {
romHandler.forceFullyEvolvedTrainerPokes(settings.getTrainersForceFullyEvolvedLevel());
}
if (settings.isRandomizeTrainerClassNames()) {
romHandler.randomizeTrainerClassNames(settings.getTrainerClasses());
}
if (settings.isRandomizeTrainerNames()) {
romHandler.randomizeTrainerNames(settings.getTrainerNames());
}
maybeLogTrainerChanges(log,romHandler);
if (settings.getMovesetsMod() == Settings.MovesetsMod.METRONOME_ONLY) {
romHandler.metronomeOnlyMode();
}
List<Trainer> trainers=romHandler.getTrainers();
for (Trainer t : trainers) {
for (TrainerPokemon tpk : t.pokemon) {
checkValue=addToCV(checkValue,tpk.level,tpk.pokemon.number);
}
}
checkValue=maybeChangeAndLogStaticPokemon(log,romHandler,raceMode,checkValue);
if (settings.isUseMinimumCatchRate()) {
boolean gen5=romHandler instanceof Gen5RomHandler;
int normalMin, legendaryMin;
switch (settings.getMinimumCatchRateLevel()) {
case 1:
default :
normalMin=gen5 ? 50 : 75;
legendaryMin=gen5 ? 25 : 37;
break;
case 2:
normalMin=gen5 ? 100 : 128;
legendaryMin=gen5 ? 45 : 64;
break;
case 3:
normalMin=gen5 ? 180 : 200;
legendaryMin=gen5 ? 75 : 100;
break;
case 4:
normalMin=legendaryMin=255;
break;
}
romHandler.minimumCatchRate(normalMin,legendaryMin);
}
switch (settings.getWildPokemonMod()) {
case RANDOM:
romHandler.randomEncounters(settings.isUseTimeBasedEncounters(),settings.getWildPokemonRestrictionMod() == Settings.WildPokemonRestrictionMod.CATCH_EM_ALL,settings.getWildPokemonRestrictionMod() == Settings.WildPokemonRestrictionMod.TYPE_THEME_AREAS,settings.getWildPokemonRestrictionMod() == Settings.WildPokemonRestrictionMod.SIMILAR_STRENGTH,settings.isBlockWildLegendaries());
break;
case AREA_MAPPING:
romHandler.area1to1Encounters(settings.isUseTimeBasedEncounters(),settings.getWildPokemonRestrictionMod() == Settings.WildPokemonRestrictionMod.CATCH_EM_ALL,settings.getWildPokemonRestrictionMod() == Settings.WildPokemonRestrictionMod.TYPE_THEME_AREAS,settings.getWildPokemonRestrictionMod() == Settings.WildPokemonRestrictionMod.SIMILAR_STRENGTH,settings.isBlockWildLegendaries());
break;
case GLOBAL_MAPPING:
romHandler.game1to1Encounters(settings.isUseTimeBasedEncounters(),settings.getWildPokemonRestrictionMod() == Settings.WildPokemonRestrictionMod.SIMILAR_STRENGTH,settings.isBlockWildLegendaries());
break;
default :
break;
}
maybeLogWildPokemonChanges(log,romHandler);
List<EncounterSet> encounters=romHandler.getEncounters(settings.isUseTimeBasedEncounters());
for (EncounterSet es : encounters) {
for (Encounter e : es.encounters) {
checkValue=addToCV(checkValue,e.level,e.pokemon.number);
}
}
if (!(settings.getMovesetsMod() == Settings.MovesetsMod.METRONOME_ONLY) && settings.getTmsMod() == Settings.TMsMod.RANDOM) {
double goodDamagingProb=settings.isTmsForceGoodDamaging() ? settings.getTmsGoodDamagingPercent() / 100.0 : 0;
romHandler.randomizeTMMoves(noBrokenMoves,settings.isKeepFieldMoveTMs(),goodDamagingProb);
log.println("String_Node_Str");
List<Integer> tmMoves=romHandler.getTMMoves();
for (int i=0; i < tmMoves.size(); i++) {
log.printf("String_Node_Str" + NEWLINE,i + 1,moves.get(tmMoves.get(i)).name);
checkValue=addToCV(checkValue,tmMoves.get(i));
}
log.println();
}
 else if (settings.getMovesetsMod() == Settings.MovesetsMod.METRONOME_ONLY) {
log.println("String_Node_Str" + NEWLINE);
}
 else {
log.println("String_Node_Str" + NEWLINE);
}
switch (settings.getTmsHmsCompatibilityMod()) {
case RANDOM_PREFER_TYPE:
romHandler.randomizeTMHMCompatibility(true);
break;
case COMPLETELY_RANDOM:
romHandler.randomizeTMHMCompatibility(false);
break;
case FULL:
romHandler.fullTMHMCompatibility();
break;
default :
break;
}
if (settings.isTmLevelUpMoveSanity()) {
romHandler.ensureTMCompatSanity();
}
if (settings.isFullHMCompat()) {
romHandler.fullHMCompatibility();
}
if (romHandler.hasMoveTutors()) {
if (!(settings.getMovesetsMod() == Settings.MovesetsMod.METRONOME_ONLY) && settings.getMoveTutorMovesMod() == Settings.MoveTutorMovesMod.RANDOM) {
List<Integer> oldMtMoves=romHandler.getMoveTutorMoves();
double goodDamagingProb=settings.isTutorsForceGoodDamaging() ? settings.getTutorsGoodDamagingPercent() / 100.0 : 0;
romHandler.randomizeMoveTutorMoves(noBrokenMoves,settings.isKeepFieldMoveTutors(),goodDamagingProb);
log.println("String_Node_Str");
List<Integer> newMtMoves=romHandler.getMoveTutorMoves();
for (int i=0; i < newMtMoves.size(); i++) {
log.printf("String_Node_Str" + NEWLINE,moves.get(oldMtMoves.get(i)).name,moves.get(newMtMoves.get(i)).name);
checkValue=addToCV(checkValue,newMtMoves.get(i));
}
log.println();
}
 else if (settings.getMovesetsMod() == Settings.MovesetsMod.METRONOME_ONLY) {
log.println("String_Node_Str" + NEWLINE);
}
 else {
log.println("String_Node_Str" + NEWLINE);
}
switch (settings.getMoveTutorsCompatibilityMod()) {
case RANDOM_PREFER_TYPE:
romHandler.randomizeMoveTutorCompatibility(true);
break;
case COMPLETELY_RANDOM:
romHandler.randomizeMoveTutorCompatibility(false);
break;
case FULL:
romHandler.fullMoveTutorCompatibility();
break;
default :
break;
}
if (settings.isTutorLevelUpMoveSanity()) {
romHandler.ensureMoveTutorCompatSanity();
}
}
List<IngameTrade> oldTrades=romHandler.getIngameTrades();
if (settings.getInGameTradesMod() == Settings.InGameTradesMod.RANDOMIZE_GIVEN) {
romHandler.randomizeIngameTrades(false,settings.getNicknames(),settings.isRandomizeInGameTradesNicknames(),settings.getTrainerNames(),settings.isRandomizeInGameTradesOTs(),settings.isRandomizeInGameTradesIVs(),settings.isRandomizeInGameTradesItems());
}
 else if (settings.getInGameTradesMod() == Settings.InGameTradesMod.RANDOMIZE_GIVEN_AND_REQUESTED) {
romHandler.randomizeIngameTrades(true,settings.getNicknames(),settings.isRandomizeInGameTradesNicknames(),settings.getTrainerNames(),settings.isRandomizeInGameTradesOTs(),settings.isRandomizeInGameTradesIVs(),settings.isRandomizeInGameTradesItems());
}
if (!(settings.getInGameTradesMod() == Settings.InGameTradesMod.UNCHANGED)) {
log.println("String_Node_Str");
List<IngameTrade> newTrades=romHandler.getIngameTrades();
int size=oldTrades.size();
for (int i=0; i < size; i++) {
IngameTrade oldT=oldTrades.get(i);
IngameTrade newT=newTrades.get(i);
log.printf("String_Node_Str" + NEWLINE,oldT.requestedPokemon.name,oldT.nickname,oldT.givenPokemon.name,newT.requestedPokemon.name,newT.nickname,newT.givenPokemon.name);
}
log.println();
}
if (settings.getFieldItemsMod() == Settings.FieldItemsMod.SHUFFLE) {
romHandler.shuffleFieldItems();
}
 else if (settings.getFieldItemsMod() == Settings.FieldItemsMod.RANDOM) {
romHandler.randomizeFieldItems(settings.isBanBadRandomFieldItems());
}
romHandler.applySignature();
romHandler.writeCheckValueToROM(checkValue);
romHandler.saveRom(filename);
log.println("String_Node_Str");
log.println("String_Node_Str" + romHandler.getROMName() + "String_Node_Str");
log.println("String_Node_Str" + (System.currentTimeMillis() - startTime) + "String_Node_Str");
log.println("String_Node_Str" + RandomSource.callsSinceSeed());
log.println("String_Node_Str");
return checkValue;
}

Fixed version (ground truth):
public int randomize(final String filename,final PrintStream log,long seed){
  final long startTime=System.currentTimeMillis();
  RandomSource.seed(seed);
  final boolean raceMode=settings.isRaceMode();
  int checkValue=0;
  if (settings.isLimitPokemon()) {
    romHandler.setPokemonPool(settings.getCurrentRestrictions());
    romHandler.removeEvosForPokemonPool();
  }
 else {
    romHandler.setPokemonPool(null);
  }
  if (settings.isUpdateMoves()) {
    romHandler.initMoveUpdates();
    if (!(romHandler instanceof Gen5RomHandler)) {
      romHandler.updateMovesToGen5();
    }
    if (!settings.isUpdateMovesLegacy()) {
      romHandler.updateMovesToGen6();
    }
    romHandler.printMoveUpdates();
  }
  if (settings.isRandomizeMovePowers()) {
    romHandler.randomizeMovePowers();
  }
  if (settings.isRandomizeMoveAccuracies()) {
    romHandler.randomizeMoveAccuracies();
  }
  if (settings.isRandomizeMovePPs()) {
    romHandler.randomizeMovePPs();
  }
  if (settings.isRandomizeMoveTypes()) {
    romHandler.randomizeMoveTypes();
  }
  if (settings.isRandomizeMoveCategory() && romHandler.hasPhysicalSpecialSplit()) {
    romHandler.randomizeMoveCategory();
  }
  List<Move> moves=romHandler.getMoves();
  int currentMiscTweaks=settings.getCurrentMiscTweaks();
  if (romHandler.miscTweaksAvailable() != 0) {
    int codeTweaksAvailable=romHandler.miscTweaksAvailable();
    List<MiscTweak> tweaksToApply=new ArrayList<MiscTweak>();
    for (    MiscTweak mt : MiscTweak.allTweaks) {
      if ((codeTweaksAvailable & mt.getValue()) > 0 && (currentMiscTweaks & mt.getValue()) > 0) {
        tweaksToApply.add(mt);
      }
    }
    Collections.sort(tweaksToApply);
    for (    MiscTweak mt : tweaksToApply) {
      romHandler.applyMiscTweak(mt);
    }
  }
  if (settings.isUpdateBaseStats()) {
    romHandler.updatePokemonStats();
  }
switch (settings.getBaseStatisticsMod()) {
case SHUFFLE:
    romHandler.shufflePokemonStats(settings.isBaseStatsFollowEvolutions());
  break;
case RANDOM:
romHandler.randomizePokemonStats(settings.isBaseStatsFollowEvolutions());
break;
default :
break;
}
if (settings.isStandardizeEXPCurves()) {
romHandler.standardizeEXPCurves();
}
if (romHandler.abilitiesPerPokemon() > 0 && settings.getAbilitiesMod() == Settings.AbilitiesMod.RANDOMIZE) {
romHandler.randomizeAbilities(settings.isAbilitiesFollowEvolutions(),settings.isAllowWonderGuard(),settings.isBanTrappingAbilities(),settings.isBanNegativeAbilities());
}
switch (settings.getTypesMod()) {
case RANDOM_FOLLOW_EVOLUTIONS:
romHandler.randomizePokemonTypes(true);
break;
case COMPLETELY_RANDOM:
romHandler.randomizePokemonTypes(false);
break;
default :
break;
}
if (settings.isRandomizeWildPokemonHeldItems()) {
romHandler.randomizeWildHeldItems(settings.isBanBadRandomWildPokemonHeldItems());
}
maybeLogBaseStatAndTypeChanges(log,romHandler);
for (Pokemon pkmn : romHandler.getPokemon()) {
if (pkmn != null) {
checkValue=addToCV(checkValue,pkmn.hp,pkmn.attack,pkmn.defense,pkmn.speed,pkmn.spatk,pkmn.spdef,pkmn.ability1,pkmn.ability2,pkmn.ability3);
}
}
if (settings.getEvolutionsMod() == Settings.EvolutionsMod.RANDOM) {
romHandler.randomizeEvolutions(settings.isEvosSimilarStrength(),settings.isEvosSameTyping(),settings.isEvosMaxThreeStages(),settings.isEvosForceChange());
log.println("String_Node_Str");
List<Pokemon> allPokes=romHandler.getPokemon();
for (Pokemon pk : allPokes) {
if (pk != null) {
int numEvos=pk.evolutionsFrom.size();
if (numEvos > 0) {
StringBuilder evoStr=new StringBuilder(pk.evolutionsFrom.get(0).to.name);
for (int i=1; i < numEvos; i++) {
if (i == numEvos - 1) {
evoStr.append("String_Node_Str" + pk.evolutionsFrom.get(i).to.name);
}
 else {
evoStr.append("String_Node_Str" + pk.evolutionsFrom.get(i).to.name);
}
}
log.println(pk.name + "String_Node_Str" + evoStr.toString());
}
}
}
log.println();
}
if (settings.isChangeImpossibleEvolutions()) {
romHandler.removeTradeEvolutions(!(settings.getMovesetsMod() == Settings.MovesetsMod.UNCHANGED));
}
if (settings.isMakeEvolutionsEasier()) {
romHandler.condenseLevelEvolutions(40,30);
}
maybeChangeAndLogStarters(log,romHandler);
maybeLogMoveChanges(log,romHandler);
boolean noBrokenMoves=settings.doBlockBrokenMoves();
boolean forceFourLv1s=romHandler.supportsFourStartingMoves() && settings.isStartWithFourMoves();
double msGoodDamagingProb=settings.isMovesetsForceGoodDamaging() ? settings.getMovesetsGoodDamagingPercent() / 100.0 : 0;
if (settings.getMovesetsMod() == Settings.MovesetsMod.RANDOM_PREFER_SAME_TYPE) {
romHandler.randomizeMovesLearnt(true,noBrokenMoves,forceFourLv1s,msGoodDamagingProb);
}
 else if (settings.getMovesetsMod() == Settings.MovesetsMod.COMPLETELY_RANDOM) {
romHandler.randomizeMovesLearnt(false,noBrokenMoves,forceFourLv1s,msGoodDamagingProb);
}
if (settings.isReorderDamagingMoves()) {
romHandler.orderDamagingMovesByDamage();
}
if (settings.getMovesetsMod() == Settings.MovesetsMod.UNCHANGED) {
log.println("String_Node_Str" + NEWLINE);
}
 else if (settings.getMovesetsMod() == Settings.MovesetsMod.METRONOME_ONLY) {
log.println("String_Node_Str" + NEWLINE);
}
 else {
log.println("String_Node_Str");
List<String> movesets=new ArrayList<String>();
Map<Pokemon,List<MoveLearnt>> moveData=romHandler.getMovesLearnt();
for (Pokemon pkmn : moveData.keySet()) {
StringBuilder sb=new StringBuilder();
sb.append(String.format("String_Node_Str",pkmn.number,pkmn.name));
List<MoveLearnt> data=moveData.get(pkmn);
boolean first=true;
for (MoveLearnt ml : data) {
if (!first) {
sb.append("String_Node_Str");
}
try {
sb.append(moves.get(ml.move).name).append("String_Node_Str").append(ml.level);
}
 catch (NullPointerException ex) {
sb.append("String_Node_Str" + ml.level);
}
first=false;
}
movesets.add(sb.toString());
}
Collections.sort(movesets);
for (String moveset : movesets) {
log.println(moveset);
}
log.println();
}
if (settings.getTrainersMod() == Settings.TrainersMod.RANDOM) {
romHandler.randomizeTrainerPokes(settings.isTrainersUsePokemonOfSimilarStrength(),settings.isTrainersBlockLegendaries(),settings.isTrainersBlockEarlyWonderGuard());
}
 else if (settings.getTrainersMod() == Settings.TrainersMod.TYPE_THEMED) {
romHandler.typeThemeTrainerPokes(settings.isTrainersUsePokemonOfSimilarStrength(),settings.isTrainersMatchTypingDistribution(),settings.isTrainersBlockLegendaries(),settings.isTrainersBlockEarlyWonderGuard());
}
if ((settings.getTrainersMod() != Settings.TrainersMod.UNCHANGED || settings.getStartersMod() != Settings.StartersMod.UNCHANGED) && settings.isRivalCarriesStarterThroughout()) {
romHandler.rivalCarriesStarter();
}
if (settings.isTrainersForceFullyEvolved()) {
romHandler.forceFullyEvolvedTrainerPokes(settings.getTrainersForceFullyEvolvedLevel());
}
if (romHandler.canChangeTrainerText()) {
if (settings.isRandomizeTrainerClassNames()) {
romHandler.randomizeTrainerClassNames(settings.getTrainerClasses());
}
if (settings.isRandomizeTrainerNames()) {
romHandler.randomizeTrainerNames(settings.getTrainerNames());
}
}
maybeLogTrainerChanges(log,romHandler);
if (settings.getMovesetsMod() == Settings.MovesetsMod.METRONOME_ONLY) {
romHandler.metronomeOnlyMode();
}
List<Trainer> trainers=romHandler.getTrainers();
for (Trainer t : trainers) {
for (TrainerPokemon tpk : t.pokemon) {
checkValue=addToCV(checkValue,tpk.level,tpk.pokemon.number);
}
}
checkValue=maybeChangeAndLogStaticPokemon(log,romHandler,raceMode,checkValue);
if (settings.isUseMinimumCatchRate()) {
boolean gen5=romHandler instanceof Gen5RomHandler;
int normalMin, legendaryMin;
switch (settings.getMinimumCatchRateLevel()) {
case 1:
default :
normalMin=gen5 ? 50 : 75;
legendaryMin=gen5 ? 25 : 37;
break;
case 2:
normalMin=gen5 ? 100 : 128;
legendaryMin=gen5 ? 45 : 64;
break;
case 3:
normalMin=gen5 ? 180 : 200;
legendaryMin=gen5 ? 75 : 100;
break;
case 4:
normalMin=legendaryMin=255;
break;
}
romHandler.minimumCatchRate(normalMin,legendaryMin);
}
switch (settings.getWildPokemonMod()) {
case RANDOM:
romHandler.randomEncounters(settings.isUseTimeBasedEncounters(),settings.getWildPokemonRestrictionMod() == Settings.WildPokemonRestrictionMod.CATCH_EM_ALL,settings.getWildPokemonRestrictionMod() == Settings.WildPokemonRestrictionMod.TYPE_THEME_AREAS,settings.getWildPokemonRestrictionMod() == Settings.WildPokemonRestrictionMod.SIMILAR_STRENGTH,settings.isBlockWildLegendaries());
break;
case AREA_MAPPING:
romHandler.area1to1Encounters(settings.isUseTimeBasedEncounters(),settings.getWildPokemonRestrictionMod() == Settings.WildPokemonRestrictionMod.CATCH_EM_ALL,settings.getWildPokemonRestrictionMod() == Settings.WildPokemonRestrictionMod.TYPE_THEME_AREAS,settings.getWildPokemonRestrictionMod() == Settings.WildPokemonRestrictionMod.SIMILAR_STRENGTH,settings.isBlockWildLegendaries());
break;
case GLOBAL_MAPPING:
romHandler.game1to1Encounters(settings.isUseTimeBasedEncounters(),settings.getWildPokemonRestrictionMod() == Settings.WildPokemonRestrictionMod.SIMILAR_STRENGTH,settings.isBlockWildLegendaries());
break;
default :
break;
}
maybeLogWildPokemonChanges(log,romHandler);
List<EncounterSet> encounters=romHandler.getEncounters(settings.isUseTimeBasedEncounters());
for (EncounterSet es : encounters) {
for (Encounter e : es.encounters) {
checkValue=addToCV(checkValue,e.level,e.pokemon.number);
}
}
if (!(settings.getMovesetsMod() == Settings.MovesetsMod.METRONOME_ONLY) && settings.getTmsMod() == Settings.TMsMod.RANDOM) {
double goodDamagingProb=settings.isTmsForceGoodDamaging() ? settings.getTmsGoodDamagingPercent() / 100.0 : 0;
romHandler.randomizeTMMoves(noBrokenMoves,settings.isKeepFieldMoveTMs(),goodDamagingProb);
log.println("String_Node_Str");
List<Integer> tmMoves=romHandler.getTMMoves();
for (int i=0; i < tmMoves.size(); i++) {
log.printf("String_Node_Str" + NEWLINE,i + 1,moves.get(tmMoves.get(i)).name);
checkValue=addToCV(checkValue,tmMoves.get(i));
}
log.println();
}
 else if (settings.getMovesetsMod() == Settings.MovesetsMod.METRONOME_ONLY) {
log.println("String_Node_Str" + NEWLINE);
}
 else {
log.println("String_Node_Str" + NEWLINE);
}
switch (settings.getTmsHmsCompatibilityMod()) {
case RANDOM_PREFER_TYPE:
romHandler.randomizeTMHMCompatibility(true);
break;
case COMPLETELY_RANDOM:
romHandler.randomizeTMHMCompatibility(false);
break;
case FULL:
romHandler.fullTMHMCompatibility();
break;
default :
break;
}
if (settings.isTmLevelUpMoveSanity()) {
romHandler.ensureTMCompatSanity();
}
if (settings.isFullHMCompat()) {
romHandler.fullHMCompatibility();
}
if (romHandler.hasMoveTutors()) {
if (!(settings.getMovesetsMod() == Settings.MovesetsMod.METRONOME_ONLY) && settings.getMoveTutorMovesMod() == Settings.MoveTutorMovesMod.RANDOM) {
List<Integer> oldMtMoves=romHandler.getMoveTutorMoves();
double goodDamagingProb=settings.isTutorsForceGoodDamaging() ? settings.getTutorsGoodDamagingPercent() / 100.0 : 0;
romHandler.randomizeMoveTutorMoves(noBrokenMoves,settings.isKeepFieldMoveTutors(),goodDamagingProb);
log.println("String_Node_Str");
List<Integer> newMtMoves=romHandler.getMoveTutorMoves();
for (int i=0; i < newMtMoves.size(); i++) {
log.printf("String_Node_Str" + NEWLINE,moves.get(oldMtMoves.get(i)).name,moves.get(newMtMoves.get(i)).name);
checkValue=addToCV(checkValue,newMtMoves.get(i));
}
log.println();
}
 else if (settings.getMovesetsMod() == Settings.MovesetsMod.METRONOME_ONLY) {
log.println("String_Node_Str" + NEWLINE);
}
 else {
log.println("String_Node_Str" + NEWLINE);
}
switch (settings.getMoveTutorsCompatibilityMod()) {
case RANDOM_PREFER_TYPE:
romHandler.randomizeMoveTutorCompatibility(true);
break;
case COMPLETELY_RANDOM:
romHandler.randomizeMoveTutorCompatibility(false);
break;
case FULL:
romHandler.fullMoveTutorCompatibility();
break;
default :
break;
}
if (settings.isTutorLevelUpMoveSanity()) {
romHandler.ensureMoveTutorCompatSanity();
}
}
List<IngameTrade> oldTrades=romHandler.getIngameTrades();
if (settings.getInGameTradesMod() == Settings.InGameTradesMod.RANDOMIZE_GIVEN) {
romHandler.randomizeIngameTrades(false,settings.getNicknames(),settings.isRandomizeInGameTradesNicknames(),settings.getTrainerNames(),settings.isRandomizeInGameTradesOTs(),settings.isRandomizeInGameTradesIVs(),settings.isRandomizeInGameTradesItems());
}
 else if (settings.getInGameTradesMod() == Settings.InGameTradesMod.RANDOMIZE_GIVEN_AND_REQUESTED) {
romHandler.randomizeIngameTrades(true,settings.getNicknames(),settings.isRandomizeInGameTradesNicknames(),settings.getTrainerNames(),settings.isRandomizeInGameTradesOTs(),settings.isRandomizeInGameTradesIVs(),settings.isRandomizeInGameTradesItems());
}
if (!(settings.getInGameTradesMod() == Settings.InGameTradesMod.UNCHANGED)) {
log.println("String_Node_Str");
List<IngameTrade> newTrades=romHandler.getIngameTrades();
int size=oldTrades.size();
for (int i=0; i < size; i++) {
IngameTrade oldT=oldTrades.get(i);
IngameTrade newT=newTrades.get(i);
log.printf("String_Node_Str" + NEWLINE,oldT.requestedPokemon.name,oldT.nickname,oldT.givenPokemon.name,newT.requestedPokemon.name,newT.nickname,newT.givenPokemon.name);
}
log.println();
}
if (settings.getFieldItemsMod() == Settings.FieldItemsMod.SHUFFLE) {
romHandler.shuffleFieldItems();
}
 else if (settings.getFieldItemsMod() == Settings.FieldItemsMod.RANDOM) {
romHandler.randomizeFieldItems(settings.isBanBadRandomFieldItems());
}
romHandler.applySignature();
romHandler.writeCheckValueToROM(checkValue);
romHandler.saveRom(filename);
log.println("String_Node_Str");
log.println("String_Node_Str" + romHandler.getROMName() + "String_Node_Str");
log.println("String_Node_Str" + (System.currentTimeMillis() - startTime) + "String_Node_Str");
log.println("String_Node_Str" + RandomSource.callsSinceSeed());
log.println("String_Node_Str");
return checkValue;
}