From 2a9175f5fb43d21bb7c8ab38066a847f8c7ef5b6 Mon Sep 17 00:00:00 2001 From: hispidence Date: Tue, 25 Jan 2022 23:52:20 +0000 Subject: [PATCH] Partially integrate ScriptInterfaceFlow and replace instances of direct access to Animations members. --- Scripting/include/Scripting/GameFlowScript.h | 16 +++++++++++++--- Scripting/src/GameFlowScript.cpp | 7 ++++++- TR5Main/Game/Lara/lara_basic.cpp | 2 +- TR5Main/Game/Lara/lara_cheat.cpp | 2 +- TR5Main/Game/Lara/lara_crawl.cpp | 8 ++++---- TR5Main/Game/Lara/lara_helpers.cpp | 2 +- TR5Main/Game/Lara/lara_jump.cpp | 2 +- TR5Main/Game/Lara/lara_monkey.cpp | 2 +- TR5Main/Game/Lara/lara_tests.cpp | 18 +++++++++--------- 9 files changed, 37 insertions(+), 22 deletions(-) diff --git a/Scripting/include/Scripting/GameFlowScript.h b/Scripting/include/Scripting/GameFlowScript.h index 904a942aa..694f5726f 100644 --- a/Scripting/include/Scripting/GameFlowScript.h +++ b/Scripting/include/Scripting/GameFlowScript.h @@ -8,6 +8,7 @@ #include "GameScriptAudioTrack.h" #include "GameScriptAnimations.h" #include "ScriptInterfaceGame.h" +#include "ScriptInterfaceFlow.h" enum class TITLE_TYPE { @@ -15,7 +16,7 @@ enum class TITLE_TYPE BACKGROUND }; -class GameFlow : public LuaHandler +class GameFlow : public LuaHandler, public ScriptInterfaceFlow { private: GameScriptSettings m_settings; @@ -63,7 +64,16 @@ public: void SetIntroImagePath(std::string const& path); void SetTitleScreenImagePath(std::string const& path); void SetGameFarView(byte val); + bool IsFlyCheatEnabled() const; + + bool HasCrawlExtended() const { return Animations.CrawlExtended; } + bool HasCrouchRoll() const { return Animations.CrouchRoll; } + bool HasCrawlspaceSwandive() const { return Animations.CrawlspaceSwandive; } + bool HasMonkeyTurn180() const { return Animations.MonkeyTurn180; } + bool HasMonkeyAutoJump() const { return Animations.MonkeyAutoJump; } + bool HasOscillateHang() const { return Animations.OscillateHang; } + bool HasAFKPose() const { return Animations.Pose; } }; -extern GameFlow* g_GameFlow; -extern ScriptInterfaceGame * g_GameScript; +extern ScriptInterfaceFlow* g_GameFlow; +extern ScriptInterfaceGame* g_GameScript; diff --git a/Scripting/src/GameFlowScript.cpp b/Scripting/src/GameFlowScript.cpp index 89025a7a5..7e32dfc25 100644 --- a/Scripting/src/GameFlowScript.cpp +++ b/Scripting/src/GameFlowScript.cpp @@ -16,7 +16,7 @@ using std::string; using std::vector; using std::unordered_map; -GameFlow* g_GameFlow; +ScriptInterfaceFlow* g_GameFlow; ScriptInterfaceGame* g_GameScript; GameFlow::GameFlow(sol::state* lua) : LuaHandler{ lua } @@ -231,6 +231,11 @@ int GameFlow::GetNumLevels() const return Levels.size(); } +bool GameFlow::IsFlyCheatEnabled() const +{ + return FlyCheat; +} + bool GameFlow::DoGameflow() { // We start with the title level diff --git a/TR5Main/Game/Lara/lara_basic.cpp b/TR5Main/Game/Lara/lara_basic.cpp index 195b77ede..f8ed32002 100644 --- a/TR5Main/Game/Lara/lara_basic.cpp +++ b/TR5Main/Game/Lara/lara_basic.cpp @@ -492,7 +492,7 @@ void lara_as_idle(ITEM_INFO* item, COLL_INFO* coll) // movement lock will be rather obnoxious. // Adding some idle breathing would also be nice. @Sezz 2021.10.31 if (info->poseCount >= LARA_POSE_TIME && TestLaraPose(item, coll) && - g_GameFlow->Animations.Pose) + g_GameFlow->HasAFKPose()) { item->goalAnimState = LS_POSE; return; diff --git a/TR5Main/Game/Lara/lara_cheat.cpp b/TR5Main/Game/Lara/lara_cheat.cpp index e59e14030..a69f2ee9c 100644 --- a/TR5Main/Game/Lara/lara_cheat.cpp +++ b/TR5Main/Game/Lara/lara_cheat.cpp @@ -67,7 +67,7 @@ void lara_as_swimcheat(ITEM_INFO* item, COLL_INFO* coll) void LaraCheatyBits() { - if (g_GameFlow->FlyCheat) + if (g_GameFlow->IsFlyCheatEnabled()) { if (KeyMap[DIK_O]) { diff --git a/TR5Main/Game/Lara/lara_crawl.cpp b/TR5Main/Game/Lara/lara_crawl.cpp index 40c7f6c17..5f16f7e90 100644 --- a/TR5Main/Game/Lara/lara_crawl.cpp +++ b/TR5Main/Game/Lara/lara_crawl.cpp @@ -63,7 +63,7 @@ void lara_as_crouch_idle(ITEM_INFO* item, COLL_INFO* coll) { if (TrInput & IN_SPRINT && TestLaraCrouchRoll(item, coll) && info->gunStatus == LG_HANDS_FREE && - g_GameFlow->Animations.CrouchRoll) + g_GameFlow->HasCrouchRoll()) { item->goalAnimState = LS_CROUCH_ROLL; return; @@ -242,7 +242,7 @@ void lara_as_crouch_turn_left(ITEM_INFO* item, COLL_INFO* coll) info->waterStatus != LW_WADE) { if (TrInput & IN_SPRINT && TestLaraCrouchRoll(item, coll) && - g_GameFlow->Animations.CrouchRoll) + g_GameFlow->HasCrouchRoll()) { item->goalAnimState = LS_CROUCH_ROLL; return; @@ -298,7 +298,7 @@ void lara_as_crouch_turn_right(ITEM_INFO* item, COLL_INFO* coll) info->waterStatus != LW_WADE) { if (TrInput & IN_SPRINT && TestLaraCrouchRoll(item, coll) && - g_GameFlow->Animations.CrouchRoll) + g_GameFlow->HasCrouchRoll()) { item->goalAnimState = LS_CROUCH_ROLL; return; @@ -380,7 +380,7 @@ void lara_as_crawl_idle(ITEM_INFO* item, COLL_INFO* coll) if (TrInput & IN_FORWARD) { if (TrInput & (IN_ACTION | IN_JUMP) && TestLaraCrawlVault(item, coll) && - g_GameFlow->Animations.CrawlExtended) + g_GameFlow->HasCrawlExtended()) { DoLaraCrawlVault(item, coll); return; diff --git a/TR5Main/Game/Lara/lara_helpers.cpp b/TR5Main/Game/Lara/lara_helpers.cpp index 1847ce0f4..3990a2a5d 100644 --- a/TR5Main/Game/Lara/lara_helpers.cpp +++ b/TR5Main/Game/Lara/lara_helpers.cpp @@ -218,7 +218,7 @@ void HandleLaraMovementParameters(ITEM_INFO* item, COLL_INFO* coll) if (info->poseCount < LARA_POSE_TIME && TestLaraPose(item, coll) && !(TrInput & (IN_WAKE | IN_LOOK)) && - g_GameFlow->Animations.Pose) + g_GameFlow->HasAFKPose()) { info->poseCount++; } diff --git a/TR5Main/Game/Lara/lara_jump.cpp b/TR5Main/Game/Lara/lara_jump.cpp index 6665dc657..19e49183f 100644 --- a/TR5Main/Game/Lara/lara_jump.cpp +++ b/TR5Main/Game/Lara/lara_jump.cpp @@ -601,7 +601,7 @@ void lara_col_swandive(ITEM_INFO* item, COLL_INFO* coll) ; else if (info->keepCrouched || abs(probe.Position.Ceiling - probe.Position.Floor) < LARA_HEIGHT && - g_GameFlow->Animations.CrawlspaceSwandive) + g_GameFlow->HasCrawlspaceSwandive()) { SetAnimation(item, LA_SPRINT_TO_CROUCH_LEFT, 10); diff --git a/TR5Main/Game/Lara/lara_monkey.cpp b/TR5Main/Game/Lara/lara_monkey.cpp index b1604cb02..d23b73ce5 100644 --- a/TR5Main/Game/Lara/lara_monkey.cpp +++ b/TR5Main/Game/Lara/lara_monkey.cpp @@ -92,7 +92,7 @@ void lara_col_monkey_idle(ITEM_INFO* item, COLL_INFO* coll) { item->goalAnimState = LS_MONKEYSWING_TURN_RIGHT; } - else if (TrInput & IN_ROLL && g_GameFlow->Animations.MonkeyTurn180) + else if (TrInput & IN_ROLL && g_GameFlow->HasMonkeyTurn180()) { item->goalAnimState = LS_MONKEYSWING_TURN_180; } diff --git a/TR5Main/Game/Lara/lara_tests.cpp b/TR5Main/Game/Lara/lara_tests.cpp index 33e00913c..7002461b2 100644 --- a/TR5Main/Game/Lara/lara_tests.cpp +++ b/TR5Main/Game/Lara/lara_tests.cpp @@ -121,7 +121,7 @@ bool TestLaraVault(ITEM_INFO* item, COLL_INFO* coll) // Vault to crouch up one step. if (coll->Front.Floor < 0 && // Lower floor bound. coll->Front.Floor > -STEPUP_HEIGHT && // Upper floor bound. - g_GameFlow->Animations.CrawlExtended) + g_GameFlow->HasCrawlExtended()) { if (abs((coll->Front.Ceiling - coll->Setup.Height) - coll->Front.Floor) > LARA_HEIGHT_CRAWL) // Front clamp buffer. Presumably, nothing more is necessary, but tend to this in the future. @Sezz 2021.11.06 { @@ -153,7 +153,7 @@ bool TestLaraVault(ITEM_INFO* item, COLL_INFO* coll) else if (abs((coll->Front.Ceiling - coll->Setup.Height) - coll->Front.Floor) > LARA_HEIGHT_CRAWL && // Front clamp buffer. abs((coll->FrontLeft.Ceiling - coll->Setup.Height) - coll->FrontLeft.Floor) > LARA_HEIGHT_CRAWL && // Left clamp buffer. abs((coll->FrontRight.Ceiling - coll->Setup.Height) - coll->FrontRight.Floor) > LARA_HEIGHT_CRAWL && // Right clamp buffer. - g_GameFlow->Animations.CrawlExtended) + g_GameFlow->HasCrawlExtended()) { item->animNumber = LA_VAULT_TO_CROUCH_2CLICK; item->frameNumber = GetFrameNumber(item, 0); @@ -183,7 +183,7 @@ bool TestLaraVault(ITEM_INFO* item, COLL_INFO* coll) else if (abs((coll->Front.Ceiling - coll->Setup.Height) - coll->Front.Floor) > LARA_HEIGHT_CRAWL && // Front clamp buffer. abs((coll->FrontLeft.Ceiling - coll->Setup.Height) - coll->FrontLeft.Floor) > LARA_HEIGHT_CRAWL && // Left clamp buffer. abs((coll->FrontRight.Ceiling - coll->Setup.Height) - coll->FrontRight.Floor) > LARA_HEIGHT_CRAWL && // Right clamp buffer. - g_GameFlow->Animations.CrawlExtended) + g_GameFlow->HasCrawlExtended()) { item->animNumber = LA_VAULT_TO_CROUCH_3CLICK; item->frameNumber = GetFrameNumber(item, 0); @@ -266,7 +266,7 @@ bool TestLaraVault(ITEM_INFO* item, COLL_INFO* coll) // Auto jump to monkey swing. if (info->canMonkeySwing && !TestLaraSwamp(item) && - g_GameFlow->Animations.MonkeyAutoJump) + g_GameFlow->HasMonkeyAutoJump()) { short roomNum = item->roomNumber; int ceiling = (GetCeiling(GetFloor(item->pos.xPos, item->pos.yPos, item->pos.zPos, &roomNum), @@ -545,7 +545,7 @@ bool TestLaraHangJump(ITEM_INFO* item, COLL_INFO* coll) if (TestHangSwingIn(item, angle)) { - if (g_GameFlow->Animations.OscillateHang) + if (g_GameFlow->HasOscillateHang()) { ResetLaraFlex(item); SetAnimation(item, LA_REACH_TO_HANG_OSCILLATE); @@ -1107,7 +1107,7 @@ bool TestHangSwingIn(ITEM_INFO* item, short angle) if (floorHeight != NO_HEIGHT) { - if (g_GameFlow->Animations.OscillateHang) + if (g_GameFlow->HasOscillateHang()) { if (floorHeight - y > 0 && ceilingHeight - y < -400) return true; @@ -1370,7 +1370,7 @@ bool TestLaraWaterClimbOut(ITEM_INFO* item, COLL_INFO* coll) { if (headroom < LARA_HEIGHT) { - if (g_GameFlow->Animations.CrawlExtended) + if (g_GameFlow->HasCrawlExtended()) SetAnimation(item, LA_ONWATER_TO_CROUCH_1CLICK); else return false; @@ -1382,7 +1382,7 @@ bool TestLaraWaterClimbOut(ITEM_INFO* item, COLL_INFO* coll) { if (headroom < LARA_HEIGHT) { - if (g_GameFlow->Animations.CrawlExtended) + if (g_GameFlow->HasCrawlExtended()) SetAnimation(item, LA_ONWATER_TO_CROUCH_M1CLICK); else return false; @@ -1395,7 +1395,7 @@ bool TestLaraWaterClimbOut(ITEM_INFO* item, COLL_INFO* coll) { if (headroom < LARA_HEIGHT) { - if (g_GameFlow->Animations.CrawlExtended) + if (g_GameFlow->HasCrawlExtended()) SetAnimation(item, LA_ONWATER_TO_CROUCH_0CLICK); else return false;