merged opcode classes that came in explicit and implicit variants

actorid
Marc Zinnschlag 14 years ago
parent 67a745cdf6
commit 2ffe1206a6

@ -103,6 +103,7 @@ set(GAMESCRIPT_HEADER
mwscript/controlextensions.hpp mwscript/controlextensions.hpp
mwscript/extensions.hpp mwscript/extensions.hpp
mwscript/globalscripts.hpp mwscript/globalscripts.hpp
mwscript/ref.hpp
) )
source_group(apps\\openmw\\mwscript FILES ${GAMESCRIPT} ${GAMESCRIPT_HEADER}) source_group(apps\\openmw\\mwscript FILES ${GAMESCRIPT} ${GAMESCRIPT_HEADER})

@ -8,6 +8,7 @@
#include <components/interpreter/opcodes.hpp> #include <components/interpreter/opcodes.hpp>
#include "interpretercontext.hpp" #include "interpretercontext.hpp"
#include "ref.hpp"
#include <iostream> #include <iostream>
@ -15,46 +16,14 @@ namespace MWScript
{ {
namespace Ai namespace Ai
{ {
template<class R>
class OpAiTravel : public Interpreter::Opcode1 class OpAiTravel : public Interpreter::Opcode1
{ {
public: public:
virtual void execute (Interpreter::Runtime& runtime, unsigned int arg0) virtual void execute (Interpreter::Runtime& runtime, unsigned int arg0)
{ {
MWScript::InterpreterContext& context MWWorld::Ptr ptr = R()(runtime);
= static_cast<MWScript::InterpreterContext&> (runtime.getContext());
MWWorld::Ptr ptr = context.getReference();
Interpreter::Type_Float x = runtime[0].mInteger;
runtime.pop();
Interpreter::Type_Float y = runtime[0].mInteger;
runtime.pop();
Interpreter::Type_Float z = runtime[0].mInteger;
runtime.pop();
// discard additional arguments (reset), because we have no idea what they mean.
for (unsigned int i=0; i<arg0; ++i) runtime.pop();
std::cout << "AiTravel: " << x << ", " << y << ", " << z << std::endl;
}
};
class OpAiTravelExplicit : public Interpreter::Opcode1
{
public:
virtual void execute (Interpreter::Runtime& runtime, unsigned int arg0)
{
MWScript::InterpreterContext& context
= static_cast<MWScript::InterpreterContext&> (runtime.getContext());
std::string id = runtime.getStringLiteral (runtime[0].mInteger);
runtime.pop();
MWWorld::Ptr ptr = context.getWorld().getPtr (id, false);
Interpreter::Type_Float x = runtime[0].mInteger; Interpreter::Type_Float x = runtime[0].mInteger;
runtime.pop(); runtime.pop();
@ -72,56 +41,14 @@ namespace MWScript
} }
}; };
template<class R>
class OpAiEscort : public Interpreter::Opcode1 class OpAiEscort : public Interpreter::Opcode1
{ {
public: public:
virtual void execute (Interpreter::Runtime& runtime, unsigned int arg0) virtual void execute (Interpreter::Runtime& runtime, unsigned int arg0)
{ {
MWScript::InterpreterContext& context MWWorld::Ptr ptr = R()(runtime);
= static_cast<MWScript::InterpreterContext&> (runtime.getContext());
std::string id = runtime.getStringLiteral (runtime[0].mInteger);
runtime.pop();
MWWorld::Ptr ptr = context.getReference();
std::string actor = runtime.getStringLiteral (runtime[0].mInteger);
runtime.pop();
Interpreter::Type_Float duration = runtime[0].mInteger;
runtime.pop();
Interpreter::Type_Float x = runtime[0].mInteger;
runtime.pop();
Interpreter::Type_Float y = runtime[0].mInteger;
runtime.pop();
Interpreter::Type_Float z = runtime[0].mInteger;
runtime.pop();
// discard additional arguments (reset), because we have no idea what they mean.
for (unsigned int i=0; i<arg0; ++i) runtime.pop();
std::cout << "AiEscort: " << x << ", " << y << ", " << z << ", " << duration
<< std::endl;
}
};
class OpAiEscortExplicit : public Interpreter::Opcode1
{
public:
virtual void execute (Interpreter::Runtime& runtime, unsigned int arg0)
{
MWScript::InterpreterContext& context
= static_cast<MWScript::InterpreterContext&> (runtime.getContext());
std::string id = runtime.getStringLiteral (runtime[0].mInteger);
runtime.pop();
MWWorld::Ptr ptr = context.getWorld().getPtr (id, false);
std::string actor = runtime.getStringLiteral (runtime[0].mInteger); std::string actor = runtime.getStringLiteral (runtime[0].mInteger);
runtime.pop(); runtime.pop();
@ -146,16 +73,14 @@ namespace MWScript
} }
}; };
template<class R>
class OpGetAiPackageDone : public Interpreter::Opcode0 class OpGetAiPackageDone : public Interpreter::Opcode0
{ {
public: public:
virtual void execute (Interpreter::Runtime& runtime) virtual void execute (Interpreter::Runtime& runtime)
{ {
MWScript::InterpreterContext& context MWWorld::Ptr ptr = R()(runtime);
= static_cast<MWScript::InterpreterContext&> (runtime.getContext());
MWWorld::Ptr ptr = context.getReference();
Interpreter::Type_Integer value = 0; Interpreter::Type_Integer value = 0;
@ -163,25 +88,6 @@ namespace MWScript
} }
}; };
class OpGetAiPackageDoneExplicit : public Interpreter::Opcode0
{
public:
virtual void execute (Interpreter::Runtime& runtime)
{
MWScript::InterpreterContext& context
= static_cast<MWScript::InterpreterContext&> (runtime.getContext());
std::string id = runtime.getStringLiteral (runtime[0].mInteger);
runtime.pop();
MWWorld::Ptr ptr = context.getWorld().getPtr (id, false);
Interpreter::Type_Integer value = 0;
runtime.push (value);
}
};
const int opcodeAiTravel = 0x20000; const int opcodeAiTravel = 0x20000;
@ -204,12 +110,13 @@ namespace MWScript
void installOpcodes (Interpreter::Interpreter& interpreter) void installOpcodes (Interpreter::Interpreter& interpreter)
{ {
interpreter.installSegment3 (opcodeAiTravel, new OpAiTravel); interpreter.installSegment3 (opcodeAiTravel, new OpAiTravel<ImplicitRef>);
interpreter.installSegment3 (opcodeAiTravelExplicit, new OpAiTravelExplicit); interpreter.installSegment3 (opcodeAiTravelExplicit, new OpAiTravel<ExplicitRef>);
interpreter.installSegment3 (opcodeAiEscort, new OpAiEscort); interpreter.installSegment3 (opcodeAiEscort, new OpAiEscort<ImplicitRef>);
interpreter.installSegment3 (opcodeAiEscortExplicit, new OpAiEscortExplicit); interpreter.installSegment3 (opcodeAiEscortExplicit, new OpAiEscort<ExplicitRef>);
interpreter.installSegment5 (opcodeGetAiPackageDone, new OpGetAiPackageDone); interpreter.installSegment5 (opcodeGetAiPackageDone, new OpGetAiPackageDone<ImplicitRef>);
interpreter.installSegment5 (opcodeGetAiPackageDoneExplicit, new OpGetAiPackageDoneExplicit); interpreter.installSegment5 (opcodeGetAiPackageDoneExplicit,
new OpGetAiPackageDone<ExplicitRef>);
} }
} }
} }

@ -14,52 +14,24 @@
#include "../mwworld/containerutil.hpp" #include "../mwworld/containerutil.hpp"
#include "interpretercontext.hpp" #include "interpretercontext.hpp"
#include "ref.hpp"
namespace MWScript namespace MWScript
{ {
namespace Container namespace Container
{ {
template<class R>
class OpAddItem : public Interpreter::Opcode0 class OpAddItem : public Interpreter::Opcode0
{ {
public: public:
virtual void execute (Interpreter::Runtime& runtime) virtual void execute (Interpreter::Runtime& runtime)
{ {
MWScript::InterpreterContext& context MWWorld::Ptr ptr = R()(runtime);
= static_cast<MWScript::InterpreterContext&> (runtime.getContext());
std::string item = runtime.getStringLiteral (runtime[0].mInteger);
runtime.pop();
Interpreter::Type_Integer count = runtime[0].mInteger;
runtime.pop();
if (count<0)
throw std::runtime_error ("second argument for AddItem must be non-negative");
MWWorld::Ptr ptr = context.getReference();
MWWorld::ManualRef ref (context.getWorld().getStore(), item);
ref.getPtr().getRefData().setCount (count);
MWWorld::Class::get (ref.getPtr()).insertIntoContainer (ref.getPtr(),
MWWorld::Class::get (ptr).getContainerStore (ptr));
}
};
class OpAddItemExplicit : public Interpreter::Opcode0
{
public:
virtual void execute (Interpreter::Runtime& runtime)
{
MWScript::InterpreterContext& context MWScript::InterpreterContext& context
= static_cast<MWScript::InterpreterContext&> (runtime.getContext()); = static_cast<MWScript::InterpreterContext&> (runtime.getContext());
std::string id = runtime.getStringLiteral (runtime[0].mInteger);
runtime.pop();
std::string item = runtime.getStringLiteral (runtime[0].mInteger); std::string item = runtime.getStringLiteral (runtime[0].mInteger);
runtime.pop(); runtime.pop();
@ -69,8 +41,6 @@ namespace MWScript
if (count<0) if (count<0)
throw std::runtime_error ("second argument for AddItem must be non-negative"); throw std::runtime_error ("second argument for AddItem must be non-negative");
MWWorld::Ptr ptr = context.getWorld().getPtr (id, false);
MWWorld::ManualRef ref (context.getWorld().getStore(), item); MWWorld::ManualRef ref (context.getWorld().getStore(), item);
ref.getPtr().getRefData().setCount (count); ref.getPtr().getRefData().setCount (count);
@ -80,55 +50,21 @@ namespace MWScript
} }
}; };
template<class R>
class OpGetItemCount : public Interpreter::Opcode0 class OpGetItemCount : public Interpreter::Opcode0
{ {
public: public:
virtual void execute (Interpreter::Runtime& runtime) virtual void execute (Interpreter::Runtime& runtime)
{ {
MWScript::InterpreterContext& context MWWorld::Ptr ptr = R()(runtime);
= static_cast<MWScript::InterpreterContext&> (runtime.getContext());
std::string item = runtime.getStringLiteral (runtime[0].mInteger);
runtime.pop();
MWWorld::Ptr ptr = context.getReference();
std::vector<MWWorld::Ptr> list;
MWWorld::listItemsInContainer (item,
MWWorld::Class::get (ptr).getContainerStore (ptr),
context.getWorld().getStore(), list);
Interpreter::Type_Integer sum = 0;
for (std::vector<MWWorld::Ptr>::iterator iter (list.begin()); iter!=list.end();
++iter)
{
sum += iter->getRefData().getCount();
}
runtime.push (sum);
}
};
class OpGetItemCountExplicit : public Interpreter::Opcode0
{
public:
virtual void execute (Interpreter::Runtime& runtime)
{
MWScript::InterpreterContext& context MWScript::InterpreterContext& context
= static_cast<MWScript::InterpreterContext&> (runtime.getContext()); = static_cast<MWScript::InterpreterContext&> (runtime.getContext());
std::string id = runtime.getStringLiteral (runtime[0].mInteger);
runtime.pop();
std::string item = runtime.getStringLiteral (runtime[0].mInteger); std::string item = runtime.getStringLiteral (runtime[0].mInteger);
runtime.pop(); runtime.pop();
MWWorld::Ptr ptr = context.getWorld().getPtr (id, false);
std::vector<MWWorld::Ptr> list; std::vector<MWWorld::Ptr> list;
MWWorld::listItemsInContainer (item, MWWorld::listItemsInContainer (item,
@ -147,65 +83,18 @@ namespace MWScript
} }
}; };
template<class R>
class OpRemoveItem : public Interpreter::Opcode0 class OpRemoveItem : public Interpreter::Opcode0
{ {
public: public:
virtual void execute (Interpreter::Runtime& runtime) virtual void execute (Interpreter::Runtime& runtime)
{ {
MWScript::InterpreterContext& context MWWorld::Ptr ptr = R()(runtime);
= static_cast<MWScript::InterpreterContext&> (runtime.getContext());
std::string item = runtime.getStringLiteral (runtime[0].mInteger);
runtime.pop();
Interpreter::Type_Integer count = runtime[0].mInteger;
runtime.pop();
if (count<0)
throw std::runtime_error ("second argument for RemoveItem must be non-negative");
MWWorld::Ptr ptr = context.getReference();
std::vector<MWWorld::Ptr> list;
MWWorld::listItemsInContainer (item,
MWWorld::Class::get (ptr).getContainerStore (ptr),
context.getWorld().getStore(), list);
for (std::vector<MWWorld::Ptr>::iterator iter (list.begin());
iter!=list.end() && count;
++iter)
{
if (iter->getRefData().getCount()<=count)
{
count -= iter->getRefData().getCount();
iter->getRefData().setCount (0);
}
else
{
iter->getRefData().setCount (iter->getRefData().getCount()-count);
count = 0;
}
}
// To be fully compatible with original Morrowind, we would need to check if
// count is >= 0 here and throw an exception. But let's be tollerant instead.
}
};
class OpRemoveItemExplicit : public Interpreter::Opcode0
{
public:
virtual void execute (Interpreter::Runtime& runtime)
{
MWScript::InterpreterContext& context MWScript::InterpreterContext& context
= static_cast<MWScript::InterpreterContext&> (runtime.getContext()); = static_cast<MWScript::InterpreterContext&> (runtime.getContext());
std::string id = runtime.getStringLiteral (runtime[0].mInteger);
runtime.pop();
std::string item = runtime.getStringLiteral (runtime[0].mInteger); std::string item = runtime.getStringLiteral (runtime[0].mInteger);
runtime.pop(); runtime.pop();
@ -215,8 +104,6 @@ namespace MWScript
if (count<0) if (count<0)
throw std::runtime_error ("second argument for RemoveItem must be non-negative"); throw std::runtime_error ("second argument for RemoveItem must be non-negative");
MWWorld::Ptr ptr = context.getWorld().getPtr (id, false);
std::vector<MWWorld::Ptr> list; std::vector<MWWorld::Ptr> list;
MWWorld::listItemsInContainer (item, MWWorld::listItemsInContainer (item,
@ -262,12 +149,12 @@ namespace MWScript
void installOpcodes (Interpreter::Interpreter& interpreter) void installOpcodes (Interpreter::Interpreter& interpreter)
{ {
interpreter.installSegment5 (opcodeAddItem, new OpAddItem); interpreter.installSegment5 (opcodeAddItem, new OpAddItem<ImplicitRef>);
interpreter.installSegment5 (opcodeAddItemExplicit, new OpAddItemExplicit); interpreter.installSegment5 (opcodeAddItemExplicit, new OpAddItem<ExplicitRef>);
interpreter.installSegment5 (opcodeGetItemCount, new OpGetItemCount); interpreter.installSegment5 (opcodeGetItemCount, new OpGetItemCount<ImplicitRef>);
interpreter.installSegment5 (opcodeGetItemCountExplicit, new OpGetItemCountExplicit); interpreter.installSegment5 (opcodeGetItemCountExplicit, new OpGetItemCount<ExplicitRef>);
interpreter.installSegment5 (opcodeRemoveItem, new OpRemoveItem); interpreter.installSegment5 (opcodeRemoveItem, new OpRemoveItem<ImplicitRef>);
interpreter.installSegment5 (opcodeRemoveItemExplicit, new OpRemoveItemExplicit); interpreter.installSegment5 (opcodeRemoveItemExplicit, new OpRemoveItem<ExplicitRef>);
} }
} }
} }

@ -7,10 +7,11 @@
#include <components/interpreter/runtime.hpp> #include <components/interpreter/runtime.hpp>
#include <components/interpreter/opcodes.hpp> #include <components/interpreter/opcodes.hpp>
#include "interpretercontext.hpp"
#include "../mwworld/class.hpp" #include "../mwworld/class.hpp"
#include "interpretercontext.hpp"
#include "ref.hpp"
namespace MWScript namespace MWScript
{ {
namespace Misc namespace Misc
@ -55,42 +56,14 @@ namespace MWScript
} }
}; };
template<class R>
class OpLock : public Interpreter::Opcode1 class OpLock : public Interpreter::Opcode1
{ {
public: public:
virtual void execute (Interpreter::Runtime& runtime, unsigned int arg0) virtual void execute (Interpreter::Runtime& runtime, unsigned int arg0)
{ {
InterpreterContext& context = MWWorld::Ptr ptr = R()(runtime);
static_cast<InterpreterContext&> (runtime.getContext());
MWWorld::Ptr ptr = context.getReference();
Interpreter::Type_Integer lockLevel = 100;
if (arg0==1)
{
lockLevel = runtime[0].mInteger;
runtime.pop();
}
MWWorld::Class::get (ptr).lock (ptr, lockLevel);
}
};
class OpLockExplicit : public Interpreter::Opcode1
{
public:
virtual void execute (Interpreter::Runtime& runtime, unsigned int arg0)
{
InterpreterContext& context =
static_cast<InterpreterContext&> (runtime.getContext());
std::string id = runtime.getStringLiteral (runtime[0].mInteger);
runtime.pop();
MWWorld::Ptr ptr = context.getWorld().getPtr (id, false);
Interpreter::Type_Integer lockLevel = 100; Interpreter::Type_Integer lockLevel = 100;
@ -104,34 +77,14 @@ namespace MWScript
} }
}; };
template<class R>
class OpUnlock : public Interpreter::Opcode0 class OpUnlock : public Interpreter::Opcode0
{ {
public: public:
virtual void execute (Interpreter::Runtime& runtime) virtual void execute (Interpreter::Runtime& runtime)
{ {
InterpreterContext& context = MWWorld::Ptr ptr = R()(runtime);
static_cast<InterpreterContext&> (runtime.getContext());
MWWorld::Ptr ptr = context.getReference();
MWWorld::Class::get (ptr).unlock (ptr);
}
};
class OpUnlockExplicit : public Interpreter::Opcode0
{
public:
virtual void execute (Interpreter::Runtime& runtime)
{
InterpreterContext& context =
static_cast<InterpreterContext&> (runtime.getContext());
std::string id = runtime.getStringLiteral (runtime[0].mInteger);
runtime.pop();
MWWorld::Ptr ptr = context.getWorld().getPtr (id, false);
MWWorld::Class::get (ptr).unlock (ptr); MWWorld::Class::get (ptr).unlock (ptr);
} }
@ -160,10 +113,10 @@ namespace MWScript
interpreter.installSegment5 (opcodeXBox, new OpXBox); interpreter.installSegment5 (opcodeXBox, new OpXBox);
interpreter.installSegment5 (opcodeOnActivate, new OpOnActivate); interpreter.installSegment5 (opcodeOnActivate, new OpOnActivate);
interpreter.installSegment5 (opcodeActivate, new OpActivate); interpreter.installSegment5 (opcodeActivate, new OpActivate);
interpreter.installSegment3 (opcodeLock, new OpLock); interpreter.installSegment3 (opcodeLock, new OpLock<ImplicitRef>);
interpreter.installSegment3 (opcodeLockExplicit, new OpLockExplicit); interpreter.installSegment3 (opcodeLockExplicit, new OpLock<ExplicitRef>);
interpreter.installSegment5 (opcodeUnlock, new OpUnlock); interpreter.installSegment5 (opcodeUnlock, new OpUnlock<ImplicitRef>);
interpreter.installSegment5 (opcodeUnlockExplicit, new OpUnlockExplicit); interpreter.installSegment5 (opcodeUnlockExplicit, new OpUnlock<ExplicitRef>);
} }
} }
} }

@ -0,0 +1,41 @@
#ifndef GAME_MWSCRIPT_REF_H
#define GAME_MWSCRIPT_REF_H
#include <string>
#include <components/interpreter/runtime.hpp>
#include "../mwworld/ptr.hpp"
#include "../mwworld/world.hpp"
#include "interpretercontext.hpp"
namespace MWScript
{
struct ExplicitRef
{
MWWorld::Ptr operator() (Interpreter::Runtime& runtime) const
{
MWScript::InterpreterContext& context
= static_cast<MWScript::InterpreterContext&> (runtime.getContext());
std::string id = runtime.getStringLiteral (runtime[0].mInteger);
runtime.pop();
return context.getWorld().getPtr (id, false);
}
};
struct ImplicitRef
{
MWWorld::Ptr operator() (Interpreter::Runtime& runtime) const
{
MWScript::InterpreterContext& context
= static_cast<MWScript::InterpreterContext&> (runtime.getContext());
return context.getReference();
}
};
}
#endif

@ -7,22 +7,26 @@
#include <components/interpreter/runtime.hpp> #include <components/interpreter/runtime.hpp>
#include <components/interpreter/opcodes.hpp> #include <components/interpreter/opcodes.hpp>
#include "interpretercontext.hpp"
#include "../mwworld/world.hpp" #include "../mwworld/world.hpp"
#include "../mwsound/soundmanager.hpp" #include "../mwsound/soundmanager.hpp"
#include "interpretercontext.hpp"
#include "ref.hpp"
namespace MWScript namespace MWScript
{ {
namespace Sound namespace Sound
{ {
template<class R>
class OpSay : public Interpreter::Opcode0 class OpSay : public Interpreter::Opcode0
{ {
public: public:
virtual void execute (Interpreter::Runtime& runtime) virtual void execute (Interpreter::Runtime& runtime)
{ {
MWWorld::Ptr ptr = R()(runtime);
MWScript::InterpreterContext& context MWScript::InterpreterContext& context
= static_cast<MWScript::InterpreterContext&> (runtime.getContext()); = static_cast<MWScript::InterpreterContext&> (runtime.getContext());
@ -32,296 +36,173 @@ namespace MWScript
std::string text = runtime.getStringLiteral (runtime[0].mInteger); std::string text = runtime.getStringLiteral (runtime[0].mInteger);
runtime.pop(); runtime.pop();
context.getSoundManager().say (context.getReference(), file); context.getSoundManager().say (ptr, file);
context.messageBox (text); context.messageBox (text);
} }
}; };
template<class R>
class OpSayDone : public Interpreter::Opcode0 class OpSayDone : public Interpreter::Opcode0
{ {
public: public:
virtual void execute (Interpreter::Runtime& runtime) virtual void execute (Interpreter::Runtime& runtime)
{ {
MWWorld::Ptr ptr = R()(runtime);
MWScript::InterpreterContext& context MWScript::InterpreterContext& context
= static_cast<MWScript::InterpreterContext&> (runtime.getContext()); = static_cast<MWScript::InterpreterContext&> (runtime.getContext());
runtime.push (context.getSoundManager().sayDone (context.getReference())); runtime.push (context.getSoundManager().sayDone (ptr));
} }
}; };
class OpStreamMusic : public Interpreter::Opcode0 class OpStreamMusic : public Interpreter::Opcode0
{ {
public: public:
virtual void execute (Interpreter::Runtime& runtime) virtual void execute (Interpreter::Runtime& runtime)
{ {
MWScript::InterpreterContext& context MWScript::InterpreterContext& context
= static_cast<MWScript::InterpreterContext&> (runtime.getContext()); = static_cast<MWScript::InterpreterContext&> (runtime.getContext());
std::string sound = runtime.getStringLiteral (runtime[0].mInteger); std::string sound = runtime.getStringLiteral (runtime[0].mInteger);
runtime.pop(); runtime.pop();
context.getSoundManager().streamMusic (sound); context.getSoundManager().streamMusic (sound);
} }
}; };
class OpPlaySound : public Interpreter::Opcode0 class OpPlaySound : public Interpreter::Opcode0
{ {
public: public:
virtual void execute (Interpreter::Runtime& runtime) virtual void execute (Interpreter::Runtime& runtime)
{ {
MWScript::InterpreterContext& context MWScript::InterpreterContext& context
= static_cast<MWScript::InterpreterContext&> (runtime.getContext()); = static_cast<MWScript::InterpreterContext&> (runtime.getContext());
std::string sound = runtime.getStringLiteral (runtime[0].mInteger); std::string sound = runtime.getStringLiteral (runtime[0].mInteger);
runtime.pop(); runtime.pop();
context.getSoundManager().playSound (sound, 1.0, 1.0); context.getSoundManager().playSound (sound, 1.0, 1.0);
} }
}; };
class OpPlaySoundVP : public Interpreter::Opcode0 class OpPlaySoundVP : public Interpreter::Opcode0
{ {
public: public:
virtual void execute (Interpreter::Runtime& runtime) virtual void execute (Interpreter::Runtime& runtime)
{ {
MWScript::InterpreterContext& context MWScript::InterpreterContext& context
= static_cast<MWScript::InterpreterContext&> (runtime.getContext()); = static_cast<MWScript::InterpreterContext&> (runtime.getContext());
std::string sound = runtime.getStringLiteral (runtime[0].mInteger); std::string sound = runtime.getStringLiteral (runtime[0].mInteger);
runtime.pop(); runtime.pop();
Interpreter::Type_Float volume = runtime[0].mFloat; Interpreter::Type_Float volume = runtime[0].mFloat;
runtime.pop(); runtime.pop();
Interpreter::Type_Float pitch = runtime[0].mFloat; Interpreter::Type_Float pitch = runtime[0].mFloat;
runtime.pop(); runtime.pop();
context.getSoundManager().playSound (sound, volume, pitch); context.getSoundManager().playSound (sound, volume, pitch);
} }
}; };
template<class R>
class OpPlaySound3D : public Interpreter::Opcode0 class OpPlaySound3D : public Interpreter::Opcode0
{ {
bool mLoop; bool mLoop;
public: public:
OpPlaySound3D (bool loop) : mLoop (loop) {} OpPlaySound3D (bool loop) : mLoop (loop) {}
virtual void execute (Interpreter::Runtime& runtime) virtual void execute (Interpreter::Runtime& runtime)
{ {
MWWorld::Ptr ptr = R()(runtime);
MWScript::InterpreterContext& context MWScript::InterpreterContext& context
= static_cast<MWScript::InterpreterContext&> (runtime.getContext()); = static_cast<MWScript::InterpreterContext&> (runtime.getContext());
std::string sound = runtime.getStringLiteral (runtime[0].mInteger); std::string sound = runtime.getStringLiteral (runtime[0].mInteger);
runtime.pop(); runtime.pop();
context.getSoundManager().playSound3D (context.getReference(), sound, context.getSoundManager().playSound3D (ptr, sound, 1.0, 1.0, mLoop);
1.0, 1.0, mLoop); }
} };
};
template<class R>
class OpPlaySoundVP3D : public Interpreter::Opcode0 class OpPlaySoundVP3D : public Interpreter::Opcode0
{ {
bool mLoop; bool mLoop;
public: public:
OpPlaySoundVP3D (bool loop) : mLoop (loop) {} OpPlaySoundVP3D (bool loop) : mLoop (loop) {}
virtual void execute (Interpreter::Runtime& runtime) virtual void execute (Interpreter::Runtime& runtime)
{ {
MWWorld::Ptr ptr = R()(runtime);
MWScript::InterpreterContext& context MWScript::InterpreterContext& context
= static_cast<MWScript::InterpreterContext&> (runtime.getContext()); = static_cast<MWScript::InterpreterContext&> (runtime.getContext());
std::string sound = runtime.getStringLiteral (runtime[0].mInteger); std::string sound = runtime.getStringLiteral (runtime[0].mInteger);
runtime.pop(); runtime.pop();
Interpreter::Type_Float volume = runtime[0].mFloat; Interpreter::Type_Float volume = runtime[0].mFloat;
runtime.pop(); runtime.pop();
Interpreter::Type_Float pitch = runtime[0].mFloat; Interpreter::Type_Float pitch = runtime[0].mFloat;
runtime.pop(); runtime.pop();
context.getSoundManager().playSound3D (context.getReference(), sound, volume,
pitch, mLoop);
} context.getSoundManager().playSound3D (ptr, sound, volume, pitch, mLoop);
};
class OpStopSound : public Interpreter::Opcode0 }
{
public:
virtual void execute (Interpreter::Runtime& runtime)
{
MWScript::InterpreterContext& context
= static_cast<MWScript::InterpreterContext&> (runtime.getContext());
std::string sound = runtime.getStringLiteral (runtime[0].mInteger);
runtime.pop();
context.getSoundManager().stopSound3D (context.getReference(), sound);
}
};
class OpGetSoundPlaying : public Interpreter::Opcode0
{
public:
virtual void execute (Interpreter::Runtime& runtime)
{
MWScript::InterpreterContext& context
= static_cast<MWScript::InterpreterContext&> (runtime.getContext());
int index = runtime[0].mInteger;
runtime.pop();
runtime.push (context.getSoundManager().getSoundPlaying (
context.getReference(), runtime.getStringLiteral (index)));
}
}; };
class OpSayExplicit : public Interpreter::Opcode0
{
public:
virtual void execute (Interpreter::Runtime& runtime)
{
MWScript::InterpreterContext& context
= static_cast<MWScript::InterpreterContext&> (runtime.getContext());
std::string id = runtime.getStringLiteral (runtime[0].mInteger); template<class R>
runtime.pop(); class OpStopSound : public Interpreter::Opcode0
std::string file = runtime.getStringLiteral (runtime[0].mInteger);
runtime.pop();
std::string text = runtime.getStringLiteral (runtime[0].mInteger);
runtime.pop();
context.getSoundManager().say (context.getWorld().getPtr (id, true),
file);
}
};
class OpSayDoneExplicit : public Interpreter::Opcode0
{ {
public: public:
virtual void execute (Interpreter::Runtime& runtime)
{
MWScript::InterpreterContext& context
= static_cast<MWScript::InterpreterContext&> (runtime.getContext());
std::string id = runtime.getStringLiteral (runtime[0].mInteger);
runtime.pop();
runtime.push (context.getSoundManager().sayDone (
context.getWorld().getPtr (id, true)));
}
};
class OpPlaySound3DExplicit : public Interpreter::Opcode0
{
bool mLoop;
public:
OpPlaySound3DExplicit (bool loop) : mLoop (loop) {}
virtual void execute (Interpreter::Runtime& runtime) virtual void execute (Interpreter::Runtime& runtime)
{ {
MWScript::InterpreterContext& context MWWorld::Ptr ptr = R()(runtime);
= static_cast<MWScript::InterpreterContext&> (runtime.getContext());
std::string id = runtime.getStringLiteral (runtime[0].mInteger);
runtime.pop();
std::string sound = runtime.getStringLiteral (runtime[0].mInteger);
runtime.pop();
context.getSoundManager().playSound3D (
context.getWorld().getPtr (id, true), sound, 1.0, 1.0, mLoop);
}
};
class OpPlaySoundVP3DExplicit : public Interpreter::Opcode0
{
bool mLoop;
public:
OpPlaySoundVP3DExplicit (bool loop) : mLoop (loop) {}
virtual void execute (Interpreter::Runtime& runtime)
{
MWScript::InterpreterContext& context MWScript::InterpreterContext& context
= static_cast<MWScript::InterpreterContext&> (runtime.getContext()); = static_cast<MWScript::InterpreterContext&> (runtime.getContext());
std::string id = runtime.getStringLiteral (runtime[0].mInteger);
runtime.pop();
std::string sound = runtime.getStringLiteral (runtime[0].mInteger); std::string sound = runtime.getStringLiteral (runtime[0].mInteger);
runtime.pop(); runtime.pop();
Interpreter::Type_Float volume = runtime[0].mFloat;
runtime.pop();
Interpreter::Type_Float pitch = runtime[0].mFloat; context.getSoundManager().stopSound3D (ptr, sound);
runtime.pop(); }
};
context.getSoundManager().playSound3D (
context.getWorld().getPtr (id, true), sound, volume, pitch, mLoop);
}
};
class OpStopSoundExplicit : public Interpreter::Opcode0 template<class R>
class OpGetSoundPlaying : public Interpreter::Opcode0
{ {
public: public:
virtual void execute (Interpreter::Runtime& runtime)
{
MWScript::InterpreterContext& context
= static_cast<MWScript::InterpreterContext&> (runtime.getContext());
std::string id = runtime.getStringLiteral (runtime[0].mInteger);
runtime.pop();
std::string sound = runtime.getStringLiteral (runtime[0].mInteger);
runtime.pop();
context.getSoundManager().stopSound3D (
context.getWorld().getPtr (id, true), sound);
}
};
class OpGetSoundPlayingExplicit : public Interpreter::Opcode0
{
public:
virtual void execute (Interpreter::Runtime& runtime) virtual void execute (Interpreter::Runtime& runtime)
{ {
MWWorld::Ptr ptr = R()(runtime);
MWScript::InterpreterContext& context MWScript::InterpreterContext& context
= static_cast<MWScript::InterpreterContext&> (runtime.getContext()); = static_cast<MWScript::InterpreterContext&> (runtime.getContext());
std::string id = runtime.getStringLiteral (runtime[0].mInteger);
runtime.pop();
int index = runtime[0].mInteger; int index = runtime[0].mInteger;
runtime.pop(); runtime.pop();
runtime.push (context.getSoundManager().getSoundPlaying ( runtime.push (context.getSoundManager().getSoundPlaying (
context.getWorld().getPtr (id, true), ptr, runtime.getStringLiteral (index)));
runtime.getStringLiteral (index))); }
} };
};
const int opcodeSay = 0x2000001; const int opcodeSay = 0x2000001;
const int opcodeSayDone = 0x2000002; const int opcodeSayDone = 0x2000002;
const int opcodeStreamMusic = 0x2000003; const int opcodeStreamMusic = 0x2000003;
@ -342,7 +223,7 @@ namespace MWScript
const int opcodePlayLoopSound3DVPExplicit = 0x200001e; const int opcodePlayLoopSound3DVPExplicit = 0x200001e;
const int opcodeStopSoundExplicit = 0x200001f; const int opcodeStopSoundExplicit = 0x200001f;
const int opcodeGetSoundPlayingExplicit = 0x2000020; const int opcodeGetSoundPlayingExplicit = 0x2000020;
void registerExtensions (Compiler::Extensions& extensions) void registerExtensions (Compiler::Extensions& extensions)
{ {
extensions.registerInstruction ("say", "SS", opcodeSay, opcodeSayExplicit); extensions.registerInstruction ("say", "SS", opcodeSay, opcodeSayExplicit);
@ -361,37 +242,37 @@ namespace MWScript
extensions.registerInstruction ("stopsound", "c", opcodeStopSound, extensions.registerInstruction ("stopsound", "c", opcodeStopSound,
opcodeStopSoundExplicit); opcodeStopSoundExplicit);
extensions.registerFunction ("getsoundplaying", 'l', "c", opcodeGetSoundPlaying, extensions.registerFunction ("getsoundplaying", 'l', "c", opcodeGetSoundPlaying,
opcodeGetSoundPlayingExplicit); opcodeGetSoundPlayingExplicit);
} }
void installOpcodes (Interpreter::Interpreter& interpreter) void installOpcodes (Interpreter::Interpreter& interpreter)
{ {
interpreter.installSegment5 (opcodeSay, new OpSay); interpreter.installSegment5 (opcodeSay, new OpSay<ImplicitRef>);
interpreter.installSegment5 (opcodeSayDone, new OpSayDone); interpreter.installSegment5 (opcodeSayDone, new OpSayDone<ImplicitRef>);
interpreter.installSegment5 (opcodeStreamMusic, new OpStreamMusic); interpreter.installSegment5 (opcodeStreamMusic, new OpStreamMusic);
interpreter.installSegment5 (opcodePlaySound, new OpPlaySound); interpreter.installSegment5 (opcodePlaySound, new OpPlaySound);
interpreter.installSegment5 (opcodePlaySoundVP, new OpPlaySoundVP); interpreter.installSegment5 (opcodePlaySoundVP, new OpPlaySoundVP);
interpreter.installSegment5 (opcodePlaySound3D, new OpPlaySound3D (false)); interpreter.installSegment5 (opcodePlaySound3D, new OpPlaySound3D<ImplicitRef> (false));
interpreter.installSegment5 (opcodePlaySound3DVP, new OpPlaySoundVP3D (false)); interpreter.installSegment5 (opcodePlaySound3DVP, new OpPlaySoundVP3D<ImplicitRef> (false));
interpreter.installSegment5 (opcodePlayLoopSound3D, new OpPlaySound3D (true)); interpreter.installSegment5 (opcodePlayLoopSound3D, new OpPlaySound3D<ImplicitRef> (true));
interpreter.installSegment5 (opcodePlayLoopSound3DVP, new OpPlaySoundVP3D (true)); interpreter.installSegment5 (opcodePlayLoopSound3DVP,
interpreter.installSegment5 (opcodeStopSound, new OpStopSound); new OpPlaySoundVP3D<ImplicitRef> (true));
interpreter.installSegment5 (opcodeGetSoundPlaying, new OpGetSoundPlaying); interpreter.installSegment5 (opcodeStopSound, new OpStopSound<ImplicitRef>);
interpreter.installSegment5 (opcodeGetSoundPlaying, new OpGetSoundPlaying<ImplicitRef>);
interpreter.installSegment5 (opcodeSayExplicit, new OpSayExplicit);
interpreter.installSegment5 (opcodeSayDoneExplicit, new OpSayDoneExplicit); interpreter.installSegment5 (opcodeSayExplicit, new OpSay<ExplicitRef>);
interpreter.installSegment5 (opcodeSayDoneExplicit, new OpSayDone<ExplicitRef>);
interpreter.installSegment5 (opcodePlaySound3DExplicit, interpreter.installSegment5 (opcodePlaySound3DExplicit,
new OpPlaySound3DExplicit (false)); new OpPlaySound3D<ExplicitRef> (false));
interpreter.installSegment5 (opcodePlaySound3DVPExplicit, interpreter.installSegment5 (opcodePlaySound3DVPExplicit,
new OpPlaySoundVP3DExplicit (false)); new OpPlaySoundVP3D<ExplicitRef> (false));
interpreter.installSegment5 (opcodePlayLoopSound3DExplicit, interpreter.installSegment5 (opcodePlayLoopSound3DExplicit,
new OpPlaySound3DExplicit (true)); new OpPlaySound3D<ExplicitRef> (true));
interpreter.installSegment5 (opcodePlayLoopSound3DVPExplicit, interpreter.installSegment5 (opcodePlayLoopSound3DVPExplicit,
new OpPlaySoundVP3DExplicit (true)); new OpPlaySoundVP3D<ExplicitRef> (true));
interpreter.installSegment5 (opcodeStopSoundExplicit, new OpStopSoundExplicit); interpreter.installSegment5 (opcodeStopSoundExplicit, new OpStopSound<ExplicitRef>);
interpreter.installSegment5 (opcodeGetSoundPlayingExplicit, interpreter.installSegment5 (opcodeGetSoundPlayingExplicit,
new OpGetSoundPlayingExplicit); new OpGetSoundPlaying<ExplicitRef>);
} }
} }
} }

@ -12,11 +12,13 @@
#include "../mwmechanics/creaturestats.hpp" #include "../mwmechanics/creaturestats.hpp"
#include "interpretercontext.hpp" #include "interpretercontext.hpp"
#include "ref.hpp"
namespace MWScript namespace MWScript
{ {
namespace Stats namespace Stats
{ {
template<class R>
class OpGetAttribute : public Interpreter::Opcode0 class OpGetAttribute : public Interpreter::Opcode0
{ {
int mIndex; int mIndex;
@ -27,36 +29,7 @@ namespace MWScript
virtual void execute (Interpreter::Runtime& runtime) virtual void execute (Interpreter::Runtime& runtime)
{ {
MWScript::InterpreterContext& context MWWorld::Ptr ptr = R()(runtime);
= static_cast<MWScript::InterpreterContext&> (runtime.getContext());
MWWorld::Ptr ptr = context.getReference();
Interpreter::Type_Integer value =
MWWorld::Class::get (ptr).getCreatureStats (ptr).mAttributes[mIndex].
getModified();
runtime.push (value);
}
};
class OpGetAttributeExplicit : public Interpreter::Opcode0
{
int mIndex;
public:
OpGetAttributeExplicit (int index) : mIndex (index) {}
virtual void execute (Interpreter::Runtime& runtime)
{
MWScript::InterpreterContext& context
= static_cast<MWScript::InterpreterContext&> (runtime.getContext());
std::string id = runtime.getStringLiteral (runtime[0].mInteger);
runtime.pop();
MWWorld::Ptr ptr = context.getWorld().getPtr (id, false);
Interpreter::Type_Integer value = Interpreter::Type_Integer value =
MWWorld::Class::get (ptr).getCreatureStats (ptr).mAttributes[mIndex]. MWWorld::Class::get (ptr).getCreatureStats (ptr).mAttributes[mIndex].
@ -66,6 +39,7 @@ namespace MWScript
} }
}; };
template<class R>
class OpSetAttribute : public Interpreter::Opcode0 class OpSetAttribute : public Interpreter::Opcode0
{ {
int mIndex; int mIndex;
@ -76,45 +50,17 @@ namespace MWScript
virtual void execute (Interpreter::Runtime& runtime) virtual void execute (Interpreter::Runtime& runtime)
{ {
MWScript::InterpreterContext& context MWWorld::Ptr ptr = R()(runtime);
= static_cast<MWScript::InterpreterContext&> (runtime.getContext());
Interpreter::Type_Integer value = runtime[0].mInteger; Interpreter::Type_Integer value = runtime[0].mInteger;
runtime.pop(); runtime.pop();
MWWorld::Ptr ptr = context.getReference();
MWWorld::Class::get (ptr).getCreatureStats (ptr).mAttributes[mIndex].
setModified (value, 0);
}
};
class OpSetAttributeExplicit : public Interpreter::Opcode0
{
int mIndex;
public:
OpSetAttributeExplicit (int index) : mIndex (index) {}
virtual void execute (Interpreter::Runtime& runtime)
{
MWScript::InterpreterContext& context
= static_cast<MWScript::InterpreterContext&> (runtime.getContext());
std::string id = runtime.getStringLiteral (runtime[0].mInteger);
runtime.pop();
Interpreter::Type_Integer value = runtime[0].mInteger;
runtime.pop();
MWWorld::Ptr ptr = context.getWorld().getPtr (id, false);
MWWorld::Class::get (ptr).getCreatureStats (ptr).mAttributes[mIndex]. MWWorld::Class::get (ptr).getCreatureStats (ptr).mAttributes[mIndex].
setModified (value, 0); setModified (value, 0);
} }
}; };
template<class R>
class OpModAttribute : public Interpreter::Opcode0 class OpModAttribute : public Interpreter::Opcode0
{ {
int mIndex; int mIndex;
@ -125,14 +71,11 @@ namespace MWScript
virtual void execute (Interpreter::Runtime& runtime) virtual void execute (Interpreter::Runtime& runtime)
{ {
MWScript::InterpreterContext& context MWWorld::Ptr ptr = R()(runtime);
= static_cast<MWScript::InterpreterContext&> (runtime.getContext());
Interpreter::Type_Integer value = runtime[0].mInteger; Interpreter::Type_Integer value = runtime[0].mInteger;
runtime.pop(); runtime.pop();
MWWorld::Ptr ptr = context.getReference();
value += MWWorld::Class::get (ptr).getCreatureStats (ptr).mAttributes[mIndex]. value += MWWorld::Class::get (ptr).getCreatureStats (ptr).mAttributes[mIndex].
getModified(); getModified();
@ -141,36 +84,7 @@ namespace MWScript
} }
}; };
class OpModAttributeExplicit : public Interpreter::Opcode0 template<class R>
{
int mIndex;
public:
OpModAttributeExplicit (int index) : mIndex (index) {}
virtual void execute (Interpreter::Runtime& runtime)
{
MWScript::InterpreterContext& context
= static_cast<MWScript::InterpreterContext&> (runtime.getContext());
std::string id = runtime.getStringLiteral (runtime[0].mInteger);
runtime.pop();
Interpreter::Type_Integer value = runtime[0].mInteger;
runtime.pop();
MWWorld::Ptr ptr = context.getWorld().getPtr (id, false);
value +=
MWWorld::Class::get (ptr).getCreatureStats (ptr).mAttributes[mIndex].
getModified();
MWWorld::Class::get (ptr).getCreatureStats (ptr).mAttributes[mIndex].
setModified (value, 0, 100);
}
};
class OpGetDynamic : public Interpreter::Opcode0 class OpGetDynamic : public Interpreter::Opcode0
{ {
int mIndex; int mIndex;
@ -181,46 +95,7 @@ namespace MWScript
virtual void execute (Interpreter::Runtime& runtime) virtual void execute (Interpreter::Runtime& runtime)
{ {
MWScript::InterpreterContext& context MWWorld::Ptr ptr = R()(runtime);
= static_cast<MWScript::InterpreterContext&> (runtime.getContext());
MWWorld::Ptr ptr = context.getReference();
if (mIndex==0 && MWWorld::Class::get (ptr).hasItemHealth (ptr))
{
// health is a special case
Interpreter::Type_Integer value =
MWWorld::Class::get (ptr).getItemMaxHealth (ptr);
runtime.push (value);
return;
}
Interpreter::Type_Integer value =
MWWorld::Class::get (ptr).getCreatureStats (ptr).mDynamic[mIndex].
getCurrent();
runtime.push (value);
}
};
class OpGetDynamicExplicit : public Interpreter::Opcode0
{
int mIndex;
public:
OpGetDynamicExplicit (int index) : mIndex (index) {}
virtual void execute (Interpreter::Runtime& runtime)
{
MWScript::InterpreterContext& context
= static_cast<MWScript::InterpreterContext&> (runtime.getContext());
std::string id = runtime.getStringLiteral (runtime[0].mInteger);
runtime.pop();
MWWorld::Ptr ptr = context.getWorld().getPtr (id, false);
if (mIndex==0 && MWWorld::Class::get (ptr).hasItemHealth (ptr)) if (mIndex==0 && MWWorld::Class::get (ptr).hasItemHealth (ptr))
{ {
@ -240,6 +115,7 @@ namespace MWScript
} }
}; };
template<class R>
class OpSetDynamic : public Interpreter::Opcode0 class OpSetDynamic : public Interpreter::Opcode0
{ {
int mIndex; int mIndex;
@ -250,45 +126,17 @@ namespace MWScript
virtual void execute (Interpreter::Runtime& runtime) virtual void execute (Interpreter::Runtime& runtime)
{ {
MWScript::InterpreterContext& context MWWorld::Ptr ptr = R()(runtime);
= static_cast<MWScript::InterpreterContext&> (runtime.getContext());
Interpreter::Type_Integer value = runtime[0].mInteger; Interpreter::Type_Integer value = runtime[0].mInteger;
runtime.pop(); runtime.pop();
MWWorld::Ptr ptr = context.getReference();
MWWorld::Class::get (ptr).getCreatureStats (ptr).mDynamic[mIndex].
setModified (value, 0);
}
};
class OpSetDynamicExplicit : public Interpreter::Opcode0
{
int mIndex;
public:
OpSetDynamicExplicit (int index) : mIndex (index) {}
virtual void execute (Interpreter::Runtime& runtime)
{
MWScript::InterpreterContext& context
= static_cast<MWScript::InterpreterContext&> (runtime.getContext());
std::string id = runtime.getStringLiteral (runtime[0].mInteger);
runtime.pop();
Interpreter::Type_Integer value = runtime[0].mInteger;
runtime.pop();
MWWorld::Ptr ptr = context.getWorld().getPtr (id, false);
MWWorld::Class::get (ptr).getCreatureStats (ptr).mDynamic[mIndex]. MWWorld::Class::get (ptr).getCreatureStats (ptr).mDynamic[mIndex].
setModified (value, 0); setModified (value, 0);
} }
}; };
template<class R>
class OpModDynamic : public Interpreter::Opcode0 class OpModDynamic : public Interpreter::Opcode0
{ {
int mIndex; int mIndex;
@ -299,14 +147,11 @@ namespace MWScript
virtual void execute (Interpreter::Runtime& runtime) virtual void execute (Interpreter::Runtime& runtime)
{ {
MWScript::InterpreterContext& context MWWorld::Ptr ptr = R()(runtime);
= static_cast<MWScript::InterpreterContext&> (runtime.getContext());
Interpreter::Type_Integer diff = runtime[0].mInteger; Interpreter::Type_Integer diff = runtime[0].mInteger;
runtime.pop(); runtime.pop();
MWWorld::Ptr ptr = context.getReference();
MWMechanics::CreatureStats& stats = MWWorld::Class::get (ptr).getCreatureStats (ptr); MWMechanics::CreatureStats& stats = MWWorld::Class::get (ptr).getCreatureStats (ptr);
Interpreter::Type_Integer current = stats.mDynamic[mIndex].getCurrent(); Interpreter::Type_Integer current = stats.mDynamic[mIndex].getCurrent();
@ -318,40 +163,7 @@ namespace MWScript
} }
}; };
class OpModDynamicExplicit : public Interpreter::Opcode0 template<class R>
{
int mIndex;
public:
OpModDynamicExplicit (int index) : mIndex (index) {}
virtual void execute (Interpreter::Runtime& runtime)
{
MWScript::InterpreterContext& context
= static_cast<MWScript::InterpreterContext&> (runtime.getContext());
std::string id = runtime.getStringLiteral (runtime[0].mInteger);
runtime.pop();
Interpreter::Type_Integer diff = runtime[0].mInteger;
runtime.pop();
MWWorld::Ptr ptr = context.getWorld().getPtr (id, false);
MWMechanics::CreatureStats& stats =
MWWorld::Class::get (ptr).getCreatureStats (ptr);
Interpreter::Type_Integer current = stats.mDynamic[mIndex].getCurrent();
stats.mDynamic[mIndex].setModified (
diff + stats.mDynamic[mIndex].getModified(), 0);
stats.mDynamic[mIndex].setCurrent (diff + current);
}
};
class OpModCurrentDynamic : public Interpreter::Opcode0 class OpModCurrentDynamic : public Interpreter::Opcode0
{ {
int mIndex; int mIndex;
@ -362,14 +174,11 @@ namespace MWScript
virtual void execute (Interpreter::Runtime& runtime) virtual void execute (Interpreter::Runtime& runtime)
{ {
MWScript::InterpreterContext& context MWWorld::Ptr ptr = R()(runtime);
= static_cast<MWScript::InterpreterContext&> (runtime.getContext());
Interpreter::Type_Integer diff = runtime[0].mInteger; Interpreter::Type_Integer diff = runtime[0].mInteger;
runtime.pop(); runtime.pop();
MWWorld::Ptr ptr = context.getReference();
MWMechanics::CreatureStats& stats = MWWorld::Class::get (ptr).getCreatureStats (ptr); MWMechanics::CreatureStats& stats = MWWorld::Class::get (ptr).getCreatureStats (ptr);
Interpreter::Type_Integer current = stats.mDynamic[mIndex].getCurrent(); Interpreter::Type_Integer current = stats.mDynamic[mIndex].getCurrent();
@ -378,36 +187,7 @@ namespace MWScript
} }
}; };
class OpModCurrentDynamicExplicit : public Interpreter::Opcode0 template<class R>
{
int mIndex;
public:
OpModCurrentDynamicExplicit (int index) : mIndex (index) {}
virtual void execute (Interpreter::Runtime& runtime)
{
MWScript::InterpreterContext& context
= static_cast<MWScript::InterpreterContext&> (runtime.getContext());
std::string id = runtime.getStringLiteral (runtime[0].mInteger);
runtime.pop();
Interpreter::Type_Integer diff = runtime[0].mInteger;
runtime.pop();
MWWorld::Ptr ptr = context.getWorld().getPtr (id, false);
MWMechanics::CreatureStats& stats =
MWWorld::Class::get (ptr).getCreatureStats (ptr);
Interpreter::Type_Integer current = stats.mDynamic[mIndex].getCurrent();
stats.mDynamic[mIndex].setCurrent (diff + current);
}
};
class OpGetDynamicGetRatio : public Interpreter::Opcode0 class OpGetDynamicGetRatio : public Interpreter::Opcode0
{ {
int mIndex; int mIndex;
@ -418,10 +198,7 @@ namespace MWScript
virtual void execute (Interpreter::Runtime& runtime) virtual void execute (Interpreter::Runtime& runtime)
{ {
MWScript::InterpreterContext& context MWWorld::Ptr ptr = R()(runtime);
= static_cast<MWScript::InterpreterContext&> (runtime.getContext());
MWWorld::Ptr ptr = context.getReference();
MWMechanics::CreatureStats& stats = MWWorld::Class::get (ptr).getCreatureStats (ptr); MWMechanics::CreatureStats& stats = MWWorld::Class::get (ptr).getCreatureStats (ptr);
@ -436,38 +213,7 @@ namespace MWScript
} }
}; };
class OpGetDynamicGetRatioExplicit : public Interpreter::Opcode0 template<class R>
{
int mIndex;
public:
OpGetDynamicGetRatioExplicit (int index) : mIndex (index) {}
virtual void execute (Interpreter::Runtime& runtime)
{
MWScript::InterpreterContext& context
= static_cast<MWScript::InterpreterContext&> (runtime.getContext());
std::string id = runtime.getStringLiteral (runtime[0].mInteger);
runtime.pop();
MWWorld::Ptr ptr = context.getWorld().getPtr (id, false);
MWMechanics::CreatureStats& stats =
MWWorld::Class::get (ptr).getCreatureStats (ptr);
Interpreter::Type_Float value = 0;
Interpreter::Type_Float max = stats.mDynamic[mIndex].getModified();
if (max>0)
value = stats.mDynamic[mIndex].getCurrent() / max;
runtime.push (value);
}
};
class OpGetSkill : public Interpreter::Opcode0 class OpGetSkill : public Interpreter::Opcode0
{ {
int mIndex; int mIndex;
@ -478,36 +224,7 @@ namespace MWScript
virtual void execute (Interpreter::Runtime& runtime) virtual void execute (Interpreter::Runtime& runtime)
{ {
MWScript::InterpreterContext& context MWWorld::Ptr ptr = R()(runtime);
= static_cast<MWScript::InterpreterContext&> (runtime.getContext());
MWWorld::Ptr ptr = context.getReference();
Interpreter::Type_Integer value =
MWWorld::Class::get (ptr).getNpcStats (ptr).mSkill[mIndex].
getModified();
runtime.push (value);
}
};
class OpGetSkillExplicit : public Interpreter::Opcode0
{
int mIndex;
public:
OpGetSkillExplicit (int index) : mIndex (index) {}
virtual void execute (Interpreter::Runtime& runtime)
{
MWScript::InterpreterContext& context
= static_cast<MWScript::InterpreterContext&> (runtime.getContext());
std::string id = runtime.getStringLiteral (runtime[0].mInteger);
runtime.pop();
MWWorld::Ptr ptr = context.getWorld().getPtr (id, false);
Interpreter::Type_Integer value = Interpreter::Type_Integer value =
MWWorld::Class::get (ptr).getNpcStats (ptr).mSkill[mIndex]. MWWorld::Class::get (ptr).getNpcStats (ptr).mSkill[mIndex].
@ -517,6 +234,7 @@ namespace MWScript
} }
}; };
template<class R>
class OpSetSkill : public Interpreter::Opcode0 class OpSetSkill : public Interpreter::Opcode0
{ {
int mIndex; int mIndex;
@ -527,45 +245,17 @@ namespace MWScript
virtual void execute (Interpreter::Runtime& runtime) virtual void execute (Interpreter::Runtime& runtime)
{ {
MWScript::InterpreterContext& context MWWorld::Ptr ptr = R()(runtime);
= static_cast<MWScript::InterpreterContext&> (runtime.getContext());
Interpreter::Type_Integer value = runtime[0].mInteger;
runtime.pop();
MWWorld::Ptr ptr = context.getReference();
MWWorld::Class::get (ptr).getNpcStats (ptr).mSkill[mIndex].
setModified (value, 0);
}
};
class OpSetSkillExplicit : public Interpreter::Opcode0
{
int mIndex;
public:
OpSetSkillExplicit (int index) : mIndex (index) {}
virtual void execute (Interpreter::Runtime& runtime)
{
MWScript::InterpreterContext& context
= static_cast<MWScript::InterpreterContext&> (runtime.getContext());
std::string id = runtime.getStringLiteral (runtime[0].mInteger);
runtime.pop();
Interpreter::Type_Integer value = runtime[0].mInteger; Interpreter::Type_Integer value = runtime[0].mInteger;
runtime.pop(); runtime.pop();
MWWorld::Ptr ptr = context.getWorld().getPtr (id, false);
MWWorld::Class::get (ptr).getNpcStats (ptr).mSkill[mIndex]. MWWorld::Class::get (ptr).getNpcStats (ptr).mSkill[mIndex].
setModified (value, 0); setModified (value, 0);
} }
}; };
template<class R>
class OpModSkill : public Interpreter::Opcode0 class OpModSkill : public Interpreter::Opcode0
{ {
int mIndex; int mIndex;
@ -576,14 +266,11 @@ namespace MWScript
virtual void execute (Interpreter::Runtime& runtime) virtual void execute (Interpreter::Runtime& runtime)
{ {
MWScript::InterpreterContext& context MWWorld::Ptr ptr = R()(runtime);
= static_cast<MWScript::InterpreterContext&> (runtime.getContext());
Interpreter::Type_Integer value = runtime[0].mInteger; Interpreter::Type_Integer value = runtime[0].mInteger;
runtime.pop(); runtime.pop();
MWWorld::Ptr ptr = context.getReference();
value += MWWorld::Class::get (ptr).getNpcStats (ptr).mSkill[mIndex]. value += MWWorld::Class::get (ptr).getNpcStats (ptr).mSkill[mIndex].
getModified(); getModified();
@ -592,36 +279,6 @@ namespace MWScript
} }
}; };
class OpModSkillExplicit : public Interpreter::Opcode0
{
int mIndex;
public:
OpModSkillExplicit (int index) : mIndex (index) {}
virtual void execute (Interpreter::Runtime& runtime)
{
MWScript::InterpreterContext& context
= static_cast<MWScript::InterpreterContext&> (runtime.getContext());
std::string id = runtime.getStringLiteral (runtime[0].mInteger);
runtime.pop();
Interpreter::Type_Integer value = runtime[0].mInteger;
runtime.pop();
MWWorld::Ptr ptr = context.getWorld().getPtr (id, false);
value +=
MWWorld::Class::get (ptr).getNpcStats (ptr).mSkill[mIndex].
getModified();
MWWorld::Class::get (ptr).getNpcStats (ptr).mSkill[mIndex].
setModified (value, 0, 100);
}
};
const int numberOfAttributes = 8; const int numberOfAttributes = 8;
const int opcodeGetAttribute = 0x2000027; const int opcodeGetAttribute = 0x2000027;
@ -729,53 +386,54 @@ namespace MWScript
{ {
for (int i=0; i<numberOfAttributes; ++i) for (int i=0; i<numberOfAttributes; ++i)
{ {
interpreter.installSegment5 (opcodeGetAttribute+i, new OpGetAttribute (i)); interpreter.installSegment5 (opcodeGetAttribute+i, new OpGetAttribute<ImplicitRef> (i));
interpreter.installSegment5 (opcodeGetAttributeExplicit+i, interpreter.installSegment5 (opcodeGetAttributeExplicit+i,
new OpGetAttributeExplicit (i)); new OpGetAttribute<ExplicitRef> (i));
interpreter.installSegment5 (opcodeSetAttribute+i, new OpSetAttribute (i)); interpreter.installSegment5 (opcodeSetAttribute+i, new OpSetAttribute<ImplicitRef> (i));
interpreter.installSegment5 (opcodeSetAttributeExplicit+i, interpreter.installSegment5 (opcodeSetAttributeExplicit+i,
new OpSetAttributeExplicit (i)); new OpSetAttribute<ExplicitRef> (i));
interpreter.installSegment5 (opcodeModAttribute+i, new OpModAttribute (i)); interpreter.installSegment5 (opcodeModAttribute+i, new OpModAttribute<ImplicitRef> (i));
interpreter.installSegment5 (opcodeModAttributeExplicit+i, interpreter.installSegment5 (opcodeModAttributeExplicit+i,
new OpModAttributeExplicit (i)); new OpModAttribute<ExplicitRef> (i));
} }
for (int i=0; i<numberOfDynamics; ++i) for (int i=0; i<numberOfDynamics; ++i)
{ {
interpreter.installSegment5 (opcodeGetDynamic+i, new OpGetDynamic (i)); interpreter.installSegment5 (opcodeGetDynamic+i, new OpGetDynamic<ImplicitRef> (i));
interpreter.installSegment5 (opcodeGetDynamicExplicit+i, interpreter.installSegment5 (opcodeGetDynamicExplicit+i,
new OpGetDynamicExplicit (i)); new OpGetDynamic<ExplicitRef> (i));
interpreter.installSegment5 (opcodeSetDynamic+i, new OpSetDynamic (i)); interpreter.installSegment5 (opcodeSetDynamic+i, new OpSetDynamic<ImplicitRef> (i));
interpreter.installSegment5 (opcodeSetDynamicExplicit+i, interpreter.installSegment5 (opcodeSetDynamicExplicit+i,
new OpSetDynamicExplicit (i)); new OpSetDynamic<ExplicitRef> (i));
interpreter.installSegment5 (opcodeModDynamic+i, new OpModDynamic (i)); interpreter.installSegment5 (opcodeModDynamic+i, new OpModDynamic<ImplicitRef> (i));
interpreter.installSegment5 (opcodeModDynamicExplicit+i, interpreter.installSegment5 (opcodeModDynamicExplicit+i,
new OpModDynamicExplicit (i)); new OpModDynamic<ExplicitRef> (i));
interpreter.installSegment5 (opcodeModCurrentDynamic+i, new OpModCurrentDynamic (i)); interpreter.installSegment5 (opcodeModCurrentDynamic+i,
new OpModCurrentDynamic<ImplicitRef> (i));
interpreter.installSegment5 (opcodeModCurrentDynamicExplicit+i, interpreter.installSegment5 (opcodeModCurrentDynamicExplicit+i,
new OpModCurrentDynamicExplicit (i)); new OpModCurrentDynamic<ExplicitRef> (i));
interpreter.installSegment5 (opcodeGetDynamicGetRatio+i, interpreter.installSegment5 (opcodeGetDynamicGetRatio+i,
new OpGetDynamicGetRatio (i)); new OpGetDynamicGetRatio<ImplicitRef> (i));
interpreter.installSegment5 (opcodeGetDynamicGetRatioExplicit+i, interpreter.installSegment5 (opcodeGetDynamicGetRatioExplicit+i,
new OpGetDynamicGetRatioExplicit (i)); new OpGetDynamicGetRatio<ExplicitRef> (i));
} }
for (int i=0; i<numberOfSkills; ++i) for (int i=0; i<numberOfSkills; ++i)
{ {
interpreter.installSegment5 (opcodeGetSkill+i, new OpGetSkill (i)); interpreter.installSegment5 (opcodeGetSkill+i, new OpGetSkill<ImplicitRef> (i));
interpreter.installSegment5 (opcodeGetSkillExplicit+i, new OpGetSkillExplicit (i)); interpreter.installSegment5 (opcodeGetSkillExplicit+i, new OpGetSkill<ExplicitRef> (i));
interpreter.installSegment5 (opcodeSetSkill+i, new OpSetSkill (i)); interpreter.installSegment5 (opcodeSetSkill+i, new OpSetSkill<ImplicitRef> (i));
interpreter.installSegment5 (opcodeSetSkillExplicit+i, new OpSetSkillExplicit (i)); interpreter.installSegment5 (opcodeSetSkillExplicit+i, new OpSetSkill<ExplicitRef> (i));
interpreter.installSegment5 (opcodeModSkill+i, new OpModSkill (i)); interpreter.installSegment5 (opcodeModSkill+i, new OpModSkill<ImplicitRef> (i));
interpreter.installSegment5 (opcodeModSkillExplicit+i, new OpModSkillExplicit (i)); interpreter.installSegment5 (opcodeModSkillExplicit+i, new OpModSkill<ExplicitRef> (i));
} }
} }
} }

Loading…
Cancel
Save