forked from teamnwah/openmw-tes3coop
Merge branch 'script'
This commit is contained in:
commit
82d62eb95a
5 changed files with 217 additions and 27 deletions
|
@ -356,7 +356,7 @@ void OMW::Engine::go()
|
|||
|
||||
// Create dialog system
|
||||
mEnvironment.setJournal (new MWDialogue::Journal);
|
||||
mEnvironment.setDialogueManager (new MWDialogue::DialogueManager (mExtensions));
|
||||
mEnvironment.setDialogueManager (new MWDialogue::DialogueManager (mExtensions, mVerboseScripts));
|
||||
|
||||
// Sets up the input system
|
||||
mEnvironment.setInputManager (new MWInput::InputManager (*mOgre,
|
||||
|
|
|
@ -75,11 +75,11 @@ namespace
|
|||
|
||||
namespace MWDialogue
|
||||
{
|
||||
DialogueManager::DialogueManager (const Compiler::Extensions& extensions) :
|
||||
DialogueManager::DialogueManager (const Compiler::Extensions& extensions, bool scriptVerbose) :
|
||||
mCompilerContext (MWScript::CompilerContext::Type_Dialgoue),
|
||||
mErrorStream(std::cout.rdbuf()),mErrorHandler(mErrorStream)
|
||||
, mTemporaryDispositionChange(0.f)
|
||||
, mPermanentDispositionChange(0.f)
|
||||
, mPermanentDispositionChange(0.f), mScriptVerbose (scriptVerbose)
|
||||
{
|
||||
mChoice = -1;
|
||||
mIsInChoice = false;
|
||||
|
@ -174,6 +174,8 @@ namespace MWDialogue
|
|||
|
||||
bool DialogueManager::compile (const std::string& cmd,std::vector<Interpreter::Type_Code>& code)
|
||||
{
|
||||
bool success = true;
|
||||
|
||||
try
|
||||
{
|
||||
mErrorHandler.reset();
|
||||
|
@ -195,23 +197,33 @@ namespace MWDialogue
|
|||
Compiler::ScriptParser parser(mErrorHandler,mCompilerContext, locals, false);
|
||||
|
||||
scanner.scan (parser);
|
||||
if(mErrorHandler.isGood())
|
||||
{
|
||||
parser.getCode(code);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
||||
if (!mErrorHandler.isGood())
|
||||
success = false;
|
||||
|
||||
if (success)
|
||||
parser.getCode (code);
|
||||
}
|
||||
catch (const Compiler::SourceException& /* error */)
|
||||
{
|
||||
// error has already been reported via error handler
|
||||
success = false;
|
||||
}
|
||||
catch (const std::exception& error)
|
||||
{
|
||||
printError (std::string ("An exception has been thrown: ") + error.what());
|
||||
success = false;
|
||||
}
|
||||
|
||||
return false;
|
||||
if (!success && mScriptVerbose)
|
||||
{
|
||||
std::cerr
|
||||
<< "compiling failed (dialogue script)" << std::endl
|
||||
<< cmd
|
||||
<< std::endl << std::endl;
|
||||
}
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
void DialogueManager::executeScript (const std::string& script)
|
||||
|
|
|
@ -35,6 +35,7 @@ namespace MWDialogue
|
|||
|
||||
float mTemporaryDispositionChange;
|
||||
float mPermanentDispositionChange;
|
||||
bool mScriptVerbose;
|
||||
|
||||
void parseText (const std::string& text);
|
||||
|
||||
|
@ -47,7 +48,7 @@ namespace MWDialogue
|
|||
|
||||
public:
|
||||
|
||||
DialogueManager (const Compiler::Extensions& extensions);
|
||||
DialogueManager (const Compiler::Extensions& extensions, bool scriptVerbose);
|
||||
|
||||
virtual void startDialogue (const MWWorld::Ptr& actor);
|
||||
|
||||
|
|
|
@ -31,7 +31,13 @@ op 0x2000e: PCGetRank implicit
|
|||
op 0x2000f: PCGetRank explicit
|
||||
op 0x20010: AiWander
|
||||
op 0x20011: AiWander, explicit reference
|
||||
op s 0x20012-0x3ffff unused
|
||||
op 0x20012: GetPCFacRep
|
||||
op 0x20013: GetPCFacRep, explicit reference
|
||||
op 0x20014: SetPCFacRep
|
||||
op 0x20015: SetPCFacRep, explicit reference
|
||||
op 0x20016: ModPCFacRep
|
||||
op 0x20017: ModPCFacRep, explicit reference
|
||||
op s 0x20018-0x3ffff unused
|
||||
|
||||
Segment 4:
|
||||
(not implemented yet)
|
||||
|
@ -207,5 +213,9 @@ op 0x20001a0: ShowMap
|
|||
op 0x20001a1: FillMap
|
||||
op 0x20001a2: WakeUpPc
|
||||
op 0x20001a3: GetDeadCount
|
||||
opcodes 0x20001a4-0x3ffffff unused
|
||||
op 0x20001a4: SetDisposition
|
||||
op 0x20001a5: SetDisposition, Explicit
|
||||
op 0x20001a6: GetDisposition
|
||||
op 0x20001a7: GetDisposition, Explicit
|
||||
opcodes 0x20001a8-0x3ffffff unused
|
||||
|
||||
|
|
|
@ -565,7 +565,7 @@ namespace MWScript
|
|||
{
|
||||
if(MWWorld::Class::get(ptr).getNpcStats(ptr).getFactionRanks().empty())
|
||||
{
|
||||
//throw exception?
|
||||
factionID = "";
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -601,10 +601,40 @@ namespace MWScript
|
|||
{
|
||||
MWWorld::Ptr ptr = R()(runtime);
|
||||
|
||||
// Interpreter::Type_Integer value = runtime[0].mInteger;
|
||||
Interpreter::Type_Integer value = runtime[0].mInteger;
|
||||
runtime.pop();
|
||||
|
||||
/// \todo modify disposition towards the player
|
||||
MWWorld::Class::get (ptr).getNpcStats (ptr).setBaseDisposition
|
||||
(MWWorld::Class::get (ptr).getNpcStats (ptr).getBaseDisposition() + value);
|
||||
}
|
||||
};
|
||||
|
||||
template<class R>
|
||||
class OpSetDisposition : public Interpreter::Opcode0
|
||||
{
|
||||
public:
|
||||
|
||||
virtual void execute (Interpreter::Runtime& runtime)
|
||||
{
|
||||
MWWorld::Ptr ptr = R()(runtime);
|
||||
|
||||
Interpreter::Type_Integer value = runtime[0].mInteger;
|
||||
runtime.pop();
|
||||
|
||||
MWWorld::Class::get (ptr).getNpcStats (ptr).setBaseDisposition (value);
|
||||
}
|
||||
};
|
||||
|
||||
template<class R>
|
||||
class OpGetDisposition : public Interpreter::Opcode0
|
||||
{
|
||||
public:
|
||||
|
||||
virtual void execute (Interpreter::Runtime& runtime)
|
||||
{
|
||||
MWWorld::Ptr ptr = R()(runtime);
|
||||
|
||||
runtime.push (MWWorld::Class::get (ptr).getNpcStats (ptr).getBaseDisposition());
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -619,6 +649,111 @@ namespace MWScript
|
|||
}
|
||||
};
|
||||
|
||||
template<class R>
|
||||
class OpGetPCFacRep : public Interpreter::Opcode1
|
||||
{
|
||||
public:
|
||||
|
||||
virtual void execute (Interpreter::Runtime& runtime, unsigned int arg0)
|
||||
{
|
||||
std::string factionId;
|
||||
|
||||
if (arg0==1)
|
||||
{
|
||||
factionId = runtime.getStringLiteral (runtime[0].mInteger);
|
||||
runtime.pop();
|
||||
}
|
||||
else
|
||||
{
|
||||
MWWorld::Ptr ptr = R()(runtime);
|
||||
|
||||
if (!MWWorld::Class::get (ptr).getNpcStats (ptr).getFactionRanks().empty())
|
||||
factionId = MWWorld::Class::get (ptr).getNpcStats (ptr).getFactionRanks().begin()->first;
|
||||
}
|
||||
|
||||
if (factionId.empty())
|
||||
throw std::runtime_error ("failed to determine faction");
|
||||
|
||||
boost::algorithm::to_lower (factionId);
|
||||
|
||||
MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayer().getPlayer();
|
||||
runtime.push (
|
||||
MWWorld::Class::get (player).getNpcStats (player).getFactionReputation (factionId));
|
||||
}
|
||||
};
|
||||
|
||||
template<class R>
|
||||
class OpSetPCFacRep : public Interpreter::Opcode1
|
||||
{
|
||||
public:
|
||||
|
||||
virtual void execute (Interpreter::Runtime& runtime, unsigned int arg0)
|
||||
{
|
||||
Interpreter::Type_Integer value = runtime[0].mInteger;
|
||||
runtime.pop();
|
||||
|
||||
std::string factionId;
|
||||
|
||||
if (arg0==1)
|
||||
{
|
||||
factionId = runtime.getStringLiteral (runtime[0].mInteger);
|
||||
runtime.pop();
|
||||
}
|
||||
else
|
||||
{
|
||||
MWWorld::Ptr ptr = R()(runtime);
|
||||
|
||||
if (!MWWorld::Class::get (ptr).getNpcStats (ptr).getFactionRanks().empty())
|
||||
factionId = MWWorld::Class::get (ptr).getNpcStats (ptr).getFactionRanks().begin()->first;
|
||||
}
|
||||
|
||||
if (factionId.empty())
|
||||
throw std::runtime_error ("failed to determine faction");
|
||||
|
||||
boost::algorithm::to_lower (factionId);
|
||||
|
||||
MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayer().getPlayer();
|
||||
MWWorld::Class::get (player).getNpcStats (player).setFactionReputation (factionId, value);
|
||||
}
|
||||
};
|
||||
|
||||
template<class R>
|
||||
class OpModPCFacRep : public Interpreter::Opcode1
|
||||
{
|
||||
public:
|
||||
|
||||
virtual void execute (Interpreter::Runtime& runtime, unsigned int arg0)
|
||||
{
|
||||
Interpreter::Type_Integer value = runtime[0].mInteger;
|
||||
runtime.pop();
|
||||
|
||||
std::string factionId;
|
||||
|
||||
if (arg0==1)
|
||||
{
|
||||
factionId = runtime.getStringLiteral (runtime[0].mInteger);
|
||||
runtime.pop();
|
||||
}
|
||||
else
|
||||
{
|
||||
MWWorld::Ptr ptr = R()(runtime);
|
||||
|
||||
if (!MWWorld::Class::get (ptr).getNpcStats (ptr).getFactionRanks().empty())
|
||||
factionId = MWWorld::Class::get (ptr).getNpcStats (ptr).getFactionRanks().begin()->first;
|
||||
}
|
||||
|
||||
if (factionId.empty())
|
||||
throw std::runtime_error ("failed to determine faction");
|
||||
|
||||
boost::algorithm::to_lower (factionId);
|
||||
|
||||
MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayer().getPlayer();
|
||||
MWWorld::Class::get (player).getNpcStats (player).setFactionReputation (factionId,
|
||||
MWWorld::Class::get (player).getNpcStats (player).getFactionReputation (factionId)+
|
||||
value);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
const int numberOfAttributes = 8;
|
||||
|
||||
|
@ -665,6 +800,10 @@ namespace MWScript
|
|||
const int opcodeGetPCRankExplicit = 0x2000f;
|
||||
const int opcodeModDisposition = 0x200014d;
|
||||
const int opcodeModDispositionExplicit = 0x200014e;
|
||||
const int opcodeSetDisposition = 0x20001a4;
|
||||
const int opcodeSetDispositionExplicit = 0x20001a5;
|
||||
const int opcodeGetDisposition = 0x20001a6;
|
||||
const int opcodeGetDispositionExplicit = 0x20001a7;
|
||||
|
||||
const int opcodeGetLevel = 0x200018c;
|
||||
const int opcodeGetLevelExplicit = 0x200018d;
|
||||
|
@ -673,6 +812,14 @@ namespace MWScript
|
|||
|
||||
const int opcodeGetDeadCount = 0x20001a3;
|
||||
|
||||
const int opcodeGetPCFacRep = 0x20012;
|
||||
const int opcodeGetPCFacRepExplicit = 0x20013;
|
||||
const int opcodeSetPCFacRep = 0x20014;
|
||||
const int opcodeSetPCFacRepExplicit = 0x20015;
|
||||
const int opcodeModPCFacRep = 0x20016;
|
||||
const int opcodeModPCFacRepExplicit = 0x20017;
|
||||
|
||||
|
||||
void registerExtensions (Compiler::Extensions& extensions)
|
||||
{
|
||||
static const char *attributes[numberOfAttributes] =
|
||||
|
@ -752,14 +899,22 @@ namespace MWScript
|
|||
extensions.registerInstruction("pcraiserank","/S",opcodePCRaiseRank);
|
||||
extensions.registerInstruction("pclowerrank","/S",opcodePCLowerRank);
|
||||
extensions.registerInstruction("pcjoinfaction","/S",opcodePCJoinFaction);
|
||||
extensions.registerInstruction("moddisposition","l",opcodeModDisposition,
|
||||
extensions.registerInstruction ("moddisposition","l",opcodeModDisposition,
|
||||
opcodeModDispositionExplicit);
|
||||
extensions.registerInstruction ("setdisposition","l",opcodeSetDisposition,
|
||||
opcodeSetDispositionExplicit);
|
||||
extensions.registerFunction ("getdisposition",'l', "",opcodeGetDisposition,
|
||||
opcodeGetDispositionExplicit);
|
||||
extensions.registerFunction("getpcrank",'l',"/S",opcodeGetPCRank,opcodeGetPCRankExplicit);
|
||||
|
||||
extensions.registerInstruction("setlevel", "l", opcodeSetLevel, opcodeSetLevelExplicit);
|
||||
extensions.registerFunction("getlevel", 'l', "", opcodeGetLevel, opcodeGetLevelExplicit);
|
||||
|
||||
extensions.registerFunction("getdeadcount", 'l', "c", opcodeGetDeadCount);
|
||||
extensions.registerFunction ("getdeadcount", 'l', "c", opcodeGetDeadCount);
|
||||
|
||||
extensions.registerFunction ("getpcfacrep", 'l', "/c", opcodeGetPCFacRep, opcodeGetPCFacRepExplicit);
|
||||
extensions.registerInstruction ("setpcfacrep", "/lc", opcodeSetPCFacRep, opcodeSetPCFacRepExplicit);
|
||||
extensions.registerInstruction ("modpcfacrep", "/lc", opcodeModPCFacRep, opcodeModPCFacRepExplicit);
|
||||
}
|
||||
|
||||
void installOpcodes (Interpreter::Interpreter& interpreter)
|
||||
|
@ -827,17 +982,29 @@ namespace MWScript
|
|||
interpreter.installSegment3(opcodePCRaiseRank,new OpPCRaiseRank);
|
||||
interpreter.installSegment3(opcodePCLowerRank,new OpPCLowerRank);
|
||||
interpreter.installSegment3(opcodePCJoinFaction,new OpPCJoinFaction);
|
||||
interpreter.installSegment5(opcodeModDisposition,new OpModDisposition<ImplicitRef>);
|
||||
interpreter.installSegment5(opcodeModDispositionExplicit,new OpModDisposition<ExplicitRef>);
|
||||
interpreter.installSegment3(opcodeGetPCRank,new OpGetPCRank<ImplicitRef>);
|
||||
interpreter.installSegment3(opcodeGetPCRankExplicit,new OpGetPCRank<ExplicitRef>);
|
||||
|
||||
interpreter.installSegment5(opcodeModDisposition,new OpModDisposition<ImplicitRef>);
|
||||
interpreter.installSegment5(opcodeModDispositionExplicit,new OpModDisposition<ExplicitRef>);
|
||||
interpreter.installSegment5(opcodeSetDisposition,new OpSetDisposition<ImplicitRef>);
|
||||
interpreter.installSegment5(opcodeSetDispositionExplicit,new OpSetDisposition<ExplicitRef>);
|
||||
interpreter.installSegment5(opcodeGetDisposition,new OpGetDisposition<ImplicitRef>);
|
||||
interpreter.installSegment5(opcodeGetDispositionExplicit,new OpGetDisposition<ExplicitRef>);
|
||||
|
||||
interpreter.installSegment5 (opcodeGetLevel, new OpGetLevel<ImplicitRef>);
|
||||
interpreter.installSegment5 (opcodeGetLevelExplicit, new OpGetLevel<ExplicitRef>);
|
||||
interpreter.installSegment5 (opcodeSetLevel, new OpSetLevel<ImplicitRef>);
|
||||
interpreter.installSegment5 (opcodeSetLevelExplicit, new OpSetLevel<ExplicitRef>);
|
||||
|
||||
interpreter.installSegment5 (opcodeGetDeadCount, new OpGetDeadCount);
|
||||
|
||||
interpreter.installSegment3 (opcodeGetPCFacRep, new OpGetPCFacRep<ImplicitRef>);
|
||||
interpreter.installSegment3 (opcodeGetPCFacRepExplicit, new OpGetPCFacRep<ExplicitRef>);
|
||||
interpreter.installSegment3 (opcodeSetPCFacRep, new OpSetPCFacRep<ImplicitRef>);
|
||||
interpreter.installSegment3 (opcodeSetPCFacRepExplicit, new OpSetPCFacRep<ExplicitRef>);
|
||||
interpreter.installSegment3 (opcodeModPCFacRep, new OpModPCFacRep<ImplicitRef>);
|
||||
interpreter.installSegment3 (opcodeModPCFacRepExplicit, new OpModPCFacRep<ExplicitRef>);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue