forked from teamnwah/openmw-tes3coop
added item health interface
This commit is contained in:
parent
93754b2851
commit
bfc282779b
9 changed files with 140 additions and 44 deletions
|
@ -96,12 +96,16 @@ set(GAMECLASS
|
||||||
mwclass/activator.cpp
|
mwclass/activator.cpp
|
||||||
mwclass/creature.cpp
|
mwclass/creature.cpp
|
||||||
mwclass/npc.cpp
|
mwclass/npc.cpp
|
||||||
|
mwclass/weapon.cpp
|
||||||
|
mwclass/armor.cpp
|
||||||
)
|
)
|
||||||
set(GAMECLASS_HEADER
|
set(GAMECLASS_HEADER
|
||||||
mwclass/classes.hpp
|
mwclass/classes.hpp
|
||||||
mwclass/activator.hpp
|
mwclass/activator.hpp
|
||||||
mwclass/creature.hpp
|
mwclass/creature.hpp
|
||||||
mwclass/npc.hpp
|
mwclass/npc.hpp
|
||||||
|
mwclass/weapon.hpp
|
||||||
|
mwclass/armor.hpp
|
||||||
)
|
)
|
||||||
source_group(apps\\openmw\\mwclass FILES ${GAMECLASS} ${GAMECLASS_HEADER})
|
source_group(apps\\openmw\\mwclass FILES ${GAMECLASS} ${GAMECLASS_HEADER})
|
||||||
|
|
||||||
|
|
31
apps/openmw/mwclass/armor.cpp
Normal file
31
apps/openmw/mwclass/armor.cpp
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
|
||||||
|
#include "armor.hpp"
|
||||||
|
|
||||||
|
#include <components/esm/loadarmo.hpp>
|
||||||
|
|
||||||
|
#include <components/esm_store/cell_store.hpp>
|
||||||
|
|
||||||
|
#include "../mwworld/ptr.hpp"
|
||||||
|
|
||||||
|
namespace MWClass
|
||||||
|
{
|
||||||
|
bool Armor::hasItemHealth (const MWWorld::Ptr& ptr) const
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Armor::getItemMaxHealth (const MWWorld::Ptr& ptr) const
|
||||||
|
{
|
||||||
|
ESMS::LiveCellRef<ESM::Armor, MWWorld::RefData> *ref =
|
||||||
|
ptr.get<ESM::Armor>();
|
||||||
|
|
||||||
|
return ref->base->data.health;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Armor::registerSelf()
|
||||||
|
{
|
||||||
|
boost::shared_ptr<Class> instance (new Armor);
|
||||||
|
|
||||||
|
registerClass (typeid (ESM::Armor).name(), instance);
|
||||||
|
}
|
||||||
|
}
|
22
apps/openmw/mwclass/armor.hpp
Normal file
22
apps/openmw/mwclass/armor.hpp
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
#ifndef GAME_MWCLASS_ARMOR_H
|
||||||
|
#define GAME_MWCLASS_ARMOR_H
|
||||||
|
|
||||||
|
#include "../mwworld/class.hpp"
|
||||||
|
|
||||||
|
namespace MWClass
|
||||||
|
{
|
||||||
|
class Armor : public MWWorld::Class
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
virtual bool hasItemHealth (const MWWorld::Ptr& ptr) const;
|
||||||
|
///< \return Item health data available?
|
||||||
|
|
||||||
|
virtual int getItemMaxHealth (const MWWorld::Ptr& ptr) const;
|
||||||
|
///< Return item max health or throw an exception, if class does not have item health
|
||||||
|
|
||||||
|
static void registerSelf();
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
|
@ -4,6 +4,8 @@
|
||||||
#include "activator.hpp"
|
#include "activator.hpp"
|
||||||
#include "creature.hpp"
|
#include "creature.hpp"
|
||||||
#include "npc.hpp"
|
#include "npc.hpp"
|
||||||
|
#include "weapon.hpp"
|
||||||
|
#include "armor.hpp"
|
||||||
|
|
||||||
namespace MWClass
|
namespace MWClass
|
||||||
{
|
{
|
||||||
|
@ -12,5 +14,7 @@ namespace MWClass
|
||||||
Activator::registerSelf();
|
Activator::registerSelf();
|
||||||
Creature::registerSelf();
|
Creature::registerSelf();
|
||||||
Npc::registerSelf();
|
Npc::registerSelf();
|
||||||
|
Weapon::registerSelf();
|
||||||
|
Armor::registerSelf();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
31
apps/openmw/mwclass/weapon.cpp
Normal file
31
apps/openmw/mwclass/weapon.cpp
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
|
||||||
|
#include "weapon.hpp"
|
||||||
|
|
||||||
|
#include <components/esm/loadweap.hpp>
|
||||||
|
|
||||||
|
#include <components/esm_store/cell_store.hpp>
|
||||||
|
|
||||||
|
#include "../mwworld/ptr.hpp"
|
||||||
|
|
||||||
|
namespace MWClass
|
||||||
|
{
|
||||||
|
bool Weapon::hasItemHealth (const MWWorld::Ptr& ptr) const
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Weapon::getItemMaxHealth (const MWWorld::Ptr& ptr) const
|
||||||
|
{
|
||||||
|
ESMS::LiveCellRef<ESM::Weapon, MWWorld::RefData> *ref =
|
||||||
|
ptr.get<ESM::Weapon>();
|
||||||
|
|
||||||
|
return ref->base->data.health;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Weapon::registerSelf()
|
||||||
|
{
|
||||||
|
boost::shared_ptr<Class> instance (new Weapon);
|
||||||
|
|
||||||
|
registerClass (typeid (ESM::Weapon).name(), instance);
|
||||||
|
}
|
||||||
|
}
|
22
apps/openmw/mwclass/weapon.hpp
Normal file
22
apps/openmw/mwclass/weapon.hpp
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
#ifndef GAME_MWCLASS_WEAPON_H
|
||||||
|
#define GAME_MWCLASS_WEAPON_H
|
||||||
|
|
||||||
|
#include "../mwworld/class.hpp"
|
||||||
|
|
||||||
|
namespace MWClass
|
||||||
|
{
|
||||||
|
class Weapon : public MWWorld::Class
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
virtual bool hasItemHealth (const MWWorld::Ptr& ptr) const;
|
||||||
|
///< \return Item health data available?
|
||||||
|
|
||||||
|
virtual int getItemMaxHealth (const MWWorld::Ptr& ptr) const;
|
||||||
|
///< Return item max health or throw an exception, if class does not have item health
|
||||||
|
|
||||||
|
static void registerSelf();
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
|
@ -186,31 +186,14 @@ namespace MWScript
|
||||||
|
|
||||||
MWWorld::Ptr ptr = context.getReference();
|
MWWorld::Ptr ptr = context.getReference();
|
||||||
|
|
||||||
if (mIndex==0)
|
if (mIndex==0 && MWWorld::Class::get (ptr).hasItemHealth (ptr))
|
||||||
{
|
{
|
||||||
// health is a special case
|
// health is a special case
|
||||||
if (context.getReference().getType()==
|
Interpreter::Type_Integer value =
|
||||||
typeid (ESMS::LiveCellRef<ESM::Weapon, MWWorld::RefData> *))
|
MWWorld::Class::get (ptr).getItemMaxHealth (ptr);
|
||||||
{
|
runtime.push (value);
|
||||||
ESMS::LiveCellRef<ESM::Weapon, MWWorld::RefData> *ref =
|
|
||||||
context.getReference().get<ESM::Weapon>();
|
|
||||||
|
|
||||||
Interpreter::Type_Integer value = ref->base->data.health;
|
return;
|
||||||
runtime.push (value);
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
else if (context.getReference().getType()==
|
|
||||||
typeid (ESMS::LiveCellRef<ESM::Armor, MWWorld::RefData> *))
|
|
||||||
{
|
|
||||||
ESMS::LiveCellRef<ESM::Armor, MWWorld::RefData> *ref =
|
|
||||||
context.getReference().get<ESM::Armor>();
|
|
||||||
|
|
||||||
Interpreter::Type_Integer value = ref->base->data.health;
|
|
||||||
runtime.push (value);
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Interpreter::Type_Integer value =
|
Interpreter::Type_Integer value =
|
||||||
|
@ -239,31 +222,14 @@ namespace MWScript
|
||||||
|
|
||||||
MWWorld::Ptr ptr = context.getWorld().getPtr (id, false);
|
MWWorld::Ptr ptr = context.getWorld().getPtr (id, false);
|
||||||
|
|
||||||
if (mIndex==0)
|
if (mIndex==0 && MWWorld::Class::get (ptr).hasItemHealth (ptr))
|
||||||
{
|
{
|
||||||
// health is a special case
|
// health is a special case
|
||||||
if (context.getWorld().getPtr (id, false).getType()==
|
Interpreter::Type_Integer value =
|
||||||
typeid (ESMS::LiveCellRef<ESM::Weapon, MWWorld::RefData> *))
|
MWWorld::Class::get (ptr).getItemMaxHealth (ptr);
|
||||||
{
|
runtime.push (value);
|
||||||
ESMS::LiveCellRef<ESM::Weapon, MWWorld::RefData> *ref =
|
|
||||||
context.getWorld().getPtr (id, false).get<ESM::Weapon>();
|
|
||||||
|
|
||||||
Interpreter::Type_Integer value = ref->base->data.health;
|
return;
|
||||||
runtime.push (value);
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
else if (context.getWorld().getPtr (id, false).getType()==
|
|
||||||
typeid (ESMS::LiveCellRef<ESM::Armor, MWWorld::RefData> *))
|
|
||||||
{
|
|
||||||
ESMS::LiveCellRef<ESM::Armor, MWWorld::RefData> *ref =
|
|
||||||
context.getWorld().getPtr (id, false).get<ESM::Armor>();
|
|
||||||
|
|
||||||
Interpreter::Type_Integer value = ref->base->data.health;
|
|
||||||
runtime.push (value);
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Interpreter::Type_Integer value =
|
Interpreter::Type_Integer value =
|
||||||
|
|
|
@ -18,6 +18,16 @@ namespace MWWorld
|
||||||
throw std::runtime_error ("class does not have creature stats");
|
throw std::runtime_error ("class does not have creature stats");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Class::hasItemHealth (const Ptr& ptr) const
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Class::getItemMaxHealth (const Ptr& ptr) const
|
||||||
|
{
|
||||||
|
throw std::runtime_error ("class does not have item health");
|
||||||
|
}
|
||||||
|
|
||||||
const Class& Class::get (const std::string& key)
|
const Class& Class::get (const std::string& key)
|
||||||
{
|
{
|
||||||
std::map<std::string, boost::shared_ptr<Class> >::const_iterator iter = sClasses.find (key);
|
std::map<std::string, boost::shared_ptr<Class> >::const_iterator iter = sClasses.find (key);
|
||||||
|
|
|
@ -36,6 +36,12 @@ namespace MWWorld
|
||||||
///< Return creature stats or throw an exception, if class does not have creature stats
|
///< Return creature stats or throw an exception, if class does not have creature stats
|
||||||
/// (default implementation: throw an exceoption)
|
/// (default implementation: throw an exceoption)
|
||||||
|
|
||||||
|
virtual bool hasItemHealth (const Ptr& ptr) const;
|
||||||
|
///< \return Item health data available? (default implementation: false)
|
||||||
|
|
||||||
|
virtual int getItemMaxHealth (const Ptr& ptr) const;
|
||||||
|
///< Return item max health or throw an exception, if class does not have item health
|
||||||
|
/// (default implementation: throw an exceoption)
|
||||||
|
|
||||||
static const Class& get (const std::string& key);
|
static const Class& get (const std::string& key);
|
||||||
///< If there is no class for this \a key, an exception is thrown.
|
///< If there is no class for this \a key, an exception is thrown.
|
||||||
|
|
Loading…
Reference in a new issue