Skip to content

Commit

Permalink
Closes #108 Fix teleport costs (#195)
Browse files Browse the repository at this point in the history
  • Loading branch information
xavieran authored Jun 29, 2024
1 parent 633931e commit b749ebb
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 26 deletions.
33 changes: 15 additions & 18 deletions bak/temple.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,25 +40,22 @@ void RemoveBlessing(BAK::InventoryItem& item)
}
}

Royals CalculateTeleportCost(unsigned source, unsigned dest)
Royals CalculateTeleportCost(
unsigned srcTemple,
unsigned dstTemple,
glm::vec2 srcPos,
glm::vec2 dstPos,
unsigned teleportMultiplier,
unsigned teleportConstant)
{
ASSERT(source > 0 && dest > 0);
ASSERT(source <= 13 && dest <= 13);
static constexpr unsigned costMatrix[12][12] = {
{0, 85, 88, 112, 167, 149, 172, 184, 106, 159, 120, 158},
{85, 0, 70, 105, 136, 123, 138, 139, 61, 113, 119, 129},
{88, 70, 0, 84, 129, 111, 140, 152, 83, 127, 99, 120},
{88, 70, 105, 0, 99, 81, 134, 146, 103, 134, 59, 91},
{88, 70, 105, 99, 0, 70, 102, 131, 129, 124, 105, 61},
{88, 70, 105, 99, 70, 0, 102, 131, 115, 121, 75, 49},
{88, 70, 105, 99, 70, 102, 0, 89, 137, 97, 151, 120},
{88, 70, 105, 99, 70, 102, 89, 0, 128, 75, 161, 140},
{88, 70, 105, 99, 70, 102, 89, 128, 0, 102, 121, 131},
{88, 70, 105, 99, 70, 102, 89, 128, 102, 0, 151, 129},
{88, 70, 105, 99, 70, 102, 89, 128, 102, 151, 0, 63},
{88, 70, 105, 99, 70, 102, 89, 128, 102, 151, 63, 0}
};
return GetRoyals(Sovereigns{costMatrix[source - 1][dest - 1]});
ASSERT(srcTemple > 0 && dstTemple > 0);
ASSERT(srcTemple <= 13 && dstTemple <= 13);
auto xDiff = static_cast<unsigned>(std::abs(srcPos.x - dstPos.x));
auto yDiff = static_cast<unsigned>(std::abs(srcPos.y - dstPos.y));
auto cost = std::max(xDiff, yDiff) + (std::min(xDiff, yDiff) * 3) / 8;
cost = ((cost * teleportMultiplier) + teleportConstant) * 10;
cost = (cost + 5) / 10;
return Royals{cost};
}

Royals CalculateCureCost(
Expand Down
8 changes: 7 additions & 1 deletion bak/temple.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,13 @@ Royals CalculateBlessPrice(const BAK::InventoryItem& item, const ShopStats& shop
void BlessItem(BAK::InventoryItem& item, const ShopStats& shop);
void RemoveBlessing(BAK::InventoryItem& item);

Royals CalculateTeleportCost(unsigned source, unsigned dest);
Royals CalculateTeleportCost(
unsigned srcTemple,
unsigned dstTemple,
glm::vec2 srcPos,
glm::vec2 dstPos,
unsigned teleportMultiplier,
unsigned teleportConstant);

Royals CalculateCureCost(
unsigned cureFactor,
Expand Down
2 changes: 1 addition & 1 deletion gui/IGuiManager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class IGuiManager
virtual void ShowCast(bool inCombat) = 0;
virtual void ShowFullMap() = 0;
virtual void ShowGameStartMap() = 0;
virtual void ShowTeleport(unsigned sourceTemple) = 0;
virtual void ShowTeleport(unsigned sourceTemple, BAK::ShopStats* temple) = 0;
virtual void ShowCureScreen(
unsigned templeNumber,
unsigned cureFactor,
Expand Down
4 changes: 3 additions & 1 deletion gui/gdsScene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,9 @@ void GDSScene::DoTeleport()
if (mGameState.GetMoreThanOneTempleSeen())
{
assert(mSceneHotspots.GetTempleNumber());
mGuiManager.ShowTeleport(*mSceneHotspots.GetTempleNumber());
mGuiManager.ShowTeleport(
*mSceneHotspots.GetTempleNumber(),
&mGameState.GetContainerForGDSScene(mReference)->GetShop());
}
else
{
Expand Down
4 changes: 2 additions & 2 deletions gui/guiManager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -641,9 +641,9 @@ class GuiManager final : public Widget, public IGuiManager
});
}

void ShowTeleport(unsigned sourceTemple) override
void ShowTeleport(unsigned sourceTemple, BAK::ShopStats* temple) override
{
mTeleportScreen.SetSourceTemple(sourceTemple);
mTeleportScreen.SetSourceTemple(sourceTemple, temple);
DoFade(.8, [this]{
mCursor.PopCursor();
mScreenStack.PushScreen(&mTeleportScreen);
Expand Down
24 changes: 21 additions & 3 deletions gui/teleportScreen.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "bak/dialogSources.hpp"
#include "bak/encounter/teleport.hpp"
#include "bak/layout.hpp"
#include "bak/shop.hpp"
#include "bak/sounds.hpp"
#include "bak/temple.hpp"

Expand Down Expand Up @@ -179,9 +180,11 @@ class TeleportScreen : public Widget, public IDialogScene
}
}

void SetSourceTemple(unsigned sourceTemple)
void SetSourceTemple(unsigned sourceTemple, BAK::ShopStats* temple)
{
mState = State::Idle;
assert(temple);
mTemple = temple;
mSource = sourceTemple;
mChosenDest = std::nullopt;
for (unsigned i = 0; i < mTeleportDests.size(); i++)
Expand Down Expand Up @@ -230,7 +233,7 @@ class TeleportScreen : public Widget, public IDialogScene
}
else
{
const auto cost = BAK::Temple::CalculateTeleportCost(mSource, templeNumber);
const auto cost = CalculateCost(templeNumber);
if (cost < mGameState.GetMoney())
{
mGameState.GetParty().LoseMoney(cost);
Expand Down Expand Up @@ -275,7 +278,7 @@ class TeleportScreen : public Widget, public IDialogScene
std::string MakeCostString(unsigned templeNumber)
{
std::stringstream ss{};
ss << "Cost: " << BAK::ToShopDialogString(BAK::Temple::CalculateTeleportCost(mSource, templeNumber));
ss << "Cost: " << BAK::ToShopDialogString(CalculateCost(templeNumber));
return ss.str();
}

Expand Down Expand Up @@ -308,6 +311,20 @@ class TeleportScreen : public Widget, public IDialogScene
}

private:
BAK::Royals CalculateCost(unsigned templeNumber)
{
assert(mTemple);
const auto srcPos = mLayout.GetWidget(mSource - 1).mPosition;
const auto dstPos = mLayout.GetWidget(templeNumber - 1).mPosition;
return BAK::Temple::CalculateTeleportCost(
mSource,
templeNumber,
srcPos,
dstPos,
mTemple->mHaggleAnnoyanceFactor,
mTemple->mCategories);
}

IGuiManager& mGuiManager;
const Font& mFont;
BAK::GameState& mGameState;
Expand All @@ -317,6 +334,7 @@ class TeleportScreen : public Widget, public IDialogScene

State mState;
unsigned mSource;
BAK::ShopStats* mTemple;
std::optional<unsigned> mHighlightedDest;
std::optional<unsigned> mChosenDest;
bool mNeedRefresh;
Expand Down

0 comments on commit b749ebb

Please sign in to comment.