From bf31a3d68b86bcdcb7d12c9513ad20efec1a29b5 Mon Sep 17 00:00:00 2001 From: Adngel Date: Wed, 3 Aug 2022 00:12:12 +0200 Subject: [PATCH] Revision - The Do-Actions and the Make_Targetable functions, have been removed from this code, and implemented as a Lua Module to be shared externally. - With the new Trigger approach, this commitment removes the implementation of the parameters feature. - Created a new function: GetSlotHP(), So Lua can read the default life points designated for the enemies. (useful for life percentages and such). - Changed the functions: GetItemFlag and SetItemFlag to GetItemFlags and SetItemFlags So they fits with the variable name they are referencing. --- TombEngine/Game/control/volume.cpp | 6 +- TombEngine/Game/control/volume.h | 4 - .../Scripting/Internal/ReservedScriptNames.h | 14 +- .../Internal/TEN/Logic/LogicHandler.cpp | 20 -- .../Internal/TEN/Logic/LogicHandler.h | 2 - .../TEN/Objects/Moveable/MoveableObject.cpp | 216 ++---------------- .../TEN/Objects/Moveable/MoveableObject.h | 15 +- TombEngine/Specific/level.cpp | 18 +- 8 files changed, 36 insertions(+), 259 deletions(-) diff --git a/TombEngine/Game/control/volume.cpp b/TombEngine/Game/control/volume.cpp index 1cef406d9..29fbb8f8a 100644 --- a/TombEngine/Game/control/volume.cpp +++ b/TombEngine/Game/control/volume.cpp @@ -58,13 +58,13 @@ namespace TEN::Control::Volumes { volume->Status = TriggerStatus::Entering; if (!volume->OnEnter.empty()) - g_GameScript->ExecuteFunction(volume->OnEnter, triggerer, volume->ParamOnEnter); + g_GameScript->ExecuteFunction(volume->OnEnter, triggerer); } else { volume->Status = TriggerStatus::Inside; if (!volume->OnInside.empty()) - g_GameScript->ExecuteFunction(volume->OnInside, triggerer, volume->ParamOnInside); + g_GameScript->ExecuteFunction(volume->OnInside, triggerer); } } else @@ -73,7 +73,7 @@ namespace TEN::Control::Volumes { volume->Status = TriggerStatus::Leaving; if (!volume->OnLeave.empty()) - g_GameScript->ExecuteFunction(volume->OnLeave, triggerer, volume->ParamOnLeave); + g_GameScript->ExecuteFunction(volume->OnLeave, triggerer); } else volume->Status = TriggerStatus::Outside; diff --git a/TombEngine/Game/control/volume.h b/TombEngine/Game/control/volume.h index 01c77f3d5..878dd3ee3 100644 --- a/TombEngine/Game/control/volume.h +++ b/TombEngine/Game/control/volume.h @@ -41,10 +41,6 @@ struct TriggerVolume std::string OnInside; std::string OnLeave; - std::string ParamOnEnter = "nil"; - std::string ParamOnInside = "nil"; - std::string ParamOnLeave = "nil"; - int Activators; bool OneShot; diff --git a/TombEngine/Scripting/Internal/ReservedScriptNames.h b/TombEngine/Scripting/Internal/ReservedScriptNames.h index b328ce8a8..cf12549f0 100644 --- a/TombEngine/Scripting/Internal/ReservedScriptNames.h +++ b/TombEngine/Scripting/Internal/ReservedScriptNames.h @@ -25,7 +25,6 @@ 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_MakeNotTargetable[]= "MakeNotTargetable"; static constexpr char ScriptReserved_GetColor[] = "GetColor"; static constexpr char ScriptReserved_SetColor[] = "SetColor"; static constexpr char ScriptReserved_GetPosition[] = "GetPosition"; @@ -44,6 +43,7 @@ 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_GetSlotHP[] = "GetSlotHP"; static constexpr char ScriptReserved_GetFrameNumber[] = "GetFrame"; static constexpr char ScriptReserved_SetFrameNumber[] = "SetFrame"; static constexpr char ScriptReserved_GetAnimNumber[] = "GetAnim"; @@ -53,8 +53,8 @@ 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_GetItemFlag[] = "GetItemFlag"; -static constexpr char ScriptReserved_SetItemFlag[] = "SetItemFlag"; +static constexpr char ScriptReserved_GetItemFlags[] = "GetItemFlags"; +static constexpr char ScriptReserved_SetItemFlags[] = "SetItemFlags"; static constexpr char ScriptReserved_GetHitStatus[] = "GetHitStatus"; static constexpr char ScriptReserved_GetActive[] = "GetActive"; static constexpr char ScriptReserved_GetRoom[] = "GetRoom"; @@ -75,14 +75,6 @@ static constexpr char ScriptReserved_GetOnCollidedWithRoom[] = "GetOnCollidedWit static constexpr char ScriptReserved_SetOnCollidedWithRoom[] = "SetOnCollidedWithRoom"; static constexpr char ScriptReserved_ToLength[] = "ToLength"; -static constexpr char ScriptReserved_DoGoToNode[] = "DoGoToNode"; -static constexpr char ScriptReserved_DoGoDirectlyToNode[] = "DoGoDirectlyToNode"; -static constexpr char ScriptReserved_DoGoNextNode[] = "DoGoNextNode"; -static constexpr char ScriptReserved_DoNewBehaviour[] = "DoNewBehaviour"; -static constexpr char ScriptReserved_DoWaitForLara[] = "DoWaitForLara"; -static constexpr char ScriptReserved_DoRunDefault[] = "DoRunDefault"; -static constexpr char ScriptReserved_DoScareGuide[] = "DoScareGuide"; - // Flow Functions static constexpr char ScriptReserved_AddLevel[] = "AddLevel"; static constexpr char ScriptReserved_SetIntroImagePath[] = "SetIntroImagePath"; diff --git a/TombEngine/Scripting/Internal/TEN/Logic/LogicHandler.cpp b/TombEngine/Scripting/Internal/TEN/Logic/LogicHandler.cpp index 300774ef3..79fcc07c2 100644 --- a/TombEngine/Scripting/Internal/TEN/Logic/LogicHandler.cpp +++ b/TombEngine/Scripting/Internal/TEN/Logic/LogicHandler.cpp @@ -382,26 +382,6 @@ void LogicHandler::ExecuteFunction(std::string const& name, TEN::Control::Volume } } -void LogicHandler::ExecuteFunction(std::string const& name, TEN::Control::Volumes::VolumeTriggerer triggerer, std::string const& parameter) -{ - sol::protected_function_result r; - sol::protected_function func = (*m_handler.GetState())["LevelFuncs"][name.c_str()]; - if (std::holds_alternative(triggerer)) - { - r = func(parameter, std::make_unique(std::get(triggerer), true)); - } - else - { - r = func(parameter); - } - - if (!r.valid()) - { - sol::error err = r; - ScriptAssertF(false, "Could not execute function {}: {}", name, err.what()); - } -} - static void doCallback(sol::protected_function const & func, std::optional dt = std::nullopt) { auto r = dt.has_value() ? func(dt) : func(); diff --git a/TombEngine/Scripting/Internal/TEN/Logic/LogicHandler.h b/TombEngine/Scripting/Internal/TEN/Logic/LogicHandler.h index 335283291..1c56a3733 100644 --- a/TombEngine/Scripting/Internal/TEN/Logic/LogicHandler.h +++ b/TombEngine/Scripting/Internal/TEN/Logic/LogicHandler.h @@ -56,8 +56,6 @@ public: void ExecuteFunction(std::string const& luaFuncName, short idOne, short idTwo) override; void ExecuteFunction(std::string const & name, TEN::Control::Volumes::VolumeTriggerer) override; - void ExecuteFunction(std::string const& name, TEN::Control::Volumes::VolumeTriggerer, std::string const& parameter) override; - void GetVariables(std::vector& vars) override; void ResetVariables(); diff --git a/TombEngine/Scripting/Internal/TEN/Objects/Moveable/MoveableObject.cpp b/TombEngine/Scripting/Internal/TEN/Objects/Moveable/MoveableObject.cpp index 74fecad9e..7c85e48de 100644 --- a/TombEngine/Scripting/Internal/TEN/Objects/Moveable/MoveableObject.cpp +++ b/TombEngine/Scripting/Internal/TEN/Objects/Moveable/MoveableObject.cpp @@ -153,45 +153,6 @@ void Moveable::Register(sol::table & parent) // @function Moveable:MakeInvisible ScriptReserved_MakeInvisible, &Moveable::MakeInvisible, -/// Make the item not targetable by Lara. -// @function Moveable:MakeNotTargetable -// @tparam boolean value, true to make him not targetable, false to make him targetable again, Default is true. -ScriptReserved_MakeNotTargetable, & Moveable::MakeNotTargetable, - -/// Make the actor moves through its AI_Follow path till the indicated value. -// @function Moveable:DoGoToNode -// @tparam short value, the ocb number of the AI_Follow object where this actor must go. -ScriptReserved_DoGoToNode, & Moveable::DoGoToNode, - -/// Make the actor moves directly to the indicated AI_Follow object, ignoring the other nodes before. -// @function Moveable:DoGoDirectlyToNode -// @tparam short value, the ocb number of the AI_Follow object where this actor must go. -ScriptReserved_DoGoDirectlyToNode, & Moveable::DoGoDirectlyToNode, - -/// Make the actor moves to the AI_Follow object with the next ocb value -// @function Moveable:DoGoNextNode -ScriptReserved_DoGoNextNode, & Moveable::DoGoNextNode, - -/// Make the guide follow his own path goal, instead of follow the communal path moved with flipeffect 30. Set to false to reactivate classic behaviour. -// @function Moveable:DoNewBehaviour -// @tparam boolean value, true activate or deactivate the new behaviour. Default is true. -ScriptReserved_DoNewBehaviour, & Moveable::DoNewBehaviour, - -/// Make the guide to wait for Lara to be near before to activate a heavy trigger action. -// @function Moveable:DoWaitForLara -// @tparam boolean value, true to make it wait, false to make it continue with no wait. Default is true. -ScriptReserved_DoWaitForLara, & Moveable::DoWaitForLara, - -/// Make the guide to run instead of walk. -// @function Moveable:DoRunDefault -// @tparam boolean value, true to make it run to the next AI node, false to restore the original behaviour. Default is false. -ScriptReserved_DoRunDefault, & Moveable::DoRunDefault, - -/// The next time the guide reads an inscription, it will activate his scared routine. -// @function Moveable:DoScareGuide -// @tparam boolean value, true to activate the order, flase to cancel it. Default is true. -ScriptReserved_DoScareGuide, & Moveable::DoScareGuide, - /// Get the status of object. // possible values: // 0 - not active @@ -297,6 +258,11 @@ ScriptReserved_DoScareGuide, & Moveable::DoScareGuide, // @tparam int HP the amount of HP to give the moveable ScriptReserved_SetHP, &Moveable::SetHP, +/// Get HP definded for that object type (hit points/health points) (Read Only). +// @function Moveable:GetSlotHP +// @tparam int ID of the moveable slot type. +ScriptReserved_GetSlotHP, & Moveable::GetSlotHP, + /// Get OCB (object code bit) of the moveable // @function Moveable:GetOCB // @treturn int the moveable's current OCB value @@ -307,15 +273,15 @@ ScriptReserved_DoScareGuide, & Moveable::DoScareGuide, // @tparam int OCB the new value for the moveable's OCB ScriptReserved_SetOCB, &Moveable::SetOCB, -/// Get ItemFlag[x] (object code bit) of the moveable -// @function Moveable:GetItemFlag -// @treturn short value from the moveable's ItemFlag[x] -ScriptReserved_GetItemFlag, & Moveable::GetItemFlag, +/// Get ItemFlags[x] (object code bit) of the moveable +// @function Moveable:GetItemFlags +// @treturn short value from the moveable's ItemFlags[x] +ScriptReserved_GetItemFlags, & Moveable::GetItemFlags, -/// Set ItemFlag[x] (object code bit) of the moveable -// @function Moveable:SetItemFlag -// @tparam short value to store in the moveable's ItemFlag[x] -ScriptReserved_SetItemFlag, & Moveable::SetItemFlag, +/// Set ItemFlags[x] (object code bit) of the moveable +// @function Moveable:SetItemFlags +// @tparam short value to store in the moveable's ItemFlags[x] +ScriptReserved_SetItemFlags, & Moveable::SetItemFlags, /// Get the moveable's color // @function Moveable:GetColor @@ -579,8 +545,11 @@ void Moveable::SetHP(short hp) ScriptAssert(false, "Invalid HP value: " + std::to_string(hp)); if (hp < 0) { - hp = 0; - ScriptWarn("Setting HP to 0."); + if (hp != NOT_TARGETABLE) + { + hp = 0; + ScriptWarn("Setting HP to 0."); + } } else if (hp > Objects[m_item->ObjectNumber].HitPoints) { @@ -592,6 +561,11 @@ void Moveable::SetHP(short hp) m_item->HitPoints = hp; } +short Moveable::GetSlotHP() const +{ + return (Objects[m_item->ObjectNumber].HitPoints); +} + short Moveable::GetOCB() const { return m_item->TriggerFlags; @@ -602,12 +576,12 @@ void Moveable::SetOCB(short ocb) m_item->TriggerFlags = ocb; } -short Moveable::GetItemFlag(int index) const +short Moveable::GetItemFlags(int index) const { return m_item->ItemFlags[index]; } -void Moveable::SetItemFlag(short value, int index) +void Moveable::SetItemFlags(short value, int index) { m_item->ItemFlags[index] = value; } @@ -800,146 +774,6 @@ void Moveable::MakeInvisible() dynamic_cast(g_GameScriptEntities)->TryRemoveColliding(m_num); } -void Moveable::MakeNotTargetable(bool isNotTargetable) -{ - if (isNotTargetable) - m_item->HitPoints = NOT_TARGETABLE; - else - m_item->HitPoints = Objects[m_item->ObjectNumber].HitPoints; -} - -void Moveable::DoGoToNode(short nodeId) -{ - GAME_OBJECT_ID objId = m_item->ObjectNumber; - switch (objId) - { - case ID_GUIDE: - m_item:DoNewBehaviour(); - if (nodeId <= m_item->ItemFlags[4]) - { - m_item->ItemFlags[3] = nodeId; - m_item->ItemFlags[2] |= (1 << 3); //turn on bit 3 for flag_RetryNodeSearch - } - m_item->ItemFlags[4] = nodeId; - break; - default: - std::string InfoStr = "The Lua function DoGoToNode hasn't got actions for the object " + m_item->LuaName + "."; - TENLog(InfoStr, LogLevel::Warning, LogConfig::All); - break; - } -} - -void Moveable::DoGoDirectlyToNode(short nodeId) -{ - GAME_OBJECT_ID objId = m_item->ObjectNumber; - switch (objId) - { - case ID_GUIDE: - m_item:DoNewBehaviour(); - m_item->ItemFlags[2] |= (1 << 3); //turn on bit 3 for flag_RetryNodeSearch - m_item->ItemFlags[3] = nodeId; - m_item->ItemFlags[4] = nodeId; - break; - default: - std::string InfoStr = "The Lua function DoGoDirectlyToNode hasn't got actions for the object " + m_item->LuaName + "."; - TENLog(InfoStr, LogLevel::Warning, LogConfig::All); - break; - } -} - -void Moveable::DoGoNextNode() -{ - GAME_OBJECT_ID objId = m_item->ObjectNumber; - switch (objId) - { - case ID_GUIDE: - m_item:DoNewBehaviour(); - m_item->ItemFlags[4] ++; - break; - default: - std::string InfoStr = "The Lua function DoGoNextNode hasn't got actions for the object " + m_item->LuaName + "."; - TENLog(InfoStr, LogLevel::Warning, LogConfig::All); - break; - } -} - -void Moveable::DoNewBehaviour(bool isNewBehaviour) -{ - GAME_OBJECT_ID objId = m_item->ObjectNumber; - switch (objId) - { - case ID_GUIDE: - if (isNewBehaviour) - { - m_item->ItemFlags[2] |= (1 << 0); //turn on bit 0 for flag_NewlBehaviour - }else{ - m_item->ItemFlags[2] &= ~(1 << 0); //turn off bit 0 for flag_NewlBehaviour - } - break; - default: - std::string InfoStr = "The Lua function DoNewBehaviour hasn't got actions for the object " + m_item->LuaName + "."; - TENLog(InfoStr, LogLevel::Warning, LogConfig::All); - break; - } -} - -void Moveable::DoWaitForLara(bool isWaitForLara) -{ - GAME_OBJECT_ID objId = m_item->ObjectNumber; - switch (objId) - { - case ID_GUIDE: - if (isWaitForLara) - { - m_item->ItemFlags[2] &= ~(1 << 1); //turn off bit 1 for flag_IgnoreLaraDistance - }else{ - m_item->ItemFlags[2] |= (1 << 1); //turn on bit 1 for flag_IgnoreLaraDistance - } - break; - default: - std::string InfoStr = "The Lua function DoWaitForLara hasn't got actions for the object " + m_item->LuaName + "."; - TENLog(InfoStr, LogLevel::Warning, LogConfig::All); - break; - } -} - -void Moveable::DoRunDefault(bool isRunDefault) -{ - GAME_OBJECT_ID objId = m_item->ObjectNumber; - switch (objId) - { - case ID_GUIDE: - if (isRunDefault) - { - m_item->ItemFlags[2] |= (1 << 2); //turn on bit 2 for flag_RunDefault - }else{ - m_item->ItemFlags[2] &= ~(1 << 2); //turn off bit 2 for flag_RunDefault - } - break; - default: - std::string InfoStr = "The Lua function DoRunDefault hasn't got actions for the object " + m_item->LuaName + "."; - TENLog(InfoStr, LogLevel::Warning, LogConfig::All); - break; - } -} - -void Moveable::DoScareGuide(bool isScaryInscription) -{ - if (m_item->ObjectNumber != ID_GUIDE) - { - std::string InfoStr = "The Lua function DoScareGuide hasn't got actions for the object " + m_item->LuaName + ", it only works for GUIDE objects."; - TENLog(InfoStr, LogLevel::Warning, LogConfig::All); - return; - } - - if (isScaryInscription) - { - m_item->ItemFlags[2] |= (1 << 4); //turn on bit 4 for flag_ScaryInscription - }else{ - m_item->ItemFlags[2] &= ~(1 << 4); //turn off bit 4 for flag_ScaryInscription - } -} - void Moveable::Invalidate() { // keep m_item as it is so that we can properly remove it from the moveables set when diff --git a/TombEngine/Scripting/Internal/TEN/Objects/Moveable/MoveableObject.h b/TombEngine/Scripting/Internal/TEN/Objects/Moveable/MoveableObject.h index 000642e30..608831153 100644 --- a/TombEngine/Scripting/Internal/TEN/Objects/Moveable/MoveableObject.h +++ b/TombEngine/Scripting/Internal/TEN/Objects/Moveable/MoveableObject.h @@ -58,14 +58,16 @@ public: [[nodiscard]] short GetHP() const; void SetHP(short hp); + [[nodiscard]] short GetSlotHP() const; + [[nodiscard]] short GetOCB() const; void SetOCB(short ocb); [[nodiscard]] aiBitsType GetAIBits() const; void SetAIBits(aiBitsType const & bits); - [[nodiscard]] short GetItemFlag(int index = 0) const; - void SetItemFlag(short value, int index = 0); + [[nodiscard]] short GetItemFlags(int index = 0) const; + void SetItemFlags(short value, int index = 0); [[nodiscard]] bool GetHitStatus() const; @@ -78,15 +80,6 @@ public: void EnableItem(); void DisableItem(); void MakeInvisible(); - void MakeNotTargetable(bool isNotTargetable = true); - - void DoGoToNode(short nodeId); - void DoGoDirectlyToNode(short nodeId); - void DoGoNextNode(); - void DoNewBehaviour( bool isNewBehaviour = true); - void DoWaitForLara( bool isWaitForLara = true); - void DoRunDefault( bool isRunDefault = false); - void DoScareGuide(bool isScaryInscription = true); [[nodiscard]] std::string GetOnHit() const; void SetOnHit(std::string const &); diff --git a/TombEngine/Specific/level.cpp b/TombEngine/Specific/level.cpp index 34a910718..09f690e59 100644 --- a/TombEngine/Specific/level.cpp +++ b/TombEngine/Specific/level.cpp @@ -791,23 +791,7 @@ void ReadRooms() numBytes = ReadInt8(); ReadBytes(buffer, numBytes); volume.OnLeave = std::string(buffer, buffer + numBytes); - - std::string temporalParameter; - numBytes = ReadInt8(); - ReadBytes(buffer, numBytes); - temporalParameter = std::string(buffer, buffer + numBytes); - volume.ParamOnEnter = (temporalParameter.empty()) ? "nil" : temporalParameter; - - numBytes = ReadInt8(); - ReadBytes(buffer, numBytes); - temporalParameter = std::string(buffer, buffer + numBytes); - volume.ParamOnInside = (temporalParameter.empty()) ? "nil" : temporalParameter; - - numBytes = ReadInt8(); - ReadBytes(buffer, numBytes); - temporalParameter = std::string(buffer, buffer + numBytes); - volume.ParamOnLeave = (temporalParameter.empty()) ? "nil" : temporalParameter; - + volume.OneShot = ReadInt8(); volume.Status = TriggerStatus::Outside;