#include "npc.hpp" #include #include "../mwmechanics/creaturestats.hpp" #include "../mwmechanics/npcstats.hpp" #include "../mwworld/ptr.hpp" #include "../mwworld/actiontalk.hpp" #include "../mwworld/environment.hpp" #include "../mwworld/world.hpp" #include "../mwrender/cellimp.hpp" #include "../mwmechanics/mechanicsmanager.hpp" namespace MWClass { std::string Npc::getId (const MWWorld::Ptr& ptr) const { ESMS::LiveCellRef *ref = ptr.get(); return ref->base->mId; } void Npc::insertObj (const MWWorld::Ptr& ptr, MWRender::CellRenderImp& cellRender, MWWorld::Environment& environment) const { ESMS::LiveCellRef *ref = ptr.get(); assert (ref->base != NULL); std::string headID = ref->base->head; //get the part of the bodypart id which describes the race and the gender std::string bodyRaceID = headID.substr(0, headID.find_last_of("head_") - 4); std::string headModel = "meshes\\" + environment.mWorld->getStore().bodyParts.find(headID)->model; MWRender::Rendering rendering (cellRender, ref->ref); cellRender.insertMesh (headModel); //TODO: define consts for each bodypart e.g. chest, foot, wrist... and put the parts in the // right place const ESM::BodyPart *bodyPart = environment.mWorld->getStore().bodyParts.search (bodyRaceID + "chest"); if (bodyPart) cellRender.insertMesh("meshes\\" + bodyPart->model); ref->mData.setHandle (rendering.end (ref->mData.isEnabled())); } void Npc::enable (const MWWorld::Ptr& ptr, MWWorld::Environment& environment) const { environment.mMechanicsManager->addActor (ptr); } void Npc::disable (const MWWorld::Ptr& ptr, MWWorld::Environment& environment) const { environment.mMechanicsManager->removeActor (ptr); } std::string Npc::getName (const MWWorld::Ptr& ptr) const { ESMS::LiveCellRef *ref = ptr.get(); return ref->base->name; } MWMechanics::CreatureStats& Npc::getCreatureStats (const MWWorld::Ptr& ptr) const { if (!ptr.getRefData().getCreatureStats().get()) { boost::shared_ptr stats ( new MWMechanics::CreatureStats); ESMS::LiveCellRef *ref = ptr.get(); stats->mAttributes[0].set (ref->base->npdt52.strength); stats->mAttributes[1].set (ref->base->npdt52.intelligence); stats->mAttributes[2].set (ref->base->npdt52.willpower); stats->mAttributes[3].set (ref->base->npdt52.agility); stats->mAttributes[4].set (ref->base->npdt52.speed); stats->mAttributes[5].set (ref->base->npdt52.endurance); stats->mAttributes[6].set (ref->base->npdt52.personality); stats->mAttributes[7].set (ref->base->npdt52.luck); stats->mDynamic[0].set (ref->base->npdt52.health); stats->mDynamic[1].set (ref->base->npdt52.mana); stats->mDynamic[2].set (ref->base->npdt52.fatigue); ptr.getRefData().getCreatureStats() = stats; } return *ptr.getRefData().getCreatureStats(); } MWMechanics::NpcStats& Npc::getNpcStats (const MWWorld::Ptr& ptr) const { if (!ptr.getRefData().getNpcStats().get()) { // xxx boost::shared_ptr stats ( new MWMechanics::NpcStats); ESMS::LiveCellRef *ref = ptr.get(); if (!ref->base->faction.empty()) { // TODO research how initial rank is stored. The information in loadnpc.hpp are at // best very unclear. stats->mFactionRank[ref->base->faction] = 0; } ptr.getRefData().getNpcStats() = stats; } return *ptr.getRefData().getNpcStats(); } boost::shared_ptr Npc::activate (const MWWorld::Ptr& ptr, const MWWorld::Ptr& actor, const MWWorld::Environment& environment) const { return boost::shared_ptr (new MWWorld::ActionTalk (ptr)); } MWWorld::ContainerStore& Npc::getContainerStore (const MWWorld::Ptr& ptr) const { if (!ptr.getRefData().getContainerStore().get()) { boost::shared_ptr > store ( new MWWorld::ContainerStore); // TODO add initial content ptr.getRefData().getContainerStore() = store; } return *ptr.getRefData().getContainerStore(); } std::string Npc::getScript (const MWWorld::Ptr& ptr) const { ESMS::LiveCellRef *ref = ptr.get(); return ref->base->script; } void Npc::registerSelf() { boost::shared_ptr instance (new Npc); registerClass (typeid (ESM::NPC).name(), instance); } }