Add GetState/SetState, meshswap/visibility funcs, correctly use SetAnim

This commit is contained in:
Lwmte 2022-07-09 14:17:07 +03:00
parent 953504be44
commit cbe4fe3ec3
3 changed files with 139 additions and 53 deletions

View file

@ -20,54 +20,60 @@ static constexpr char ScriptReserved_DisplayString[] = "DisplayString";
static constexpr char ScriptReserved_Vec3[] = "Vec3";
// Member functions
static constexpr char ScriptReserved_new[] = "new";
static constexpr char ScriptReserved_Init[] = "Init";
static constexpr char ScriptReserved_Enable[] = "Enable";
static constexpr char ScriptReserved_Disable[] = "Disable";
static constexpr char ScriptReserved_MakeInvisible[] = "MakeInvisible";
static constexpr char ScriptReserved_Explode[] = "Explode";
static constexpr char ScriptReserved_GetColor[] = "GetColor";
static constexpr char ScriptReserved_SetColor[] = "SetColor";
static constexpr char ScriptReserved_GetPosition[] = "GetPosition";
static constexpr char ScriptReserved_GetJointPosition[] = "GetJointPosition";
static constexpr char ScriptReserved_SetPosition[] = "SetPosition";
static constexpr char ScriptReserved_GetRotation[] = "GetRotation";
static constexpr char ScriptReserved_SetRotation[] = "SetRotation";
static constexpr char ScriptReserved_GetRotationY[] = "GetRotationY";
static constexpr char ScriptReserved_SetRotationY[] = "SetRotationY";
static constexpr char ScriptReserved_GetName[] = "GetName";
static constexpr char ScriptReserved_SetName[] = "SetName";
static constexpr char ScriptReserved_GetSlot[] = "GetSlot";
static constexpr char ScriptReserved_SetSlot[] = "SetSlot";
static constexpr char ScriptReserved_GetObjectID[] = "GetObjectID";
static constexpr char ScriptReserved_SetObjectID[] = "SetObjectID";
static constexpr char ScriptReserved_GetSoundID[] = "GetSoundID";
static constexpr char ScriptReserved_SetSoundID[] = "SetSoundID";
static constexpr char ScriptReserved_GetHP[] = "GetHP";
static constexpr char ScriptReserved_SetHP[] = "SetHP";
static constexpr char ScriptReserved_GetFrameNumber[] = "GetFrame";
static constexpr char ScriptReserved_SetFrameNumber[] = "SetFrame";
static constexpr char ScriptReserved_GetAnimNumber[] = "GetAnim";
static constexpr char ScriptReserved_SetAnimNumber[] = "SetAnim";
static constexpr char ScriptReserved_GetOCB[] = "GetOCB";
static constexpr char ScriptReserved_SetOCB[] = "SetOCB";
static constexpr char ScriptReserved_GetStatus[] = "GetStatus";
static constexpr char ScriptReserved_GetAIBits[] = "GetAIBits";
static constexpr char ScriptReserved_SetAIBits[] = "SetAIBits";
static constexpr char ScriptReserved_GetHitStatus[] = "GetHitStatus";
static constexpr char ScriptReserved_GetActive[] = "GetActive";
static constexpr char ScriptReserved_GetRoom[] = "GetRoom";
static constexpr char ScriptReserved_SetRoom[] = "SetRoom";
static constexpr char ScriptReserved_GetStrength[] = "GetStrength";
static constexpr char ScriptReserved_SetStrength[] = "SetStrength";
static constexpr char ScriptReserved_GetValid[] = "GetValid";
static constexpr char ScriptReserved_Destroy[] = "Destroy";
static constexpr char ScriptReserved_GetKey[] = "GetKey";
static constexpr char ScriptReserved_SetKey[] = "SetKey";
static constexpr char ScriptReserved_GetOnKilled[] = "GetOnKilled";
static constexpr char ScriptReserved_SetOnKilled[] = "SetOnKilled";
static constexpr char ScriptReserved_GetOnHit[] = "GetOnHit";
static constexpr char ScriptReserved_SetOnHit[] = "SetOnHit";
static constexpr char ScriptReserved_new[] = "new";
static constexpr char ScriptReserved_Init[] = "Init";
static constexpr char ScriptReserved_Enable[] = "Enable";
static constexpr char ScriptReserved_Disable[] = "Disable";
static constexpr char ScriptReserved_MakeInvisible[] = "MakeInvisible";
static constexpr char ScriptReserved_Explode[] = "Explode";
static constexpr char ScriptReserved_GetColor[] = "GetColor";
static constexpr char ScriptReserved_SetColor[] = "SetColor";
static constexpr char ScriptReserved_GetPosition[] = "GetPosition";
static constexpr char ScriptReserved_GetJointPosition[] = "GetJointPosition";
static constexpr char ScriptReserved_SetPosition[] = "SetPosition";
static constexpr char ScriptReserved_GetRotation[] = "GetRotation";
static constexpr char ScriptReserved_SetRotation[] = "SetRotation";
static constexpr char ScriptReserved_GetRotationY[] = "GetRotationY";
static constexpr char ScriptReserved_SetRotationY[] = "SetRotationY";
static constexpr char ScriptReserved_GetName[] = "GetName";
static constexpr char ScriptReserved_SetName[] = "SetName";
static constexpr char ScriptReserved_GetSlot[] = "GetSlot";
static constexpr char ScriptReserved_SetSlot[] = "SetSlot";
static constexpr char ScriptReserved_GetObjectID[] = "GetObjectID";
static constexpr char ScriptReserved_SetObjectID[] = "SetObjectID";
static constexpr char ScriptReserved_GetSoundID[] = "GetSoundID";
static constexpr char ScriptReserved_SetSoundID[] = "SetSoundID";
static constexpr char ScriptReserved_GetHP[] = "GetHP";
static constexpr char ScriptReserved_SetHP[] = "SetHP";
static constexpr char ScriptReserved_GetFrameNumber[] = "GetFrame";
static constexpr char ScriptReserved_SetFrameNumber[] = "SetFrame";
static constexpr char ScriptReserved_GetAnimNumber[] = "GetAnim";
static constexpr char ScriptReserved_SetAnimNumber[] = "SetAnim";
static constexpr char ScriptReserved_GetStateNumber[] = "GetState";
static constexpr char ScriptReserved_SetStateNumber[] = "SetState";
static constexpr char ScriptReserved_GetOCB[] = "GetOCB";
static constexpr char ScriptReserved_SetOCB[] = "SetOCB";
static constexpr char ScriptReserved_GetStatus[] = "GetStatus";
static constexpr char ScriptReserved_GetAIBits[] = "GetAIBits";
static constexpr char ScriptReserved_SetAIBits[] = "SetAIBits";
static constexpr char ScriptReserved_GetMeshVisibility[] = "GetMeshVisibility";
static constexpr char ScriptReserved_SetMeshVisibility[] = "SetMeshVisibility";
static constexpr char ScriptReserved_GetMeshSwap[] = "GetMeshSwap";
static constexpr char ScriptReserved_SetMeshSwap[] = "SetMeshSwap";
static constexpr char ScriptReserved_GetHitStatus[] = "GetHitStatus";
static constexpr char ScriptReserved_GetActive[] = "GetActive";
static constexpr char ScriptReserved_GetRoom[] = "GetRoom";
static constexpr char ScriptReserved_SetRoom[] = "SetRoom";
static constexpr char ScriptReserved_GetStrength[] = "GetStrength";
static constexpr char ScriptReserved_SetStrength[] = "SetStrength";
static constexpr char ScriptReserved_GetValid[] = "GetValid";
static constexpr char ScriptReserved_Destroy[] = "Destroy";
static constexpr char ScriptReserved_GetKey[] = "GetKey";
static constexpr char ScriptReserved_SetKey[] = "SetKey";
static constexpr char ScriptReserved_GetOnKilled[] = "GetOnKilled";
static constexpr char ScriptReserved_SetOnKilled[] = "SetOnKilled";
static constexpr char ScriptReserved_GetOnHit[] = "GetOnHit";
static constexpr char ScriptReserved_SetOnHit[] = "SetOnHit";
static constexpr char ScriptReserved_GetOnCollidedWithObject[] = "GetOnCollidedWithObject";
static constexpr char ScriptReserved_SetOnCollidedWithObject[] = "SetOnCollidedWithObject";
static constexpr char ScriptReserved_GetOnCollidedWithRoom[] = "GetOnCollidedWithRoom";

