From a5e70f55cd73dc83ac05c8b23fd44a7772e63404 Mon Sep 17 00:00:00 2001 From: Lpsd <40902730+Lpsd@users.noreply.github.com> Date: Sun, 15 Oct 2023 03:52:14 +0100 Subject: [PATCH] Use std::optional in STaskState Requires moving to Client Deathmatch due to Game SA not supporting C++17 --- Client/mods/deathmatch/logic/CClientGame.cpp | 11 ++++--- Client/mods/deathmatch/logic/CClientTask.h | 31 +++++++++++++++++++ Client/sdk/game/CTaskManager.h | 32 -------------------- 3 files changed, 38 insertions(+), 36 deletions(-) diff --git a/Client/mods/deathmatch/logic/CClientGame.cpp b/Client/mods/deathmatch/logic/CClientGame.cpp index 8e7bea0fc4..6b4b16c40c 100644 --- a/Client/mods/deathmatch/logic/CClientGame.cpp +++ b/Client/mods/deathmatch/logic/CClientGame.cpp @@ -1005,14 +1005,17 @@ void CClientGame::DoPulsePostFrame() while (it != taskStates.end()) { STaskState taskState = (*it); - auto taskSecondary = (taskState.eSecondaryType == -1) ? nullptr : taskManager->GetTaskSecondary(taskState.eSecondaryType); - bool useState = (taskState.eSubTask == -1 && taskState.eSecondaryTask == -1); + + auto taskSecondary = + (!taskState.eSecondaryType.has_value()) ? nullptr : taskManager->GetTaskSecondary(taskState.eSecondaryType.value()); + bool useState = (!taskState.eSubTask.has_value() && !taskState.eSecondaryTask.has_value()); if (!useState) { - if (taskSub != nullptr && taskState.eSubTask == taskSub->GetTaskType()) + if (taskSub != nullptr && taskState.eSubTask.has_value() && taskState.eSubTask.value() == taskSub->GetTaskType()) useState = true; - else if (taskSecondary != nullptr && taskState.eSecondaryTask == taskSecondary->GetTaskType()) + else if (taskSecondary != nullptr && taskState.eSecondaryTask.has_value() && + taskState.eSecondaryTask.value() == taskSecondary->GetTaskType()) useState = true; } diff --git a/Client/mods/deathmatch/logic/CClientTask.h b/Client/mods/deathmatch/logic/CClientTask.h index 5e8d48fbe5..0a6e8f588b 100644 --- a/Client/mods/deathmatch/logic/CClientTask.h +++ b/Client/mods/deathmatch/logic/CClientTask.h @@ -13,6 +13,7 @@ #include #include "lua/LuaCommon.h" #include "CClientEntity.h" +#include class CClientEntity; class CClientManager; @@ -23,6 +24,36 @@ class CPed; class CTask; class CVehicle; +struct STaskState +{ + bool bUseZone; + std::string strState; + std::optional eSubTask = {}; + std::optional eSecondaryTask = {}; + std::optional eSecondaryType = {}; +}; + +static const std::multimap g_playerTaskStates{ + {TASK_COMPLEX_JUMP, {true, "Climbing around in", TASK_SIMPLE_CLIMB}}, + {TASK_SIMPLE_GANG_DRIVEBY, {true, "Doing a drive-by in"}}, + {TASK_SIMPLE_DRIVEBY_SHOOT, {true, "Doing a drive-by in"}}, + {TASK_SIMPLE_DIE, {false, "Blub blub...", TASK_SIMPLE_DROWN}}, + {TASK_SIMPLE_DIE, {false, "Breathing water", TASK_SIMPLE_DROWN}}, + {TASK_SIMPLE_DIE, {true, "Drowning in", TASK_SIMPLE_DROWN}}, + {TASK_SIMPLE_PLAYER_ON_FOOT, {true, "Ducking for cover in", {}, TASK_SIMPLE_DUCK, TASK_SECONDARY_DUCK}}, + {TASK_SIMPLE_PLAYER_ON_FOOT, {true, "Fighting in", {}, TASK_SIMPLE_FIGHT, TASK_SECONDARY_ATTACK}}, + {TASK_SIMPLE_PLAYER_ON_FOOT, {true, "Throwing fists in", {}, TASK_SIMPLE_FIGHT, TASK_SECONDARY_ATTACK}}, + {TASK_SIMPLE_PLAYER_ON_FOOT, {true, "Blastin' fools in", {}, TASK_SIMPLE_USE_GUN, TASK_SECONDARY_ATTACK}}, + {TASK_SIMPLE_PLAYER_ON_FOOT, {true, "Shooting up", {}, TASK_SIMPLE_USE_GUN, TASK_SECONDARY_ATTACK}}, + {TASK_SIMPLE_JETPACK, {true, "Jetpacking in"}}, + {TASK_SIMPLE_PLAYER_ON_FOOT, {true, "Literally on fire in", {}, TASK_SIMPLE_PLAYER_ON_FIRE, TASK_SECONDARY_PARTIAL_ANIM}}, + {TASK_SIMPLE_PLAYER_ON_FOOT, {true, "Burning up in", {}, TASK_SIMPLE_PLAYER_ON_FIRE, TASK_SECONDARY_PARTIAL_ANIM}}, + {TASK_COMPLEX_IN_WATER, {true, "Swimming in", TASK_SIMPLE_SWIM}}, + {TASK_COMPLEX_IN_WATER, {true, "Floating around in", TASK_SIMPLE_SWIM}}, + {TASK_COMPLEX_IN_WATER, {false, "Being chased by a shark", TASK_SIMPLE_SWIM}}, + {TASK_SIMPLE_CHOKING, {true, "Choking to death in"}}, +}; + class CClientTask { public: diff --git a/Client/sdk/game/CTaskManager.h b/Client/sdk/game/CTaskManager.h index 1348a9a679..3467f34928 100644 --- a/Client/sdk/game/CTaskManager.h +++ b/Client/sdk/game/CTaskManager.h @@ -13,8 +13,6 @@ class CTask; -#include "TaskTypes.h" - enum { TASK_PRIORITY_PHYSICAL_RESPONSE = 0, @@ -43,36 +41,6 @@ enum ABORT_PRIORITY_IMMEDIATE }; -struct STaskState -{ - bool bUseZone; - std::string strState; - eTaskType eSubTask = static_cast(-1); - eTaskType eSecondaryTask = static_cast(-1); - eSecondaryTaskType eSecondaryType = static_cast(-1); -}; - -static const std::multimap g_playerTaskStates{ - {TASK_COMPLEX_JUMP, {true, "Climbing around in", TASK_SIMPLE_CLIMB}}, - {TASK_SIMPLE_GANG_DRIVEBY, {true, "Doing a drive-by in"}}, - {TASK_SIMPLE_DRIVEBY_SHOOT, {true, "Doing a drive-by in"}}, - {TASK_SIMPLE_DIE, {false, "Blub blub...", TASK_SIMPLE_DROWN}}, - {TASK_SIMPLE_DIE, {false, "Breathing water", TASK_SIMPLE_DROWN}}, - {TASK_SIMPLE_DIE, {true, "Drowning in", TASK_SIMPLE_DROWN}}, - {TASK_SIMPLE_PLAYER_ON_FOOT, {true, "Ducking for cover in", {}, TASK_SIMPLE_DUCK, TASK_SECONDARY_DUCK}}, - {TASK_SIMPLE_PLAYER_ON_FOOT, {true, "Fighting in", {}, TASK_SIMPLE_FIGHT, TASK_SECONDARY_ATTACK}}, - {TASK_SIMPLE_PLAYER_ON_FOOT, {true, "Throwing fists in", {}, TASK_SIMPLE_FIGHT, TASK_SECONDARY_ATTACK}}, - {TASK_SIMPLE_PLAYER_ON_FOOT, {true, "Blastin' fools in", TASK_SIMPLE_USE_GUN}}, - {TASK_SIMPLE_PLAYER_ON_FOOT, {true, "Shooting up", TASK_SIMPLE_USE_GUN}}, - {TASK_SIMPLE_JETPACK, {true, "Jetpacking in"}}, - {TASK_SIMPLE_PLAYER_ON_FOOT, {true, "Literally on fire in", {}, TASK_SIMPLE_PLAYER_ON_FIRE, TASK_SECONDARY_PARTIAL_ANIM}}, - {TASK_SIMPLE_PLAYER_ON_FOOT, {true, "Burning up in", {}, TASK_SIMPLE_PLAYER_ON_FIRE, TASK_SECONDARY_PARTIAL_ANIM}}, - {TASK_COMPLEX_IN_WATER, {true, "Swimming in", TASK_SIMPLE_SWIM}}, - {TASK_COMPLEX_IN_WATER, {true, "Floating around in", TASK_SIMPLE_SWIM}}, - {TASK_COMPLEX_IN_WATER, {false, "Being chased by a shark", TASK_SIMPLE_SWIM}}, - {TASK_SIMPLE_CHOKING, {true, "Choking to death in"}}, -}; - class CTaskManager { public: