Skip to content

Commit

Permalink
Swap LogicVars out for ItemLogic enum.
Browse files Browse the repository at this point in the history
  • Loading branch information
Malkierian committed Jul 13, 2024
1 parent 2eafd73 commit dc0b70d
Show file tree
Hide file tree
Showing 11 changed files with 693 additions and 495 deletions.
2 changes: 1 addition & 1 deletion soh/soh/Enhancements/randomizer/3drando/fill.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ std::vector<RandomizerCheck> GetAccessibleLocations(const std::vector<Randomizer
int gsCount = 0;
const int maxGsCount = mode == SearchMode::GeneratePlaythrough ? GetMaxGSCount() : 0; //If generating playthrough want the max that's possibly useful, else doesn't matter
bool bombchusFound = false;
std::vector<std::variant<bool*, uint8_t*>> buyIgnores;
std::vector<ItemLogic> buyIgnores;

//Variables for search
std::vector<Rando::ItemLocation*> newItemLocations;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ Rando::Entrance* Area::GetExit(RandomizerRegion exitToReturn) {
}

bool Area::CanPlantBeanCheck() const {
return (logic->MagicBean || logic->MagicBeanPack) && BothAgesCheck();
return Rando::Context::GetInstance()->GetAmmo(ITEM_BEAN) > 0 && BothAgesCheck();
}

bool Area::AllAccountedFor() const {
Expand Down
35 changes: 26 additions & 9 deletions soh/soh/Enhancements/randomizer/context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -395,9 +395,7 @@ void Context::ParseHintJson(nlohmann::json spoilerFileJson) {
CreateStaticHints();
}



std::map<RandomizerGet, uint32_t> RandoGetToFlag = {
std::map<RandomizerGet, uint32_t> Context::RandoGetToFlag = {
{ RG_KOKIRI_SWORD, EQUIP_FLAG_SWORD_KOKIRI },
{ RG_MASTER_SWORD, EQUIP_FLAG_SWORD_MASTER },
{ RG_BIGGORON_SWORD, EQUIP_FLAG_SWORD_BGS },
Expand Down Expand Up @@ -428,7 +426,7 @@ std::map<RandomizerGet, uint32_t> RandoGetToFlag = {
{ RG_OCARINA_C_RIGHT_BUTTON, RAND_INF_HAS_OCARINA_C_RIGHT }
};

std::map<uint32_t, uint32_t> RandoGetToDungeonScene = {
std::map<uint32_t, uint32_t> Context::RandoGetToDungeonScene = {
{ RG_FOREST_TEMPLE_SMALL_KEY, SCENE_FOREST_TEMPLE },
{ RG_FIRE_TEMPLE_SMALL_KEY, SCENE_FIRE_TEMPLE },
{ RG_WATER_TEMPLE_SMALL_KEY, SCENE_WATER_TEMPLE },
Expand Down Expand Up @@ -476,7 +474,7 @@ std::map<uint32_t, uint32_t> RandoGetToDungeonScene = {
{ RG_TREASURE_GAME_SMALL_KEY, SCENE_TREASURE_BOX_SHOP }
};

std::map<uint32_t, uint32_t> RandoGetToQuestItem = {
std::map<uint32_t, uint32_t> Context::RandoGetToQuestItem = {
{ RG_FOREST_MEDALLION, QUEST_MEDALLION_FOREST },
{ RG_FIRE_MEDALLION, QUEST_MEDALLION_FIRE },
{ RG_WATER_MEDALLION, QUEST_MEDALLION_WATER },
Expand All @@ -502,6 +500,10 @@ std::map<uint32_t, uint32_t> RandoGetToQuestItem = {
{ RG_GERUDO_MEMBERSHIP_CARD, QUEST_GERUDO_CARD },
};

std::map<uint32_t, uint32_t> RandoGetToItemID = {

};

uint32_t HookshotLookup[3] = { ITEM_NONE, ITEM_HOOKSHOT, ITEM_LONGSHOT };
uint32_t OcarinaLookup[3] = { ITEM_NONE, ITEM_OCARINA_FAIRY, ITEM_OCARINA_TIME };

Expand All @@ -518,7 +520,7 @@ void Context::ApplyItemEffect(Item& item, bool remove) {
switch (item.GetItemType()) {
case ITEMTYPE_ITEM:
{
if (item.GetGIEntry()->getItemCategory == ITEM_CATEGORY_MAJOR || item.GetGIEntry()->getItemCategory == ITEM_CATEGORY_LESSER) {
//if (item.GetGIEntry()->getItemCategory == ITEM_CATEGORY_MAJOR || item.GetGIEntry()->getItemCategory == ITEM_CATEGORY_LESSER) {
switch (randoGet) {
case RG_STONE_OF_AGONY:
case RG_GERUDO_MEMBERSHIP_CARD:
Expand Down Expand Up @@ -628,6 +630,12 @@ void Context::ApplyItemEffect(Item& item, bool remove) {
SetUpgrade(UPG_SCALE, newLevel);
}
} break;
case RG_DEKU_NUTS_5:
case RG_DEKU_NUTS_10:
case RG_BUY_DEKU_NUTS_5:
case RG_BUY_DEKU_NUTS_10:
SetInventory(ITEM_NUT, (remove ? ITEM_NONE : ITEM_NUT));
break;
case RG_PROGRESSIVE_NUT_UPGRADE:
{
auto currentLevel = CurrentUpgrade(UPG_NUTS);
Expand All @@ -637,6 +645,11 @@ void Context::ApplyItemEffect(Item& item, bool remove) {
}
SetUpgrade(UPG_NUTS, newLevel);
} break;
case RG_DEKU_STICK_1:
case RG_BUY_DEKU_STICK_1:
case RG_STICKS:
SetInventory(ITEM_STICK, (remove ? ITEM_NONE : ITEM_STICK));
break;
case RG_PROGRESSIVE_STICK_UPGRADE:
{
auto currentLevel = CurrentUpgrade(UPG_STICKS);
Expand All @@ -646,6 +659,10 @@ void Context::ApplyItemEffect(Item& item, bool remove) {
}
SetUpgrade(UPG_STICKS, newLevel);
} break;
case RG_BOMBCHU_5:
case RG_BOMBCHU_10:
case RG_BOMBCHU_20:
case RG_BOMBCHU_DROP:
case RG_PROGRESSIVE_BOMBCHUS:
SetInventory(ITEM_BOMBCHU, (remove ? ITEM_NONE : ITEM_BOMBCHU));
break;
Expand All @@ -670,11 +687,11 @@ void Context::ApplyItemEffect(Item& item, bool remove) {
SetInventory(ITEM_OCARINA_FAIRY, OcarinaLookup[i]);
} break;
case ITEM_HEART_CONTAINER:
mSaveContext->health += (remove ? -4 : 4);
mSaveContext->healthCapacity += (remove ? -16 : 16);
break;
case ITEM_HEART_PIECE:
case ITEM_HEART_PIECE_2:
mSaveContext->health += (remove ? -1 : 1);
mSaveContext->healthCapacity += (remove ? -4 : 4);
break;
case RG_BOOMERANG:
case RG_LENS_OF_TRUTH:
Expand Down Expand Up @@ -738,7 +755,7 @@ void Context::ApplyItemEffect(Item& item, bool remove) {
mSaveContext->triforcePiecesCollected += (remove ? -1 : 1);
break;
}
} // junk items don't have variables, so we can skip them
//} // junk items don't have variables, so we can skip them
}
break;
case ITEMTYPE_EQUIP:
Expand Down
4 changes: 4 additions & 0 deletions soh/soh/Enhancements/randomizer/context.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ class Context {
void GenerateLocationPool();
static std::vector<RandomizerCheck> GetLocations(const std::vector<RandomizerCheck>& locationPool,
Category categoryInclude, Category categoryExclude = Category::cNull);
static std::map<uint32_t, uint32_t> RandoGetToQuestItem;
static std::map<uint32_t, uint32_t> RandoGetToDungeonScene;
static std::map<RandomizerGet, uint32_t> RandoGetToFlag;
static std::map<uint32_t, uint32_t> RandoGetToItemID;
void AddExcludedOptions();
void LocationReset();
void ClearItemLocations();
Expand Down
2 changes: 1 addition & 1 deletion soh/soh/Enhancements/randomizer/hint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ const std::vector<std::string> Hint::GetAllMessageStrings(MessageFormat format)
std::vector<std::string> hintMessages = {};
uint8_t numMessages = GetNumberOfMessages();
for (int c = 0; c < numMessages; c++){
hintMessages.push_back(GetHintMessage(format, c).GetForCurrentLanguage(format));
// hintMessages.push_back(GetHintMessage(format, c).GetForCurrentLanguage(format));
}
return hintMessages;
}
Expand Down
63 changes: 21 additions & 42 deletions soh/soh/Enhancements/randomizer/item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace Rando {
Item::Item() : randomizerGet(RG_NONE), type(ITEMTYPE_ITEM), getItemId(GI_NONE), advancement(false), hintKey(RHT_NONE),
progressive(false), price(0) {}
Item::Item(const RandomizerGet randomizerGet_, Text name_, const ItemType type_, const int16_t getItemId_,
const bool advancement_, bool* logicVar_, const RandomizerHintTextKey hintKey_, const uint16_t itemId_,
const bool advancement_, ItemLogic logicVar_, const RandomizerHintTextKey hintKey_, const uint16_t itemId_,
const uint16_t objectId_, const uint16_t gid_, const uint16_t textId_, const uint16_t field_,
const int16_t chestAnimation_, const GetItemCategory category_, const uint16_t modIndex_,
const bool progressive_, const uint16_t price_)
Expand All @@ -28,28 +28,7 @@ Item::Item(const RandomizerGet randomizerGet_, Text name_, const ItemType type_,
}

Item::Item(const RandomizerGet randomizerGet_, Text name_, const ItemType type_, const int16_t getItemId_,
const bool advancement_, uint8_t* logicVar_, const RandomizerHintTextKey hintKey_, const uint16_t itemId_,
const uint16_t objectId_, const uint16_t gid_, const uint16_t textId_, const uint16_t field_,
const int16_t chestAnimation_, const GetItemCategory category_, const uint16_t modIndex_,
const bool progressive_, const uint16_t price_)
: randomizerGet(randomizerGet_), name(std::move(name_)), type(type_), getItemId(getItemId_),
advancement(advancement_), logicVar(logicVar_), hintKey(hintKey_), progressive(progressive_), price(price_) {
if (modIndex_ == MOD_RANDOMIZER || getItemId > 0x7D) {
giEntry = std::make_shared<GetItemEntry>(GetItemEntry{itemId_, field_, static_cast<int16_t>((chestAnimation_ != CHEST_ANIM_SHORT ? 1 : -1) * (gid_ + 1)), textId_, objectId_, modIndex_, TABLE_RANDOMIZER, static_cast<int16_t>(randomizerGet_), gid_, true, ITEM_FROM_NPC, category_, static_cast<uint16_t>(randomizerGet_), modIndex_, NULL});
} else {
giEntry = std::make_shared<GetItemEntry>(GetItemEntry{itemId_, field_, static_cast<int16_t>((chestAnimation_ != CHEST_ANIM_SHORT ? 1 : -1) * (gid_ + 1)), textId_, objectId_, modIndex_, TABLE_VANILLA, getItemId_, gid_, true, ITEM_FROM_NPC, category_, itemId_, modIndex_, NULL});
}
}

Item::Item(const RandomizerGet randomizerGet_, Text name_, const ItemType type_, const int16_t getItemId_,
const bool advancement_, bool* logicVar_, const RandomizerHintTextKey hintKey_, const bool progressive_,
const uint16_t price_)
: randomizerGet(randomizerGet_), name(std::move(name_)), type(type_), getItemId(getItemId_),
advancement(advancement_), logicVar(logicVar_), hintKey(hintKey_), progressive(progressive_), price(price_) {
}

Item::Item(const RandomizerGet randomizerGet_, Text name_, const ItemType type_, const int16_t getItemId_,
const bool advancement_, uint8_t* logicVar_, const RandomizerHintTextKey hintKey_, const bool progressive_,
const bool advancement_, ItemLogic logicVar_, const RandomizerHintTextKey hintKey_, const bool progressive_,
const uint16_t price_)
: randomizerGet(randomizerGet_), name(std::move(name_)), type(type_), getItemId(getItemId_),
advancement(advancement_), logicVar(logicVar_), hintKey(hintKey_), progressive(progressive_), price(price_) {
Expand All @@ -59,29 +38,29 @@ Item::Item(const RandomizerGet randomizerGet_, Text name_, const ItemType type_,

void Item::ApplyEffect() const {
// If this is a key ring, logically add as many keys as we could need
if (RHT_FOREST_TEMPLE_KEY_RING <= hintKey && hintKey <= RHT_GANONS_CASTLE_KEY_RING) {
*std::get<uint8_t*>(logicVar) += 10;
} else {
if (std::holds_alternative<bool*>(logicVar)) {
*std::get<bool*>(logicVar) = true;
} else {
*std::get<uint8_t*>(logicVar) += 1;
}
}
//if (RHT_FOREST_TEMPLE_KEY_RING <= hintKey && hintKey <= RHT_GANONS_CASTLE_KEY_RING) {
// *std::get<uint8_t*>(logicVar) += 10;
//} else {
// if (std::holds_alternative<bool*>(logicVar)) {
// *std::get<bool*>(logicVar) = true;
// } else {
// *std::get<uint8_t*>(logicVar) += 1;
// }
//}
Rando::Context::GetInstance()->ApplyItemEffect(StaticData::RetrieveItem(this->randomizerGet), false);
Rando::Context::GetInstance()->GetLogic()->UpdateHelpers();
}

void Item::UndoEffect() const {
if (RHT_FOREST_TEMPLE_KEY_RING <= hintKey && hintKey <= RHT_GANONS_CASTLE_KEY_RING) {
*std::get<uint8_t*>(logicVar) -= 10;
} else {
if (std::holds_alternative<bool*>(logicVar)) {
*std::get<bool*>(logicVar) = false;
} else {
*std::get<uint8_t*>(logicVar) -= 1;
}
}
//if (RHT_FOREST_TEMPLE_KEY_RING <= hintKey && hintKey <= RHT_GANONS_CASTLE_KEY_RING) {
// *std::get<uint8_t*>(logicVar) -= 10;
//} else {
// if (std::holds_alternative<bool*>(logicVar)) {
// *std::get<bool*>(logicVar) = false;
// } else {
// *std::get<uint8_t*>(logicVar) -= 1;
// }
//}
Rando::Context::GetInstance()->GetLogic()->UpdateHelpers();
}

Expand All @@ -101,7 +80,7 @@ ItemType Item::GetItemType() const {
return type;
}

std::variant<bool*, uint8_t*> Item::GetLogicVar() const {
ItemLogic Item::GetLogicVar() const {
return logicVar;
}

Expand Down
16 changes: 5 additions & 11 deletions soh/soh/Enhancements/randomizer/item.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,11 @@ class Item {
public:
Item();
Item(RandomizerGet randomizerGet_, Text name_, ItemType type_, int16_t getItemId_, bool advancement_,
bool* logicVar_, RandomizerHintTextKey hintKey_, uint16_t itemId_, uint16_t objectId_, uint16_t gid_,
uint16_t textId_, uint16_t field_, int16_t chestAnimation_, GetItemCategory category_,
uint16_t modIndex_, bool progressive_ = false, uint16_t price_ = 0);
Item(RandomizerGet randomizerGet_, Text name_, ItemType type_, int16_t getItemId_, bool advancement_,
uint8_t* logicVar_, RandomizerHintTextKey hintKey_, uint16_t itemId_, uint16_t objectId_, uint16_t gid_,
ItemLogic logicVar_, RandomizerHintTextKey hintKey_, uint16_t itemId_, uint16_t objectId_, uint16_t gid_,
uint16_t textId_, uint16_t field_, int16_t chestAnimation_, GetItemCategory category_, uint16_t modIndex_,
bool progressive_ = false, uint16_t price_ = 0);
Item(RandomizerGet randomizerGet_, Text name_, ItemType type_, int16_t getItemId_, bool advancement_,
bool* logicVar_, RandomizerHintTextKey hintKey_, bool progressive_ = false, uint16_t price_ = 0);
Item(RandomizerGet randomizerGet_, Text name_, ItemType type_, int16_t getItemId_, bool advancement_,
uint8_t* logicVar_, RandomizerHintTextKey hintKey_, bool progressive_ = false, uint16_t price_ = 0);
ItemLogic logicVar_, RandomizerHintTextKey hintKey_, bool progressive_ = false, uint16_t price_ = 0);
~Item();

void ApplyEffect() const;
Expand All @@ -52,7 +46,7 @@ class Item {
bool IsAdvancement() const;
int GetItemID() const;
ItemType GetItemType() const;
std::variant<bool*, uint8_t*> GetLogicVar() const;
ItemLogic GetLogicVar() const;
RandomizerGet GetRandomizerGet() const;
uint16_t GetPrice() const;
std::shared_ptr<GetItemEntry> GetGIEntry() const;
Expand All @@ -74,11 +68,11 @@ class Item {
ItemType type;
int16_t getItemId;
bool advancement;
std::variant<bool*, uint8_t*> logicVar;
ItemLogic logicVar;
RandomizerHintTextKey hintKey;
bool progressive;
uint16_t price;
bool playthrough = false;
std::shared_ptr<GetItemEntry> giEntry;
std::shared_ptr<GetItemEntry> giEntry;
};
}
Loading

0 comments on commit dc0b70d

Please sign in to comment.