Skip to content

Commit 27d3f2d

Browse files
authored
Merge pull request #134 from gymnast86/main
Fix fill issue when starting with or plandomizing a lot of spoils
2 parents 08d2153 + 5746c6d commit 27d3f2d

3 files changed

Lines changed: 60 additions & 5 deletions

File tree

logic/Fill.cpp

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,17 +54,28 @@ static FillError fastFill(ItemPool& items, LocationPool& locations)
5454
static FillError fillTheRest(WorldPool& worlds, ItemPool& items, LocationPool& locations)
5555
{
5656
FillError err;
57-
// First place the junk already in the pool
57+
// First place the non consumable junk already in the pool
58+
// Filter out the consumable junk to place afterwards
59+
auto consumableJunk = filterAndEraseFromPool(items, [](const Item& i){return i.isConsumableJunkItem();});
5860
FILL_ERROR_CHECK(fastFill(items, locations));
5961

60-
// When the item pool is empty, get random junk for the remaining locations
62+
// For the remaining locations, get items from the consumable junk. If the consumable junk runs out, just get more random
63+
// consumable junk
6164
for (auto location : locations)
6265
{
6366
if (location->currentItem.getGameItemId() == GameItem::INVALID)
6467
{
65-
auto item = getRandomJunk();
66-
location->currentItem = location->world->getItem(item);
67-
LOG_TO_DEBUG("Placed " + item + " at " + location->getName() + " in world " + std::to_string(location->world->getWorldId() + 1));
68+
Item item;
69+
if (!consumableJunk.empty())
70+
{
71+
item = popRandomElement(consumableJunk);
72+
}
73+
else
74+
{
75+
item = location->world->getItem(getRandomJunk());
76+
}
77+
location->currentItem = item;
78+
LOG_TO_DEBUG("Placed " + item.getName() + " at " + location->getName() + " in world " + std::to_string(location->world->getWorldId() + 1));
6879
}
6980
}
7081
return FillError::NONE;

logic/GameItem.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -770,6 +770,11 @@ Item::Item(GameItem gameItemId_, World* world_) :
770770
gameItemId(gameItemId_),
771771
world(world_)
772772
{
773+
if (junkConsumables.contains(gameItemId))
774+
{
775+
junkConsumable = true;
776+
}
777+
773778
if (junkItems.contains(gameItemId) || (isAnyOf(gameItemId, GameItem::HeartContainer, GameItem::PieceOfHeart) && world && world->getStartingHeartCount() >= 3))
774779
{
775780
originallyJunk = true;
@@ -891,6 +896,11 @@ bool Item::isJunkItem() const
891896
return junkItem;
892897
}
893898

899+
bool Item::isConsumableJunkItem() const
900+
{
901+
return junkConsumable;
902+
}
903+
894904
bool Item::wasAlwaysJunkItem() const
895905
{
896906
return originallyJunk;

logic/GameItem.hpp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,38 @@ static const std::set<GameItem> junkItems = {
354354
GameItem::TinglesChart
355355
};
356356

357+
static const std::set<GameItem> junkConsumables = {
358+
GameItem::HeartDrop,
359+
GameItem::GreenRupee,
360+
GameItem::BlueRupee,
361+
GameItem::YellowRupee,
362+
GameItem::RedRupee,
363+
GameItem::PurpleRupee,
364+
GameItem::OrangeRupee,
365+
GameItem::SmallMagicDrop,
366+
GameItem::LargeMagicDrop,
367+
GameItem::FiveBombs,
368+
GameItem::TenBombs,
369+
GameItem::TwentyBombs,
370+
GameItem::ThirtyBombs,
371+
GameItem::SilverRupee,
372+
GameItem::TenArrows,
373+
GameItem::TwentyArrows,
374+
GameItem::ThirtyArrows,
375+
GameItem::Fairy,
376+
GameItem::YellowRupee2, //joke message
377+
GameItem::ThreeHearts,
378+
GameItem::JoyPendant,
379+
GameItem::SkullNecklace,
380+
GameItem::BokoBabaSeed,
381+
GameItem::GoldenFeather,
382+
GameItem::KnightsCrest,
383+
GameItem::RedChuJelly,
384+
GameItem::GreenChuJelly,
385+
GameItem::AllPurposeBait,
386+
GameItem::HyoiPear,
387+
};
388+
357389
static const std::set<GameItem> dungeonItems = {
358390
GameItem::DRCSmallKey,
359391
GameItem::DRCBigKey,
@@ -405,6 +437,7 @@ class Item
405437
void setName(const std::string& language, const Text::Type& type, const std::string& name_);
406438
void setAsJunkItem();
407439
bool isJunkItem() const;
440+
bool isConsumableJunkItem() const;
408441
bool wasAlwaysJunkItem() const;
409442
bool isDungeonItem() const;
410443
bool isMap() const;
@@ -424,6 +457,7 @@ class Item
424457
std::unordered_set<Location*> chainLocations = {};
425458
bool dungeonItem = false;
426459
bool junkItem = false;
460+
bool junkConsumable = false;
427461
bool originallyJunk = false;
428462
World* world = nullptr; // The world that this item is *FOR*
429463
};

0 commit comments

Comments
 (0)