Skip to content

Commit

Permalink
Display correct container icon when opening containers
Browse files Browse the repository at this point in the history
  • Loading branch information
xavieran committed Jan 20, 2024
1 parent 40e486d commit 124554b
Show file tree
Hide file tree
Showing 25 changed files with 302 additions and 129 deletions.
4 changes: 2 additions & 2 deletions app/main3d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ int main(int argc, char** argv)
{
currentTile = camera.GetGameTile();
logger.Debug() << "New tile: " << currentTile << "\n";
gameRunner.mGameState.Apply([](auto& fb){ BAK::State::ClearTileRecentEncounters(fb); });
gameRunner.mGameState.Apply(BAK::State::ClearTileRecentEncounters);
}
};

Expand Down Expand Up @@ -253,7 +253,7 @@ int main(int argc, char** argv)
}});
inputHandler.Bind(GLFW_KEY_X, [&]{ if (guiManager.InMainView()) cameraPtr->RotateVerticalUp(); });
inputHandler.Bind(GLFW_KEY_Y, [&]{ if (guiManager.InMainView()) cameraPtr->RotateVerticalDown(); });
inputHandler.Bind(GLFW_KEY_C, [&]{ if (guiManager.InMainView()) gameRunner.mGameState.Apply([](auto& fb){ BAK::State::ClearTileRecentEncounters(fb); }); });
inputHandler.Bind(GLFW_KEY_C, [&]{ if (guiManager.InMainView()) gameRunner.mGameState.Apply(BAK::State::ClearTileRecentEncounters); });

inputHandler.Bind(GLFW_KEY_BACKSPACE, [&]{ if (root.OnKeyEvent(Gui::KeyPress{GLFW_KEY_BACKSPACE})){ ;} });
inputHandler.BindCharacter([&](char character){ if(root.OnKeyEvent(Gui::Character{character})){ ;} });
Expand Down
1 change: 1 addition & 0 deletions bak/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ add_library(bak
dialogChoice.hpp dialogChoice.cpp
dialogSources.hpp
dialogTarget.hpp dialogTarget.cpp
entityType.hpp entityType.cpp
fixedObject.hpp fixedObject.cpp
fileBufferFactory.hpp fileBufferFactory.cpp
font.hpp font.cpp
Expand Down
4 changes: 2 additions & 2 deletions bak/character.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ class Character final : public IContainer
staffCount++;
}
}
ASSERT(staffCount == 1);
ASSERT(staffCount <= 1);
}
else
{
Expand All @@ -274,7 +274,7 @@ class Character final : public IContainer
swordCount++;
}
}
ASSERT(swordCount == 1);
ASSERT(swordCount <= 1);

