Skip to content

Commit

Permalink
Tighten up weight table handling for morning fog
Browse files Browse the repository at this point in the history
  • Loading branch information
OreCruncher committed Jan 4, 2025
1 parent 6b69db6 commit 3df1a75
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,7 @@ public static <T> Optional<T> makeSelection(final List<? extends IItem<T>> selec
if (selections.size() == 1)
return Optional.of(selections.getFirst().data());

int totalWeight = WeightedRandom.getTotalWeight(selections);

if (totalWeight == 0)
return Optional.empty();

int targetWeight = randomizer.nextInt(totalWeight);
return WeightedRandom.getWeightedItem(selections, targetWeight).map(IItem::data);
return WeightedRandom.getRandomItem(randomizer, selections).map(IItem::data);
}

public interface IItem<T> extends WeightedEntry {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,9 @@ else if (this.seasonInfo.isWinter())
// Shouldn't get here, but...
return FogDensity.NONE;

var totalWeight = WeightedRandom.getTotalWeight(selections);
var targetWeight = Randomizer.current().nextInt(totalWeight);
return WeightedRandom.getWeightedItem(selections, targetWeight).map(WeightedEntry.Wrapper::data).orElseThrow();
return WeightedRandom
.getRandomItem(Randomizer.current(), selections)
.map(WeightedEntry.Wrapper::data)
.orElseThrow();
}
}

0 comments on commit 3df1a75

Please sign in to comment.