npc.cpp 19 KB
Newer Older
1 2 3

#include "npc.hpp"

4 5
#include <memory>

scrawl's avatar
scrawl committed
6 7
#include <boost/algorithm/string.hpp>

8 9
#include <OgreSceneNode.h>

10 11
#include <components/esm/loadnpc.hpp>

12 13
#include "../mwbase/environment.hpp"
#include "../mwbase/world.hpp"
14
#include "../mwbase/mechanicsmanager.hpp"
15
#include "../mwbase/windowmanager.hpp"
16

Marc Zinnschlag's avatar
Marc Zinnschlag committed
17
#include "../mwmechanics/creaturestats.hpp"
Marc Zinnschlag's avatar
Marc Zinnschlag committed
18
#include "../mwmechanics/npcstats.hpp"
19
#include "../mwmechanics/movement.hpp"
Marc Zinnschlag's avatar
Marc Zinnschlag committed
20

21
#include "../mwworld/ptr.hpp"
22
#include "../mwworld/actiontalk.hpp"
scrawl's avatar
scrawl committed
23
#include "../mwworld/actionopen.hpp"
24
#include "../mwworld/inventorystore.hpp"
Marc Zinnschlag's avatar
Marc Zinnschlag committed
25
#include "../mwworld/customdata.hpp"
26
#include "../mwworld/physicssystem.hpp"
27

28
#include "../mwrender/actors.hpp"
29
#include "../mwrender/renderinginterface.hpp"
30

31
#include "../mwgui/tooltips.hpp"
32

Marc Zinnschlag's avatar
Marc Zinnschlag committed
33
namespace
34 35 36
{
    const Ogre::Radian kOgrePi (Ogre::Math::PI);
    const Ogre::Radian kOgrePiOverTwo (Ogre::Math::PI / Ogre::Real(2.0));
37 38 39 40

    struct CustomData : public MWWorld::CustomData
    {
        MWMechanics::NpcStats mNpcStats;
41
        MWMechanics::CreatureStats mCreatureStats;
42
        MWMechanics::Movement mMovement;
43
        MWWorld::InventoryStore mInventoryStore;
44 45 46 47 48 49 50 51

        virtual MWWorld::CustomData *clone() const;
    };

    MWWorld::CustomData *CustomData::clone() const
    {
        return new CustomData (*this);
    }
52 53
}

