From a4b588d1b54d86fb210df9dc0ded865d28df2645 Mon Sep 17 00:00:00 2001 From: David Cernat Date: Thu, 26 Jul 2018 04:36:12 +0300 Subject: [PATCH] [General] Add optional timestamps to journal entries in PlayerJournal --- apps/openmw-mp/Script/Functions/Quests.cpp | 21 +++++++ apps/openmw-mp/Script/Functions/Quests.hpp | 56 ++++++++++++------- apps/openmw/mwbase/journal.hpp | 11 +++- apps/openmw/mwdialogue/journalimp.cpp | 26 ++++++++- apps/openmw/mwdialogue/journalimp.hpp | 11 +++- apps/openmw/mwmp/LocalPlayer.cpp | 13 ++++- components/openmw-mp/Base/BasePlayer.hpp | 3 + components/openmw-mp/Base/BaseStructs.hpp | 11 ++++ .../Packets/Player/PacketPlayerJournal.cpp | 9 +++ 9 files changed, 138 insertions(+), 23 deletions(-) diff --git a/apps/openmw-mp/Script/Functions/Quests.cpp b/apps/openmw-mp/Script/Functions/Quests.cpp index c0a3bf419..ed841f7b9 100644 --- a/apps/openmw-mp/Script/Functions/Quests.cpp +++ b/apps/openmw-mp/Script/Functions/Quests.cpp @@ -50,6 +50,27 @@ void QuestFunctions::AddJournalEntry(unsigned short pid, const char* quest, unsi journalItem.quest = quest; journalItem.index = index; journalItem.actorRefId = actorRefId; + journalItem.hasTimestamp = false; + + player->journalChanges.journalItems.push_back(journalItem); +} + +void QuestFunctions::AddJournalEntryWithTimestamp(unsigned short pid, const char* quest, unsigned int index, const char* actorRefId, + unsigned int daysPassed, unsigned int month, unsigned int day) noexcept +{ + Player *player; + GET_PLAYER(pid, player, ); + + mwmp::JournalItem journalItem; + journalItem.type = JournalItem::ENTRY; + journalItem.quest = quest; + journalItem.index = index; + journalItem.actorRefId = actorRefId; + journalItem.hasTimestamp = true; + + journalItem.timestamp.daysPassed = daysPassed; + journalItem.timestamp.month = month; + journalItem.timestamp.day = day; player->journalChanges.journalItems.push_back(journalItem); } diff --git a/apps/openmw-mp/Script/Functions/Quests.hpp b/apps/openmw-mp/Script/Functions/Quests.hpp index 3ed40370c..587e8ae6f 100644 --- a/apps/openmw-mp/Script/Functions/Quests.hpp +++ b/apps/openmw-mp/Script/Functions/Quests.hpp @@ -2,30 +2,31 @@ #define OPENMW_QUESTAPI_HPP #define QUESTAPI \ - {"InitializeJournalChanges", QuestFunctions::InitializeJournalChanges},\ - {"InitializeKillChanges", QuestFunctions::InitializeKillChanges},\ + {"InitializeJournalChanges", QuestFunctions::InitializeJournalChanges},\ + {"InitializeKillChanges", QuestFunctions::InitializeKillChanges},\ \ - {"GetJournalChangesSize", QuestFunctions::GetJournalChangesSize},\ - {"GetKillChangesSize", QuestFunctions::GetKillChangesSize},\ + {"GetJournalChangesSize", QuestFunctions::GetJournalChangesSize},\ + {"GetKillChangesSize", QuestFunctions::GetKillChangesSize},\ \ - {"AddJournalEntry", QuestFunctions::AddJournalEntry},\ - {"AddJournalIndex", QuestFunctions::AddJournalIndex},\ - {"AddKill", QuestFunctions::AddKill},\ + {"AddJournalEntry", QuestFunctions::AddJournalEntry},\ + {"AddJournalEntryWithTimestamp", QuestFunctions::AddJournalEntryWithTimestamp},\ + {"AddJournalIndex", QuestFunctions::AddJournalIndex},\ + {"AddKill", QuestFunctions::AddKill},\ \ - {"SetReputation", QuestFunctions::SetReputation},\ + {"SetReputation", QuestFunctions::SetReputation},\ \ - {"GetJournalItemQuest", QuestFunctions::GetJournalItemQuest},\ - {"GetJournalItemIndex", QuestFunctions::GetJournalItemIndex},\ - {"GetJournalItemType", QuestFunctions::GetJournalItemType},\ - {"GetJournalItemActorRefId", QuestFunctions::GetJournalItemActorRefId},\ - {"GetKillRefId", QuestFunctions::GetKillRefId},\ - {"GetKillNumber", QuestFunctions::GetKillNumber},\ + {"GetJournalItemQuest", QuestFunctions::GetJournalItemQuest},\ + {"GetJournalItemIndex", QuestFunctions::GetJournalItemIndex},\ + {"GetJournalItemType", QuestFunctions::GetJournalItemType},\ + {"GetJournalItemActorRefId", QuestFunctions::GetJournalItemActorRefId},\ + {"GetKillRefId", QuestFunctions::GetKillRefId},\ + {"GetKillNumber", QuestFunctions::GetKillNumber},\ \ - {"GetReputation", QuestFunctions::GetReputation},\ + {"GetReputation", QuestFunctions::GetReputation},\ \ - {"SendJournalChanges", QuestFunctions::SendJournalChanges},\ - {"SendKillChanges", QuestFunctions::SendKillChanges},\ - {"SendReputation", QuestFunctions::SendReputation} + {"SendJournalChanges", QuestFunctions::SendJournalChanges},\ + {"SendKillChanges", QuestFunctions::SendKillChanges},\ + {"SendReputation", QuestFunctions::SendReputation} class QuestFunctions { @@ -68,7 +69,8 @@ public: static unsigned int GetKillChangesSize(unsigned short pid) noexcept; /** - * \brief Add a new journal item of type ENTRY to the journal changes for a player. + * \brief Add a new journal item of type ENTRY to the journal changes for a player, + * with a specific timestamp. * * \param pid The player ID whose journal changes should be used. * \param quest The quest of the journal item. @@ -78,6 +80,22 @@ public: */ static void AddJournalEntry(unsigned short pid, const char* quest, unsigned int index, const char* actorRefId) noexcept; + /** + * \brief Add a new journal item of type ENTRY to the journal changes for a player, + * with a specific timestamp. + * + * \param pid The player ID whose journal changes should be used. + * \param quest The quest of the journal item. + * \param index The quest index of the journal item. + * \param actorRefId The actor refId of the journal item. + * \param The daysPassed for the journal item. + * \param The month for the journal item. + * \param The day of the month for the journal item. + * \return void + */ + static void AddJournalEntryWithTimestamp(unsigned short pid, const char* quest, unsigned int index, const char* actorRefId, + unsigned int daysPassed, unsigned int month, unsigned int day) noexcept; + /** * \brief Add a new journal item of type INDEX to the journal changes for a player. * diff --git a/apps/openmw/mwbase/journal.hpp b/apps/openmw/mwbase/journal.hpp index a46d7cef5..60616797b 100644 --- a/apps/openmw/mwbase/journal.hpp +++ b/apps/openmw/mwbase/journal.hpp @@ -60,9 +60,18 @@ namespace MWBase End of tes3mp addition */ - virtual void addEntry (const std::string& id, int index, const MWWorld::Ptr& actor) = 0; + /* + Start of tes3mp change (minor) + + Make it possible to override current time when adding journal entries, by adding + optional timestamp override arguments + */ + virtual void addEntry (const std::string& id, int index, const MWWorld::Ptr& actor, int daysPassed = -1, int month = -1, int day = -1) = 0; ///< Add a journal entry. /// @param actor Used as context for replacing of escape sequences (%name, etc). + /* + End of tes3mp change (major) + */ virtual void setJournalIndex (const std::string& id, int index) = 0; ///< Set the journal index without adding an entry. diff --git a/apps/openmw/mwdialogue/journalimp.cpp b/apps/openmw/mwdialogue/journalimp.cpp index e99429e27..aa5dfac56 100644 --- a/apps/openmw/mwdialogue/journalimp.cpp +++ b/apps/openmw/mwdialogue/journalimp.cpp @@ -93,7 +93,16 @@ namespace MWDialogue End of tes3mp addition */ - void Journal::addEntry (const std::string& id, int index, const MWWorld::Ptr& actor) + /* + Start of tes3mp change (minor) + + Make it possible to override current time when adding journal entries, by adding + optional timestamp override arguments + */ + void Journal::addEntry (const std::string& id, int index, const MWWorld::Ptr& actor, int daysPassed, int month, int day) + /* + End of tes3mp change (major) + */ { // bail out if we already have heard this... std::string infoId = JournalEntry::idFromIndex (id, index); @@ -110,6 +119,21 @@ namespace MWDialogue StampedJournalEntry entry = StampedJournalEntry::makeFromQuest (id, index, actor); + /* + Start of tes3mp addition + + Override the entry's timestamp if provided with valid time arguments + */ + if (daysPassed != -1 && month != -1 && day != -1) + { + entry.mDay = daysPassed; + entry.mMonth = month; + entry.mDayOfMonth = day; + } + /* + End of tes3mp addition + */ + Quest& quest = getQuest (id); quest.addEntry (entry); // we are doing slicing on purpose here diff --git a/apps/openmw/mwdialogue/journalimp.hpp b/apps/openmw/mwdialogue/journalimp.hpp index 7de5a9a4c..d185e525b 100644 --- a/apps/openmw/mwdialogue/journalimp.hpp +++ b/apps/openmw/mwdialogue/journalimp.hpp @@ -39,9 +39,18 @@ namespace MWDialogue End of tes3mp addition */ - virtual void addEntry (const std::string& id, int index, const MWWorld::Ptr& actor); + /* + Start of tes3mp change (minor) + + Make it possible to override current time when adding journal entries, by adding + optional timestamp override arguments + */ + virtual void addEntry (const std::string& id, int index, const MWWorld::Ptr& actor, int daysPassed = -1, int month = -1, int day = -1); ///< Add a journal entry. /// @param actor Used as context for replacing of escape sequences (%name, etc). + /* + End of tes3mp change (major) + */ virtual void setJournalIndex (const std::string& id, int index); ///< Set the journal index without adding an entry. diff --git a/apps/openmw/mwmp/LocalPlayer.cpp b/apps/openmw/mwmp/LocalPlayer.cpp index 28e746222..50cd7b59c 100644 --- a/apps/openmw/mwmp/LocalPlayer.cpp +++ b/apps/openmw/mwmp/LocalPlayer.cpp @@ -723,7 +723,17 @@ void LocalPlayer::addJournalItems() try { if (journalItem.type == JournalItem::ENTRY) - MWBase::Environment::get().getJournal()->addEntry(journalItem.quest, journalItem.index, ptrFound); + { + if (journalItem.hasTimestamp) + { + MWBase::Environment::get().getJournal()->addEntry(journalItem.quest, journalItem.index, ptrFound, + journalItem.timestamp.daysPassed, journalItem.timestamp.month, journalItem.timestamp.day); + } + else + { + MWBase::Environment::get().getJournal()->addEntry(journalItem.quest, journalItem.index, ptrFound); + } + } else MWBase::Environment::get().getJournal()->setJournalIndex(journalItem.quest, journalItem.index); } @@ -1455,6 +1465,7 @@ void LocalPlayer::sendJournalEntry(const std::string& quest, int index, const MW journalItem.quest = quest; journalItem.index = index; journalItem.actorRefId = actor.getCellRef().getRefId(); + journalItem.hasTimestamp = false; journalChanges.journalItems.push_back(journalItem); diff --git a/components/openmw-mp/Base/BasePlayer.hpp b/components/openmw-mp/Base/BasePlayer.hpp index 259ac6e87..d08de8034 100644 --- a/components/openmw-mp/Base/BasePlayer.hpp +++ b/components/openmw-mp/Base/BasePlayer.hpp @@ -35,6 +35,9 @@ namespace mwmp std::string actorRefId; + bool hasTimestamp; + mwmp::Time timestamp; + int type; // 0 - An entire entry, 1 - An index }; diff --git a/components/openmw-mp/Base/BaseStructs.hpp b/components/openmw-mp/Base/BaseStructs.hpp index 391af7232..6ee08d243 100644 --- a/components/openmw-mp/Base/BaseStructs.hpp +++ b/components/openmw-mp/Base/BaseStructs.hpp @@ -19,6 +19,17 @@ namespace mwmp SERVER_SCRIPT = 5 }; + struct Time + { + float hour; + int day; + int month; + int year; + + int daysPassed; + float timeScale; + }; + struct Item { std::string refId; diff --git a/components/openmw-mp/Packets/Player/PacketPlayerJournal.cpp b/components/openmw-mp/Packets/Player/PacketPlayerJournal.cpp index f7b3b0d6e..d8ab43930 100644 --- a/components/openmw-mp/Packets/Player/PacketPlayerJournal.cpp +++ b/components/openmw-mp/Packets/Player/PacketPlayerJournal.cpp @@ -34,6 +34,15 @@ void PacketPlayerJournal::Packet(RakNet::BitStream *bs, bool send) if (journalItem.type == JournalItem::ENTRY) { RW(journalItem.actorRefId, send, true); + + RW(journalItem.hasTimestamp, send); + + if (journalItem.hasTimestamp) + { + RW(journalItem.timestamp.daysPassed, send); + RW(journalItem.timestamp.month, send); + RW(journalItem.timestamp.day, send); + } } if (!send)