convertacdt.cpp 4.97 KB
Newer Older
1
2
3
4
5
6
#include <string>
#include <iostream>
#include <limits>

#include <components/misc/stringops.hpp>

7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include "convertacdt.hpp"

namespace ESSImport
{

    int translateDynamicIndex(int mwIndex)
    {
        if (mwIndex == 1)
            return 2;
        else if (mwIndex == 2)
            return 1;
        return mwIndex;
    }

    void convertACDT (const ACDT& acdt, ESM::CreatureStats& cStats)
    {
        for (int i=0; i<3; ++i)
        {
            int writeIndex = translateDynamicIndex(i);
            cStats.mDynamic[writeIndex].mBase = acdt.mDynamic[i][1];
            cStats.mDynamic[writeIndex].mMod = acdt.mDynamic[i][1];
            cStats.mDynamic[writeIndex].mCurrent = acdt.mDynamic[i][0];
        }
        for (int i=0; i<8; ++i)
        {
32
33
34
            cStats.mAttributes[i].mBase = static_cast<int>(acdt.mAttributes[i][1]);
            cStats.mAttributes[i].mMod = static_cast<int>(acdt.mAttributes[i][0]);
            cStats.mAttributes[i].mCurrent = static_cast<int>(acdt.mAttributes[i][0]);
35
        }
36
        cStats.mGoldPool = acdt.mGoldPool;
dteviot's avatar
dteviot committed
37
38
        cStats.mTalkedTo = (acdt.mFlags & TalkedToPlayer) != 0;
        cStats.mAttacked = (acdt.mFlags & Attacked) != 0;
39
40
    }

scrawl's avatar
scrawl committed
41
42
    void convertACSC (const ACSC& acsc, ESM::CreatureStats& cStats)
    {
dteviot's avatar
dteviot committed
43
        cStats.mDead = (acsc.mFlags & Dead) != 0;
scrawl's avatar
scrawl committed
44
45
    }

46
47
48
49
    void convertNpcData (const ActorData& actorData, ESM::NpcStats& npcStats)
    {
        for (int i=0; i<ESM::Skill::Length; ++i)
        {
scrawl's avatar
scrawl committed
50
51
52
            npcStats.mSkills[i].mMod = actorData.mSkills[i][1];
            npcStats.mSkills[i].mCurrent = actorData.mSkills[i][1];
            npcStats.mSkills[i].mBase = actorData.mSkills[i][0];
53
        }
54
55

        npcStats.mTimeToStartDrowning = actorData.mACDT.mBreathMeter;
56
57
    }

58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
    void convertANIS (const ANIS& anis, ESM::AnimationState& state)
    {
        static const char* animGroups[] =
        {
            "Idle", "Idle2", "Idle3", "Idle4", "Idle5", "Idle6", "Idle7", "Idle8", "Idle9", "Idlehh", "Idle1h", "Idle2c",
            "Idle2w", "IdleSwim", "IdleSpell", "IdleCrossbow", "IdleSneak", "IdleStorm", "Torch", "Hit1", "Hit2", "Hit3",
            "Hit4", "Hit5", "SwimHit1", "SwimHit2", "SwimHit3", "Death1", "Death2", "Death3", "Death4", "Death5",
            "DeathKnockDown", "DeathKnockOut", "KnockDown", "KnockOut", "SwimDeath", "SwimDeath2", "SwimDeath3",
            "SwimDeathKnockDown", "SwimDeathKnockOut", "SwimKnockOut", "SwimKnockDown", "SwimWalkForward",
            "SwimWalkBack", "SwimWalkLeft", "SwimWalkRight", "SwimRunForward", "SwimRunBack", "SwimRunLeft",
            "SwimRunRight", "SwimTurnLeft", "SwimTurnRight", "WalkForward", "WalkBack", "WalkLeft", "WalkRight",
            "TurnLeft", "TurnRight", "RunForward", "RunBack", "RunLeft", "RunRight", "SneakForward", "SneakBack",
            "SneakLeft", "SneakRight", "Jump", "WalkForwardhh", "WalkBackhh", "WalkLefthh", "WalkRighthh",
            "TurnLefthh", "TurnRighthh", "RunForwardhh", "RunBackhh", "RunLefthh", "RunRighthh", "SneakForwardhh",
            "SneakBackhh", "SneakLefthh", "SneakRighthh", "Jumphh", "WalkForward1h", "WalkBack1h", "WalkLeft1h",
            "WalkRight1h", "TurnLeft1h", "TurnRight1h", "RunForward1h", "RunBack1h", "RunLeft1h", "RunRight1h",
            "SneakForward1h", "SneakBack1h", "SneakLeft1h", "SneakRight1h", "Jump1h", "WalkForward2c", "WalkBack2c",
            "WalkLeft2c", "WalkRight2c", "TurnLeft2c", "TurnRight2c", "RunForward2c", "RunBack2c", "RunLeft2c",
            "RunRight2c", "SneakForward2c", "SneakBack2c", "SneakLeft2c", "SneakRight2c", "Jump2c", "WalkForward2w",
            "WalkBack2w", "WalkLeft2w", "WalkRight2w", "TurnLeft2w", "TurnRight2w", "RunForward2w", "RunBack2w",
            "RunLeft2w", "RunRight2w", "SneakForward2w", "SneakBack2w", "SneakLeft2w", "SneakRight2w", "Jump2w",
            "SpellCast", "SpellTurnLeft", "SpellTurnRight", "Attack1", "Attack2", "Attack3", "SwimAttack1",
            "SwimAttack2", "SwimAttack3", "HandToHand", "Crossbow", "BowAndArrow", "ThrowWeapon", "WeaponOneHand",
            "WeaponTwoHand", "WeaponTwoWide", "Shield", "PickProbe", "InventoryHandToHand", "InventoryWeaponOneHand",
            "InventoryWeaponTwoHand", "InventoryWeaponTwoWide"
        };

        if (anis.mGroupIndex < (sizeof(animGroups) / sizeof(*animGroups)))
        {
            std::string group(animGroups[anis.mGroupIndex]);
            Misc::StringUtils::lowerCaseInPlace(group);

            ESM::AnimationState::ScriptedAnimation scriptedAnim;
            scriptedAnim.mGroup = group;
            scriptedAnim.mTime = anis.mTime;
            scriptedAnim.mAbsolute = true;
            // Neither loop count nor queueing seems to be supported by the ess format.
            scriptedAnim.mLoopCount = std::numeric_limits<size_t>::max();
            state.mScriptedAnims.push_back(scriptedAnim);
        }
        else
            // TODO: Handle 0xFF index, which seems to be used for finished animations.
            std::cerr << "unknown animation group index: " << static_cast<unsigned int>(anis.mGroupIndex) << std::endl;
    }

103
}