diff --git a/TombEngine/Objects/TR4/Entity/tr4_guide.cpp b/TombEngine/Objects/TR4/Entity/tr4_guide.cpp index 22c8ca802..1790458a3 100644 --- a/TombEngine/Objects/TR4/Entity/tr4_guide.cpp +++ b/TombEngine/Objects/TR4/Entity/tr4_guide.cpp @@ -26,7 +26,8 @@ namespace TEN::Entities::TR4 GUIDE_STATE_IGNITE_TORCH = 11, GUIDE_STATE_LOOK_BACK = 22, GUIDE_STATE_TORCH_ATTACK = 31, - GUIDE_STATE_PICKUP_TORCH = 37 + GUIDE_STATE_PICKUP_TORCH = 37, + GUIDE_STATE_READ_INSCRIPTION = 39 }; ///ITEMFLAGS @@ -220,6 +221,7 @@ namespace TEN::Entities::TR4 bool flag_IgnoreLaraDistance = ((item->ItemFlags[2] & (1 << 1)) != 0) ? true : false; bool flag_RunDefault = ((item->ItemFlags[2] & (1 << 2)) != 0) ? true : false; bool flag_RetryNodeSearch = ((item->ItemFlags[2] & (1 << 3)) != 0) ? true : false; + bool flag_ScaryInscription = ((item->ItemFlags[2] & (1 << 4)) != 0) ? true : false; short GoalNode = (flag_NewlBehaviour) ? item->ItemFlags[4] : Lara.Location; @@ -302,8 +304,8 @@ namespace TEN::Entities::TR4 case 0x28: //Action Read Inscription if (laraAI.distance < pow(SECTOR(2), 2) || flag_IgnoreLaraDistance) { - item->Animation.TargetState = 39; - item->Animation.RequiredState = 39; + item->Animation.TargetState = GUIDE_STATE_READ_INSCRIPTION; + item->Animation.RequiredState = GUIDE_STATE_READ_INSCRIPTION; } break; @@ -715,7 +717,7 @@ namespace TEN::Entities::TR4 break; - case 39: + case GUIDE_STATE_READ_INSCRIPTION: if (item->Animation.FrameNumber >= g_Level.Anims[item->Animation.AnimNumber].frameBase + 20) { if (item->Animation.FrameNumber == g_Level.Anims[item->Animation.AnimNumber].frameBase + 20) @@ -731,12 +733,17 @@ namespace TEN::Entities::TR4 break; } - if (item->Animation.FrameNumber == g_Level.Anims[item->Animation.AnimNumber].frameBase + 70 && item->RoomNumber == 70) + if (item->Animation.FrameNumber == g_Level.Anims[item->Animation.AnimNumber].frameBase + 70 && flag_ScaryInscription) { item->Animation.RequiredState = GUIDE_STATE_RUN; item->MeshSwapBits |= 0x200000; SoundEffect(SFX_TR4_GUIDE_SCARE, &item->Pose); } + if (item->Animation.FrameNumber == g_Level.Anims[item->Animation.AnimNumber].frameBase + 185 && flag_ScaryInscription) + { + item->ItemFlags[2] &= ~(1 << 4); //turn off bit 4 for flag_ScaryInscription + item->MeshSwapBits &= 0xDFFFFF; + } } else if (enemy->Pose.Orientation.y - item->Pose.Orientation.y <= ANGLE(2.0f)) { diff --git a/TombEngine/Scripting/Internal/ReservedScriptNames.h b/TombEngine/Scripting/Internal/ReservedScriptNames.h index 8d9ee2195..b328ce8a8 100644 --- a/TombEngine/Scripting/Internal/ReservedScriptNames.h +++ b/TombEngine/Scripting/Internal/ReservedScriptNames.h @@ -81,6 +81,7 @@ 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"; diff --git a/TombEngine/Scripting/Internal/TEN/Objects/Moveable/MoveableObject.cpp b/TombEngine/Scripting/Internal/TEN/Objects/Moveable/MoveableObject.cpp index 56222aa04..74fecad9e 100644 --- a/TombEngine/Scripting/Internal/TEN/Objects/Moveable/MoveableObject.cpp +++ b/TombEngine/Scripting/Internal/TEN/Objects/Moveable/MoveableObject.cpp @@ -187,6 +187,10 @@ ScriptReserved_DoWaitForLara, & Moveable::DoWaitForLara, // @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: @@ -919,6 +923,23 @@ void Moveable::DoRunDefault(bool isRunDefault) } } +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 7d520ab0a..000642e30 100644 --- a/TombEngine/Scripting/Internal/TEN/Objects/Moveable/MoveableObject.h +++ b/TombEngine/Scripting/Internal/TEN/Objects/Moveable/MoveableObject.h @@ -86,6 +86,7 @@ public: 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 &);