1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-03-30 07:21:12 +00:00

Introduced attacktype enum, fixed lua docs

This commit is contained in:
Max Yari 2024-06-21 23:18:13 +02:00
parent 2ef0568dda
commit b01b76b81e
4 changed files with 36 additions and 11 deletions

View File

@ -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,8 +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["AttackTYPE"] = LuaUtil::makeStrictReadOnly(context.mLua->tableFromPairs<std::string_view, int>(
{ { "NoAttack", 0 }, { "Attack", 1 }, { "Chop", 1 }, { "Slash", 2 }, { "Thrust", 3 } }));
selfAPI["AttackTYPE"]
= 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");

View File

@ -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,13 +240,13 @@ namespace MWMechanics
namespace
{
std::string_view attackTypeName(int attackTypeNum)
std::string_view attackTypeName(AttackType attackType)
{
if (attackTypeNum == 1)
if (attackType == AttackType::Chop)
return "chop";
else if (attackTypeNum == 2)
else if (attackType == AttackType::Slash)
return "slash";
else if (attackTypeNum == 3)
else if (attackType == AttackType::Thrust)
return "thrust";
else
return "";
@ -376,9 +377,11 @@ namespace MWMechanics
stats.setMovementFlag(MWMechanics::CreatureStats::Flag_Run, controls.mRun);
stats.setMovementFlag(MWMechanics::CreatureStats::Flag_Sneak, controls.mSneak);
int attackTypeNum = controls.mUse & 3;
stats.setAttackingOrSpell(attackTypeNum != 0);
stats.setAttackType(attackTypeName(attackTypeNum));
// Same as mUse % max AttackType int value
AttackType attackType = static_cast<AttackType>(controls.mUse % static_cast<int>(AttackType::Thrust));
stats.setAttackingOrSpell(attackType != AttackType::NoAttack);
stats.setAttackType(attackTypeName(attackType));
controls.mChanged = false;
}

View File

@ -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

View File

@ -37,11 +37,12 @@
-- @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 Accepts an @{#AttackTYPE} value. Activates the readied weapon/spell according to a provided value. For weapons, keeping this value modified will charge the attack until set to @{#AttackTYPE.NoAttack}.
-- @field [parent=#ActorControls] #number use Accepts an @{#AttackTYPE} value. Activates the readied weapon/spell according to a provided value. For weapons, keeping this value modified will charge the attack until set to @{#AttackTYPE.NoAttack}. If an @{#AttackTYPE} not appropriate for a currently equipped weapon provided - an appropriate @{#AttackTYPE} will be used instead.
---
-- @type AttackTYPE
-- @field #number NoAttack
-- @field #number Attack
-- @field #number Any
-- @field #number Chop
-- @field #number Swing
-- @field #number Thrust