Accept an implicit reference in Journal (Fixes #3135)

coverity_scan
scrawl 9 years ago
parent ef20962fc5
commit f315a4386f

@ -50,8 +50,9 @@ namespace MWBase
virtual ~Journal() {} virtual ~Journal() {}
virtual void addEntry (const std::string& id, int index) = 0; virtual void addEntry (const std::string& id, int index, const MWWorld::Ptr& actor) = 0;
///< Add a journal entry. ///< Add a journal entry.
/// @param actor Used as context for replacing of escape sequences (%name, etc).
virtual void setJournalIndex (const std::string& id, int index) = 0; virtual void setJournalIndex (const std::string& id, int index) = 0;
///< Set the journal index without adding an entry. ///< Set the journal index without adding an entry.

@ -102,8 +102,8 @@ namespace MWDialogue
{} {}
StampedJournalEntry::StampedJournalEntry (const std::string& topic, const std::string& infoId, StampedJournalEntry::StampedJournalEntry (const std::string& topic, const std::string& infoId,
int day, int month, int dayOfMonth) int day, int month, int dayOfMonth, const MWWorld::Ptr& actor)
: JournalEntry (topic, infoId, MWWorld::Ptr()), mDay (day), mMonth (month), mDayOfMonth (dayOfMonth) : JournalEntry (topic, infoId, actor), mDay (day), mMonth (month), mDayOfMonth (dayOfMonth)
{} {}
StampedJournalEntry::StampedJournalEntry (const ESM::JournalEntry& record) StampedJournalEntry::StampedJournalEntry (const ESM::JournalEntry& record)
@ -119,12 +119,12 @@ namespace MWDialogue
entry.mDayOfMonth = mDayOfMonth; entry.mDayOfMonth = mDayOfMonth;
} }
StampedJournalEntry StampedJournalEntry::makeFromQuest (const std::string& topic, int index) StampedJournalEntry StampedJournalEntry::makeFromQuest (const std::string& topic, int index, const MWWorld::Ptr& actor)
{ {
int day = MWBase::Environment::get().getWorld()->getGlobalInt ("dayspassed"); int day = MWBase::Environment::get().getWorld()->getGlobalInt ("dayspassed");
int month = MWBase::Environment::get().getWorld()->getGlobalInt ("month"); int month = MWBase::Environment::get().getWorld()->getGlobalInt ("month");
int dayOfMonth = MWBase::Environment::get().getWorld()->getGlobalInt ("day"); int dayOfMonth = MWBase::Environment::get().getWorld()->getGlobalInt ("day");
return StampedJournalEntry (topic, idFromIndex (topic, index), day, month, dayOfMonth); return StampedJournalEntry (topic, idFromIndex (topic, index), day, month, dayOfMonth, actor);
} }
} }

@ -64,13 +64,13 @@ namespace MWDialogue
StampedJournalEntry(); StampedJournalEntry();
StampedJournalEntry (const std::string& topic, const std::string& infoId, StampedJournalEntry (const std::string& topic, const std::string& infoId,
int day, int month, int dayOfMonth); int day, int month, int dayOfMonth, const MWWorld::Ptr& actor);
StampedJournalEntry (const ESM::JournalEntry& record); StampedJournalEntry (const ESM::JournalEntry& record);
void write (ESM::JournalEntry& entry) const; void write (ESM::JournalEntry& entry) const;
static StampedJournalEntry makeFromQuest (const std::string& topic, int index); static StampedJournalEntry makeFromQuest (const std::string& topic, int index, const MWWorld::Ptr& actor);
}; };
} }

@ -75,7 +75,7 @@ namespace MWDialogue
mTopics.clear(); mTopics.clear();
} }
void Journal::addEntry (const std::string& id, int index) void Journal::addEntry (const std::string& id, int index, const MWWorld::Ptr& actor)
{ {
// bail out of we already have heard this... // bail out of we already have heard this...
std::string infoId = JournalEntry::idFromIndex (id, index); std::string infoId = JournalEntry::idFromIndex (id, index);
@ -83,7 +83,7 @@ namespace MWDialogue
if (i->mTopic == id && i->mInfoId == infoId) if (i->mTopic == id && i->mInfoId == infoId)
return; return;
StampedJournalEntry entry = StampedJournalEntry::makeFromQuest (id, index); StampedJournalEntry entry = StampedJournalEntry::makeFromQuest (id, index, actor);
mJournal.push_back (entry); mJournal.push_back (entry);

@ -29,8 +29,9 @@ namespace MWDialogue
virtual void clear(); virtual void clear();
virtual void addEntry (const std::string& id, int index); virtual void addEntry (const std::string& id, int index, const MWWorld::Ptr& actor);
///< Add a journal entry. ///< Add a journal entry.
/// @param actor Used as context for replacing of escape sequences (%name, etc).
virtual void setJournalIndex (const std::string& id, int index); virtual void setJournalIndex (const std::string& id, int index);
///< Set the journal index without adding an entry. ///< Set the journal index without adding an entry.

@ -22,12 +22,17 @@ namespace MWScript
{ {
namespace Dialogue namespace Dialogue
{ {
template <class R>
class OpJournal : public Interpreter::Opcode0 class OpJournal : public Interpreter::Opcode0
{ {
public: public:
virtual void execute (Interpreter::Runtime& runtime) virtual void execute (Interpreter::Runtime& runtime)
{ {
MWWorld::Ptr ptr = R()(runtime, false); // required=false
if (ptr.isEmpty())
ptr = MWBase::Environment::get().getWorld()->getPlayerPtr();
std::string quest = runtime.getStringLiteral (runtime[0].mInteger); std::string quest = runtime.getStringLiteral (runtime[0].mInteger);
runtime.pop(); runtime.pop();
@ -37,7 +42,7 @@ namespace MWScript
// Invoking Journal with a non-existing index is allowed, and triggers no errors. Seriously? :( // Invoking Journal with a non-existing index is allowed, and triggers no errors. Seriously? :(
try try
{ {
MWBase::Environment::get().getJournal()->addEntry (quest, index); MWBase::Environment::get().getJournal()->addEntry (quest, index, ptr);
} }
catch (...) catch (...)
{ {
@ -270,7 +275,7 @@ namespace MWScript
void installOpcodes (Interpreter::Interpreter& interpreter) void installOpcodes (Interpreter::Interpreter& interpreter)
{ {
interpreter.installSegment5 (Compiler::Dialogue::opcodeJournal, new OpJournal); interpreter.installSegment5 (Compiler::Dialogue::opcodeJournal, new OpJournal<ImplicitRef>);
interpreter.installSegment5 (Compiler::Dialogue::opcodeSetJournalIndex, new OpSetJournalIndex); interpreter.installSegment5 (Compiler::Dialogue::opcodeSetJournalIndex, new OpSetJournalIndex);
interpreter.installSegment5 (Compiler::Dialogue::opcodeGetJournalIndex, new OpGetJournalIndex); interpreter.installSegment5 (Compiler::Dialogue::opcodeGetJournalIndex, new OpGetJournalIndex);
interpreter.installSegment5 (Compiler::Dialogue::opcodeAddTopic, new OpAddTopic); interpreter.installSegment5 (Compiler::Dialogue::opcodeAddTopic, new OpAddTopic);

Loading…
Cancel
Save