diff options
author | tom-overton <tom.overton@outlook.com> | 2021-09-18 03:40:24 -0700 |
---|---|---|
committer | tom-overton <tom.overton@outlook.com> | 2021-09-18 03:41:37 -0700 |
commit | 9729580efa8819a19a81cb96c566558077bfe79b (patch) | |
tree | 2687dba10e25b9bbdda21c71d2db681ecbddf164 /src | |
parent | 85ebbc75af711207702ee386c405621127ad3512 (diff) |
Improve logging of Pickup items
Before, we were just logging the items based on what they replaced.
Most people probably don't have the vanilla Pickup tables memorized, so
instead we now log the probability of every item for each level range.
This leads to some redundancy in R/S and FR/LG but oh well.
Diffstat (limited to 'src')
9 files changed, 189 insertions, 45 deletions
diff --git a/src/com/dabomstew/pkrandom/Randomizer.java b/src/com/dabomstew/pkrandom/Randomizer.java index 28d741f..c48d3ee 100644 --- a/src/com/dabomstew/pkrandom/Randomizer.java +++ b/src/com/dabomstew/pkrandom/Randomizer.java @@ -645,9 +645,8 @@ public class Randomizer { // Pickup Items
if (settings.getPickupItemsMod() == Settings.PickupItemsMod.RANDOM) {
- List<Integer> oldPickupItems = romHandler.getPickupItems();
romHandler.randomizePickupItems(settings);
- logPickupItems(log, oldPickupItems);
+ logPickupItems(log);
}
// Test output for placement history
@@ -1225,14 +1224,33 @@ public class Randomizer { log.println();
}
- private void logPickupItems(final PrintStream log, List<Integer> oldPickupItems) {
- List<Integer> pickupItems = romHandler.getPickupItems();
+ private void logPickupItems(final PrintStream log) {
+ List<PickupItem> pickupItems = romHandler.getPickupItems();
String[] itemNames = romHandler.getItemNames();
log.println("--Pickup Items--");
- for (int i = 0; i < oldPickupItems.size(); i++) {
- int item = pickupItems.get(i);
- int oldItem = oldPickupItems.get(i);
- log.printf("%s => %s", itemNames[oldItem], itemNames[item]);
+ for (int levelRange = 0; levelRange < 10; levelRange++) {
+ int startingLevel = (levelRange * 10) + 1;
+ int endingLevel = (levelRange + 1) * 10;
+ log.printf("Level %s-%s", startingLevel, endingLevel);
+ log.println();
+ TreeMap<Integer, List<String>> itemListPerProbability = new TreeMap<>();
+ for (PickupItem pickupItem : pickupItems) {
+ int probability = pickupItem.probabilities[levelRange];
+ if (itemListPerProbability.containsKey(probability)) {
+ itemListPerProbability.get(probability).add(itemNames[pickupItem.item]);
+ } else if (probability > 0) {
+ List<String> itemList = new ArrayList<>();
+ itemList.add(itemNames[pickupItem.item]);
+ itemListPerProbability.put(probability, itemList);
+ }
+ }
+ for (Map.Entry<Integer, List<String>> itemListPerProbabilityEntry : itemListPerProbability.descendingMap().entrySet()) {
+ int probability = itemListPerProbabilityEntry.getKey();
+ List<String> itemList = itemListPerProbabilityEntry.getValue();
+ String itemsString = String.join(", ", itemList);
+ log.printf("%d%%: %s", probability, itemsString);
+ log.println();
+ }
log.println();
}
log.println();
diff --git a/src/com/dabomstew/pkrandom/pokemon/PickupItem.java b/src/com/dabomstew/pkrandom/pokemon/PickupItem.java new file mode 100644 index 0000000..601ee7e --- /dev/null +++ b/src/com/dabomstew/pkrandom/pokemon/PickupItem.java @@ -0,0 +1,11 @@ +package com.dabomstew.pkrandom.pokemon; + +public class PickupItem { + public int item; + public int[] probabilities; + + public PickupItem(int item) { + this.item = item; + this.probabilities = new int[10]; + } +} diff --git a/src/com/dabomstew/pkrandom/romhandlers/AbstractRomHandler.java b/src/com/dabomstew/pkrandom/romhandlers/AbstractRomHandler.java index 1e9e151..b35ff48 100755 --- a/src/com/dabomstew/pkrandom/romhandlers/AbstractRomHandler.java +++ b/src/com/dabomstew/pkrandom/romhandlers/AbstractRomHandler.java @@ -4904,16 +4904,19 @@ public abstract class AbstractRomHandler implements RomHandler { boolean banBadItems = settings.isBanBadRandomPickupItems();
ItemList possibleItems = banBadItems ? this.getNonBadItems() : this.getAllowedItems();
- List<Integer> currentItems = this.getPickupItems();
- List<Integer> newItems = new ArrayList<>();
+ List<PickupItem> currentItems = this.getPickupItems();
+ List<PickupItem> newItems = new ArrayList<>();
for (int i = 0; i < currentItems.size(); i++) {
+ int item;
if (this.generationOfPokemon() == 3 || this.generationOfPokemon() == 4) {
// Allow TMs in Gen 3/4 since they aren't infinite (and you get TMs from Pickup in the vanilla game)
- newItems.add(possibleItems.randomItem(this.random));
+ item = possibleItems.randomItem(this.random);
} else {
- newItems.add(possibleItems.randomNonTM(this.random));
+ item = possibleItems.randomNonTM(this.random);
}
-
+ PickupItem pickupItem = new PickupItem(item);
+ pickupItem.probabilities = Arrays.copyOf(currentItems.get(i).probabilities, currentItems.size());
+ newItems.add(pickupItem);
}
this.setPickupItems(newItems);
@@ -6368,12 +6371,12 @@ public abstract class AbstractRomHandler implements RomHandler { }
@Override
- public List<Integer> getPickupItems() {
+ public List<PickupItem> getPickupItems() {
return new ArrayList<>();
}
@Override
- public void setPickupItems(List<Integer> pickupItems) {
+ public void setPickupItems(List<PickupItem> pickupItems) {
// do nothing
}
}
diff --git a/src/com/dabomstew/pkrandom/romhandlers/Gen3RomHandler.java b/src/com/dabomstew/pkrandom/romhandlers/Gen3RomHandler.java index 4a14722..0ae3d46 100755 --- a/src/com/dabomstew/pkrandom/romhandlers/Gen3RomHandler.java +++ b/src/com/dabomstew/pkrandom/romhandlers/Gen3RomHandler.java @@ -2770,11 +2770,12 @@ public class Gen3RomHandler extends AbstractGBRomHandler { }
@Override
- public List<Integer> getPickupItems() {
- List<Integer> pickupItems = new ArrayList<>();
+ public List<PickupItem> getPickupItems() {
+ List<PickupItem> pickupItems = new ArrayList<>();
int pickupItemCount = romEntry.getValue("PickupItemCount");
int sizeOfPickupEntry = romEntry.romType == Gen3Constants.RomType_Em ? 2 : 4;
+ // If we haven't found the pickup table for this ROM already, find it.
if (pickupItemsTableOffset == 0) {
String pickupTableStartLocator = romEntry.getString("PickupTableStartLocator");
int offset = find(pickupTableStartLocator);
@@ -2783,23 +2784,66 @@ public class Gen3RomHandler extends AbstractGBRomHandler { }
}
+ // Assuming we've found the pickup table, extract the items out of it.
if (pickupItemsTableOffset > 0) {
for (int i = 0; i < pickupItemCount; i++) {
int itemOffset = pickupItemsTableOffset + (sizeOfPickupEntry * i);
int item = FileFunctions.read2ByteInt(rom, itemOffset);
- pickupItems.add(item);
+ PickupItem pickupItem = new PickupItem(item);
+ pickupItems.add(pickupItem);
+ }
+ }
+
+ // Assuming we got the items from the last step, fill out the probabilities based on the game.
+ if (pickupItems.size() > 0) {
+ if (romEntry.romType == Gen3Constants.RomType_Ruby || romEntry.romType == Gen3Constants.RomType_Sapp) {
+ for (int levelRange = 0; levelRange < 10; levelRange++) {
+ pickupItems.get(0).probabilities[levelRange] = 30;
+ pickupItems.get(7).probabilities[levelRange] = 5;
+ pickupItems.get(8).probabilities[levelRange] = 4;
+ pickupItems.get(9).probabilities[levelRange] = 1;
+ for (int i = 1; i < 7; i++) {
+ pickupItems.get(i).probabilities[levelRange] = 10;
+ }
+ }
+ } else if (romEntry.romType == Gen3Constants.RomType_FRLG) {
+ for (int levelRange = 0; levelRange < 10; levelRange++) {
+ pickupItems.get(0).probabilities[levelRange] = 15;
+ for (int i = 1; i < 7; i++) {
+ pickupItems.get(i).probabilities[levelRange] = 10;
+ }
+ for (int i = 7; i < 11; i++) {
+ pickupItems.get(i).probabilities[levelRange] = 5;
+ }
+ for (int i = 11; i < 16; i++) {
+ pickupItems.get(i).probabilities[levelRange] = 1;
+ }
+ }
+ } else {
+ for (int levelRange = 0; levelRange < 10; levelRange++) {
+ int startingCommonItemOffset = levelRange;
+ int startingRareItemOffset = 18 + levelRange;
+ pickupItems.get(startingCommonItemOffset).probabilities[levelRange] = 30;
+ for (int i = 1; i < 7; i++) {
+ pickupItems.get(startingCommonItemOffset + i).probabilities[levelRange] = 10;
+ }
+ pickupItems.get(startingCommonItemOffset + 7).probabilities[levelRange] = 4;
+ pickupItems.get(startingCommonItemOffset + 8).probabilities[levelRange] = 4;
+ pickupItems.get(startingRareItemOffset).probabilities[levelRange] = 1;
+ pickupItems.get(startingRareItemOffset + 1).probabilities[levelRange] = 1;
+ }
}
}
return pickupItems;
}
@Override
- public void setPickupItems(List<Integer> pickupItems) {
+ public void setPickupItems(List<PickupItem> pickupItems) {
int sizeOfPickupEntry = romEntry.romType == Gen3Constants.RomType_Em ? 2 : 4;
if (pickupItemsTableOffset > 0) {
for (int i = 0; i < pickupItems.size(); i++) {
int itemOffset = pickupItemsTableOffset + (sizeOfPickupEntry * i);
- FileFunctions.write2ByteInt(rom, itemOffset, pickupItems.get(i));
+ FileFunctions.write2ByteInt(rom, itemOffset, pickupItems.get(i).item);
}
}
}
diff --git a/src/com/dabomstew/pkrandom/romhandlers/Gen4RomHandler.java b/src/com/dabomstew/pkrandom/romhandlers/Gen4RomHandler.java index aab3628..a23e8c7 100755 --- a/src/com/dabomstew/pkrandom/romhandlers/Gen4RomHandler.java +++ b/src/com/dabomstew/pkrandom/romhandlers/Gen4RomHandler.java @@ -3997,8 +3997,8 @@ public class Gen4RomHandler extends AbstractDSRomHandler { }
@Override
- public List<Integer> getPickupItems() {
- List<Integer> pickupItems = new ArrayList<>();
+ public List<PickupItem> getPickupItems() {
+ List<PickupItem> pickupItems = new ArrayList<>();
try {
byte[] battleOverlay = readOverlay(romEntry.getInt("BattleOvlNumber"));
if (pickupItemsTableOffset == 0) {
@@ -4007,22 +4007,44 @@ public class Gen4RomHandler extends AbstractDSRomHandler { pickupItemsTableOffset = offset;
}
}
+
+ // If we haven't found the pickup table for this ROM already, find it.
if (rarePickupItemsTableOffset == 0) {
int offset = find(battleOverlay, Gen4Constants.rarePickupTableLocator);
if (offset > 0) {
rarePickupItemsTableOffset = offset;
}
}
+
+ // Assuming we've found the pickup table, extract the items out of it.
if (pickupItemsTableOffset > 0 && rarePickupItemsTableOffset > 0) {
for (int i = 0; i < Gen4Constants.numberOfCommonPickupItems; i++) {
int itemOffset = pickupItemsTableOffset + (2 * i);
int item = FileFunctions.read2ByteInt(battleOverlay, itemOffset);
- pickupItems.add(item);
+ PickupItem pickupItem = new PickupItem(item);
+ pickupItems.add(pickupItem);
}
for (int i = 0; i < Gen4Constants.numberOfRarePickupItems; i++) {
int itemOffset = rarePickupItemsTableOffset + (2 * i);
int item = FileFunctions.read2ByteInt(battleOverlay, itemOffset);
- pickupItems.add(item);
+ PickupItem pickupItem = new PickupItem(item);
+ pickupItems.add(pickupItem);
+ }
+ }
+
+ // Assuming we got the items from the last step, fill out the probabilities.
+ if (pickupItems.size() > 0) {
+ for (int levelRange = 0; levelRange < 10; levelRange++) {
+ int startingCommonItemOffset = levelRange;
+ int startingRareItemOffset = 18 + levelRange;
+ pickupItems.get(startingCommonItemOffset).probabilities[levelRange] = 30;
+ for (int i = 1; i < 7; i++) {
+ pickupItems.get(startingCommonItemOffset + i).probabilities[levelRange] = 10;
+ }
+ pickupItems.get(startingCommonItemOffset + 7).probabilities[levelRange] = 4;
+ pickupItems.get(startingCommonItemOffset + 8).probabilities[levelRange] = 4;
+ pickupItems.get(startingRareItemOffset).probabilities[levelRange] = 1;
+ pickupItems.get(startingRareItemOffset + 1).probabilities[levelRange] = 1;
}
}
} catch (IOException e) {
@@ -4032,19 +4054,19 @@ public class Gen4RomHandler extends AbstractDSRomHandler { }
@Override
- public void setPickupItems(List<Integer> pickupItems) {
+ public void setPickupItems(List<PickupItem> pickupItems) {
try {
if (pickupItemsTableOffset > 0 && rarePickupItemsTableOffset > 0) {
byte[] battleOverlay = readOverlay(romEntry.getInt("BattleOvlNumber"));
- Iterator<Integer> itemIterator = pickupItems.iterator();
+ Iterator<PickupItem> itemIterator = pickupItems.iterator();
for (int i = 0; i < Gen4Constants.numberOfCommonPickupItems; i++) {
int itemOffset = pickupItemsTableOffset + (2 * i);
- int item = itemIterator.next();
+ int item = itemIterator.next().item;
FileFunctions.write2ByteInt(battleOverlay, itemOffset, item);
}
for (int i = 0; i < Gen4Constants.numberOfRarePickupItems; i++) {
int itemOffset = rarePickupItemsTableOffset + (2 * i);
- int item = itemIterator.next();
+ int item = itemIterator.next().item;
FileFunctions.write2ByteInt(battleOverlay, itemOffset, item);
}
writeOverlay(romEntry.getInt("BattleOvlNumber"), battleOverlay);
diff --git a/src/com/dabomstew/pkrandom/romhandlers/Gen5RomHandler.java b/src/com/dabomstew/pkrandom/romhandlers/Gen5RomHandler.java index f2a363f..c5208ad 100755 --- a/src/com/dabomstew/pkrandom/romhandlers/Gen5RomHandler.java +++ b/src/com/dabomstew/pkrandom/romhandlers/Gen5RomHandler.java @@ -3819,21 +3819,42 @@ public class Gen5RomHandler extends AbstractDSRomHandler { }
@Override
- public List<Integer> getPickupItems() {
- List<Integer> pickupItems = new ArrayList<>();
+ public List<PickupItem> getPickupItems() {
+ List<PickupItem> pickupItems = new ArrayList<>();
try {
byte[] battleOverlay = readOverlay(romEntry.getInt("PickupOvlNumber"));
+
+ // If we haven't found the pickup table for this ROM already, find it.
if (pickupItemsTableOffset == 0) {
int offset = find(battleOverlay, Gen5Constants.pickupTableLocator);
if (offset > 0) {
pickupItemsTableOffset = offset;
}
}
+
+ // Assuming we've found the pickup table, extract the items out of it.
if (pickupItemsTableOffset > 0) {
for (int i = 0; i < Gen5Constants.numberOfPickupItems; i++) {
int itemOffset = pickupItemsTableOffset + (2 * i);
int item = FileFunctions.read2ByteInt(battleOverlay, itemOffset);
- pickupItems.add(item);
+ PickupItem pickupItem = new PickupItem(item);
+ pickupItems.add(pickupItem);
+ }
+ }
+
+ // Assuming we got the items from the last step, fill out the probabilities.
+ if (pickupItems.size() > 0) {
+ for (int levelRange = 0; levelRange < 10; levelRange++) {
+ int startingRareItemOffset = levelRange;
+ int startingCommonItemOffset = 11 + levelRange;
+ pickupItems.get(startingCommonItemOffset).probabilities[levelRange] = 30;
+ for (int i = 1; i < 7; i++) {
+ pickupItems.get(startingCommonItemOffset + i).probabilities[levelRange] = 10;
+ }
+ pickupItems.get(startingCommonItemOffset + 7).probabilities[levelRange] = 4;
+ pickupItems.get(startingCommonItemOffset + 8).probabilities[levelRange] = 4;
+ pickupItems.get(startingRareItemOffset).probabilities[levelRange] = 1;
+ pickupItems.get(startingRareItemOffset + 1).probabilities[levelRange] = 1;
}
}
} catch (IOException e) {
@@ -3843,13 +3864,13 @@ public class Gen5RomHandler extends AbstractDSRomHandler { }
@Override
- public void setPickupItems(List<Integer> pickupItems) {
+ public void setPickupItems(List<PickupItem> pickupItems) {
try {
if (pickupItemsTableOffset > 0) {
byte[] battleOverlay = readOverlay(romEntry.getInt("PickupOvlNumber"));
for (int i = 0; i < Gen5Constants.numberOfPickupItems; i++) {
int itemOffset = pickupItemsTableOffset + (2 * i);
- int item = pickupItems.get(i);
+ int item = pickupItems.get(i).item;
FileFunctions.write2ByteInt(battleOverlay, itemOffset, item);
}
writeOverlay(romEntry.getInt("PickupOvlNumber"), battleOverlay);
diff --git a/src/com/dabomstew/pkrandom/romhandlers/Gen6RomHandler.java b/src/com/dabomstew/pkrandom/romhandlers/Gen6RomHandler.java index 26894fe..b1a9cc1 100644 --- a/src/com/dabomstew/pkrandom/romhandlers/Gen6RomHandler.java +++ b/src/com/dabomstew/pkrandom/romhandlers/Gen6RomHandler.java @@ -3594,30 +3594,51 @@ public class Gen6RomHandler extends Abstract3DSRomHandler { } @Override - public List<Integer> getPickupItems() { - List<Integer> pickupItems = new ArrayList<>(); + public List<PickupItem> getPickupItems() { + List<PickupItem> pickupItems = new ArrayList<>(); + + // If we haven't found the pickup table for this ROM already, find it. if (pickupItemsTableOffset == 0) { int offset = find(code, Gen6Constants.pickupTableLocator); if (offset > 0) { pickupItemsTableOffset = offset; } } + + // Assuming we've found the pickup table, extract the items out of it. if (pickupItemsTableOffset > 0) { for (int i = 0; i < Gen6Constants.numberOfPickupItems; i++) { int itemOffset = pickupItemsTableOffset + (2 * i); int item = FileFunctions.read2ByteInt(code, itemOffset); - pickupItems.add(item); + PickupItem pickupItem = new PickupItem(item); + pickupItems.add(pickupItem); + } + } + + // Assuming we got the items from the last step, fill out the probabilities. + if (pickupItems.size() > 0) { + for (int levelRange = 0; levelRange < 10; levelRange++) { + int startingCommonItemOffset = levelRange; + int startingRareItemOffset = 18 + levelRange; + pickupItems.get(startingCommonItemOffset).probabilities[levelRange] = 30; + for (int i = 1; i < 7; i++) { + pickupItems.get(startingCommonItemOffset + i).probabilities[levelRange] = 10; + } + pickupItems.get(startingCommonItemOffset + 7).probabilities[levelRange] = 4; + pickupItems.get(startingCommonItemOffset + 8).probabilities[levelRange] = 4; + pickupItems.get(startingRareItemOffset).probabilities[levelRange] = 1; + pickupItems.get(startingRareItemOffset + 1).probabilities[levelRange] = 1; } } return pickupItems; } @Override - public void setPickupItems(List<Integer> pickupItems) { + public void setPickupItems(List<PickupItem> pickupItems) { if (pickupItemsTableOffset > 0) { for (int i = 0; i < Gen6Constants.numberOfPickupItems; i++) { int itemOffset = pickupItemsTableOffset + (2 * i); - int item = pickupItems.get(i); + int item = pickupItems.get(i).item; FileFunctions.write2ByteInt(code, itemOffset, item); } } diff --git a/src/com/dabomstew/pkrandom/romhandlers/Gen7RomHandler.java b/src/com/dabomstew/pkrandom/romhandlers/Gen7RomHandler.java index 9c39fb7..ac40a78 100644 --- a/src/com/dabomstew/pkrandom/romhandlers/Gen7RomHandler.java +++ b/src/com/dabomstew/pkrandom/romhandlers/Gen7RomHandler.java @@ -3173,8 +3173,8 @@ public class Gen7RomHandler extends Abstract3DSRomHandler { } @Override - public List<Integer> getPickupItems() { - List<Integer> pickupItems = new ArrayList<>(); + public List<PickupItem> getPickupItems() { + List<PickupItem> pickupItems = new ArrayList<>(); try { GARCArchive pickupGarc = this.readGARC(romEntry.getString("PickupData"), false); byte[] pickupData = pickupGarc.getFile(0); @@ -3182,7 +3182,11 @@ public class Gen7RomHandler extends Abstract3DSRomHandler { for (int i = 0; i < numberOfPickupItems; i++) { int offset = 4 + (i * 0xC); int item = FileFunctions.read2ByteInt(pickupData, offset); - pickupItems.add(item); + PickupItem pickupItem = new PickupItem(item); + for (int levelRange = 0; levelRange < 10; levelRange++) { + pickupItem.probabilities[levelRange] = pickupData[offset + levelRange + 2]; + } + pickupItems.add(pickupItem); } } catch (IOException e) { throw new RandomizerIOException(e); @@ -3191,13 +3195,13 @@ public class Gen7RomHandler extends Abstract3DSRomHandler { } @Override - public void setPickupItems(List<Integer> pickupItems) { + public void setPickupItems(List<PickupItem> pickupItems) { try { GARCArchive pickupGarc = this.readGARC(romEntry.getString("PickupData"), false); byte[] pickupData = pickupGarc.getFile(0); for (int i = 0; i < pickupItems.size(); i++) { int offset = 4 + (i * 0xC); - int item = pickupItems.get(i); + int item = pickupItems.get(i).item; FileFunctions.write2ByteInt(pickupData, offset, item); } this.writeGARC(romEntry.getString("PickupData"), pickupGarc); diff --git a/src/com/dabomstew/pkrandom/romhandlers/RomHandler.java b/src/com/dabomstew/pkrandom/romhandlers/RomHandler.java index f4aa9ba..3efe5dc 100755 --- a/src/com/dabomstew/pkrandom/romhandlers/RomHandler.java +++ b/src/com/dabomstew/pkrandom/romhandlers/RomHandler.java @@ -525,9 +525,9 @@ public interface RomHandler { // Pickup Items
// ============
- List<Integer> getPickupItems();
+ List<PickupItem> getPickupItems();
- void setPickupItems(List<Integer> pickupItems);
+ void setPickupItems(List<PickupItem> pickupItems);
void randomizePickupItems(Settings settings);
|