mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-01-06 00:55:50 +00:00
implemented teleport doors (only for the player for now)
This commit is contained in:
parent
7e5ddae3b3
commit
002345270b
@ -80,6 +80,7 @@ set(GAMEWORLD
|
||||
mwworld/world.cpp
|
||||
mwworld/globals.cpp
|
||||
mwworld/class.cpp
|
||||
mwworld/actionteleport.cpp
|
||||
)
|
||||
set(GAMEWORLD_HEADER
|
||||
mwworld/refdata.hpp
|
||||
@ -90,6 +91,7 @@ set(GAMEWORLD_HEADER
|
||||
mwworld/class.hpp
|
||||
mwworld/action.hpp
|
||||
mwworld/nullaction.hpp
|
||||
mwworld/actionteleport.hpp
|
||||
)
|
||||
source_group(apps\\openmw\\mwworld FILES ${GAMEWORLD} ${GAMEWORLD_HEADER})
|
||||
|
||||
|
@ -5,7 +5,13 @@
|
||||
|
||||
#include <components/esm_store/cell_store.hpp>
|
||||
|
||||
#include "../mwrender/playerpos.hpp"
|
||||
|
||||
#include "../mwworld/ptr.hpp"
|
||||
#include "../mwworld/nullaction.hpp"
|
||||
#include "../mwworld/actionteleport.hpp"
|
||||
#include "../mwworld/environment.hpp"
|
||||
#include "../mwworld/world.hpp"
|
||||
|
||||
namespace MWClass
|
||||
{
|
||||
@ -17,6 +23,36 @@ namespace MWClass
|
||||
return ref->base->name;
|
||||
}
|
||||
|
||||
boost::shared_ptr<MWWorld::Action> Door::activate (const MWWorld::Ptr& ptr,
|
||||
const MWWorld::Ptr& actor, const MWWorld::Environment& environment) const
|
||||
{
|
||||
ESMS::LiveCellRef<ESM::Door, MWWorld::RefData> *ref =
|
||||
ptr.get<ESM::Door>();
|
||||
|
||||
if (ref->ref.teleport)
|
||||
{
|
||||
// teleport door
|
||||
if (environment.mWorld->getPlayerPos().getPlayer()==actor)
|
||||
{
|
||||
// the player is using the door
|
||||
return boost::shared_ptr<MWWorld::Action> (
|
||||
new MWWorld::ActionTeleportPlayer (ref->ref.destCell, ref->ref.doorDest));
|
||||
}
|
||||
else
|
||||
{
|
||||
// another NPC or a create is using the door
|
||||
// TODO return action for teleporting other NPC/creature
|
||||
return boost::shared_ptr<MWWorld::Action> (new MWWorld::NullAction);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// animated door
|
||||
// TODO return action for rotating the door
|
||||
return boost::shared_ptr<MWWorld::Action> (new MWWorld::NullAction);
|
||||
}
|
||||
}
|
||||
|
||||
void Door::registerSelf()
|
||||
{
|
||||
boost::shared_ptr<Class> instance (new Door);
|
||||
|
@ -13,6 +13,10 @@ namespace MWClass
|
||||
///< \return name (the one that is to be presented to the user; not the internal one);
|
||||
/// can return an empty string.
|
||||
|
||||
virtual boost::shared_ptr<MWWorld::Action> activate (const MWWorld::Ptr& ptr,
|
||||
const MWWorld::Ptr& actor, const MWWorld::Environment& environment) const;
|
||||
///< Generate action for activation
|
||||
|
||||
static void registerSelf();
|
||||
};
|
||||
}
|
||||
|
18
apps/openmw/mwworld/actionteleport.cpp
Normal file
18
apps/openmw/mwworld/actionteleport.cpp
Normal file
@ -0,0 +1,18 @@
|
||||
|
||||
#include "actionteleport.hpp"
|
||||
|
||||
#include "environment.hpp"
|
||||
#include "world.hpp"
|
||||
|
||||
namespace MWWorld
|
||||
{
|
||||
ActionTeleportPlayer::ActionTeleportPlayer (const std::string& cellName,
|
||||
const ESM::Position& position)
|
||||
: mCellName (cellName), mPosition (position)
|
||||
{}
|
||||
|
||||
void ActionTeleportPlayer::ActionTeleportPlayer::execute (Environment& environment)
|
||||
{
|
||||
environment.mWorld->changeCell (mCellName, mPosition);
|
||||
}
|
||||
}
|
25
apps/openmw/mwworld/actionteleport.hpp
Normal file
25
apps/openmw/mwworld/actionteleport.hpp
Normal file
@ -0,0 +1,25 @@
|
||||
#ifndef GAME_MWWORLD_ACTIONTELEPORT_H
|
||||
#define GAME_MWWORLD_ACTIONTELEPORT_H
|
||||
|
||||
#include <string>
|
||||
|
||||
#include <components/esm/defs.hpp>
|
||||
|
||||
#include "action.hpp"
|
||||
|
||||
namespace MWWorld
|
||||
{
|
||||
class ActionTeleportPlayer : public Action
|
||||
{
|
||||
std::string mCellName;
|
||||
ESM::Position mPosition;
|
||||
|
||||
public:
|
||||
|
||||
ActionTeleportPlayer (const std::string& cellName, const ESM::Position& position);
|
||||
|
||||
virtual void execute (Environment& environment);
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
@ -29,12 +29,14 @@ namespace MWWorld
|
||||
throw std::runtime_error ("class does not have item health");
|
||||
}
|
||||
|
||||
boost::shared_ptr<Action> Class::activate (const Ptr& ptr, const Ptr& actor) const
|
||||
boost::shared_ptr<Action> Class::activate (const Ptr& ptr, const Ptr& actor,
|
||||
const Environment& environment) const
|
||||
{
|
||||
return boost::shared_ptr<Action> (new NullAction);
|
||||
}
|
||||
|
||||
boost::shared_ptr<Action> Class::use (const Ptr& ptr) const
|
||||
boost::shared_ptr<Action> Class::use (const Ptr& ptr,
|
||||
const Environment& environment) const
|
||||
{
|
||||
return boost::shared_ptr<Action> (new NullAction);
|
||||
}
|
||||
|
@ -49,10 +49,12 @@ namespace MWWorld
|
||||
///< Return item max health or throw an exception, if class does not have item health
|
||||
/// (default implementation: throw an exceoption)
|
||||
|
||||
virtual boost::shared_ptr<Action> activate (const Ptr& ptr, const Ptr& actor) const;
|
||||
virtual boost::shared_ptr<Action> activate (const Ptr& ptr, const Ptr& actor,
|
||||
const Environment& environment) const;
|
||||
///< Generate action for activation (default implementation: return a null action).
|
||||
|
||||
virtual boost::shared_ptr<Action> use (const Ptr& ptr) const;
|
||||
virtual boost::shared_ptr<Action> use (const Ptr& ptr, const Environment& environment)
|
||||
const;
|
||||
///< Generate action for using via inventory menu (default implementation: return a
|
||||
/// null action).
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user