View file

@ -220,15 +220,28 @@ void Moveable::Register(sol::table & parent)
// shiva:SetObjectID(TEN.Objects.ObjID.BIGMEDI_ITEM)
ScriptReserved_SetObjectID, &Moveable::SetObjectID,
/// Retrieve the index of the current animation.
// This corresponds to the number shown in the item's state ID field in WadTool.
// @function Moveable:GetState
// @treturn int the index of the active state
ScriptReserved_GetStateNumber, &Moveable::GetStateNumber,
/// Set the object's state to the one specified by the given index.
// Performs no bounds checking. *Ensure the number given is correct, else
// object may end up in corrupted animation state.*
// @function Moveable:SetState
// @tparam int index the index of the desired state
ScriptReserved_SetStateNumber, &Moveable::SetStateNumber,
/// Retrieve the index of the current animation.
// This corresponds to the number shown in the item's animation list in WadTool.
// @function Moveable:GetAnim
// @treturn int the index of the active animation
ScriptReserved_GetAnimNumber, &Moveable::GetAnimNumber,
/// Set the opject's animation to the one specified by the given index.
/// Set the object's animation to the one specified by the given index.
// Performs no bounds checking. *Ensure the number given is correct, else
// the program is likely to crash with an unhelpful error message.*
// object may end up in corrupted animation state.*
// @function Moveable:SetAnim
// @tparam int index the index of the desired anim
ScriptReserved_SetAnimNumber, &Moveable::SetAnimNumber,
@ -293,6 +306,36 @@ void Moveable::Register(sol::table & parent)
// sas:SetAIBits({1, 0, 0, 0, 0, 0})
ScriptReserved_SetAIBits, &Moveable::SetAIBits,
/// Get state of specified mesh visibility of object
// Returns true if specified mesh is visible on an object, and false
// if it is not visible.
// @function Moveable:GetMeshVisibility
// @tparam int index of a mesh
// @treturn bool visibility status
ScriptReserved_GetMeshVisibility, &Moveable::GetMeshVisibility,
/// Set state of specified mesh visibility of object
// Use this to show or hide specified mesh of an object.
// @function Moveable:SetMeshVisibility
// @tparam int index of a mesh
// @tparam bool status, visible or invisible
ScriptReserved_SetMeshVisibility, &Moveable::SetMeshVisibility,
/// Get state of specified mesh swap of object
// Returns true if specified mesh is swapped on an object, and false
// if it is not swapped.
// @function Moveable:GetMeshSwap
// @tparam int index of a mesh
// @treturn bool mesh swap status
ScriptReserved_GetMeshSwap, &Moveable::GetMeshSwap,
/// Set state of specified mesh swap of object
// Use this to swap specified mesh of an object.
// @function Moveable:SetMeshSwap
// @tparam int index of a mesh
// @tparam bool status, swapped or not
ScriptReserved_SetMeshSwap, &Moveable::SetMeshSwap,
/// Get the hit status of the object
// @function Moveable:GetHitStatus
// @treturn bool true if the moveable was hit by something in the last gameplay frame, false otherwise
@ -576,6 +619,16 @@ void Moveable::SetAIBits(aiBitsType const & bits)
}
}
int Moveable::GetStateNumber() const
{
return m_item->Animation.ActiveState;
}
void Moveable::SetStateNumber(int stateNumber)
{
m_item->Animation.TargetState = stateNumber;
}
int Moveable::GetAnimNumber() const
{
return m_item->Animation.AnimNumber - Objects[m_item->ObjectNumber].animIndex;
@ -583,8 +636,7 @@ int Moveable::GetAnimNumber() const
void Moveable::SetAnimNumber(int animNumber)
{
//TODO fixme: we need bounds checking with an error message once it's in the level file format
m_item->Animation.AnimNumber = animNumber + Objects[m_item->ObjectNumber].animIndex;
SetAnimation(m_item, animNumber);
}
int Moveable::GetFrameNumber() const
@ -592,7 +644,6 @@ int Moveable::GetFrameNumber() const
return m_item->Animation.FrameNumber - g_Level.Anims[m_item->Animation.AnimNumber].frameBase;
}
void Moveable::SetFrameNumber(int frameNumber)
{
auto const fBase = g_Level.Anims[m_item->Animation.AnimNumber].frameBase;
@ -651,6 +702,32 @@ short Moveable::GetStatus() const
return m_item->Status;
}
bool Moveable::GetMeshVisibility(int meshId) const
{
return m_item->TestBits(JointBitType::Mesh, meshId);
}
void Moveable::SetMeshVisibility(int meshId, bool visible)
{
if (visible)
m_item->SetBits(JointBitType::Mesh, meshId);
else
m_item->ClearBits(JointBitType::Mesh, meshId);
}
bool Moveable::GetMeshSwap(int meshId) const
{
return m_item->TestBits(JointBitType::MeshSwap, meshId);
}
void Moveable::SetMeshSwap(int meshId, bool swapped)
{
if (swapped)
m_item->SetBits(JointBitType::MeshSwap, meshId);
else
m_item->ClearBits(JointBitType::MeshSwap, meshId);
}
void Moveable::EnableItem()
{
if (!m_item->Active)

View file

@ -45,6 +45,9 @@ public:
[[nodiscard]] Rotation GetRot() const;
void SetRot(Rotation const& rot);
[[nodiscard]] int GetStateNumber() const;
void SetStateNumber(int stateNumber);
[[nodiscard]] int GetAnimNumber() const;
void SetAnimNumber(int animNumber);