Skip to content

Commit 426c411

Browse files
committed
Added CDecisionMakerTypes class
1 parent 9d8e820 commit 426c411

File tree

5 files changed

+157
-32
lines changed

5 files changed

+157
-32
lines changed

plugin_sa/game_sa/CDecisionMaker.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Plugin-SDK (Grand Theft Auto San Andreas) header file
2+
Plugin-SDK (Grand Theft Auto San Andreas) source file
33
Authors: GTA Community. See more here
44
https://github.com/DK22Pac/plugin-sdk
55
Do not delete this comment block. Respect others' work!
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
Plugin-SDK (Grand Theft Auto San Andreas) source file
3+
Authors: GTA Community. See more here
4+
https://github.com/DK22Pac/plugin-sdk
5+
Do not delete this comment block. Respect others' work!
6+
*/
7+
#include "CDecisionMakerTypes.h"
8+
9+
CDecisionMakerTypes* CDecisionMakerTypes::GetInstance() {
10+
return plugin::CallAndReturn<CDecisionMakerTypes*, 0x4684F0>();
11+
}
12+
13+
eDecisionMakerType CDecisionMakerTypes::AddDecisionMaker(CDecisionMaker* templateDm, eDecisionMakerType dm, bool bDecisionMakerForMission) {
14+
return plugin::CallMethodAndReturn<eDecisionMakerType, 0x607050, CDecisionMakerTypes*, CDecisionMaker*, eDecisionMakerType, bool>(this, templateDm, dm, bDecisionMakerForMission);
15+
}
16+
17+
void CDecisionMakerTypes::RemoveDecisionMaker(eDecisionMakerType dm) {
18+
return plugin::Call<0x6043A0>(dm);
19+
}
20+
21+
void CDecisionMakerTypes::AddEventResponse(eDecisionMakerType dm, eEventType eventType, eTaskType taskId, DecisionChances chances, DecisionContext context) {
22+
float chancesF[4]; // internally converted back to byte
23+
chancesF[0] = chances.toNeutral;
24+
chancesF[1] = chances.toPlayer;
25+
chancesF[2] = chances.toFriend;
26+
chancesF[3] = chances.toEnemy;
27+
28+
plugin::CallMethod<0x6044C0, CDecisionMakerTypes*, eDecisionMakerType, eEventType, eTaskType, float*, DecisionContext&>(this, dm, eventType, taskId, chancesF, context);
29+
}
30+
31+
void CDecisionMakerTypes::FlushDecisionMakerEventResponse(eDecisionMakerType dm, eEventType eventId) {
32+
plugin::CallMethod<0x604490>(this, dm, eventId);
33+
}
34+
35+
eTaskType CDecisionMakerTypes::MakeDecision(CPedGroup* pedGroup, eEventType eventType, int eventSourceType, bool bIsPedInVehicle, eTaskType taskId1, eTaskType taskId2, eTaskType taskId3, eTaskType taskId4) {
36+
return plugin::CallMethodAndReturn<eTaskType, 0x606F80, CDecisionMakerTypes*, CPedGroup*, int, int, bool, int, int, int, int>(
37+
this, pedGroup, eventType, eventSourceType, bIsPedInVehicle, taskId1, taskId2, taskId3, taskId4);
38+
}
39+
40+
void CDecisionMakerTypes::MakeDecision(CPed* ped, eEventType eventType, int eventSourceType, bool bIsPedInVehicle, eTaskType taskTypeToAvoid1, eTaskType taskTypeToAvoid2, eTaskType taskTypeToAvoid3, eTaskType taskTypeToSeek, bool bUseInGroupDecisionMaker, short& taskType, short& facialTaskType) {
41+
plugin::CallMethod<0x606E70>(this, ped, eventType, eventSourceType, bIsPedInVehicle, taskTypeToAvoid1, taskTypeToAvoid2, taskTypeToAvoid3, taskTypeToSeek, bUseInGroupDecisionMaker, &taskType, &facialTaskType);
42+
}
43+
44+
void CDecisionMakerTypes::LoadEventIndices() {
45+
plugin::CallMethod<0x600840>(this);
46+
}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/*
2+
Plugin-SDK (Grand Theft Auto San Andreas) header file
3+
Authors: GTA Community. See more here
4+
https://github.com/DK22Pac/plugin-sdk
5+
Do not delete this comment block. Respect others' work!
6+
*/
7+
#pragma once
8+
9+
#include "CDecision.h"
10+
#include "CDecisionMaker.h"
11+
#include "eEventType.h"
12+
#include "eTaskType.h"
13+
14+
class CPed;
15+
class CPedGroup;
16+
17+
enum class PLUGIN_API eDecisionMakerType : int {
18+
UNKNOWN = -1,
19+
20+
PED_GROUPMEMBER,
21+
PED_COP,
22+
PED_RANDOM1,
23+
PED_RANDOM2,
24+
PED_RANDOM3,
25+
PED_FIREMAN,
26+
PED_EMPTY,
27+
PED_INDOORS,
28+
29+
GROUP_RANDOM_AGGRESSIVE,
30+
GROUP_RANDOM_PASSIVE,
31+
32+
MISSION0,
33+
MISSION1,
34+
MISSION2,
35+
MISSION3,
36+
MISSION4,
37+
MISSION5,
38+
MISSION6,
39+
MISSION7,
40+
MISSION8,
41+
MISSION9,
42+
43+
COUNT_TOTAL,
44+
COUNT_GAME_DM = MISSION0, // Number of built-in decision makers
45+
};
46+
47+
class CDecisionMakerTypes {
48+
public:
49+
static constexpr auto NUM_TYPES = 20u;
50+
51+
static inline auto& ScriptReferenceIndex = *(std::array<unsigned short, NUM_TYPES>*)0xC0AFF4;
52+
static inline auto& m_IsActive = *(std::array<bool, NUM_TYPES>*)0xC0B01C;
53+
54+
static CDecisionMakerTypes* GetInstance(); // get global Decision Maker manager
55+
56+
eDecisionMakerType AddDecisionMaker(CDecisionMaker* templateDm, eDecisionMakerType dm = eDecisionMakerType::UNKNOWN, bool bDecisionMakerForMission = false);
57+
void RemoveDecisionMaker(eDecisionMakerType dm);
58+
59+
void AddEventResponse(eDecisionMakerType dm, eEventType eventType, eTaskType taskId, DecisionChances chances, DecisionContext context);
60+
void FlushDecisionMakerEventResponse(eDecisionMakerType dm, eEventType eventId);
61+
62+
eTaskType MakeDecision(CPedGroup* pedGroup, eEventType eventType, int eventSourceType, bool bIsPedInVehicle, eTaskType taskId1, eTaskType taskId2, eTaskType taskId3, eTaskType taskId4);
63+
void MakeDecision(CPed* ped, eEventType eventType, int eventSourceType, bool bIsPedInVehicle, eTaskType taskTypeToAvoid1, eTaskType taskTypeToAvoid2, eTaskType taskTypeToAvoid3, eTaskType taskTypeToSeek, bool bUseInGroupDecisionMaker, short& taskType, short& facialTaskType);
64+
65+
void LoadEventIndices();
66+
67+
public:
68+
int m_NoOfDecisionMakers;
69+
CDecisionMaker m_DecisionMakers[(size_t)eDecisionMakerType::COUNT_TOTAL];
70+
int m_EventIndices[(size_t)eEventType::EVENT_TOTAL_NUM_EVENTS];
71+
CDecisionMaker m_DefaultRandomPedDecisionMaker;
72+
CDecisionMaker m_DefaultMissionPedDecisionMaker;
73+
CDecisionMaker m_DefaultPlayerPedDecisionMaker;
74+
CDecisionMaker m_DefaultRandomPedGroupDecisionMaker;
75+
CDecisionMaker m_DefaultMissionPedGroupDecisionMaker;
76+
};

