Skip to content

Commit

Permalink
Game: store journal sections as an enum
Browse files Browse the repository at this point in the history
  • Loading branch information
lynxlynxlynx committed Mar 26, 2024
1 parent cade7a3 commit 91f6616
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 22 deletions.
10 changes: 2 additions & 8 deletions gemrb/core/DialogHandler.cpp
Expand Up @@ -39,20 +39,14 @@

namespace GemRB {

//translate section values (journal, quests, solved, user)
static const ieByte* sectionMap;
static const ieByte bg2Sections[4] = { 4, 1, 2, 0 };
static const ieByte noSections[4] = { 0, 0, 0, 0 };

// FIXME: arbitrary guess value
#define DIALOG_MOVE_SPEED 75

DialogHandler::DialogHandler(void)
{
// translate section values (journal, quests, solved, user)
if (core->HasFeature(GFFlags::JOURNAL_HAS_SECTIONS)) {
sectionMap = bg2Sections;
} else {
sectionMap = noSections;
sectionMap = { JournalSection::UserBit, JournalSection::Unsolved, JournalSection::Solved, JournalSection::Main };
}
}

Expand Down
4 changes: 4 additions & 0 deletions gemrb/core/DialogHandler.h
Expand Up @@ -24,6 +24,8 @@
#include "exports.h"

#include "Dialog.h"
#include "Game.h"

#include "Scriptable/Scriptable.h"

namespace GemRB {
Expand Down Expand Up @@ -63,6 +65,8 @@ class GEM_EXPORT DialogHandler {

int initialState = -1;
Point prevViewPortLoc;

std::array<JournalSection, 4> sectionMap {};
};

}
Expand Down
10 changes: 5 additions & 5 deletions gemrb/core/Game.cpp
Expand Up @@ -1002,20 +1002,20 @@ void Game::DeleteJournalGroup(ieByte group)
}
}
/* returns true if it modified or added a journal entry */
bool Game::AddJournalEntry(ieStrRef strRef, ieByte section, ieByte group, ieStrRef feedback)
bool Game::AddJournalEntry(ieStrRef strRef, JournalSection section, ieByte group, ieStrRef feedback)
{
GAMJournalEntry* je = FindJournalEntry(strRef);
if (je) {
//don't set this entry again in the same section
if (je->Section == section) {
if (je->Section == UnderType(section)) {
return false;
}
if ((section == IE_GAM_QUEST_DONE) && group) {
if ((section == JournalSection::Solved) && group) {
//removing all of this group and adding a new entry
DeleteJournalGroup(group);
} else {
//modifying existing entry
je->Section = section;
je->Section = UnderType(section);
je->Group = group;
ieDword chapter = 0;
if (!core->HasFeature(GFFlags::NO_NEW_VARIABLES)) {
Expand All @@ -1034,7 +1034,7 @@ bool Game::AddJournalEntry(ieStrRef strRef, ieByte section, ieByte group, ieStrR
}
je->Chapter = (ieByte) chapter;
je->unknown09 = 0;
je->Section = section;
je->Section = UnderType(section);
je->Group = group;
je->Text = strRef;

Expand Down
13 changes: 8 additions & 5 deletions gemrb/core/Game.h
Expand Up @@ -130,10 +130,13 @@ enum RestChecks {
// SONG_BATTLE_LOSE
// SONG_MISC0-4

#define IE_GAM_JOURNAL 0
#define IE_GAM_QUEST_UNSOLVED 1
#define IE_GAM_QUEST_DONE 2
#define IE_GAM_JOURNAL_USER 3
enum class JournalSection : uint8_t {
Main,
Unsolved,
Solved,
User,
UserBit
};

/**
* @struct GAMJournalEntry
Expand Down Expand Up @@ -384,7 +387,7 @@ class GEM_EXPORT Game : public Scriptable {
/** Adds a journal entry from dialog data.
* Time and chapter are calculated on the fly
* Returns false if the entry already exists */
bool AddJournalEntry(ieStrRef strRef, ieByte section, ieByte group, ieStrRef feedback = ieStrRef::INVALID);
bool AddJournalEntry(ieStrRef strRef, JournalSection section, ieByte group, ieStrRef feedback = ieStrRef::INVALID);
/** Adds a journal entry while loading the .gam structure */
void AddJournalEntry(GAMJournalEntry* entry);
unsigned int GetJournalCount() const;
Expand Down
5 changes: 2 additions & 3 deletions gemrb/core/GameScript/Actions.cpp
Expand Up @@ -3795,15 +3795,14 @@ void GameScript::IncrementExtraProficiency(Scriptable* Sender, Action* parameter
//the third parameter is a GemRB extension
void GameScript::AddJournalEntry(Scriptable* /*Sender*/, Action* parameters)
{
core->GetGame()->AddJournalEntry(ieStrRef(parameters->int0Parameter), (ieByte) parameters->int1Parameter, (ieByte) parameters->int2Parameter);
core->GetGame()->AddJournalEntry(ieStrRef(parameters->int0Parameter), (JournalSection) parameters->int1Parameter, (ieByte) parameters->int2Parameter);
}

void GameScript::SetQuestDone(Scriptable* /*Sender*/, Action* parameters)
{
Game *game = core->GetGame();
game->DeleteJournalEntry(ieStrRef(parameters->int0Parameter));
game->AddJournalEntry(ieStrRef(parameters->int0Parameter), IE_GAM_QUEST_DONE, (ieByte) parameters->int2Parameter);

game->AddJournalEntry(ieStrRef(parameters->int0Parameter), JournalSection::Solved, (ieByte) parameters->int2Parameter);
}

void GameScript::RemoveJournalEntry(Scriptable* /*Sender*/, Action* parameters)
Expand Down
2 changes: 1 addition & 1 deletion gemrb/plugins/GUIScript/GUIScript.cpp
Expand Up @@ -5166,7 +5166,7 @@ static PyObject* GemRB_SetJournalEntry(PyObject * /*self*/, PyObject * args)
if (chapter == ieDword(-1)) {
chapter = game->GetGlobal("CHAPTER", -1);
}
game->AddJournalEntry(strref, (ieByte) section, (ieByte) chapter, msg2);
game->AddJournalEntry(strref, (JournalSection) section, (ieByte) chapter, msg2);
}

Py_RETURN_NONE;
Expand Down

0 comments on commit 91f6616

Please sign in to comment.