[General] Add optional timestamps to journal entries in PlayerJournal

pull/471/head
David Cernat 7 years ago
parent ea8a41160c
commit a4b588d1b5

@ -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);
}

@ -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.
*

@ -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.

@ -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

@ -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.

@ -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);

@ -35,6 +35,9 @@ namespace mwmp
std::string actorRefId;
bool hasTimestamp;
mwmp::Time timestamp;
int type; // 0 - An entire entry, 1 - An index
};

@ -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;

@ -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)

Loading…
Cancel
Save