unsigned crossbowCount = 0;
for (const auto& item : GetInventory().GetItems())
Expand Down
4 changes: 2 additions & 2 deletions bak/encounter/encounter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ enum class EncounterType : std::uint16_t
{
Background = 0, // DEF_BKGR.DAT?? teleport??
Combat = 1, // DEF_COMB.DAT
Comment = 2, // ???
Comment = 2, // no file exists, but would be DEF_COMM.DAT
Dialog = 3, // DEF_DIAL.DAT
Health = 4, // ???
Health = 4, // no file exists, but would be DEF_COMM.DAT
Sound = 5, // DEF_SOUN.DAT
Town = 6, // DEF_TOWN.DAT
Trap = 7, // DEF_TRAP.DAT
Expand Down
28 changes: 28 additions & 0 deletions bak/entityType.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#include "bak/entityType.hpp"

namespace BAK {

unsigned GetContainerTypeFromEntityType(EntityType et)
{
using enum EntityType;
switch (et)
{
case BAG: return 0;
case CHEST: return 1;
case DIRTPILE: return 2;
case TOMBSTONE: return 3;
case DEADBODY1: [[fallthrough]];
case DEADBODY2: return 4;
case TRAP: return 5;
case BUSH1: [[fallthrough]];
case BUSH2: [[fallthrough]];
case BUSH3: return 6;
// 7 is shop, which is not an entity
case CRYST: return 8;
case STUMP: return 9;
case BUILDING: return 10;
default: return 0;
}
}

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

namespace BAK {

enum class EntityType
{
TERRAIN = 0,
EXTERIOR = 1,
BRIDGE = 2,
INTERIOR = 3,
HILL = 4,
TREE = 5,
CHEST = 6,
DEADBODY1 = 7,
FENCE = 8,
GATE = 9, // RIFT GATE
BUILDING = 10,
TOMBSTONE = 12,
SIGN = 13,
TUNNEL1 = 14, // ALSO TUNNEL...
PIT = 15,
DEADBODY2 = 16,
DIRTPILE = 17,
CORN = 18,
FIRE = 19,
ENTRANCE = 20,
GROVE = 21,
FERN = 22,
DOOR = 23,
CRYST = 24,
ROCKPILE = 25,
BUSH1 = 26,
BUSH2 = 27,
BUSH3 = 28,
SLAB = 29,
STUMP = 30,
WELL = 31,
ENGINE = 33,
SCARECROW = 34,
TRAP = 35,
CATAPULT = 36,
COLUMN = 37,
LANDSCAPE = 38,
TUNNEL2 = 39, // with tunnel
BAG = 41,
LADDER = 42
};

unsigned GetContainerTypeFromEntityType(EntityType);

}
5 changes: 5 additions & 0 deletions bak/fmap.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ class FMapXY
return glm::vec2{0, 0};
//ASSERT(it != tiles.end());
const auto index = std::distance(tiles.begin(), it);
// There's no full map for Timirianya
if (zone.mValue == 9)
{
return glm::vec2{0, 0};
}
return mTileCoords[zone.mValue - 1][index];
}

Expand Down
14 changes: 8 additions & 6 deletions bak/gameData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,11 @@ Conditions GameData::LoadConditions(unsigned character)
unsigned GameData::LoadChapter()
{
mBuffer.Seek(sChapterOffset);
return mBuffer.GetUint16LE();
auto chapter = mBuffer.GetUint16LE();
mBuffer.Seek(0x64);
auto chapterAgain = mBuffer.GetUint16LE();
assert(chapter == chapterAgain);
return chapterAgain;
}

Royals GameData::LoadGold()
Expand Down Expand Up @@ -204,18 +208,16 @@ Location GameData::LoadLocation()
mBuffer.Seek(sLocationOffset);

unsigned zone = mBuffer.GetUint8();
ASSERT(zone < 12);
ASSERT(zone <= 12);
mLogger.Info() << "LOADED: Zone:" << zone << std::endl;

unsigned xtile = mBuffer.GetUint8();
unsigned ytile = mBuffer.GetUint8();
unsigned xpos = mBuffer.GetUint32LE();
unsigned ypos = mBuffer.GetUint32LE();

//mBuffer.DumpAndSkip(5);
mBuffer.Skip(5);
std::uint16_t heading = mBuffer.GetUint8();
mBuffer.Skip(1);
mLogger.Info() << "Unknown: " << mBuffer.GetArray<5>() << "\n";
std::uint16_t heading = mBuffer.GetUint16LE() >> 8;

mLogger.Info() << "Tile: " << xtile << "," << ytile << std::endl;
mLogger.Info() << "Pos: " << xpos << "," << ypos << std::endl;
Expand Down
10 changes: 5 additions & 5 deletions bak/gameState.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,18 +132,18 @@ class GameState
const TextVariableStore& GetTextVariableStore() const { return mTextVariableStore; }
TextVariableStore& GetTextVariableStore() { return mTextVariableStore; }

template <typename F>
bool Apply(F&& func)
template <typename F, typename ...Args>
bool Apply(F&& func, Args&&... args)
{
if (mGameData)
{
if constexpr (std::is_same_v<decltype(func(mGameData->GetFileBuffer())), bool>)
if constexpr (std::is_same_v<decltype(func(mGameData->GetFileBuffer(), args...)), bool>)
{
return std::invoke(func, mGameData->GetFileBuffer());
return std::invoke(func, mGameData->GetFileBuffer(), args...);
}
else
{
std::invoke(func, mGameData->GetFileBuffer());
std::invoke(func, mGameData->GetFileBuffer(), args...);
}
}

Expand Down
35 changes: 25 additions & 10 deletions bak/state/encounter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ bool CheckActive(
zone,
encounter.GetTileIndex(),
encounterIndex);
const bool encounterFlag1450 = ReadEventBool(
fb,
CalculateRecentEncounterStateFlag(encounterIndex));
const bool recentlyEncountered = CheckRecentlyEncountered(fb, encounterIndex);
// event flag 1 - this flag must be set to encounter the event
const bool eventFlag1 = encounter.mSaveAddress != 0
? (ReadEventBool(fb, encounter.mSaveAddress) == 1)
Expand All @@ -32,7 +30,7 @@ bool CheckActive(
? ReadEventBool(fb, encounter.mSaveAddress2)
: false;
return !(alreadyEncountered
|| encounterFlag1450
|| recentlyEncountered
|| eventFlag1
|| eventFlag2);
}
Expand All @@ -51,8 +49,9 @@ bool CheckCombatActive(

assert(std::holds_alternative<Encounter::Combat>(encounter.GetEncounter()));
const auto combatIndex = std::get<Encounter::Combat>(encounter.GetEncounter()).mCombatIndex;
// If this flag is not set then this combat hasn't been seen
const bool encounterFlag1464 = !CheckCombatEncounterStateFlag(fb, combatIndex);

// If this flag is set then this combat hasn't been seen
const bool encounterFlag1464 = CheckCombatEncounterStateFlag(fb, combatIndex);

// event flag 1 - this flag must be set to encounter the event
const bool eventFlag1 = encounter.mSaveAddress != 0
Expand All @@ -63,6 +62,11 @@ bool CheckCombatActive(
? ReadEventBool(fb, encounter.mSaveAddress2)
: false;

Logging::LogInfo(__FUNCTION__) << " alreadyEncountered: " << alreadyEncountered
<< " combatEncounterStateFlag: " << encounterFlag1464
<< " eventFlag1: " << eventFlag1
<< " eventFlag2: " << eventFlag2 << "\n";

return !(alreadyEncountered
|| encounterFlag1464
|| eventFlag1
Expand Down Expand Up @@ -98,10 +102,7 @@ void SetPostDialogEventFlags(
}

// Inhibit for this tile
SetEventFlagTrue(
fb,
CalculateRecentEncounterStateFlag(
encounterIndex));
SetRecentlyEncountered(fb, encounterIndex);
}

}
Expand Down Expand Up @@ -214,12 +215,26 @@ unsigned CalculateRecentEncounterStateFlag(
return offset + encounterIndex;
}

bool CheckRecentlyEncountered(FileBuffer& fb, std::uint8_t encounterIndex)
{
return ReadEventBool(fb, CalculateRecentEncounterStateFlag(encounterIndex));
}

void SetRecentlyEncountered(FileBuffer& fb, std::uint8_t encounterIndex)
{
SetEventFlagTrue(
fb,
CalculateRecentEncounterStateFlag(
encounterIndex));
}

void ClearTileRecentEncounters(
FileBuffer& fb)
{
for (unsigned i = 0; i < 10; i++)
{
SetEventFlagFalse(fb, CalculateRecentEncounterStateFlag(i));
SetEventFlagFalse(fb, CalculateCombatEncounterScoutedStateFlag(i));
}
}
}
4 changes: 3 additions & 1 deletion bak/state/encounter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ void SetCombatEncounterScoutedState(
FileBuffer&,
std::uint8_t encounterIndex, bool state);

void ClearTileRecentEncounters(FileBuffer& fb);
void SetRecentlyEncountered(FileBuffer&, std::uint8_t encounterIndex);
bool CheckRecentlyEncountered(FileBuffer&, std::uint8_t encounterIndex);
void ClearTileRecentEncounters(FileBuffer&);

}
45 changes: 1 addition & 44 deletions bak/worldFactory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,56 +16,13 @@
#include "graphics/meshObject.hpp"

#include "bak/fileBufferFactory.hpp"
#include "bak/entityType.hpp"

#include <functional>
#include <optional>

namespace BAK {

enum class EntityType
{
TERRAIN = 0,
EXTERIOR = 1,
BRIDGE = 2,
INTERIOR = 3,
HILL = 4,
TREE = 5,
CHEST = 6,
DEADBODY1 = 7,
FENCE = 8,
GATE = 9, // RIFT GATE
BUILDING = 10,
TOMBSTONE = 12,
SIGN = 13,
TUNNEL1 = 14, // ALSO TUNNEL...
PIT = 15,
DEADBODY2 = 16,
DIRTPILE = 17,
CORN = 18,
FIRE = 19,
ENTRANCE = 20,
GROVE = 21,
FERN = 22,
DOOR = 23,
CRYST = 24,
ROCKPILE = 25,
BUSH1 = 26,
BUSH2 = 27,
BUSH3 = 28,
SLAB = 29,
STUMP = 30,
WELL = 31,
ENGINE = 33,
SCARECROW = 34,
TRAP = 35,
CATAPULT = 36,
COLUMN = 37,
LANDSCAPE = 38,
TUNNEL2 = 39, // with tunnel
BAG = 41,
LADDER = 42
};

class ZoneTextureStore
{
public:
Expand Down
Loading

0 comments on commit 124554b

Please sign in to comment.