1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-01-15 20:49:56 +00:00
openmw-tes3mp/apps/openmw/mwscript/dialogueextensions.cpp

148 lines
5.2 KiB
C++
Raw Normal View History

#include "dialogueextensions.hpp"
#include <components/compiler/extensions.hpp>
#include <components/interpreter/interpreter.hpp>
#include <components/interpreter/runtime.hpp>
#include <components/interpreter/opcodes.hpp>
#include "../mwdialogue/journal.hpp"
2012-02-10 21:02:24 +00:00
#include "../mwdialogue/dialoguemanager.hpp"
#include "interpretercontext.hpp"
namespace MWScript
{
namespace Dialogue
{
class OpJournal : public Interpreter::Opcode0
{
public:
virtual void execute (Interpreter::Runtime& runtime)
{
MWScript::InterpreterContext& context
= static_cast<MWScript::InterpreterContext&> (runtime.getContext());
std::string quest = runtime.getStringLiteral (runtime[0].mInteger);
runtime.pop();
Interpreter::Type_Integer index = runtime[0].mInteger;
runtime.pop();
context.getEnvironment().mJournal->addEntry (quest, index);
}
};
class OpSetJournalIndex : public Interpreter::Opcode0
{
public:
virtual void execute (Interpreter::Runtime& runtime)
{
MWScript::InterpreterContext& context
= static_cast<MWScript::InterpreterContext&> (runtime.getContext());
std::string quest = runtime.getStringLiteral (runtime[0].mInteger);
runtime.pop();
Interpreter::Type_Integer index = runtime[0].mInteger;
runtime.pop();
context.getEnvironment().mJournal->setJournalIndex (quest, index);
}
};
class OpGetJournalIndex : public Interpreter::Opcode0
{
public:
virtual void execute (Interpreter::Runtime& runtime)
{
MWScript::InterpreterContext& context
= static_cast<MWScript::InterpreterContext&> (runtime.getContext());
std::string quest = runtime.getStringLiteral (runtime[0].mInteger);
runtime.pop();
int index = context.getEnvironment().mJournal->getJournalIndex (quest);
runtime.push (index);
}
};
2012-02-10 21:02:24 +00:00
class OpAddTopic : public Interpreter::Opcode0
{
public:
virtual void execute (Interpreter::Runtime& runtime)
{
MWScript::InterpreterContext& context
= static_cast<MWScript::InterpreterContext&> (runtime.getContext());
std::string topic = runtime.getStringLiteral (runtime[0].mInteger);
runtime.pop();
context.getEnvironment().mDialogueManager->addTopic(topic);
}
};
2012-03-07 17:52:27 +00:00
class OpChoice : public Interpreter::Opcode1
{
public:
virtual void execute (Interpreter::Runtime& runtime, unsigned int arg0)
{
std::cout << "CHOICE" << arg0;
arg0 = 4;
2012-03-07 17:52:27 +00:00
MWScript::InterpreterContext& context
= static_cast<MWScript::InterpreterContext&> (runtime.getContext());
MWDialogue::DialogueManager* dialogue = context.getEnvironment().mDialogueManager;
//int choice = 1;
while(arg0>0)
{
std::string question = runtime.getStringLiteral (runtime[0].mInteger);
runtime.pop();
arg0 = arg0 -1;
Interpreter::Type_Integer choice = 1;
if(arg0>0)
{
choice = runtime[0].mInteger;
runtime.pop();
arg0 = arg0 -1;
}
dialogue->askQuestion(question,choice);
}
}
};
const int opcodeJournal = 0x2000133;
const int opcodeSetJournalIndex = 0x2000134;
const int opcodeGetJournalIndex = 0x2000135;
2012-02-10 21:02:24 +00:00
const int opcodeAddTopic = 0x200013a;
2012-03-07 17:52:27 +00:00
const int opcodeChoice = 0x2000a;
void registerExtensions (Compiler::Extensions& extensions)
{
extensions.registerInstruction ("journal", "cl", opcodeJournal);
extensions.registerInstruction ("setjournalindex", "cl", opcodeSetJournalIndex);
extensions.registerFunction ("getjournalindex", 'l', "c", opcodeGetJournalIndex);
2012-03-07 17:52:27 +00:00
extensions.registerInstruction ("addtopic", "S" , opcodeAddTopic);
extensions.registerInstruction ("choice", "/SlSl", opcodeChoice);
}
void installOpcodes (Interpreter::Interpreter& interpreter)
{
interpreter.installSegment5 (opcodeJournal, new OpJournal);
interpreter.installSegment5 (opcodeSetJournalIndex, new OpSetJournalIndex);
interpreter.installSegment5 (opcodeGetJournalIndex, new OpGetJournalIndex);
2012-03-07 17:52:27 +00:00
interpreter.installSegment5 (opcodeAddTopic, new OpAddTopic);
interpreter.installSegment3 (opcodeChoice,new OpChoice);
}
}
}