Skip to content

Commit

Permalink
Use std::optional in STaskState
Browse files Browse the repository at this point in the history
Requires moving to Client Deathmatch due to Game SA not supporting C++17
  • Loading branch information
Lpsd committed Oct 15, 2023
1 parent d6a27b2 commit a5e70f5
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 36 deletions.
11 changes: 7 additions & 4 deletions Client/mods/deathmatch/logic/CClientGame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
31 changes: 31 additions & 0 deletions Client/mods/deathmatch/logic/CClientTask.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <list>
#include "lua/LuaCommon.h"
#include "CClientEntity.h"
#include <game/CTaskManager.h>

class CClientEntity;
class CClientManager;
Expand All @@ -23,6 +24,36 @@ class CPed;
class CTask;
class CVehicle;

struct STaskState
{
bool bUseZone;
std::string strState;
std::optional<eTaskType> eSubTask = {};
std::optional<eTaskType> eSecondaryTask = {};
std::optional<eSecondaryTaskType> eSecondaryType = {};
};

static const std::multimap<eTaskType, STaskState> 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:
Expand Down
32 changes: 0 additions & 32 deletions Client/sdk/game/CTaskManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@

class CTask;

#include "TaskTypes.h"

enum
{
TASK_PRIORITY_PHYSICAL_RESPONSE = 0,
Expand Down Expand Up @@ -43,36 +41,6 @@ enum
ABORT_PRIORITY_IMMEDIATE
};

struct STaskState
{
bool bUseZone;
std::string strState;
eTaskType eSubTask = static_cast<eTaskType>(-1);
eTaskType eSecondaryTask = static_cast<eTaskType>(-1);
eSecondaryTaskType eSecondaryType = static_cast<eSecondaryTaskType>(-1);
};

static const std::multimap<eTaskType, STaskState> 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:
Expand Down

0 comments on commit a5e70f5

Please sign in to comment.