54
namespace MWClass
55
{
56 57
    void Npc::ensureCustomData (const MWWorld::Ptr& ptr) const
    {
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
        static bool inited = false;
        if(!inited)
        {
            const MWBase::World *world = MWBase::Environment::get().getWorld();
            const MWWorld::Store<ESM::GameSetting> &gmst = world->getStore().get<ESM::GameSetting>();

            fMinWalkSpeed = gmst.find("fMinWalkSpeed");
            fMaxWalkSpeed = gmst.find("fMaxWalkSpeed");
            fEncumberedMoveEffect = gmst.find("fEncumberedMoveEffect");
            fSneakSpeedMultiplier = gmst.find("fSneakSpeedMultiplier");
            fAthleticsRunBonus = gmst.find("fAthleticsRunBonus");
            fBaseRunMultiplier = gmst.find("fBaseRunMultiplier");
            fMinFlySpeed = gmst.find("fMinFlySpeed");
            fMaxFlySpeed = gmst.find("fMaxFlySpeed");
            fSwimRunBase = gmst.find("fSwimRunBase");
            fSwimRunAthleticsMult = gmst.find("fSwimRunAthleticsMult");
74 75 76 77 78
            fJumpEncumbranceBase = gmst.find("fJumpEncumbranceBase");
            fJumpEncumbranceMultiplier = gmst.find("fJumpEncumbranceMultiplier");
            fJumpAcrobaticsBase = gmst.find("fJumpAcrobaticsBase");
            fJumpAcroMultiplier = gmst.find("fJumpAcroMultiplier");
            fJumpRunMultiplier = gmst.find("fJumpRunMultiplier");
79 80 81 82 83
            // Added in Tribunal/Bloodmoon, may not exist
            fWereWolfRunMult = gmst.search("fWereWolfRunMult");

            inited = true;
        }
84 85
        if (!ptr.getRefData().getCustomData())
        {
86
            std::auto_ptr<CustomData> data(new CustomData);
87

88
            MWWorld::LiveCellRef<ESM::NPC> *ref = ptr.get<ESM::NPC>();
89

90
            // NPC stats
greye's avatar
greye committed
91
            if (!ref->mBase->mFaction.empty())
92
            {
greye's avatar
greye committed
93
                std::string faction = ref->mBase->mFaction;
eduard's avatar
eduard committed
94
                Misc::StringUtils::toLower(faction);
greye's avatar
greye committed
95
                if(ref->mBase->mNpdt52.mGold != -10)
96
                {
greye's avatar
greye committed
97
                    data->mNpcStats.getFactionRanks()[faction] = (int)ref->mBase->mNpdt52.mRank;
98 99 100
                }
                else
                {
greye's avatar
greye committed
101
                    data->mNpcStats.getFactionRanks()[faction] = (int)ref->mBase->mNpdt12.mRank;
102
                }
103 104
            }

105
            // creature stats
greye's avatar
greye committed
106
            if(ref->mBase->mNpdt52.mGold != -10)
107 108
            {
                for (int i=0; i<27; ++i)
greye's avatar
greye committed
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123
                    data->mNpcStats.getSkill (i).setBase (ref->mBase->mNpdt52.mSkills[i]);

                data->mCreatureStats.getAttribute(0).set (ref->mBase->mNpdt52.mStrength);
                data->mCreatureStats.getAttribute(1).set (ref->mBase->mNpdt52.mIntelligence);
                data->mCreatureStats.getAttribute(2).set (ref->mBase->mNpdt52.mWillpower);
                data->mCreatureStats.getAttribute(3).set (ref->mBase->mNpdt52.mAgility);
                data->mCreatureStats.getAttribute(4).set (ref->mBase->mNpdt52.mSpeed);
                data->mCreatureStats.getAttribute(5).set (ref->mBase->mNpdt52.mEndurance);
                data->mCreatureStats.getAttribute(6).set (ref->mBase->mNpdt52.mPersonality);
                data->mCreatureStats.getAttribute(7).set (ref->mBase->mNpdt52.mLuck);
                data->mCreatureStats.setHealth (ref->mBase->mNpdt52.mHealth);
                data->mCreatureStats.setMagicka (ref->mBase->mNpdt52.mMana);
                data->mCreatureStats.setFatigue (ref->mBase->mNpdt52.mFatigue);

                data->mCreatureStats.setLevel(ref->mBase->mNpdt52.mLevel);
scrawl's avatar
scrawl committed
124
                data->mNpcStats.setBaseDisposition(ref->mBase->mNpdt52.mDisposition);
125
                data->mNpcStats.setReputation(ref->mBase->mNpdt52.mReputation);
126 127 128
            }
            else
            {
129 130 131 132 133 134
                for (int i=0; i<8; ++i)
                    data->mCreatureStats.getAttribute (i).set (10);

                for (int i=0; i<3; ++i)
                    data->mCreatureStats.setDynamic (i, 10);

135 136 137
                data->mCreatureStats.setLevel(ref->mBase->mNpdt12.mLevel);
                data->mNpcStats.setBaseDisposition(ref->mBase->mNpdt12.mDisposition);
                data->mNpcStats.setReputation(ref->mBase->mNpdt12.mReputation);
138
            }
139

140 141 142 143
            data->mCreatureStats.setAiSetting (0, ref->mBase->mAiData.mHello);
            data->mCreatureStats.setAiSetting (1, ref->mBase->mAiData.mFight);
            data->mCreatureStats.setAiSetting (2, ref->mBase->mAiData.mFlee);
            data->mCreatureStats.setAiSetting (3, ref->mBase->mAiData.mAlarm);
144

145
            // spells
greye's avatar
greye committed
146 147
            for (std::vector<std::string>::const_iterator iter (ref->mBase->mSpells.mList.begin());
                iter!=ref->mBase->mSpells.mList.end(); ++iter)
148 149
                data->mCreatureStats.getSpells().add (*iter);

150
            // store
151 152 153 154
            ptr.getRefData().setCustomData (data.release());
        }
    }

Marc Zinnschlag's avatar
Marc Zinnschlag committed
155 156
    std::string Npc::getId (const MWWorld::Ptr& ptr) const
    {
157
        MWWorld::LiveCellRef<ESM::NPC> *ref =
Marc Zinnschlag's avatar
Marc Zinnschlag committed
158 159
            ptr.get<ESM::NPC>();

greye's avatar
greye committed
160
        return ref->mBase->mId;
Marc Zinnschlag's avatar
Marc Zinnschlag committed
161 162
    }

Jason Hooks's avatar
Jason Hooks committed
163
    void Npc::insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const
164
    {
Jason Hooks's avatar
Jason Hooks committed
165
        renderingInterface.getActors().insertNPC(ptr, getInventoryStore(ptr));
Jason Hooks's avatar
Jason Hooks committed
166
    }
Jason Hooks's avatar
Jason Hooks committed
167

168
    void Npc::insertObject(const MWWorld::Ptr& ptr, MWWorld::PhysicsSystem& physics) const
Jason Hooks's avatar
Jason Hooks committed
169
    {
170
        physics.addActor(ptr);
171
        MWBase::Environment::get().getMechanicsManager()->add(ptr);
greye's avatar
greye committed
172
    }
Jason Hooks's avatar
Jason Hooks committed
173

greye's avatar
greye committed
174 175
    std::string Npc::getModel(const MWWorld::Ptr &ptr) const
    {
176
        MWWorld::LiveCellRef<ESM::NPC> *ref =
Jason Hooks's avatar
Jason Hooks committed
177
            ptr.get<ESM::NPC>();
greye's avatar
greye committed
178
        assert(ref->mBase != NULL);
179

greye's avatar
greye committed
180
        std::string headID = ref->mBase->mHead;
181

greye's avatar
greye committed
182 183 184 185 186 187 188 189 190 191 192 193
        int end = headID.find_last_of("head_") - 4;
        std::string bodyRaceID = headID.substr(0, end);

        std::string model = "meshes\\base_anim.nif";
        if (bodyRaceID == "b_n_khajiit_m_" ||
            bodyRaceID == "b_n_khajiit_f_" ||
            bodyRaceID == "b_n_argonian_m_" ||
            bodyRaceID == "b_n_argonian_f_")
        {
            model = "meshes\\base_animkna.nif";
        }
        return model;
194 195 196

    }

Marc Zinnschlag's avatar
Marc Zinnschlag committed
197 198
    std::string Npc::getName (const MWWorld::Ptr& ptr) const
    {
199
        MWWorld::LiveCellRef<ESM::NPC> *ref =
Marc Zinnschlag's avatar
Marc Zinnschlag committed
200 201
            ptr.get<ESM::NPC>();

greye's avatar
greye committed
202
        return ref->mBase->mName;
Marc Zinnschlag's avatar
Marc Zinnschlag committed
203 204
    }

205
    MWMechanics::CreatureStats& Npc::getCreatureStats (const MWWorld::Ptr& ptr) const
206
    {
207
        ensureCustomData (ptr);
208

209
        return dynamic_cast<CustomData&> (*ptr.getRefData().getCustomData()).mCreatureStats;
210 211
    }

Marc Zinnschlag's avatar
Marc Zinnschlag committed
212 213
    MWMechanics::NpcStats& Npc::getNpcStats (const MWWorld::Ptr& ptr) const
    {
214
        ensureCustomData (ptr);
Marc Zinnschlag's avatar
Marc Zinnschlag committed
215

216
        return dynamic_cast<CustomData&> (*ptr.getRefData().getCustomData()).mNpcStats;
Marc Zinnschlag's avatar
Marc Zinnschlag committed
217 218
    }

219
    boost::shared_ptr<MWWorld::Action> Npc::activate (const MWWorld::Ptr& ptr,
220
        const MWWorld::Ptr& actor) const
221
    {
scrawl's avatar
scrawl committed
222
        if (MWWorld::Class::get (ptr).getCreatureStats (ptr).isDead())
223 224 225
            return boost::shared_ptr<MWWorld::Action> (new MWWorld::ActionOpen(ptr, true));
        else if (MWWorld::Class::get(actor).getStance(actor, MWWorld::Class::Sneak))
            return boost::shared_ptr<MWWorld::Action> (new MWWorld::ActionOpen(ptr)); // stealing
scrawl's avatar
scrawl committed
226 227
        else
            return boost::shared_ptr<MWWorld::Action> (new MWWorld::ActionTalk (ptr));
228
    }
Marc Zinnschlag's avatar
Marc Zinnschlag committed
229

230
    MWWorld::ContainerStore& Npc::getContainerStore (const MWWorld::Ptr& ptr)
231
        const
Marc Zinnschlag's avatar
Marc Zinnschlag committed
232
    {
233
        ensureCustomData (ptr);
Marc Zinnschlag's avatar
Marc Zinnschlag committed
234

235 236 237 238 239 240 241 242 243
        return dynamic_cast<CustomData&> (*ptr.getRefData().getCustomData()).mInventoryStore;
    }

    MWWorld::InventoryStore& Npc::getInventoryStore (const MWWorld::Ptr& ptr)
        const
    {
        ensureCustomData (ptr);

        return dynamic_cast<CustomData&> (*ptr.getRefData().getCustomData()).mInventoryStore;
Marc Zinnschlag's avatar
Marc Zinnschlag committed
244 245
    }

246 247
    std::string Npc::getScript (const MWWorld::Ptr& ptr) const
    {
248
        MWWorld::LiveCellRef<ESM::NPC> *ref =
249 250
            ptr.get<ESM::NPC>();

greye's avatar
greye committed
251
        return ref->mBase->mScript;
252 253
    }

Marc Zinnschlag's avatar
Marc Zinnschlag committed
254 255 256 257 258 259 260 261
    void Npc::setForceStance (const MWWorld::Ptr& ptr, Stance stance, bool force) const
    {
        MWMechanics::NpcStats& stats = getNpcStats (ptr);

        switch (stance)
        {
            case Run:

262
                stats.setMovementFlag (MWMechanics::NpcStats::Flag_ForceRun, force);
Marc Zinnschlag's avatar
Marc Zinnschlag committed
263 264 265 266
                break;

            case Sneak:

267
                stats.setMovementFlag (MWMechanics::NpcStats::Flag_ForceSneak, force);
Marc Zinnschlag's avatar
Marc Zinnschlag committed
268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283
                break;

            case Combat:

                throw std::runtime_error ("combat stance not enforcable for NPCs");
        }
    }

    void Npc::setStance (const MWWorld::Ptr& ptr, Stance stance, bool set) const
    {
        MWMechanics::NpcStats& stats = getNpcStats (ptr);

        switch (stance)
        {
            case Run:

284
                stats.setMovementFlag (MWMechanics::NpcStats::Flag_Run, set);
285
                break;
Marc Zinnschlag's avatar
Marc Zinnschlag committed
286 287 288

            case Sneak:

289
                stats.setMovementFlag (MWMechanics::NpcStats::Flag_Sneak, set);
Marc Zinnschlag's avatar
Marc Zinnschlag committed
290 291 292 293
                break;

            case Combat:

294 295
                // Combat stance ignored for now; need to be determined based on draw state instead of
                // being maunally set.
Marc Zinnschlag's avatar
Marc Zinnschlag committed
296 297 298 299 300 301 302 303 304 305 306 307
                break;
        }
    }

    bool Npc::getStance (const MWWorld::Ptr& ptr, Stance stance, bool ignoreForce) const
    {
        MWMechanics::NpcStats& stats = getNpcStats (ptr);

        switch (stance)
        {
            case Run:

308
                if (!ignoreForce && stats.getMovementFlag (MWMechanics::NpcStats::Flag_ForceRun))
309 310
                    return true;

311
                return stats.getMovementFlag (MWMechanics::NpcStats::Flag_Run);
Marc Zinnschlag's avatar
Marc Zinnschlag committed
312 313 314

            case Sneak:

315
                if (!ignoreForce && stats.getMovementFlag (MWMechanics::NpcStats::Flag_ForceSneak))
Marc Zinnschlag's avatar
Marc Zinnschlag committed
316 317
                    return true;

318
                return stats.getMovementFlag (MWMechanics::NpcStats::Flag_Sneak);
Marc Zinnschlag's avatar
Marc Zinnschlag committed
319 320 321

            case Combat:

322
                return false;
Marc Zinnschlag's avatar
Marc Zinnschlag committed
323 324 325 326 327
        }

        return false;
    }

328
    float Npc::getSpeed(const MWWorld::Ptr& ptr) const
Marc Zinnschlag's avatar
Marc Zinnschlag committed
329
    {
330 331
        const MWBase::World *world = MWBase::Environment::get().getWorld();
        const CustomData *npcdata = static_cast<const CustomData*>(ptr.getRefData().getCustomData());
332 333
        const MWMechanics::MagicEffects &mageffects = npcdata->mCreatureStats.getMagicEffects();

334 335 336 337 338 339 340 341
        const float normalizedEncumbrance = Npc::getEncumbrance(ptr) / Npc::getCapacity(ptr);

        float walkSpeed = fMinWalkSpeed->getFloat() + 0.01f*npcdata->mCreatureStats.getAttribute(ESM::Attribute::Speed).getModified()*
                                                      (fMaxWalkSpeed->getFloat() - fMinWalkSpeed->getFloat());
        walkSpeed *= 1.0f - fEncumberedMoveEffect->getFloat()*normalizedEncumbrance;
        walkSpeed = std::max(0.0f, walkSpeed);
        if(Npc::getStance(ptr, Sneak, false))
            walkSpeed *= fSneakSpeedMultiplier->getFloat();
342

343 344
        float runSpeed = walkSpeed*(0.01f * npcdata->mNpcStats.getSkill(ESM::Skill::Athletics).getModified() *
                                    fAthleticsRunBonus->getFloat() + fBaseRunMultiplier->getFloat());
345 346
        if(npcdata->mNpcStats.isWerewolf())
            runSpeed *= fWereWolfRunMult->getFloat();
347 348

        float moveSpeed;
349
        if(normalizedEncumbrance >= 1.0f)
350
            moveSpeed = 0.0f;
351
        else if(mageffects.get(MWMechanics::EffectKey(10/*levitate*/)).mMagnitude > 0)
352 353
        {
            float flySpeed = 0.01f*(npcdata->mCreatureStats.getAttribute(ESM::Attribute::Speed).getModified() +
354
                                    mageffects.get(MWMechanics::EffectKey(10/*levitate*/)).mMagnitude);
355 356 357 358 359 360 361 362 363 364
            flySpeed = fMinFlySpeed->getFloat() + flySpeed*(fMaxFlySpeed->getFloat() - fMinFlySpeed->getFloat());
            flySpeed *= 1.0f - fEncumberedMoveEffect->getFloat() * normalizedEncumbrance;
            flySpeed = std::max(0.0f, flySpeed);
            moveSpeed = flySpeed;
        }
        else if(world->isSwimming(ptr))
        {
            float swimSpeed = walkSpeed;
            if(Npc::getStance(ptr, Run, false))
                swimSpeed = runSpeed;
365
            swimSpeed *= 1.0f + 0.01f * mageffects.get(MWMechanics::EffectKey(1/*swift swim*/)).mMagnitude;
366 367 368 369
            swimSpeed *= fSwimRunBase->getFloat() + 0.01f*npcdata->mNpcStats.getSkill(ESM::Skill::Athletics).getModified()*
                                                    fSwimRunAthleticsMult->getFloat();
            moveSpeed = swimSpeed;
        }
scrawl's avatar
scrawl committed
370
        else if(Npc::getStance(ptr, Run, false) && !Npc::getStance(ptr, Sneak, false))
371 372 373 374 375 376 377
            moveSpeed = runSpeed;
        else
            moveSpeed = walkSpeed;
        if(getMovementSettings(ptr).mLeftRight != 0 && getMovementSettings(ptr).mForwardBackward == 0)
            moveSpeed *= 0.75f;

        return moveSpeed;
Marc Zinnschlag's avatar
Marc Zinnschlag committed
378 379
    }

380 381 382 383 384 385
    float Npc::getJump(const MWWorld::Ptr &ptr) const
    {
        const CustomData *npcdata = static_cast<const CustomData*>(ptr.getRefData().getCustomData());
        const MWMechanics::MagicEffects &mageffects = npcdata->mCreatureStats.getMagicEffects();
        const float encumbranceTerm = fJumpEncumbranceBase->getFloat() +
                                          fJumpEncumbranceMultiplier->getFloat() *
386
                                          (1.0f - Npc::getEncumbrance(ptr)/Npc::getCapacity(ptr));
387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410

        float a = npcdata->mNpcStats.getSkill(ESM::Skill::Acrobatics).getModified();
        float b = 0.0f;
        if(a > 50.0f)
        {
            b = a - 50.0f;
            a = 50.0f;
        }

        float x = fJumpAcrobaticsBase->getFloat() +
                  std::pow(a / 15.0f, fJumpAcroMultiplier->getFloat());
        x += 3 * b * fJumpAcroMultiplier->getFloat();
        x += mageffects.get(MWMechanics::EffectKey(9/*jump*/)).mMagnitude * 64;
        x *= encumbranceTerm;

        if(Npc::getStance(ptr, Run, false))
            x *= fJumpRunMultiplier->getFloat();
        x *= 1.25f;//fatigueTerm;
        x -= -627.2/*gravity constant*/;
        x /= 3;

        return x;
    }

411 412
    MWMechanics::Movement& Npc::getMovementSettings (const MWWorld::Ptr& ptr) const
    {
413
        ensureCustomData (ptr);
414

415
        return dynamic_cast<CustomData&> (*ptr.getRefData().getCustomData()).mMovement;
416 417 418 419
    }

    Ogre::Vector3 Npc::getMovementVector (const MWWorld::Ptr& ptr) const
    {
420 421 422 423
        Ogre::Vector3 vector;
        vector.x = getMovementSettings(ptr).mLeftRight;
        vector.y = getMovementSettings(ptr).mForwardBackward;
        vector.z = getMovementSettings(ptr).mUpDown;
424 425 426

        return vector;
    }
427 428 429 430 431
    
    bool Npc::isEssential (const MWWorld::Ptr& ptr) const
    {
        MWWorld::LiveCellRef<ESM::NPC> *ref =
            ptr.get<ESM::NPC>();
432

greye's avatar
greye committed
433
        return ref->mBase->mFlags & ESM::NPC::Essential;
434 435
    }
    
436 437 438 439 440
    void Npc::registerSelf()
    {
        boost::shared_ptr<Class> instance (new Npc);
        registerClass (typeid (ESM::NPC).name(), instance);
    }
441 442 443 444 445 446 447 448

    bool Npc::hasToolTip (const MWWorld::Ptr& ptr) const
    {
        /// \todo We don't want tooltips for NPCs in combat mode.

        return true;
    }

449
    MWGui::ToolTipInfo Npc::getToolTipInfo (const MWWorld::Ptr& ptr) const
450
    {
451
        MWWorld::LiveCellRef<ESM::NPC> *ref =
452 453 454
            ptr.get<ESM::NPC>();

        MWGui::ToolTipInfo info;
greye's avatar
greye committed
455
        info.caption = ref->mBase->mName;
456 457

        std::string text;
458
        if (MWBase::Environment::get().getWindowManager()->getFullHelp())
greye's avatar
greye committed
459
            text += MWGui::ToolTips::getMiscString(ref->mBase->mScript, "Script");
460 461 462 463
        info.text = text;

        return info;
    }
Marc Zinnschlag's avatar
Marc Zinnschlag committed
464

scrawl's avatar
scrawl committed
465
    float Npc::getCapacity (const MWWorld::Ptr& ptr) const
Marc Zinnschlag's avatar
Marc Zinnschlag committed
466 467
    {
        const MWMechanics::CreatureStats& stats = getCreatureStats (ptr);
greye's avatar
greye committed
468
        return stats.getAttribute(0).getModified()*5;
Marc Zinnschlag's avatar
Marc Zinnschlag committed
469
    }
470 471 472 473 474 475 476

    float Npc::getEncumbrance (const MWWorld::Ptr& ptr) const
    {
        float weight = getContainerStore (ptr).getWeight();

        const MWMechanics::CreatureStats& stats = getCreatureStats (ptr);

greye's avatar
greye committed
477
        weight -= stats.getMagicEffects().get (MWMechanics::EffectKey (8)).mMagnitude; // feather
478

greye's avatar
greye committed
479
        weight += stats.getMagicEffects().get (MWMechanics::EffectKey (7)).mMagnitude; // burden
480 481 482 483 484 485

        if (weight<0)
            weight = 0;

        return weight;
    }
486 487 488 489 490 491 492 493

    bool Npc::apply (const MWWorld::Ptr& ptr, const std::string& id,
        const MWWorld::Ptr& actor) const
    {
        MWMechanics::CreatureStats& stats = getCreatureStats (ptr);

        /// \todo consider instant effects

494
        return stats.getActiveSpells().addSpell (id, actor);
495 496 497 498 499 500 501 502
    }

    void Npc::skillUsageSucceeded (const MWWorld::Ptr& ptr, int skill, int usageType) const
    {
        MWMechanics::NpcStats& stats = getNpcStats (ptr);

        MWWorld::LiveCellRef<ESM::NPC> *ref = ptr.get<ESM::NPC>();

503 504 505 506
        const ESM::Class *class_ =
            MWBase::Environment::get().getWorld()->getStore().get<ESM::Class>().find (
                ref->mBase->mClass
            );
507 508 509

        stats.useSkill (skill, *class_, usageType);
    }
510

gugus's avatar
gugus committed
511 512 513 514 515
    void Npc::adjustRotation(const MWWorld::Ptr& ptr,float& x,float& y,float& z) const
    {
        y = 0;
        x = 0;
    }
516 517

    MWWorld::Ptr
518
    Npc::copyToCellImpl(const MWWorld::Ptr &ptr, MWWorld::CellStore &cell) const
519 520 521 522
    {
        MWWorld::LiveCellRef<ESM::NPC> *ref =
            ptr.get<ESM::NPC>();

greye's avatar
greye committed
523
        return MWWorld::Ptr(&cell.mNpcs.insert(*ref), &cell);
524
    }
525 526 527 528 529 530 531 532 533 534 535

    const ESM::GameSetting *Npc::fMinWalkSpeed;
    const ESM::GameSetting *Npc::fMaxWalkSpeed;
    const ESM::GameSetting *Npc::fEncumberedMoveEffect;
    const ESM::GameSetting *Npc::fSneakSpeedMultiplier;
    const ESM::GameSetting *Npc::fAthleticsRunBonus;
    const ESM::GameSetting *Npc::fBaseRunMultiplier;
    const ESM::GameSetting *Npc::fMinFlySpeed;
    const ESM::GameSetting *Npc::fMaxFlySpeed;
    const ESM::GameSetting *Npc::fSwimRunBase;
    const ESM::GameSetting *Npc::fSwimRunAthleticsMult;
536 537 538 539 540
    const ESM::GameSetting *Npc::fJumpEncumbranceBase;
    const ESM::GameSetting *Npc::fJumpEncumbranceMultiplier;
    const ESM::GameSetting *Npc::fJumpAcrobaticsBase;
    const ESM::GameSetting *Npc::fJumpAcroMultiplier;
    const ESM::GameSetting *Npc::fJumpRunMultiplier;
541
    const ESM::GameSetting *Npc::fWereWolfRunMult;
542
}