|
|
|
@ -61,27 +61,15 @@ struct StateInfo {
|
|
|
|
|
const char groupname[32];
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static const StateInfo sStateList[] = {
|
|
|
|
|
{ CharState_Idle, "idle" },
|
|
|
|
|
{ CharState_Idle2, "idle2" },
|
|
|
|
|
{ CharState_Idle3, "idle3" },
|
|
|
|
|
{ CharState_Idle4, "idle4" },
|
|
|
|
|
{ CharState_Idle5, "idle5" },
|
|
|
|
|
{ CharState_Idle6, "idle6" },
|
|
|
|
|
{ CharState_Idle7, "idle7" },
|
|
|
|
|
{ CharState_Idle8, "idle8" },
|
|
|
|
|
{ CharState_Idle9, "idle9" },
|
|
|
|
|
{ CharState_IdleSwim, "idleswim" },
|
|
|
|
|
{ CharState_IdleSneak, "idlesneak" },
|
|
|
|
|
|
|
|
|
|
static const StateInfo sDeathList[] = {
|
|
|
|
|
{ CharState_Death1, "death1" },
|
|
|
|
|
{ CharState_Death2, "death2" },
|
|
|
|
|
{ CharState_Death3, "death3" },
|
|
|
|
|
{ CharState_Death4, "death4" },
|
|
|
|
|
{ CharState_Death5, "death5" },
|
|
|
|
|
{ CharState_SwimDeath, "swimdeath" },
|
|
|
|
|
};
|
|
|
|
|
static const StateInfo *sStateListEnd = &sStateList[sizeof(sStateList)/sizeof(sStateList[0])];
|
|
|
|
|
|
|
|
|
|
static const StateInfo *sDeathListEnd = &sDeathList[sizeof(sDeathList)/sizeof(sDeathList[0])];
|
|
|
|
|
|
|
|
|
|
static const StateInfo sMovementList[] = {
|
|
|
|
|
{ CharState_WalkForward, "walkforward" },
|
|
|
|
@ -169,7 +157,7 @@ void CharacterController::refreshCurrentAnims(CharacterState idle, CharacterStat
|
|
|
|
|
idle = "idleswim";
|
|
|
|
|
else if(mIdleState == CharState_IdleSneak && mAnimation->hasAnimation("idlesneak"))
|
|
|
|
|
idle = "idlesneak";
|
|
|
|
|
else
|
|
|
|
|
else if(mIdleState != CharState_None)
|
|
|
|
|
{
|
|
|
|
|
idle = "idle";
|
|
|
|
|
if(weap != sWeaponTypeListEnd)
|
|
|
|
@ -182,8 +170,9 @@ void CharacterController::refreshCurrentAnims(CharacterState idle, CharacterStat
|
|
|
|
|
|
|
|
|
|
mAnimation->disable(mCurrentIdle);
|
|
|
|
|
mCurrentIdle = idle;
|
|
|
|
|
mAnimation->play(mCurrentIdle, Priority_Default, MWRender::Animation::Group_All, false,
|
|
|
|
|
1.0f, "start", "stop", 0.0f, ~0ul);
|
|
|
|
|
if(!mCurrentIdle.empty())
|
|
|
|
|
mAnimation->play(mCurrentIdle, Priority_Default, MWRender::Animation::Group_All, false,
|
|
|
|
|
1.0f, "start", "stop", 0.0f, ~0ul);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(force || movement != mMovementState)
|
|
|
|
@ -208,13 +197,13 @@ void CharacterController::refreshCurrentAnims(CharacterState idle, CharacterStat
|
|
|
|
|
|
|
|
|
|
if(!mAnimation->hasAnimation(movement))
|
|
|
|
|
{
|
|
|
|
|
std::string::size_type sneakpos = movement.find("sneak");
|
|
|
|
|
if(sneakpos == std::string::npos)
|
|
|
|
|
std::string::size_type swimpos = movement.find("swim");
|
|
|
|
|
if(swimpos == std::string::npos)
|
|
|
|
|
movement.clear();
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
movegroup = MWRender::Animation::Group_LowerBody;
|
|
|
|
|
movement.erase(sneakpos, 5);
|
|
|
|
|
movement.erase(swimpos, 4);
|
|
|
|
|
if(!mAnimation->hasAnimation(movement))
|
|
|
|
|
movement.clear();
|
|
|
|
|
}
|
|
|
|
@ -225,11 +214,11 @@ void CharacterController::refreshCurrentAnims(CharacterState idle, CharacterStat
|
|
|
|
|
mCurrentMovement = movement;
|
|
|
|
|
if(!mCurrentMovement.empty())
|
|
|
|
|
{
|
|
|
|
|
float vel, speed = 0.0f;
|
|
|
|
|
float vel, speedmult = 1.0f;
|
|
|
|
|
if(mMovementSpeed > 0.0f && (vel=mAnimation->getVelocity(mCurrentMovement)) > 1.0f)
|
|
|
|
|
speed = mMovementSpeed / vel;
|
|
|
|
|
speedmult = mMovementSpeed / vel;
|
|
|
|
|
mAnimation->play(mCurrentMovement, Priority_Movement, movegroup, false,
|
|
|
|
|
speed, "start", "stop", 0.0f, ~0ul);
|
|
|
|
|
speedmult, "start", "stop", 0.0f, ~0ul);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -243,10 +232,71 @@ void CharacterController::getWeaponGroup(WeaponType weaptype, std::string &group
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
MWWorld::ContainerStoreIterator CharacterController::getActiveWeapon(NpcStats &stats, MWWorld::InventoryStore &inv, WeaponType *weaptype)
|
|
|
|
|
{
|
|
|
|
|
if(stats.getDrawState() == DrawState_Spell)
|
|
|
|
|
{
|
|
|
|
|
*weaptype = WeapType_Spell;
|
|
|
|
|
return inv.end();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(stats.getDrawState() == MWMechanics::DrawState_Weapon)
|
|
|
|
|
{
|
|
|
|
|
MWWorld::ContainerStoreIterator weapon = inv.getSlot(MWWorld::InventoryStore::Slot_CarriedRight);
|
|
|
|
|
if(weapon == inv.end())
|
|
|
|
|
*weaptype = WeapType_HandToHand;
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
const std::string &type = weapon->getTypeName();
|
|
|
|
|
if(type == typeid(ESM::Lockpick).name() || type == typeid(ESM::Probe).name())
|
|
|
|
|
*weaptype = WeapType_PickProbe;
|
|
|
|
|
else if(type == typeid(ESM::Weapon).name())
|
|
|
|
|
{
|
|
|
|
|
MWWorld::LiveCellRef<ESM::Weapon> *ref = weapon->get<ESM::Weapon>();
|
|
|
|
|
ESM::Weapon::Type type = (ESM::Weapon::Type)ref->mBase->mData.mType;
|
|
|
|
|
switch(type)
|
|
|
|
|
{
|
|
|
|
|
case ESM::Weapon::ShortBladeOneHand:
|
|
|
|
|
case ESM::Weapon::LongBladeOneHand:
|
|
|
|
|
case ESM::Weapon::BluntOneHand:
|
|
|
|
|
case ESM::Weapon::AxeOneHand:
|
|
|
|
|
case ESM::Weapon::Arrow:
|
|
|
|
|
case ESM::Weapon::Bolt:
|
|
|
|
|
*weaptype = WeapType_OneHand;
|
|
|
|
|
break;
|
|
|
|
|
case ESM::Weapon::LongBladeTwoHand:
|
|
|
|
|
case ESM::Weapon::BluntTwoClose:
|
|
|
|
|
case ESM::Weapon::AxeTwoHand:
|
|
|
|
|
*weaptype = WeapType_TwoHand;
|
|
|
|
|
break;
|
|
|
|
|
case ESM::Weapon::BluntTwoWide:
|
|
|
|
|
case ESM::Weapon::SpearTwoWide:
|
|
|
|
|
*weaptype = WeapType_TwoWide;
|
|
|
|
|
break;
|
|
|
|
|
case ESM::Weapon::MarksmanBow:
|
|
|
|
|
*weaptype = WeapType_BowAndArrow;
|
|
|
|
|
break;
|
|
|
|
|
case ESM::Weapon::MarksmanCrossbow:
|
|
|
|
|
*weaptype = WeapType_Crossbow;
|
|
|
|
|
break;
|
|
|
|
|
case ESM::Weapon::MarksmanThrown:
|
|
|
|
|
*weaptype = WeapType_ThowWeapon;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return weapon;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return inv.getSlot(MWWorld::InventoryStore::Slot_CarriedRight);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CharacterController::CharacterController(const MWWorld::Ptr &ptr, MWRender::Animation *anim)
|
|
|
|
|
: mPtr(ptr)
|
|
|
|
|
, mAnimation(anim)
|
|
|
|
|
, mIdleState(CharState_Idle)
|
|
|
|
|
, mIdleState(CharState_None)
|
|
|
|
|
, mMovementState(CharState_None)
|
|
|
|
|
, mMovementSpeed(0.0f)
|
|
|
|
|
, mDeathState(CharState_None)
|
|
|
|
@ -255,18 +305,30 @@ CharacterController::CharacterController(const MWWorld::Ptr &ptr, MWRender::Anim
|
|
|
|
|
, mSkipAnim(false)
|
|
|
|
|
, mSecondsOfRunning(0)
|
|
|
|
|
, mSecondsOfSwimming(0)
|
|
|
|
|
, mUpdateWeapon(true)
|
|
|
|
|
{
|
|
|
|
|
if(!mAnimation)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if(MWWorld::Class::get(mPtr).isActor())
|
|
|
|
|
const MWWorld::Class &cls = MWWorld::Class::get(mPtr);
|
|
|
|
|
if(cls.isActor())
|
|
|
|
|
{
|
|
|
|
|
/* Accumulate along X/Y only for now, until we can figure out how we should
|
|
|
|
|
* handle knockout and death which moves the character down. */
|
|
|
|
|
mAnimation->setAccumulation(Ogre::Vector3(1.0f, 1.0f, 0.0f));
|
|
|
|
|
|
|
|
|
|
if(MWWorld::Class::get(mPtr).getCreatureStats(mPtr).isDead())
|
|
|
|
|
if(mPtr.getTypeName() == typeid(ESM::NPC).name())
|
|
|
|
|
{
|
|
|
|
|
getActiveWeapon(cls.getNpcStats(mPtr), cls.getInventoryStore(mPtr), &mWeaponType);
|
|
|
|
|
if(mWeaponType != WeapType_None)
|
|
|
|
|
{
|
|
|
|
|
getWeaponGroup(mWeaponType, mCurrentWeapon);
|
|
|
|
|
mUpperBodyState = UpperCharState_WeapEquiped;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(!cls.getCreatureStats(mPtr).isDead())
|
|
|
|
|
mIdleState = CharState_Idle;
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
/* FIXME: Get the actual death state used. */
|
|
|
|
|
mDeathState = CharState_Death1;
|
|
|
|
@ -276,13 +338,15 @@ CharacterController::CharacterController(const MWWorld::Ptr &ptr, MWRender::Anim
|
|
|
|
|
{
|
|
|
|
|
/* Don't accumulate with non-actors. */
|
|
|
|
|
mAnimation->setAccumulation(Ogre::Vector3(0.0f));
|
|
|
|
|
|
|
|
|
|
mIdleState = CharState_Idle;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
refreshCurrentAnims(mIdleState, mMovementState, true);
|
|
|
|
|
if(mDeathState != CharState_None)
|
|
|
|
|
{
|
|
|
|
|
const StateInfo *state = std::find_if(sStateList, sStateListEnd, FindCharState(mDeathState));
|
|
|
|
|
if(state == sStateListEnd)
|
|
|
|
|
const StateInfo *state = std::find_if(sDeathList, sDeathListEnd, FindCharState(mDeathState));
|
|
|
|
|
if(state == sDeathListEnd)
|
|
|
|
|
throw std::runtime_error("Failed to find character state "+Ogre::StringConverter::toString(mDeathState));
|
|
|
|
|
|
|
|
|
|
mCurrentDeath = state->groupname;
|
|
|
|
@ -302,6 +366,223 @@ void CharacterController::updatePtr(const MWWorld::Ptr &ptr)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool CharacterController::updateNpcState()
|
|
|
|
|
{
|
|
|
|
|
const MWWorld::Class &cls = MWWorld::Class::get(mPtr);
|
|
|
|
|
CreatureStats &crstats = cls.getCreatureStats(mPtr);
|
|
|
|
|
NpcStats &stats = cls.getNpcStats(mPtr);
|
|
|
|
|
WeaponType weaptype = WeapType_None;
|
|
|
|
|
MWWorld::InventoryStore &inv = cls.getInventoryStore(mPtr);
|
|
|
|
|
MWWorld::ContainerStoreIterator weapon = getActiveWeapon(stats, inv, &weaptype);
|
|
|
|
|
|
|
|
|
|
bool forcestateupdate = false;
|
|
|
|
|
if(weaptype != mWeaponType)
|
|
|
|
|
{
|
|
|
|
|
forcestateupdate = true;
|
|
|
|
|
|
|
|
|
|
std::string weapgroup;
|
|
|
|
|
if(weaptype == WeapType_None)
|
|
|
|
|
{
|
|
|
|
|
getWeaponGroup(mWeaponType, weapgroup);
|
|
|
|
|
mAnimation->play(weapgroup, Priority_Weapon,
|
|
|
|
|
MWRender::Animation::Group_UpperBody, true,
|
|
|
|
|
1.0f, "unequip start", "unequip stop", 0.0f, 0);
|
|
|
|
|
mUpperBodyState = UpperCharState_UnEquipingWeap;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
getWeaponGroup(weaptype, weapgroup);
|
|
|
|
|
mAnimation->showWeapons(false);
|
|
|
|
|
mAnimation->play(weapgroup, Priority_Weapon,
|
|
|
|
|
MWRender::Animation::Group_UpperBody, true,
|
|
|
|
|
1.0f, "equip start", "equip stop", 0.0f, 0);
|
|
|
|
|
mUpperBodyState = UpperCharState_EquipingWeap;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(weapon != inv.end() && !(weaptype == WeapType_None && mWeaponType == WeapType_Spell))
|
|
|
|
|
{
|
|
|
|
|
std::string soundid = (weaptype == WeapType_None) ?
|
|
|
|
|
MWWorld::Class::get(*weapon).getDownSoundId(*weapon) :
|
|
|
|
|
MWWorld::Class::get(*weapon).getUpSoundId(*weapon);
|
|
|
|
|
if(!soundid.empty())
|
|
|
|
|
{
|
|
|
|
|
MWBase::SoundManager *sndMgr = MWBase::Environment::get().getSoundManager();
|
|
|
|
|
sndMgr->playSound3D(mPtr, soundid, 1.0f, 1.0f);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
mWeaponType = weaptype;
|
|
|
|
|
getWeaponGroup(mWeaponType, mCurrentWeapon);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool isWeapon = (weapon != inv.end() && weapon->getTypeName() == typeid(ESM::Weapon).name());
|
|
|
|
|
float weapSpeed = 1.0f;
|
|
|
|
|
if(isWeapon)
|
|
|
|
|
weapSpeed = weapon->get<ESM::Weapon>()->mBase->mData.mSpeed;
|
|
|
|
|
|
|
|
|
|
float complete;
|
|
|
|
|
bool animPlaying;
|
|
|
|
|
if(crstats.getAttackingOrSpell())
|
|
|
|
|
{
|
|
|
|
|
if(mUpperBodyState == UpperCharState_WeapEquiped)
|
|
|
|
|
{
|
|
|
|
|
mAttackType.clear();
|
|
|
|
|
if(mWeaponType == WeapType_Spell)
|
|
|
|
|
{
|
|
|
|
|
const MWWorld::ESMStore &store = MWBase::Environment::get().getWorld()->getStore();
|
|
|
|
|
|
|
|
|
|
const std::string spellid = crstats.getSpells().getSelectedSpell();
|
|
|
|
|
if(!spellid.empty())
|
|
|
|
|
{
|
|
|
|
|
static const std::string schools[] = {
|
|
|
|
|
"alteration", "conjuration", "destruction", "illusion", "mysticism", "restoration"
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const ESM::Spell *spell = store.get<ESM::Spell>().find(spellid);
|
|
|
|
|
const ESM::ENAMstruct &effectentry = spell->mEffects.mList.at(0);
|
|
|
|
|
|
|
|
|
|
const ESM::MagicEffect *effect;
|
|
|
|
|
effect = store.get<ESM::MagicEffect>().find(effectentry.mEffectID);
|
|
|
|
|
|
|
|
|
|
switch(effectentry.mRange)
|
|
|
|
|
{
|
|
|
|
|
case 0: mAttackType = "self"; break;
|
|
|
|
|
case 1: mAttackType = "touch"; break;
|
|
|
|
|
case 2: mAttackType = "target"; break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
mAnimation->play(mCurrentWeapon, Priority_Weapon,
|
|
|
|
|
MWRender::Animation::Group_UpperBody, true,
|
|
|
|
|
weapSpeed, mAttackType+" start", mAttackType+" stop",
|
|
|
|
|
0.0f, 0);
|
|
|
|
|
mUpperBodyState = UpperCharState_CastingSpell;
|
|
|
|
|
|
|
|
|
|
MWBase::SoundManager *sndMgr = MWBase::Environment::get().getSoundManager();
|
|
|
|
|
if(!effect->mCastSound.empty())
|
|
|
|
|
sndMgr->playSound3D(mPtr, effect->mCastSound, 1.0f, 1.0f);
|
|
|
|
|
else
|
|
|
|
|
sndMgr->playSound3D(mPtr, schools[effect->mData.mSchool]+" cast", 1.0f, 1.0f);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if(mWeaponType != WeapType_PickProbe)
|
|
|
|
|
{
|
|
|
|
|
if(mWeaponType == WeapType_Crossbow || mWeaponType == WeapType_BowAndArrow ||
|
|
|
|
|
mWeaponType == WeapType_ThowWeapon)
|
|
|
|
|
mAttackType = "shoot";
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
int attackType = crstats.getAttackType();
|
|
|
|
|
if(isWeapon && Settings::Manager::getBool("best attack", "Game"))
|
|
|
|
|
attackType = getBestAttack(weapon->get<ESM::Weapon>()->mBase);
|
|
|
|
|
|
|
|
|
|
if (attackType == MWMechanics::CreatureStats::AT_Chop)
|
|
|
|
|
mAttackType = "chop";
|
|
|
|
|
else if (attackType == MWMechanics::CreatureStats::AT_Slash)
|
|
|
|
|
mAttackType = "slash";
|
|
|
|
|
else
|
|
|
|
|
mAttackType = "thrust";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
mAnimation->play(mCurrentWeapon, Priority_Weapon,
|
|
|
|
|
MWRender::Animation::Group_UpperBody, false,
|
|
|
|
|
weapSpeed, mAttackType+" start", mAttackType+" min attack",
|
|
|
|
|
0.0f, 0);
|
|
|
|
|
mUpperBodyState = UpperCharState_StartToMinAttack;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
animPlaying = mAnimation->getInfo(mCurrentWeapon, &complete);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
animPlaying = mAnimation->getInfo(mCurrentWeapon, &complete);
|
|
|
|
|
if(mUpperBodyState == UpperCharState_MinAttackToMaxAttack)
|
|
|
|
|
{
|
|
|
|
|
if(mAttackType != "shoot")
|
|
|
|
|
{
|
|
|
|
|
MWBase::SoundManager *sndMgr = MWBase::Environment::get().getSoundManager();
|
|
|
|
|
// NOTE: SwishL, SwishM, SwishS - large, medium, small.
|
|
|
|
|
// Based on weapon weight, speed, or attack strength?
|
|
|
|
|
sndMgr->playSound3D(mPtr, "SwishL", 1.0f, 1.0f);
|
|
|
|
|
}
|
|
|
|
|
stats.setAttackStrength(complete);
|
|
|
|
|
|
|
|
|
|
mAnimation->disable(mCurrentWeapon);
|
|
|
|
|
mAnimation->play(mCurrentWeapon, Priority_Weapon,
|
|
|
|
|
MWRender::Animation::Group_UpperBody, false,
|
|
|
|
|
weapSpeed, mAttackType+" max attack", mAttackType+" min hit",
|
|
|
|
|
1.0f-complete, 0);
|
|
|
|
|
mUpperBodyState = UpperCharState_MaxAttackToMinHit;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(!animPlaying)
|
|
|
|
|
{
|
|
|
|
|
if(mUpperBodyState == UpperCharState_EquipingWeap ||
|
|
|
|
|
mUpperBodyState == UpperCharState_FollowStartToFollowStop ||
|
|
|
|
|
mUpperBodyState == UpperCharState_CastingSpell)
|
|
|
|
|
mUpperBodyState = UpperCharState_WeapEquiped;
|
|
|
|
|
else if(mUpperBodyState == UpperCharState_UnEquipingWeap)
|
|
|
|
|
mUpperBodyState = UpperCharState_Nothing;
|
|
|
|
|
}
|
|
|
|
|
else if(complete >= 1.0f)
|
|
|
|
|
{
|
|
|
|
|
if(mUpperBodyState == UpperCharState_StartToMinAttack)
|
|
|
|
|
{
|
|
|
|
|
mAnimation->disable(mCurrentWeapon);
|
|
|
|
|
mAnimation->play(mCurrentWeapon, Priority_Weapon,
|
|
|
|
|
MWRender::Animation::Group_UpperBody, false,
|
|
|
|
|
weapSpeed, mAttackType+" min attack", mAttackType+" max attack",
|
|
|
|
|
0.0f, 0);
|
|
|
|
|
mUpperBodyState = UpperCharState_MinAttackToMaxAttack;
|
|
|
|
|
}
|
|
|
|
|
else if(mUpperBodyState == UpperCharState_MaxAttackToMinHit)
|
|
|
|
|
{
|
|
|
|
|
mAnimation->disable(mCurrentWeapon);
|
|
|
|
|
if(mAttackType == "shoot")
|
|
|
|
|
mAnimation->play(mCurrentWeapon, Priority_Weapon,
|
|
|
|
|
MWRender::Animation::Group_UpperBody, false,
|
|
|
|
|
weapSpeed, mAttackType+" min hit", mAttackType+" follow start",
|
|
|
|
|
0.0f, 0);
|
|
|
|
|
else
|
|
|
|
|
mAnimation->play(mCurrentWeapon, Priority_Weapon,
|
|
|
|
|
MWRender::Animation::Group_UpperBody, false,
|
|
|
|
|
weapSpeed, mAttackType+" min hit", mAttackType+" hit",
|
|
|
|
|
0.0f, 0);
|
|
|
|
|
mUpperBodyState = UpperCharState_MinHitToHit;
|
|
|
|
|
}
|
|
|
|
|
else if(mUpperBodyState == UpperCharState_MinHitToHit)
|
|
|
|
|
{
|
|
|
|
|
mAnimation->disable(mCurrentWeapon);
|
|
|
|
|
if(mAttackType == "shoot")
|
|
|
|
|
mAnimation->play(mCurrentWeapon, Priority_Weapon,
|
|
|
|
|
MWRender::Animation::Group_UpperBody, true,
|
|
|
|
|
weapSpeed, mAttackType+" follow start", mAttackType+" follow stop",
|
|
|
|
|
0.0f, 0);
|
|
|
|
|
else
|
|
|
|
|
mAnimation->play(mCurrentWeapon, Priority_Weapon,
|
|
|
|
|
MWRender::Animation::Group_UpperBody, true,
|
|
|
|
|
weapSpeed, mAttackType+" large follow start", mAttackType+" large follow stop",
|
|
|
|
|
0.0f, 0);
|
|
|
|
|
mUpperBodyState = UpperCharState_FollowStartToFollowStop;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
MWWorld::ContainerStoreIterator torch = inv.getSlot(MWWorld::InventoryStore::Slot_CarriedLeft);
|
|
|
|
|
if(torch != inv.end() && torch->getTypeName() == typeid(ESM::Light).name())
|
|
|
|
|
{
|
|
|
|
|
if(!mAnimation->isPlaying("torch"))
|
|
|
|
|
mAnimation->play("torch", Priority_Torch,
|
|
|
|
|
MWRender::Animation::Group_LeftArm, false,
|
|
|
|
|
1.0f, "start", "stop", 0.0f, (~(size_t)0));
|
|
|
|
|
}
|
|
|
|
|
else if(mAnimation->isPlaying("torch"))
|
|
|
|
|
mAnimation->disable("torch");
|
|
|
|
|
|
|
|
|
|
return forcestateupdate;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CharacterController::update(float duration, Movement &movement)
|
|
|
|
|
{
|
|
|
|
|
const MWWorld::Class &cls = MWWorld::Class::get(mPtr);
|
|
|
|
@ -443,206 +724,7 @@ void CharacterController::update(float duration, Movement &movement)
|
|
|
|
|
movement.mRotation[2] += rot.z;
|
|
|
|
|
|
|
|
|
|
if(mPtr.getTypeName() == typeid(ESM::NPC).name())
|
|
|
|
|
{
|
|
|
|
|
NpcStats &stats = cls.getNpcStats(mPtr);
|
|
|
|
|
WeaponType weaptype = WeapType_None;
|
|
|
|
|
MWWorld::InventoryStore &inv = cls.getInventoryStore(mPtr);
|
|
|
|
|
MWWorld::ContainerStoreIterator weapon = inv.end();
|
|
|
|
|
|
|
|
|
|
if(stats.getDrawState() == DrawState_Spell)
|
|
|
|
|
weaptype = WeapType_Spell;
|
|
|
|
|
else if(stats.getDrawState() == MWMechanics::DrawState_Weapon)
|
|
|
|
|
{
|
|
|
|
|
weapon = inv.getSlot(MWWorld::InventoryStore::Slot_CarriedRight);
|
|
|
|
|
if(weapon == inv.end())
|
|
|
|
|
weaptype = WeapType_HandToHand;
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
const std::string &type = weapon->getTypeName();
|
|
|
|
|
if(type == typeid(ESM::Lockpick).name() || type == typeid(ESM::Probe).name())
|
|
|
|
|
weaptype = WeapType_PickProbe;
|
|
|
|
|
else if(type == typeid(ESM::Weapon).name())
|
|
|
|
|
{
|
|
|
|
|
MWWorld::LiveCellRef<ESM::Weapon> *ref = weapon->get<ESM::Weapon>();
|
|
|
|
|
ESM::Weapon::Type type = (ESM::Weapon::Type)ref->mBase->mData.mType;
|
|
|
|
|
switch(type)
|
|
|
|
|
{
|
|
|
|
|
case ESM::Weapon::ShortBladeOneHand:
|
|
|
|
|
case ESM::Weapon::LongBladeOneHand:
|
|
|
|
|
case ESM::Weapon::BluntOneHand:
|
|
|
|
|
case ESM::Weapon::AxeOneHand:
|
|
|
|
|
case ESM::Weapon::Arrow:
|
|
|
|
|
case ESM::Weapon::Bolt:
|
|
|
|
|
weaptype = WeapType_OneHand;
|
|
|
|
|
break;
|
|
|
|
|
case ESM::Weapon::LongBladeTwoHand:
|
|
|
|
|
case ESM::Weapon::BluntTwoClose:
|
|
|
|
|
case ESM::Weapon::AxeTwoHand:
|
|
|
|
|
weaptype = WeapType_TwoHand;
|
|
|
|
|
break;
|
|
|
|
|
case ESM::Weapon::BluntTwoWide:
|
|
|
|
|
case ESM::Weapon::SpearTwoWide:
|
|
|
|
|
weaptype = WeapType_TwoWide;
|
|
|
|
|
break;
|
|
|
|
|
case ESM::Weapon::MarksmanBow:
|
|
|
|
|
weaptype = WeapType_BowAndArrow;
|
|
|
|
|
break;
|
|
|
|
|
case ESM::Weapon::MarksmanCrossbow:
|
|
|
|
|
weaptype = WeapType_Crossbow;
|
|
|
|
|
break;
|
|
|
|
|
case ESM::Weapon::MarksmanThrown:
|
|
|
|
|
weaptype = WeapType_ThowWeapon;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
weapon = inv.getSlot(MWWorld::InventoryStore::Slot_CarriedRight);
|
|
|
|
|
|
|
|
|
|
if(mUpdateWeapon)
|
|
|
|
|
{
|
|
|
|
|
forcestateupdate = (mWeaponType != weaptype);
|
|
|
|
|
mWeaponType = weaptype;
|
|
|
|
|
mUpdateWeapon = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(weaptype != mWeaponType)
|
|
|
|
|
{
|
|
|
|
|
forcestateupdate = true;
|
|
|
|
|
|
|
|
|
|
std::string weapgroup;
|
|
|
|
|
if(weaptype == WeapType_None)
|
|
|
|
|
{
|
|
|
|
|
getWeaponGroup(mWeaponType, weapgroup);
|
|
|
|
|
mAnimation->play(weapgroup, Priority_Weapon,
|
|
|
|
|
MWRender::Animation::Group_UpperBody, true,
|
|
|
|
|
1.0f, "unequip start", "unequip stop", 0.0f, 0);
|
|
|
|
|
mUpperBodyState = UpperCharState_UnEquipingWeap;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
getWeaponGroup(weaptype, weapgroup);
|
|
|
|
|
mAnimation->showWeapons(false);
|
|
|
|
|
mAnimation->play(weapgroup, Priority_Weapon,
|
|
|
|
|
MWRender::Animation::Group_UpperBody, true,
|
|
|
|
|
1.0f, "equip start", "equip stop", 0.0f, 0);
|
|
|
|
|
mUpperBodyState = UpperCharState_EquipingWeap;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
mWeaponType = weaptype;
|
|
|
|
|
|
|
|
|
|
if(weapon != inv.end())
|
|
|
|
|
{
|
|
|
|
|
std::string soundid = (mWeaponType == WeapType_None) ?
|
|
|
|
|
MWWorld::Class::get(*weapon).getDownSoundId(*weapon) :
|
|
|
|
|
MWWorld::Class::get(*weapon).getUpSoundId(*weapon);
|
|
|
|
|
if(!soundid.empty())
|
|
|
|
|
{
|
|
|
|
|
MWBase::SoundManager *sndMgr = MWBase::Environment::get().getSoundManager();
|
|
|
|
|
sndMgr->playSound3D(mPtr, soundid, 1.0f, 1.0f);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(weaptype != WeapType_PickProbe && weaptype != WeapType_BowAndArrow
|
|
|
|
|
&& weaptype != WeapType_Crossbow && weaptype != WeapType_ThowWeapon)
|
|
|
|
|
{
|
|
|
|
|
std::string weapgroup;
|
|
|
|
|
getWeaponGroup(mWeaponType, weapgroup);
|
|
|
|
|
float weapSpeed = 1;
|
|
|
|
|
if(weapon != inv.end()) weapSpeed = weapon->get<ESM::Weapon>()->mBase->mData.mSpeed;
|
|
|
|
|
std::string start;
|
|
|
|
|
std::string stop;
|
|
|
|
|
float complete;
|
|
|
|
|
float speedMult;
|
|
|
|
|
bool animPlaying = mAnimation->getInfo(weapgroup,&complete,&speedMult,&start,&stop);
|
|
|
|
|
|
|
|
|
|
if(cls.getCreatureStats(mPtr).getAttackingOrSpell())
|
|
|
|
|
{
|
|
|
|
|
if(mUpperBodyState == UpperCharState_WeapEquiped)
|
|
|
|
|
{
|
|
|
|
|
int attackType = cls.getCreatureStats(mPtr).getAttackType();
|
|
|
|
|
if (Settings::Manager::getBool("best attack", "Game") && weapon != inv.end())
|
|
|
|
|
attackType = getBestAttack(weapon->get<ESM::Weapon>()->mBase);
|
|
|
|
|
|
|
|
|
|
if (attackType == MWMechanics::CreatureStats::AT_Chop)
|
|
|
|
|
mAttackType = "chop";
|
|
|
|
|
else if (attackType == MWMechanics::CreatureStats::AT_Slash)
|
|
|
|
|
mAttackType = "slash";
|
|
|
|
|
else
|
|
|
|
|
mAttackType = "thrust";
|
|
|
|
|
|
|
|
|
|
mAnimation->play(weapgroup, Priority_Weapon,
|
|
|
|
|
MWRender::Animation::Group_UpperBody, false,
|
|
|
|
|
weapSpeed, mAttackType+" start", mAttackType+" min attack", 0.0f, 0);
|
|
|
|
|
mUpperBodyState = UpperCharState_StartToMinAttack;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if(mUpperBodyState == UpperCharState_MinAttackToMaxAttack)
|
|
|
|
|
{
|
|
|
|
|
if(animPlaying)
|
|
|
|
|
{
|
|
|
|
|
mAnimation->disable(weapgroup);
|
|
|
|
|
mAnimation->play(weapgroup, Priority_Weapon,
|
|
|
|
|
MWRender::Animation::Group_UpperBody, false,
|
|
|
|
|
weapSpeed, mAttackType+" max attack", mAttackType+" min hit", 1-complete, 0);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
mAnimation->play(weapgroup, Priority_Weapon,
|
|
|
|
|
MWRender::Animation::Group_UpperBody, false,
|
|
|
|
|
weapSpeed, mAttackType+" max attack", mAttackType+" min hit", 0, 0);
|
|
|
|
|
}
|
|
|
|
|
mUpperBodyState = UpperCharState_MaxAttackToMinHit;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(mUpperBodyState == UpperCharState_EquipingWeap && !animPlaying) mUpperBodyState = UpperCharState_WeapEquiped;
|
|
|
|
|
if(mUpperBodyState == UpperCharState_UnEquipingWeap && !animPlaying) mUpperBodyState = UpperCharState_Nothing;
|
|
|
|
|
if(animPlaying)
|
|
|
|
|
{
|
|
|
|
|
if(mUpperBodyState == UpperCharState_StartToMinAttack && complete == 1)
|
|
|
|
|
{
|
|
|
|
|
mAnimation->disable(weapgroup);
|
|
|
|
|
mAnimation->play(weapgroup, Priority_Weapon,
|
|
|
|
|
MWRender::Animation::Group_UpperBody, false,
|
|
|
|
|
weapSpeed, mAttackType+" min attack", mAttackType+" max attack",0, 0);
|
|
|
|
|
mUpperBodyState = UpperCharState_MinAttackToMaxAttack;
|
|
|
|
|
}
|
|
|
|
|
else if(mUpperBodyState == UpperCharState_MaxAttackToMinHit && complete == 1)
|
|
|
|
|
{
|
|
|
|
|
mAnimation->disable(weapgroup);
|
|
|
|
|
mAnimation->play(weapgroup, Priority_Weapon,
|
|
|
|
|
MWRender::Animation::Group_UpperBody, false,
|
|
|
|
|
weapSpeed, mAttackType+" min hit", mAttackType+" hit",0, 0);
|
|
|
|
|
mUpperBodyState = UpperCharState_MinHitToHit;
|
|
|
|
|
}
|
|
|
|
|
else if(mUpperBodyState == UpperCharState_MinHitToHit && complete == 1)
|
|
|
|
|
{
|
|
|
|
|
mAnimation->disable(weapgroup);
|
|
|
|
|
mAnimation->play(weapgroup, Priority_Weapon,
|
|
|
|
|
MWRender::Animation::Group_UpperBody, false,
|
|
|
|
|
weapSpeed, mAttackType+" large follow start", mAttackType+" large follow stop",0, 0);
|
|
|
|
|
mUpperBodyState = UpperCharState_LargeFollowStartToLargeFollowStop;
|
|
|
|
|
}
|
|
|
|
|
else if(mUpperBodyState == UpperCharState_LargeFollowStartToLargeFollowStop && complete == 1)
|
|
|
|
|
{
|
|
|
|
|
mUpperBodyState = UpperCharState_WeapEquiped;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MWWorld::ContainerStoreIterator torch = inv.getSlot(MWWorld::InventoryStore::Slot_CarriedLeft);
|
|
|
|
|
if(torch != inv.end() && torch->getTypeName() == typeid(ESM::Light).name())
|
|
|
|
|
{
|
|
|
|
|
if(!mAnimation->isPlaying("torch"))
|
|
|
|
|
mAnimation->play("torch", Priority_Torch,
|
|
|
|
|
MWRender::Animation::Group_LeftArm, false,
|
|
|
|
|
1.0f, "start", "stop", 0.0f, (~(size_t)0));
|
|
|
|
|
}
|
|
|
|
|
else if(mAnimation->isPlaying("torch"))
|
|
|
|
|
mAnimation->disable("torch");
|
|
|
|
|
}
|
|
|
|
|
forcestateupdate = updateNpcState();
|
|
|
|
|
|
|
|
|
|
refreshCurrentAnims(idlestate, movestate, forcestateupdate);
|
|
|
|
|
}
|
|
|
|
@ -734,8 +816,8 @@ void CharacterController::forceStateUpdate()
|
|
|
|
|
refreshCurrentAnims(mIdleState, mMovementState, true);
|
|
|
|
|
if(mDeathState != CharState_None)
|
|
|
|
|
{
|
|
|
|
|
const StateInfo *state = std::find_if(sStateList, sStateListEnd, FindCharState(mDeathState));
|
|
|
|
|
if(state == sStateListEnd)
|
|
|
|
|
const StateInfo *state = std::find_if(sDeathList, sDeathListEnd, FindCharState(mDeathState));
|
|
|
|
|
if(state == sDeathListEnd)
|
|
|
|
|
throw std::runtime_error("Failed to find character state "+Ogre::StringConverter::toString(mDeathState));
|
|
|
|
|
|
|
|
|
|
mCurrentDeath = state->groupname;
|
|
|
|
@ -747,22 +829,52 @@ void CharacterController::forceStateUpdate()
|
|
|
|
|
|
|
|
|
|
void CharacterController::kill()
|
|
|
|
|
{
|
|
|
|
|
static const CharacterState deathstates[] = {
|
|
|
|
|
CharState_Death1, CharState_Death2, CharState_Death3, CharState_Death4, CharState_Death5
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if(mDeathState != CharState_None)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
mDeathState = deathstates[(int)(rand()/((double)RAND_MAX+1.0)*5.0)];
|
|
|
|
|
const StateInfo *state = std::find_if(sStateList, sStateListEnd, FindCharState(mDeathState));
|
|
|
|
|
if(state == sStateListEnd)
|
|
|
|
|
throw std::runtime_error("Failed to find character state "+Ogre::StringConverter::toString(mDeathState));
|
|
|
|
|
if(mPtr.getTypeName() == typeid(ESM::NPC).name())
|
|
|
|
|
{
|
|
|
|
|
const StateInfo *state = NULL;
|
|
|
|
|
if(MWBase::Environment::get().getWorld()->isSwimming(mPtr))
|
|
|
|
|
{
|
|
|
|
|
mDeathState = CharState_SwimDeath;
|
|
|
|
|
state = std::find_if(sDeathList, sDeathListEnd, FindCharState(mDeathState));
|
|
|
|
|
if(state == sDeathListEnd)
|
|
|
|
|
throw std::runtime_error("Failed to find character state "+Ogre::StringConverter::toString(mDeathState));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static const CharacterState deathstates[5] = {
|
|
|
|
|
CharState_Death1, CharState_Death2, CharState_Death3, CharState_Death4, CharState_Death5
|
|
|
|
|
};
|
|
|
|
|
std::vector<CharacterState> states(&deathstates[0], &deathstates[5]);
|
|
|
|
|
|
|
|
|
|
while(states.size() > 1 && (!state || !mAnimation->hasAnimation(state->groupname)))
|
|
|
|
|
{
|
|
|
|
|
int pos = (int)(rand()/((double)RAND_MAX+1.0)*states.size());
|
|
|
|
|
mDeathState = states[pos];
|
|
|
|
|
states.erase(states.begin()+pos);
|
|
|
|
|
|
|
|
|
|
state = std::find_if(sDeathList, sDeathListEnd, FindCharState(mDeathState));
|
|
|
|
|
if(state == sDeathListEnd)
|
|
|
|
|
throw std::runtime_error("Failed to find character state "+Ogre::StringConverter::toString(mDeathState));
|
|
|
|
|
}
|
|
|
|
|
mCurrentDeath = state->groupname;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
mDeathState = CharState_Death1;
|
|
|
|
|
mCurrentDeath = "death1";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
mCurrentDeath = state->groupname;
|
|
|
|
|
if(mAnimation && !mAnimation->getInfo(mCurrentDeath))
|
|
|
|
|
if(mAnimation)
|
|
|
|
|
{
|
|
|
|
|
mAnimation->play(mCurrentDeath, Priority_Death, MWRender::Animation::Group_All,
|
|
|
|
|
false, 1.0f, "start", "stop", 0.0f, 0);
|
|
|
|
|
mAnimation->disable(mCurrentIdle);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
mIdleState = CharState_None;
|
|
|
|
|
mCurrentIdle.clear();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CharacterController::resurrect()
|
|
|
|
@ -776,5 +888,4 @@ void CharacterController::resurrect()
|
|
|
|
|
mDeathState = CharState_None;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|