|
|
|
@ -1962,6 +1962,8 @@ namespace MWMechanics
|
|
|
|
|
{
|
|
|
|
|
bool isPlayer = iter->first == player;
|
|
|
|
|
CharacterController* ctrl = iter->second->getCharacterController();
|
|
|
|
|
MWBase::LuaManager::ActorControls* luaControls =
|
|
|
|
|
MWBase::Environment::get().getLuaManager()->getActorControls(iter->first);
|
|
|
|
|
|
|
|
|
|
float distSqr = (playerPos - iter->first.getRefData().getPosition().asVec3()).length2();
|
|
|
|
|
// AI processing is only done within given distance to the player.
|
|
|
|
@ -2010,25 +2012,6 @@ namespace MWMechanics
|
|
|
|
|
return; // for now abort update of the old cell when cell changes by teleportation magic effect
|
|
|
|
|
// a better solution might be to apply cell changes at the end of the frame
|
|
|
|
|
}
|
|
|
|
|
bool controlledFromLua;
|
|
|
|
|
{
|
|
|
|
|
const MWBase::LuaManager::ActorControls* luaControls =
|
|
|
|
|
MWBase::Environment::get().getLuaManager()->getActorControls(iter->first);
|
|
|
|
|
controlledFromLua = luaControls && luaControls->controlledFromLua;
|
|
|
|
|
if (controlledFromLua && isConscious(iter->first))
|
|
|
|
|
{
|
|
|
|
|
Movement& mov = iter->first.getClass().getMovementSettings(iter->first);
|
|
|
|
|
mov.mPosition[0] = luaControls->sideMovement;
|
|
|
|
|
mov.mPosition[1] = luaControls->movement;
|
|
|
|
|
mov.mPosition[2] = luaControls->jump ? 1 : 0;
|
|
|
|
|
mov.mRotation[0] = mov.mRotation[1] = 0;
|
|
|
|
|
mov.mRotation[2] = luaControls->turn;
|
|
|
|
|
mov.mSpeedFactor = osg::Vec2(luaControls->movement, luaControls->sideMovement).length();
|
|
|
|
|
|
|
|
|
|
CreatureStats& stats = iter->first.getClass().getCreatureStats(iter->first);
|
|
|
|
|
stats.setMovementFlag(MWMechanics::CreatureStats::Flag_Run, luaControls->run);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (aiActive && inProcessingRange)
|
|
|
|
|
{
|
|
|
|
|
if (engageCombatTimerStatus == Misc::TimerStatus::Elapsed)
|
|
|
|
@ -2082,7 +2065,7 @@ namespace MWMechanics
|
|
|
|
|
if (iter->first != player)
|
|
|
|
|
{
|
|
|
|
|
CreatureStats &stats = iter->first.getClass().getCreatureStats(iter->first);
|
|
|
|
|
if (isConscious(iter->first) && !controlledFromLua)
|
|
|
|
|
if (isConscious(iter->first) && !(luaControls && luaControls->disableAI))
|
|
|
|
|
{
|
|
|
|
|
stats.getAiSequence().execute(iter->first, *ctrl, duration);
|
|
|
|
|
updateGreetingState(iter->first, *iter->second, timerUpdateHello > 0);
|
|
|
|
@ -2091,7 +2074,7 @@ namespace MWMechanics
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (aiActive && iter->first != player && isConscious(iter->first) && !controlledFromLua)
|
|
|
|
|
else if (aiActive && iter->first != player && isConscious(iter->first) && !(luaControls && luaControls->disableAI))
|
|
|
|
|
{
|
|
|
|
|
CreatureStats &stats = iter->first.getClass().getCreatureStats(iter->first);
|
|
|
|
|
stats.getAiSequence().execute(iter->first, *ctrl, duration, /*outOfRange*/true);
|
|
|
|
@ -2108,6 +2091,32 @@ namespace MWMechanics
|
|
|
|
|
if (timerUpdateEquippedLight == 0)
|
|
|
|
|
updateEquippedLight(iter->first, updateEquippedLightInterval, showTorches);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (luaControls && isConscious(iter->first))
|
|
|
|
|
{
|
|
|
|
|
Movement& mov = iter->first.getClass().getMovementSettings(iter->first);
|
|
|
|
|
CreatureStats& stats = iter->first.getClass().getCreatureStats(iter->first);
|
|
|
|
|
float speedFactor = isPlayer ? 1.f : mov.mSpeedFactor;
|
|
|
|
|
osg::Vec2f movement = osg::Vec2f(mov.mPosition[0], mov.mPosition[1]) * speedFactor;
|
|
|
|
|
float rotationZ = mov.mRotation[2];
|
|
|
|
|
bool jump = mov.mPosition[2] == 1;
|
|
|
|
|
bool runFlag = stats.getMovementFlag(MWMechanics::CreatureStats::Flag_Run);
|
|
|
|
|
if (luaControls->controlledFromLua)
|
|
|
|
|
{
|
|
|
|
|
mov.mPosition[0] = luaControls->sideMovement;
|
|
|
|
|
mov.mPosition[1] = luaControls->movement;
|
|
|
|
|
mov.mPosition[2] = luaControls->jump ? 1 : 0;
|
|
|
|
|
mov.mRotation[1] = 0;
|
|
|
|
|
mov.mRotation[2] = luaControls->turn;
|
|
|
|
|
mov.mSpeedFactor = osg::Vec2(luaControls->movement, luaControls->sideMovement).length();
|
|
|
|
|
stats.setMovementFlag(MWMechanics::CreatureStats::Flag_Run, luaControls->run);
|
|
|
|
|
}
|
|
|
|
|
luaControls->sideMovement = movement.x();
|
|
|
|
|
luaControls->movement = movement.y();
|
|
|
|
|
luaControls->turn = rotationZ;
|
|
|
|
|
luaControls->jump = jump;
|
|
|
|
|
luaControls->run = runFlag;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|