Merge branch 'master' into 'master'

An ability to specify attack type in controls.use value

See merge request OpenMW/openmw!4187
pull/3236/head
psi29a 6 months ago
commit ef0bb02def

@ -82,7 +82,7 @@ message(STATUS "Configuring OpenMW...")
set(OPENMW_VERSION_MAJOR 0)
set(OPENMW_VERSION_MINOR 49)
set(OPENMW_VERSION_RELEASE 0)
set(OPENMW_LUA_API_REVISION 62)
set(OPENMW_LUA_API_REVISION 63)
set(OPENMW_POSTPROCESSING_API_REVISION 1)
set(OPENMW_VERSION_COMMITHASH "")

@ -1,6 +1,7 @@
#include "localscripts.hpp"
#include <components/esm3/loadcell.hpp>
#include <components/esm3/loadweap.hpp>
#include <components/misc/strings/lower.hpp>
#include "../mwbase/environment.hpp"
@ -13,6 +14,7 @@
#include "../mwmechanics/aisequence.hpp"
#include "../mwmechanics/aitravel.hpp"
#include "../mwmechanics/aiwander.hpp"
#include "../mwmechanics/attacktype.hpp"
#include "../mwmechanics/creaturestats.hpp"
#include "../mwworld/class.hpp"
#include "../mwworld/ptr.hpp"
@ -63,6 +65,11 @@ namespace MWLua
selfAPI["controls"] = sol::readonly_property([](SelfObject& self) { return &self.mControls; });
selfAPI["isActive"] = [](SelfObject& self) { return &self.mIsActive; };
selfAPI["enableAI"] = [](SelfObject& self, bool v) { self.mControls.mDisableAI = !v; };
selfAPI["ATTACK_TYPE"]
= LuaUtil::makeStrictReadOnly(context.mLua->tableFromPairs<std::string_view, MWMechanics::AttackType>(
{ { "NoAttack", MWMechanics::AttackType::NoAttack }, { "Any", MWMechanics::AttackType::Any },
{ "Chop", MWMechanics::AttackType::Chop }, { "Slash", MWMechanics::AttackType::Slash },
{ "Thrust", MWMechanics::AttackType::Thrust } }));
using AiPackage = MWMechanics::AiPackage;
sol::usertype<AiPackage> aiPackage = context.mLua->sol().new_usertype<AiPackage>("AiPackage");

@ -47,6 +47,7 @@
#include "aifollow.hpp"
#include "aipursue.hpp"
#include "aiwander.hpp"
#include "attacktype.hpp"
#include "character.hpp"
#include "creaturestats.hpp"
#include "movement.hpp"
@ -239,6 +240,23 @@ namespace MWMechanics
namespace
{
std::string_view attackTypeName(AttackType attackType)
{
switch (attackType)
{
case AttackType::NoAttack:
case AttackType::Any:
return {};
case AttackType::Chop:
return "chop";
case AttackType::Slash:
return "slash";
case AttackType::Thrust:
return "thrust";
}
throw std::logic_error("Invalid attack type value: " + std::to_string(static_cast<int>(attackType)));
}
float getTimeToDestination(const AiPackage& package, const osg::Vec3f& position, float speed, float duration,
const osg::Vec3f& halfExtents)
{
@ -363,7 +381,11 @@ namespace MWMechanics
mov.mSpeedFactor = osg::Vec2(controls.mMovement, controls.mSideMovement).length();
stats.setMovementFlag(MWMechanics::CreatureStats::Flag_Run, controls.mRun);
stats.setMovementFlag(MWMechanics::CreatureStats::Flag_Sneak, controls.mSneak);
stats.setAttackingOrSpell((controls.mUse & 1) == 1);
AttackType attackType = static_cast<AttackType>(controls.mUse);
stats.setAttackingOrSpell(attackType != AttackType::NoAttack);
stats.setAttackType(attackTypeName(attackType));
controls.mChanged = false;
}
// For the player we don't need to copy these values to Lua because mwinput doesn't change them.

@ -0,0 +1,16 @@
#ifndef OPENMW_MWMECHANICS_ATTACKTYPE_H
#define OPENMW_MWMECHANICS_ATTACKTYPE_H
namespace MWMechanics
{
enum class AttackType
{
NoAttack,
Any,
Chop,
Slash,
Thrust
};
}
#endif

@ -1674,7 +1674,12 @@ namespace MWMechanics
}
}
else if (aiInactive)
mAttackType = getRandomAttackType();
{
mAttackType = getDesiredAttackType();
if (mAttackType == "")
mAttackType = getRandomAttackType();
}
// else if (mPtr != getPlayer()) use mAttackType set by AiCombat
startKey = mAttackType + ' ' + startKey;
stopKey = mAttackType + " max attack";
@ -3003,6 +3008,11 @@ namespace MWMechanics
return mPtr.getClass().getCreatureStats(mPtr).getAttackingOrSpell();
}
std::string_view CharacterController::getDesiredAttackType() const
{
return mPtr.getClass().getCreatureStats(mPtr).getAttackType();
}
void CharacterController::setActive(int active) const
{
mAnimation->setActive(active);

@ -247,6 +247,8 @@ namespace MWMechanics
bool getAttackingOrSpell() const;
void setAttackingOrSpell(bool attackingOrSpell) const;
std::string_view getDesiredAttackType() const;
void prepareHit();
public:

@ -97,6 +97,7 @@ namespace MWMechanics
protected:
int mLevel;
bool mAttackingOrSpell;
std::string mAttackType;
public:
CreatureStats();
@ -130,6 +131,7 @@ namespace MWMechanics
const MagicEffects& getMagicEffects() const;
bool getAttackingOrSpell() const { return mAttackingOrSpell; }
std::string_view getAttackType() const { return mAttackType; }
int getLevel() const;
@ -156,6 +158,8 @@ namespace MWMechanics
void setAttackingOrSpell(bool attackingOrSpell) { mAttackingOrSpell = attackingOrSpell; }
void setAttackType(std::string_view attackType) { mAttackType = attackType; }
void setLevel(int level);
void setAiSetting(AiSetting index, Stat<int> value);

@ -37,7 +37,15 @@
-- @field [parent=#ActorControls] #boolean run true - run, false - walk
-- @field [parent=#ActorControls] #boolean sneak If true - sneak
-- @field [parent=#ActorControls] #boolean jump If true - initiate a jump
-- @field [parent=#ActorControls] #number use if 1 - activates the readied weapon/spell. For weapons, keeping at 1 will charge the attack until set to 0.
-- @field [parent=#ActorControls] #ATTACK_TYPE use Activates the readied weapon/spell according to a provided value. For weapons, keeping this value modified will charge the attack until set to @{#ATTACK_TYPE.NoAttack}. If an @{#ATTACK_TYPE} not appropriate for a currently equipped weapon provided - an appropriate @{#ATTACK_TYPE} will be used instead.
---
-- @type ATTACK_TYPE
-- @field #number NoAttack
-- @field #number Any
-- @field #number Chop
-- @field #number Swing
-- @field #number Thrust
---
-- Enables or disables standard AI (enabled by default).

Loading…
Cancel
Save