Skip to content

Commit

Permalink
Issue #66 Handle door interactable
Browse files Browse the repository at this point in the history
  • Loading branch information
xavieran committed Jul 1, 2024
1 parent d1e0c5d commit ae4ac76
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 2 deletions.
2 changes: 2 additions & 0 deletions bak/dialogSources.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ class DialogSources
static constexpr auto mStump = KeyTarget{0xba};
static constexpr auto mTrappedAnimal = KeyTarget{0xab};
static constexpr auto mWell = KeyTarget{0xbc};
static constexpr auto mDoorTooClose = KeyTarget{0x9d};

static constexpr auto mCharacterIsNotASpellcaster = KeyTarget{0xd8};

Expand All @@ -201,6 +202,7 @@ class DialogSources
static constexpr auto mStartOfChapterActions =
KeyTarget{0x1e8497};
static constexpr auto mDragonsBreath = 0xc7;

};

}
2 changes: 1 addition & 1 deletion bak/gameState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ void GameState::SetDefaultDialogTextVariables()

void GameState::SetDialogTextVariable(unsigned index, unsigned attribute)
{
mLogger.Debug() << __FUNCTION__ << "(" << index << ", " << attribute << ")\n";
mLogger.Spam() << __FUNCTION__ << "(" << index << ", " << attribute << ")\n";
assert(attribute > 0);
// remember we always switch on attribute - 1...
switch (attribute - 1)
Expand Down
1 change: 1 addition & 0 deletions bak/state/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
add_library(bakState
customStateChoice.hpp customStateChoice.cpp
dialog.hpp dialog.cpp
door.hpp door.cpp
encounter.hpp encounter.cpp
event.hpp event.cpp
item.hpp item.cpp
Expand Down
22 changes: 22 additions & 0 deletions bak/state/door.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include "bak/state/door.hpp"

#include "bak/state/event.hpp"
#include "bak/state/offsets.hpp"

#include "bak/gameState.hpp"

#include "com/logger.hpp"

namespace BAK::State {

bool GetDoorState(const GameState& gs, unsigned doorIndex)
{
return gs.ReadEventBool(sDoorFlag + doorIndex);
}

void SetDoorState(FileBuffer& fb, unsigned doorIndex, bool state)
{
SetEventFlag(fb, sLockHasBeenSeenFlag + doorIndex, state);
}

}
15 changes: 15 additions & 0 deletions bak/state/door.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#pragma once

#include "bak/file/fileBuffer.hpp"

namespace BAK {
class GameState;
}

namespace BAK::State {

bool GetDoorState(const GameState&, unsigned doorIndex);
void SetDoorState(FileBuffer&, unsigned doorIndex, bool state);

}

27 changes: 26 additions & 1 deletion game/interactable/door.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,24 @@

#include "game/interactable/IInteractable.hpp"

#include "bak/dialogTarget.hpp"
#include "bak/state/door.hpp"

#include "bak/IContainer.hpp"
#include "bak/container.hpp"
#include "bak/dialog.hpp"
#include "bak/dialogSources.hpp"
#include "bak/gameState.hpp"
#include "bak/itemNumbers.hpp"

#include "graphics/glm.hpp"

#include "gui/IDialogScene.hpp"
#include "gui/IGuiManager.hpp"

#include <glm/geometric.hpp>


namespace Game::Interactable {

/*
Expand All @@ -24,10 +32,12 @@ class Door : public IInteractable
public:
Door(
Gui::IGuiManager& guiManager,
BAK::GameState& gameState,
BAK::Target target,
const EncounterCallback& encounterCallback)
:
mGuiManager{guiManager},
mGameState{gameState},
mDialogScene{
[]{},
[]{},
Expand All @@ -41,7 +51,21 @@ class Door : public IInteractable
{
mContainer = &container;

StartDialog(mDefaultDialog);
assert(mContainer->HasDialog());
auto doorIndex = std::get<BAK::KeyTarget>(
mContainer->GetDialog().mDialog).mValue >> 16;

Logging::LogInfo("Door") << "DoorIndex: " << doorIndex << " State: " << std::boolalpha << BAK::State::GetDoorState(mGameState, doorIndex) << "\n";

const auto playerPos = glm::cast<float>(mGameState.GetLocation().mPosition);
const auto doorPos = glm::cast<float>(container.GetHeader().GetPosition());
if (glm::distance(playerPos, doorPos) < 800)
{
StartDialog(BAK::DialogSources::mDoorTooClose);
}
else
{
}
}

void DialogFinished(const std::optional<BAK::ChoiceIndex>& choice)
Expand All @@ -64,6 +88,7 @@ class Door : public IInteractable

private:
Gui::IGuiManager& mGuiManager;
BAK::GameState& mGameState;
Gui::DynamicDialogScene mDialogScene;
BAK::Target mDefaultDialog;
BAK::GenericContainer* mContainer;
Expand Down
1 change: 1 addition & 0 deletions game/interactable/factory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ class InteractableFactory
case InteractableType::Door:
return std::make_unique<Door>(
mGuiManager,
mGameState,
BAK::DialogSources::mUnknownObject,
[](auto){});
case InteractableType::Corn:
Expand Down

0 comments on commit ae4ac76

Please sign in to comment.