mirror of
https://github.com/HarbourMasters/Shipwright.git
synced 2025-08-22 22:33:43 -07:00
Reset logic and ApplyOrStoreItems without applying the item effects to the save when calculating available checks.
This commit is contained in:
parent
5ffb7fbe5b
commit
23812b384b
5 changed files with 59 additions and 47 deletions
|
@ -210,7 +210,7 @@ void ProcessExits(Region* region, GetAccessibleLocationsStruct& gals, Randomizer
|
||||||
auto ctx = Rando::Context::GetInstance();
|
auto ctx = Rando::Context::GetInstance();
|
||||||
for (auto& exit : region->exits) {
|
for (auto& exit : region->exits) {
|
||||||
int16_t entranceIndex = exit.GetIndex();
|
int16_t entranceIndex = exit.GetIndex();
|
||||||
if (gals.calculatingAvailableChecks && ctx->GetOption(RSK_SHUFFLE_ENTRANCES).Get() && exit.IsShuffled() &&
|
if (logic->CalculatingAvailableChecks && ctx->GetOption(RSK_SHUFFLE_ENTRANCES).Get() && exit.IsShuffled() &&
|
||||||
entranceIndex != -1 && !Entrance_GetIsEntranceDiscovered(entranceIndex)) {
|
entranceIndex != -1 && !Entrance_GetIsEntranceDiscovered(entranceIndex)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -427,18 +427,13 @@ bool AddCheckToLogic(LocationAccess& locPair, GetAccessibleLocationsStruct& gals
|
||||||
Rando::ItemLocation* location = ctx->GetItemLocation(loc);
|
Rando::ItemLocation* location = ctx->GetItemLocation(loc);
|
||||||
RandomizerGet locItem = location->GetPlacedRandomizerGet();
|
RandomizerGet locItem = location->GetPlacedRandomizerGet();
|
||||||
|
|
||||||
if (!location->IsAddedToPool() && locPair.ConditionsMet(parentRegion, gals.calculatingAvailableChecks)) {
|
if (!location->IsAddedToPool() && locPair.ConditionsMet(parentRegion, logic->CalculatingAvailableChecks)) {
|
||||||
if (gals.calculatingAvailableChecks) {
|
|
||||||
gals.accessibleLocations.push_back(loc);
|
|
||||||
StopPerformanceTimer(PT_LOCATION_LOGIC);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
location->AddToPool();
|
location->AddToPool();
|
||||||
|
|
||||||
if (locItem == RG_NONE) {
|
if (locItem == RG_NONE || logic->CalculatingAvailableChecks) {
|
||||||
gals.accessibleLocations.push_back(loc); // Empty location, consider for placement
|
gals.accessibleLocations.push_back(loc); // Empty location, consider for placement
|
||||||
} else {
|
}
|
||||||
|
if (locItem != RG_NONE) {
|
||||||
// If ignore has a value, we want to check if the item location should be considered or not
|
// If ignore has a value, we want to check if the item location should be considered or not
|
||||||
// This is necessary due to the below preprocessing for playthrough generation
|
// This is necessary due to the below preprocessing for playthrough generation
|
||||||
if (ignore != RG_NONE) {
|
if (ignore != RG_NONE) {
|
||||||
|
@ -537,8 +532,11 @@ std::vector<RandomizerCheck> ReachabilitySearch(const std::vector<RandomizerChec
|
||||||
bool calculatingAvailableChecks /* = false */) {
|
bool calculatingAvailableChecks /* = false */) {
|
||||||
auto ctx = Rando::Context::GetInstance();
|
auto ctx = Rando::Context::GetInstance();
|
||||||
GetAccessibleLocationsStruct gals(0);
|
GetAccessibleLocationsStruct gals(0);
|
||||||
gals.calculatingAvailableChecks = calculatingAvailableChecks;
|
|
||||||
ResetLogic(ctx, gals, !calculatingAvailableChecks);
|
ResetLogic(ctx, gals, !calculatingAvailableChecks);
|
||||||
|
if (calculatingAvailableChecks) {
|
||||||
|
logic->Reset(false);
|
||||||
|
logic->CalculatingAvailableChecks = true;
|
||||||
|
}
|
||||||
do {
|
do {
|
||||||
gals.InitLoop();
|
gals.InitLoop();
|
||||||
for (size_t i = 0; i < gals.regionPool.size(); i++) {
|
for (size_t i = 0; i < gals.regionPool.size(); i++) {
|
||||||
|
|
|
@ -34,8 +34,6 @@ struct GetAccessibleLocationsStruct {
|
||||||
std::vector<RandomizerCheck> itemSphere;
|
std::vector<RandomizerCheck> itemSphere;
|
||||||
std::list<Rando::Entrance*> entranceSphere;
|
std::list<Rando::Entrance*> entranceSphere;
|
||||||
|
|
||||||
bool calculatingAvailableChecks = false;
|
|
||||||
|
|
||||||
GetAccessibleLocationsStruct(int _maxGsCount){
|
GetAccessibleLocationsStruct(int _maxGsCount){
|
||||||
regionPool = {RR_ROOT};
|
regionPool = {RR_ROOT};
|
||||||
gsCount = 0;
|
gsCount = 0;
|
||||||
|
|
|
@ -46,14 +46,20 @@ Item::~Item() = default;
|
||||||
|
|
||||||
void Item::ApplyEffect() const {
|
void Item::ApplyEffect() const {
|
||||||
auto ctx = Rando::Context::GetInstance();
|
auto ctx = Rando::Context::GetInstance();
|
||||||
ctx->GetLogic()->ApplyItemEffect(StaticData::RetrieveItem(randomizerGet), true);
|
auto logic = ctx->GetLogic();
|
||||||
ctx->GetLogic()->SetInLogic(logicVal, true);
|
if (!logic->CalculatingAvailableChecks) {
|
||||||
|
logic->ApplyItemEffect(StaticData::RetrieveItem(randomizerGet), true);
|
||||||
|
}
|
||||||
|
logic->SetInLogic(logicVal, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Item::UndoEffect() const {
|
void Item::UndoEffect() const {
|
||||||
auto ctx = Rando::Context::GetInstance();
|
auto ctx = Rando::Context::GetInstance();
|
||||||
ctx->GetLogic()->ApplyItemEffect(StaticData::RetrieveItem(randomizerGet), false);
|
auto logic = ctx->GetLogic();
|
||||||
ctx->GetLogic()->SetInLogic(logicVal, false);
|
if (!logic->CalculatingAvailableChecks) {
|
||||||
|
logic->ApplyItemEffect(StaticData::RetrieveItem(randomizerGet), false);
|
||||||
|
}
|
||||||
|
logic->SetInLogic(logicVal, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
const Text& Item::GetName() const {
|
const Text& Item::GetName() const {
|
||||||
|
|
|
@ -2331,8 +2331,10 @@ void Logic::SetInLogic(LogicVal logicVal, bool value) {
|
||||||
inLogic[logicVal] = value;
|
inLogic[logicVal] = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Logic::Reset() {
|
void Logic::Reset(bool resetSaveContext /*= true*/) {
|
||||||
NewSaveContext();
|
if (resetSaveContext) {
|
||||||
|
NewSaveContext();
|
||||||
|
}
|
||||||
StartPerformanceTimer(PT_LOGIC_RESET);
|
StartPerformanceTimer(PT_LOGIC_RESET);
|
||||||
memset(inLogic, false, sizeof(inLogic));
|
memset(inLogic, false, sizeof(inLogic));
|
||||||
// Settings-dependent variables
|
// Settings-dependent variables
|
||||||
|
@ -2371,37 +2373,39 @@ void Logic::Reset() {
|
||||||
ShadowTrialClear = false;
|
ShadowTrialClear = false;
|
||||||
LightTrialClear = false;
|
LightTrialClear = false;
|
||||||
|
|
||||||
// Ocarina C Buttons
|
if (resetSaveContext) {
|
||||||
bool ocBtnShuffle = ctx->GetOption(RSK_SHUFFLE_OCARINA_BUTTONS).Is(true);
|
// Ocarina C Buttons
|
||||||
SetRandoInf(RAND_INF_HAS_OCARINA_A, !ocBtnShuffle);
|
bool ocBtnShuffle = ctx->GetOption(RSK_SHUFFLE_OCARINA_BUTTONS).Is(true);
|
||||||
SetRandoInf(RAND_INF_HAS_OCARINA_C_UP, !ocBtnShuffle);
|
SetRandoInf(RAND_INF_HAS_OCARINA_A, !ocBtnShuffle);
|
||||||
SetRandoInf(RAND_INF_HAS_OCARINA_C_DOWN, !ocBtnShuffle);
|
SetRandoInf(RAND_INF_HAS_OCARINA_C_UP, !ocBtnShuffle);
|
||||||
SetRandoInf(RAND_INF_HAS_OCARINA_C_LEFT, !ocBtnShuffle);
|
SetRandoInf(RAND_INF_HAS_OCARINA_C_DOWN, !ocBtnShuffle);
|
||||||
SetRandoInf(RAND_INF_HAS_OCARINA_C_RIGHT, !ocBtnShuffle);
|
SetRandoInf(RAND_INF_HAS_OCARINA_C_LEFT, !ocBtnShuffle);
|
||||||
|
SetRandoInf(RAND_INF_HAS_OCARINA_C_RIGHT, !ocBtnShuffle);
|
||||||
|
|
||||||
// Progressive Items
|
// Progressive Items
|
||||||
SetUpgrade(UPG_STICKS, ctx->GetOption(RSK_SHUFFLE_DEKU_STICK_BAG).Is(true) ? 0 : 1);
|
SetUpgrade(UPG_STICKS, ctx->GetOption(RSK_SHUFFLE_DEKU_STICK_BAG).Is(true) ? 0 : 1);
|
||||||
SetUpgrade(UPG_NUTS, ctx->GetOption(RSK_SHUFFLE_DEKU_NUT_BAG).Is(true) ? 0 : 1);
|
SetUpgrade(UPG_NUTS, ctx->GetOption(RSK_SHUFFLE_DEKU_NUT_BAG).Is(true) ? 0 : 1);
|
||||||
|
|
||||||
// If we're not shuffling swim, we start with it
|
// If we're not shuffling swim, we start with it
|
||||||
if (ctx->GetOption(RSK_SHUFFLE_SWIM).Is(false)) {
|
if (ctx->GetOption(RSK_SHUFFLE_SWIM).Is(false)) {
|
||||||
SetRandoInf(RAND_INF_CAN_SWIM, true);
|
SetRandoInf(RAND_INF_CAN_SWIM, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we're not shuffling child's wallet, we start with it
|
// If we're not shuffling child's wallet, we start with it
|
||||||
if (ctx->GetOption(RSK_SHUFFLE_CHILD_WALLET).Is(false)) {
|
if (ctx->GetOption(RSK_SHUFFLE_CHILD_WALLET).Is(false)) {
|
||||||
SetRandoInf(RAND_INF_HAS_WALLET, true);
|
SetRandoInf(RAND_INF_HAS_WALLET, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we're not shuffling fishing pole, we start with it
|
// If we're not shuffling fishing pole, we start with it
|
||||||
if (ctx->GetOption(RSK_SHUFFLE_FISHING_POLE).Is(false)) {
|
if (ctx->GetOption(RSK_SHUFFLE_FISHING_POLE).Is(false)) {
|
||||||
SetRandoInf(RAND_INF_FISHING_POLE_FOUND, true);
|
SetRandoInf(RAND_INF_FISHING_POLE_FOUND, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
// If not keysanity, start with 1 logical key to account for automatically unlocking the basement door in vanilla
|
// If not keysanity, start with 1 logical key to account for automatically unlocking the basement door in
|
||||||
// FiT
|
// vanilla FiT
|
||||||
if (!IsKeysanity && ctx->GetDungeon(Rando::FIRE_TEMPLE)->IsVanilla()) {
|
if (!IsKeysanity && ctx->GetDungeon(Rando::FIRE_TEMPLE)->IsVanilla()) {
|
||||||
SetSmallKeyCount(SCENE_FIRE_TEMPLE, 1);
|
SetSmallKeyCount(SCENE_FIRE_TEMPLE, 1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Bottle Count
|
// Bottle Count
|
||||||
|
@ -2454,7 +2458,9 @@ void Logic::Reset() {
|
||||||
// Other
|
// Other
|
||||||
AtDay = false;
|
AtDay = false;
|
||||||
AtNight = false;
|
AtNight = false;
|
||||||
GetSaveContext()->linkAge = !ctx->GetOption(RSK_SELECTED_STARTING_AGE).Get();
|
if (resetSaveContext) {
|
||||||
|
GetSaveContext()->linkAge = !ctx->GetOption(RSK_SELECTED_STARTING_AGE).Get();
|
||||||
|
}
|
||||||
|
|
||||||
// Events
|
// Events
|
||||||
ShowedMidoSwordAndShield = false;
|
ShowedMidoSwordAndShield = false;
|
||||||
|
@ -2518,6 +2524,8 @@ void Logic::Reset() {
|
||||||
Spirit1FSilverRupees = false;
|
Spirit1FSilverRupees = false;
|
||||||
JabuRutoIn1F = false;
|
JabuRutoIn1F = false;
|
||||||
|
|
||||||
|
CalculatingAvailableChecks = false;
|
||||||
|
|
||||||
StopPerformanceTimer(PT_LOGIC_RESET);
|
StopPerformanceTimer(PT_LOGIC_RESET);
|
||||||
}
|
}
|
||||||
} // namespace Rando
|
} // namespace Rando
|
||||||
|
|
|
@ -183,6 +183,8 @@ class Logic {
|
||||||
|
|
||||||
/* --- END OF HELPERS AND LOCATION ACCESS --- */
|
/* --- END OF HELPERS AND LOCATION ACCESS --- */
|
||||||
|
|
||||||
|
bool CalculatingAvailableChecks = false;
|
||||||
|
|
||||||
SaveContext* mSaveContext = nullptr;
|
SaveContext* mSaveContext = nullptr;
|
||||||
Logic();
|
Logic();
|
||||||
bool CanUse(RandomizerGet itemName);
|
bool CanUse(RandomizerGet itemName);
|
||||||
|
@ -254,7 +256,7 @@ class Logic {
|
||||||
bool CanUseProjectile();
|
bool CanUseProjectile();
|
||||||
bool CanBuildRainbowBridge();
|
bool CanBuildRainbowBridge();
|
||||||
bool CanTriggerLACS();
|
bool CanTriggerLACS();
|
||||||
void Reset();
|
void Reset(bool resetSaveContext = true);
|
||||||
void SetContext(std::shared_ptr<Context> _ctx);
|
void SetContext(std::shared_ptr<Context> _ctx);
|
||||||
bool GetInLogic(LogicVal logicVal);
|
bool GetInLogic(LogicVal logicVal);
|
||||||
void SetInLogic(LogicVal logicVal, bool remove);
|
void SetInLogic(LogicVal logicVal, bool remove);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue