Merge branch 'master' into container

Conflicts:
	apps/openmw/mwclass/container.cpp
	apps/openmw/mwclass/container.hpp
	apps/openmw/mwclass/creature.cpp
	apps/openmw/mwclass/creature.hpp
	apps/openmw/mwclass/npc.cpp
	apps/openmw/mwclass/npc.hpp
	apps/openmw/mwworld/class.cpp
	apps/openmw/mwworld/class.hpp
pull/7/head
Marc Zinnschlag 15 years ago
commit 10a63b10b5

@ -38,13 +38,18 @@ void OMW::Engine::executeLocalScripts()
mEnvironment.mWorld->getLocalScripts().begin());
iter!=mEnvironment.mWorld->getLocalScripts().end(); ++iter)
{
MWScript::InterpreterContext interpreterContext (mEnvironment,
&iter->second.getRefData().getLocals(), MWWorld::Ptr (iter->second));
mScriptManager->run (iter->first, interpreterContext);
if (!mIgnoreLocalPtr.isEmpty() && mIgnoreLocalPtr!=iter->second)
{
MWScript::InterpreterContext interpreterContext (mEnvironment,
&iter->second.getRefData().getLocals(), MWWorld::Ptr (iter->second));
mScriptManager->run (iter->first, interpreterContext);
if (mEnvironment.mWorld->hasCellChanged())
break;
if (mEnvironment.mWorld->hasCellChanged())
break;
}
}
mIgnoreLocalPtr = MWWorld::Ptr();
}
bool OMW::Engine::frameStarted(const Ogre::FrameEvent& evt)
@ -74,22 +79,20 @@ bool OMW::Engine::frameStarted(const Ogre::FrameEvent& evt)
if (focusFrameCounter++ == focusUpdateFrame)
{
std::pair<std::string, float> handle = mEnvironment.mWorld->getMWScene()->getFacedHandle();
std::string handle = mEnvironment.mWorld->getFacedHandle();
std::string name;
if (!handle.first.empty())
if (!handle.empty())
{
// TODO compare handle.second with max activation range (from a GMST)
MWWorld::Ptr ptr = mEnvironment.mWorld->getPtrViaHandle (handle.first);
MWWorld::Ptr ptr = mEnvironment.mWorld->getPtrViaHandle (handle);
if (!ptr.isEmpty())
name = MWWorld::Class::get (ptr).getName (ptr);
}
if (!name.empty())
std::cout << "Object: " << name << ", distance: " << handle.second << std::endl;
std::cout << "Object: " << name << std::endl;
focusFrameCounter = 0;
}
@ -255,7 +258,7 @@ void OMW::Engine::go()
// Sets up the input system
MWInput::MWInputManager input(mOgre, mEnvironment.mWorld->getPlayerPos(),
*mEnvironment.mWindowManager, mDebug);
*mEnvironment.mWindowManager, mDebug, *this);
focusFrameCounter = 0;
@ -268,3 +271,38 @@ void OMW::Engine::go()
std::cout << "Quitting peacefully.\n";
}
void OMW::Engine::activate()
{
std::string handle = mEnvironment.mWorld->getFacedHandle();
if (handle.empty())
return;
MWWorld::Ptr ptr = mEnvironment.mWorld->getPtrViaHandle (handle);
if (ptr.isEmpty())
return;
MWScript::InterpreterContext interpreterContext (mEnvironment,
&ptr.getRefData().getLocals(), ptr);
boost::shared_ptr<MWWorld::Action> action =
MWWorld::Class::get (ptr).activate (ptr, mEnvironment.mWorld->getPlayerPos().getPlayer(),
mEnvironment);
interpreterContext.activate (ptr, action);
std::string script = MWWorld::Class::get (ptr).getScript (ptr);
if (!script.empty())
{
mIgnoreLocalPtr = ptr;
mScriptManager->run (script, interpreterContext);
}
if (!interpreterContext.hasActivationBeenHandled())
{
interpreterContext.executeActivation();
}
}

@ -11,6 +11,7 @@
#include <components/compiler/extensions.hpp>
#include "mwworld/environment.hpp"
#include "mwworld/ptr.hpp"
namespace Compiler
{
@ -68,6 +69,8 @@ namespace OMW
int focusFrameCounter;
static const int focusUpdateFrame = 10;
MWWorld::Ptr mIgnoreLocalPtr;
// not implemented
Engine (const Engine&);
Engine& operator= (const Engine&);
@ -111,12 +114,15 @@ namespace OMW
/// Enable verbose script output
void enableVerboseScripts();
/// Start as a new game.
void setNewGame();
/// Initialise and enter main loop.
void go();
/// Activate the focussed object.
void activate();
};
}

@ -17,6 +17,14 @@ namespace MWClass
return ref->base->name;
}
std::string Activator::getScript (const MWWorld::Ptr& ptr) const
{
ESMS::LiveCellRef<ESM::Activator, MWWorld::RefData> *ref =
ptr.get<ESM::Activator>();
return ref->base->script;
}
void Activator::registerSelf()
{
boost::shared_ptr<Class> instance (new Activator);

@ -13,6 +13,9 @@ namespace MWClass
///< \return name (the one that is to be presented to the user; not the internal one);
/// can return an empty string.
virtual std::string getScript (const MWWorld::Ptr& ptr) const;
///< Return name of the script attached to ptr
static void registerSelf();
};
}

@ -17,6 +17,14 @@ namespace MWClass
return ref->base->name;
}
std::string Apparatus::getScript (const MWWorld::Ptr& ptr) const
{
ESMS::LiveCellRef<ESM::Apparatus, MWWorld::RefData> *ref =
ptr.get<ESM::Apparatus>();
return ref->base->script;
}
void Apparatus::registerSelf()
{
boost::shared_ptr<Class> instance (new Apparatus);

@ -13,6 +13,9 @@ namespace MWClass
///< \return name (the one that is to be presented to the user; not the internal one);
/// can return an empty string.
virtual std::string getScript (const MWWorld::Ptr& ptr) const;
///< Return name of the script attached to ptr
static void registerSelf();
};
}

@ -30,6 +30,14 @@ namespace MWClass
return ref->base->data.health;
}
std::string Armor::getScript (const MWWorld::Ptr& ptr) const
{
ESMS::LiveCellRef<ESM::Armor, MWWorld::RefData> *ref =
ptr.get<ESM::Armor>();
return ref->base->script;
}
void Armor::registerSelf()
{
boost::shared_ptr<Class> instance (new Armor);

@ -19,6 +19,9 @@ namespace MWClass
virtual int getItemMaxHealth (const MWWorld::Ptr& ptr) const;
///< Return item max health or throw an exception, if class does not have item health
virtual std::string getScript (const MWWorld::Ptr& ptr) const;
///< Return name of the script attached to ptr
static void registerSelf();
};
}

@ -17,6 +17,14 @@ namespace MWClass
return ref->base->name;
}
std::string Book::getScript (const MWWorld::Ptr& ptr) const
{
ESMS::LiveCellRef<ESM::Book, MWWorld::RefData> *ref =
ptr.get<ESM::Book>();
return ref->base->script;
}
void Book::registerSelf()
{
boost::shared_ptr<Class> instance (new Book);

@ -13,6 +13,9 @@ namespace MWClass
///< \return name (the one that is to be presented to the user; not the internal one);
/// can return an empty string.
virtual std::string getScript (const MWWorld::Ptr& ptr) const;
///< Return name of the script attached to ptr
static void registerSelf();
};
}

@ -17,6 +17,14 @@ namespace MWClass
return ref->base->name;
}
std::string Clothing::getScript (const MWWorld::Ptr& ptr) const
{
ESMS::LiveCellRef<ESM::Clothing, MWWorld::RefData> *ref =
ptr.get<ESM::Clothing>();
return ref->base->script;
}
void Clothing::registerSelf()
{
boost::shared_ptr<Class> instance (new Clothing);

@ -13,6 +13,9 @@ namespace MWClass
///< \return name (the one that is to be presented to the user; not the internal one);
/// can return an empty string.
virtual std::string getScript (const MWWorld::Ptr& ptr) const;
///< Return name of the script attached to ptr
static void registerSelf();
};
}

@ -33,6 +33,14 @@ namespace MWClass
return *ptr.getRefData().getContainerStore();
}
std::string Container::getScript (const MWWorld::Ptr& ptr) const
{
ESMS::LiveCellRef<ESM::Container, MWWorld::RefData> *ref =
ptr.get<ESM::Container>();
return ref->base->script;
}
void Container::registerSelf()
{
boost::shared_ptr<Class> instance (new Container);

@ -17,6 +17,9 @@ namespace MWClass
const MWWorld::Ptr& ptr) const;
///< Return container store
virtual std::string getScript (const MWWorld::Ptr& ptr) const;
///< Return name of the script attached to ptr
static void registerSelf();
};
}

@ -60,6 +60,14 @@ namespace MWClass
return *ptr.getRefData().getContainerStore();
}
std::string Creature::getScript (const MWWorld::Ptr& ptr) const
{
ESMS::LiveCellRef<ESM::Creature, MWWorld::RefData> *ref =
ptr.get<ESM::Creature>();
return ref->base->script;
}
void Creature::registerSelf()
{
boost::shared_ptr<Class> instance (new Creature);

@ -20,6 +20,9 @@ namespace MWClass
const MWWorld::Ptr& ptr) const;
///< Return container store
virtual std::string getScript (const MWWorld::Ptr& ptr) const;
///< Return name of the script attached to ptr
static void registerSelf();
};
}

@ -53,6 +53,14 @@ namespace MWClass
}
}
std::string Door::getScript (const MWWorld::Ptr& ptr) const
{
ESMS::LiveCellRef<ESM::Door, MWWorld::RefData> *ref =
ptr.get<ESM::Door>();
return ref->base->script;
}
void Door::registerSelf()
{
boost::shared_ptr<Class> instance (new Door);

@ -17,6 +17,9 @@ namespace MWClass
const MWWorld::Ptr& actor, const MWWorld::Environment& environment) const;
///< Generate action for activation
virtual std::string getScript (const MWWorld::Ptr& ptr) const;
///< Return name of the script attached to ptr
static void registerSelf();
};
}

@ -17,6 +17,14 @@ namespace MWClass
return ref->base->name;
}
std::string Ingredient::getScript (const MWWorld::Ptr& ptr) const
{
ESMS::LiveCellRef<ESM::Ingredient, MWWorld::RefData> *ref =
ptr.get<ESM::Ingredient>();
return ref->base->script;
}
void Ingredient::registerSelf()
{
boost::shared_ptr<Class> instance (new Ingredient);

@ -13,6 +13,9 @@ namespace MWClass
///< \return name (the one that is to be presented to the user; not the internal one);
/// can return an empty string.
virtual std::string getScript (const MWWorld::Ptr& ptr) const;
///< Return name of the script attached to ptr
static void registerSelf();
};
}

@ -20,6 +20,14 @@ namespace MWClass
return ref->base->name;
}
std::string Light::getScript (const MWWorld::Ptr& ptr) const
{
ESMS::LiveCellRef<ESM::Light, MWWorld::RefData> *ref =
ptr.get<ESM::Light>();
return ref->base->script;
}
void Light::registerSelf()
{
boost::shared_ptr<Class> instance (new Light);

@ -13,6 +13,9 @@ namespace MWClass
///< \return name (the one that is to be presented to the user; not the internal one);
/// can return an empty string.
virtual std::string getScript (const MWWorld::Ptr& ptr) const;
///< Return name of the script attached to ptr
static void registerSelf();
};
}

@ -17,6 +17,14 @@ namespace MWClass
return ref->base->name;
}
std::string Lockpick::getScript (const MWWorld::Ptr& ptr) const
{
ESMS::LiveCellRef<ESM::Tool, MWWorld::RefData> *ref =
ptr.get<ESM::Tool>();
return ref->base->script;
}
void Lockpick::registerSelf()
{
boost::shared_ptr<Class> instance (new Lockpick);

@ -13,6 +13,9 @@ namespace MWClass
///< \return name (the one that is to be presented to the user; not the internal one);
/// can return an empty string.
virtual std::string getScript (const MWWorld::Ptr& ptr) const;
///< Return name of the script attached to ptr
static void registerSelf();
};
}

@ -17,6 +17,14 @@ namespace MWClass
return ref->base->name;
}
std::string Misc::getScript (const MWWorld::Ptr& ptr) const
{
ESMS::LiveCellRef<ESM::Misc, MWWorld::RefData> *ref =
ptr.get<ESM::Misc>();
return ref->base->script;
}
void Misc::registerSelf()
{
boost::shared_ptr<Class> instance (new Misc);

@ -13,6 +13,9 @@ namespace MWClass
///< \return name (the one that is to be presented to the user; not the internal one);
/// can return an empty string.
virtual std::string getScript (const MWWorld::Ptr& ptr) const;
///< Return name of the script attached to ptr
static void registerSelf();
};
}

@ -44,7 +44,8 @@ namespace MWClass
return *ptr.getRefData().getCreatureStats();
}
MWWorld::ContainerStore<MWWorld::RefData>& Npc::getContainerStore (const MWWorld::Ptr& ptr) const
MWWorld::ContainerStore<MWWorld::RefData>& Npc::getContainerStore (const MWWorld::Ptr& ptr)
const
{
if (!ptr.getRefData().getContainerStore().get())
{
@ -59,6 +60,14 @@ namespace MWClass
return *ptr.getRefData().getContainerStore();
}
std::string Npc::getScript (const MWWorld::Ptr& ptr) const
{
ESMS::LiveCellRef<ESM::NPC, MWWorld::RefData> *ref =
ptr.get<ESM::NPC>();
return ref->base->script;
}
void Npc::registerSelf()
{
boost::shared_ptr<Class> instance (new Npc);

@ -20,6 +20,9 @@ namespace MWClass
const MWWorld::Ptr& ptr) const;
///< Return container store
virtual std::string getScript (const MWWorld::Ptr& ptr) const;
///< Return name of the script attached to ptr
static void registerSelf();
};
}