plugin_sa/game_sa/CPedIntelligence.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,16 @@
66
*/
77
#include "CPedIntelligence.h"
88

9+
using namespace plugin;
10+
911
// Converted from thiscall void CPedIntelligence::SetPedDecisionMakerType(int newtype) 0x600B50
10-
void CPedIntelligence::SetPedDecisionMakerType(int newtype) {
11-
plugin::CallMethod<0x600B50, CPedIntelligence *, int>(this, newtype);
12+
void CPedIntelligence::SetPedDecisionMakerType(eDecisionMakerType dm) {
13+
plugin::CallMethod<0x600B50, CPedIntelligence*, eDecisionMakerType>(this, dm);
1214
}
1315

1416
// Converted from thiscall void CPedIntelligence::SetPedDecisionMakerTypeInGroup(int newtype) 0x600BB0
15-
void CPedIntelligence::SetPedDecisionMakerTypeInGroup(int newtype) {
16-
plugin::CallMethod<0x600BB0, CPedIntelligence *, int>(this, newtype);
17+
void CPedIntelligence::SetPedDecisionMakerTypeInGroup(eDecisionMakerType dm) {
18+
plugin::CallMethod<0x600BB0, CPedIntelligence*, eDecisionMakerType>(this, dm);
1719
}
1820

1921
// Converted from thiscall void CPedIntelligence::RestorePedDecisionMakerType(void) 0x600BC0

plugin_sa/game_sa/CPedIntelligence.h

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#pragma once
88

99
#include "PluginBase.h"
10+
#include "CDecisionMakerTypes.h"
1011
#include "CTaskManager.h"
1112
#include "CEventHandler.h"
1213
#include "CEventGroup.h"
@@ -28,35 +29,35 @@
2829

2930
class PLUGIN_API CPedIntelligence {
3031
public:
31-
class CPed* m_pPed;
32-
CTaskManager m_TaskMgr;
33-
CEventHandler m_eventHandler;
34-
CEventGroup m_eventGroup;
35-
unsigned int m_nDecisionMakerType;
36-
unsigned int m_nDecisionMakerTypeInGroup;
37-
float m_fHearingRange;
38-
float m_fSeeingRange;
39-
unsigned int m_nDmNumPedsToScan;
40-
float m_fDmRadius;
41-
float m_FollowNodeThresholdDistance;
42-
char m_NextEventResponseSequence;
43-
unsigned char m_nEventId;
44-
unsigned char m_nEventPriority;
45-
char field_D3;
46-
CEntityScanner m_vehicleScanner;
47-
CEntityScanner m_pedScanner;
48-
CMentalState m_mentalState;
49-
char field_188;
50-
CEventScanner m_eventScanner;
32+
class CPed* m_pPed;
33+
CTaskManager m_TaskMgr;
34+
CEventHandler m_eventHandler;
35+
CEventGroup m_eventGroup;
36+
eDecisionMakerType m_nDecisionMakerType;
37+
eDecisionMakerType m_nDecisionMakerTypeInGroup;
38+
float m_fHearingRange;
39+
float m_fSeeingRange;
40+
unsigned int m_nDmNumPedsToScan;
41+
float m_fDmRadius;
42+
float m_FollowNodeThresholdDistance;
43+
char m_NextEventResponseSequence;
44+
unsigned char m_nEventId;
45+
unsigned char m_nEventPriority;
46+
char field_D3;
47+
CEntityScanner m_vehicleScanner;
48+
CEntityScanner m_pedScanner;
49+
CMentalState m_mentalState;
50+
char field_188;
51+
CEventScanner m_eventScanner;
5152
CCollisionEventScanner m_collisionScanner;
52-
CPedStuckChecker m_pedStuckChecker;
53-
int m_AnotherStaticCounter;
54-
int m_StaticCounter;
55-
CVector m_vecLastPedPosDuringDamageEntity;
56-
class CEntity* m_apInterestingEntities[3];
53+
CPedStuckChecker m_pedStuckChecker;
54+
int m_AnotherStaticCounter;
55+
int m_StaticCounter;
56+
CVector m_vecLastPedPosDuringDamageEntity;
57+
class CEntity* m_apInterestingEntities[3];
5758

58-
void SetPedDecisionMakerType(int newtype);
59-
void SetPedDecisionMakerTypeInGroup(int newtype);
59+
void SetPedDecisionMakerType(eDecisionMakerType dm);
60+
void SetPedDecisionMakerTypeInGroup(eDecisionMakerType dm);
6061
void RestorePedDecisionMakerType();
6162
void SetHearingRange(float range);
6263
void SetSeeingRange(float range);

0 commit comments

Comments
 (0)