@ -17,6 +17,14 @@ namespace MWClass
return ref->base->name;
}
std::string Potion::getScript (const MWWorld::Ptr& ptr) const
{
ESMS::LiveCellRef<ESM::Potion, MWWorld::RefData> *ref =
ptr.get<ESM::Potion>();
return ref->base->script;
}
void Potion::registerSelf()
{
boost::shared_ptr<Class> instance (new Potion);

@ -13,6 +13,9 @@ namespace MWClass
///< \return name (the one that is to be presented to the user; not the internal one);
/// can return an empty string.
virtual std::string getScript (const MWWorld::Ptr& ptr) const;
///< Return name of the script attached to ptr
static void registerSelf();
};
}

@ -17,6 +17,14 @@ namespace MWClass
return ref->base->name;
}
std::string Probe::getScript (const MWWorld::Ptr& ptr) const
{
ESMS::LiveCellRef<ESM::Probe, MWWorld::RefData> *ref =
ptr.get<ESM::Probe>();
return ref->base->script;
}
void Probe::registerSelf()
{
boost::shared_ptr<Class> instance (new Probe);

@ -13,6 +13,9 @@ namespace MWClass
///< \return name (the one that is to be presented to the user; not the internal one);
/// can return an empty string.
virtual std::string getScript (const MWWorld::Ptr& ptr) const;
///< Return name of the script attached to ptr
static void registerSelf();
};
}

@ -17,6 +17,14 @@ namespace MWClass
return ref->base->name;
}
std::string Repair::getScript (const MWWorld::Ptr& ptr) const
{
ESMS::LiveCellRef<ESM::Repair, MWWorld::RefData> *ref =
ptr.get<ESM::Repair>();
return ref->base->script;
}
void Repair::registerSelf()
{
boost::shared_ptr<Class> instance (new Repair);

@ -13,6 +13,9 @@ namespace MWClass
///< \return name (the one that is to be presented to the user; not the internal one);
/// can return an empty string.
virtual std::string getScript (const MWWorld::Ptr& ptr) const;
///< Return name of the script attached to ptr
static void registerSelf();
};
}

@ -30,6 +30,14 @@ namespace MWClass
return ref->base->data.health;
}
std::string Weapon::getScript (const MWWorld::Ptr& ptr) const
{
ESMS::LiveCellRef<ESM::Weapon, MWWorld::RefData> *ref =
ptr.get<ESM::Weapon>();
return ref->base->script;
}
void Weapon::registerSelf()
{
boost::shared_ptr<Class> instance (new Weapon);

@ -19,6 +19,9 @@ namespace MWClass
virtual int getItemMaxHealth (const MWWorld::Ptr& ptr) const;
///< Return item max health or throw an exception, if class does not have item health
virtual std::string getScript (const MWWorld::Ptr& ptr) const;
///< Return name of the script attached to ptr
static void registerSelf();
};
}

@ -17,6 +17,8 @@
#include <libs/platform/strings.h>
#include "../mwrender/playerpos.hpp"
#include "../engine.hpp"
#include <boost/bind.hpp>
#include <boost/filesystem.hpp>
#include <OgreRoot.h>
@ -58,6 +60,7 @@ namespace MWInput
OEngine::GUI::EventInjectorPtr guiEvents;
MWRender::PlayerPos &player;
MWGui::WindowManager &windows;
OMW::Engine& mEngine;
// Count screenshots.
int shotCount;
@ -137,7 +140,7 @@ namespace MWInput
void activate()
{
mEngine.activate();
}
// Exit program now button (which is disabled in GUI mode)
@ -151,13 +154,15 @@ namespace MWInput
InputImpl(OEngine::Render::OgreRenderer &_ogre,
MWRender::PlayerPos &_player,
MWGui::WindowManager &_windows,
bool debug)
bool debug,
OMW::Engine& engine)
: ogre(_ogre),
exit(ogre.getWindow()),
input(ogre.getWindow(), !debug),
poller(input),
player(_player),
windows(_windows),
mEngine (engine),
shotCount(0)
{
using namespace OEngine::Input;
@ -275,9 +280,10 @@ namespace MWInput
MWInputManager::MWInputManager(OEngine::Render::OgreRenderer &ogre,
MWRender::PlayerPos &player,
MWGui::WindowManager &windows,
bool debug)
bool debug,
OMW::Engine& engine)
{
impl = new InputImpl(ogre,player,windows,debug);
impl = new InputImpl(ogre,player,windows,debug, engine);
}
MWInputManager::~MWInputManager()

@ -19,6 +19,11 @@ namespace MWGui
class WindowManager;
}
namespace OMW
{
class Engine;
}
namespace MWInput
{
// Forward declaration of the real implementation.
@ -37,7 +42,8 @@ namespace MWInput
MWInputManager(OEngine::Render::OgreRenderer &_ogre,
MWRender::PlayerPos &_player,
MWGui::WindowManager &_windows,
bool debug);
bool debug,
OMW::Engine& engine);
~MWInputManager();
};
}

@ -49,7 +49,7 @@ namespace MWMechanics
value = min + (mModified - mBase);
diff = value - mModified;
}
else if (mBase>max-diff)
else if (mBase+diff>max)
{
value = max + (mModified - mBase);
diff = value - mModified;

@ -76,4 +76,5 @@ op 0x2000069-0x200006b: ModDynamic (health, magicka, fatigue)
op 0x200006c-0x200006e: ModDynamic (health, magicka, fatigue), explicit reference
op 0x200006f-0x2000071: GetDynamic (health, magicka, fatigue)
op 0x2000072-0x2000074: GetDynamic (health, magicka, fatigue), explicit reference
opcodes 0x2000075-0x3ffffff unused
op 0x2000075: Activate
opcodes 0x2000076-0x3ffffff unused

@ -38,19 +38,37 @@ namespace MWScript
}
};
class OpActivate : public Interpreter::Opcode0
{
public:
virtual void execute (Interpreter::Runtime& runtime)
{
InterpreterContext& context =
static_cast<InterpreterContext&> (runtime.getContext());
MWWorld::Ptr ptr = context.getReference();
context.executeActivation();
}
};
const int opcodeXBox = 0x200000c;
const int opcodeOnActivate = 0x200000d;
const int opcodeActivate = 0x2000075;
void registerExtensions (Compiler::Extensions& extensions)
{
extensions.registerFunction ("xbox", 'l', "", opcodeXBox);
extensions.registerFunction ("onactivate", 'l', "", opcodeOnActivate);
extensions.registerInstruction ("activate", "", opcodeActivate);
}
void installOpcodes (Interpreter::Interpreter& interpreter)
{
interpreter.installSegment5 (opcodeXBox, new OpXBox);
interpreter.installSegment5 (opcodeOnActivate, new OpOnActivate);
interpreter.installSegment5 (opcodeActivate, new OpActivate);
}
}
}

@ -44,6 +44,11 @@ namespace MWWorld
ContainerStore<RefData>& Class::getContainerStore (const Ptr& ptr) const
{
throw std::runtime_error ("class does not have a container store");
}
std::string Class::getScript (const Ptr& ptr) const
{
return "";
}
const Class& Class::get (const std::string& key)

@ -64,6 +64,10 @@ namespace MWWorld
///< Return container store or throw an exception, if class does not have a
/// container store (default implementation: throw an exceoption)
virtual std::string getScript (const Ptr& ptr) const;
///< Return name of the script attached to ptr (default implementation: return an empty
/// string).
static const Class& get (const std::string& key);
///< If there is no class for this \a key, an exception is thrown.

@ -544,7 +544,7 @@ namespace MWWorld
insertInteriorScripts (*cell);
// adjust player
mPlayerPos->setPos (position.pos[0], position.pos[1], position.pos[2]);
mPlayerPos->setPos (position.pos[0], position.pos[1], position.pos[2], true);
mPlayerPos->setCell (cell);
// TODO orientation
@ -600,4 +600,15 @@ namespace MWWorld
{
mCellChanged = false;
}
std::string World::getFacedHandle()
{
std::pair<std::string, float> result = mScene.getFacedHandle();
if (result.first.empty() ||
result.second>getStore().gameSettings.find ("iMaxActivateDist")->i)
return "";
return result.first;
}
}

@ -83,8 +83,6 @@ namespace MWWorld
~World();
MWRender::MWScene* getMWScene() { return &mScene; }
MWRender::PlayerPos& getPlayerPos();
ESMS::ESMStore& getStore();
@ -133,6 +131,9 @@ namespace MWWorld
///< works only for interior cells currently.
void markCellAsUnchanged();
std::string getFacedHandle();
///< Return handle of the object the player is looking at
};
}

Loading…
Cancel
Save