Arma Reforger Explorer
1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Toggle main menu visibility
Loading...
Searching...
No Matches
AIControlComponentSerializer.c
Go to the documentation of this file.
1
class
SCR_PersistentThreatSector
2
{
3
int
idx;
4
vector
estimatedPos;
5
float
danger;
6
SCR_EAIThreatSectorFlags
flags;
7
}
8
9
class
AIControlComponentSerializer :
ScriptedComponentSerializer
10
{
11
//------------------------------------------------------------------------------------------------
12
override
static
typename
GetTargetType
()
13
{
14
return
AIControlComponent;
15
}
16
17
//------------------------------------------------------------------------------------------------
18
override
protected
ESerializeResult
Serialize
(notnull
IEntity
owner, notnull
GenericComponent
component, notnull
SaveContext
context)
19
{
20
const
SCR_ChimeraAIAgent
agent =
SCR_ChimeraAIAgent
.Cast(
SCR_AIUtils
.GetAIAgent(owner));
21
if
(!agent)
22
return
ESerializeResult
.DEFAULT;
23
24
const
SCR_AIUtilityComponent utility = agent.m_UtilityComponent;
25
if
(!utility)
26
return
ESerializeResult
.DEFAULT;
27
28
float
suppresion, shotsFired, injury, endangered;
29
utility.m_ThreatSystem.GetThreatValues(suppresion, shotsFired, injury, endangered);
30
const
bool
threatSystemDefault =
float
.AlmostEqual(suppresion + shotsFired + injury + endangered, 0);
31
32
array<ref SCR_PersistentThreatSector> threatSectors();
33
for
(
int
i = 0; i < utility.m_SectorThreatFilter.SECTOR_COUNT; ++i)
34
{
35
SCR_AIThreatSector sector = utility.m_SectorThreatFilter.GetSector(i);
36
if
(sector.m_iState == SCR_AIThreatSector.SECTOR_STATE_IDLE ||
float
.AlmostEqual(sector.m_fDanger, 0))
37
continue
;
38
39
SCR_PersistentThreatSector
threatSector();
40
threatSector.idx = i;
41
threatSector.estimatedPos = sector.m_vEstimatedPos;
42
threatSector.danger = sector.m_fDanger;
43
threatSector.flags = sector.m_eFlags;
44
threatSectors.Insert(threatSector);
45
}
46
47
if
(threatSystemDefault && threatSectors.IsEmpty())
48
return
ESerializeResult
.DEFAULT;
49
50
context.WriteValue(
"version"
, 1);
51
52
// Threat system info
53
if
(!threatSystemDefault)
54
{
55
context.StartObject(
"threatSystem"
);
// We can skip threat if it is all near 0
56
context.WriteDefault(suppresion, 0.0);
57
context.WriteDefault(shotsFired, 0.0);
58
context.WriteDefault(injury, 0.0);
59
context.WriteDefault(endangered, 0.0);
60
context.EndObject();
61
}
62
63
// Threat sectors
64
context.Write(threatSectors);
65
66
return
ESerializeResult
.OK;
67
}
68
69
//------------------------------------------------------------------------------------------------
70
override
protected
bool
Deserialize
(notnull
IEntity
owner, notnull
GenericComponent
component, notnull
LoadContext
context)
71
{
72
SCR_ChimeraAIAgent
agent =
SCR_ChimeraAIAgent
.Cast(
SCR_AIUtils
.GetAIAgent(owner));
73
if
(!agent)
74
return
true
;
75
76
SCR_AIUtilityComponent utility = agent.m_UtilityComponent;
77
if
(!utility)
78
return
true
;
79
80
int
version;
81
context.Read(version);
82
83
// Threat system info
84
if
(context.DoesObjectExist(
"threatSystem"
))
85
{
86
float
suppresion, shotsFired, injury, endangered;
87
88
context.StartObject(
"threatSystem"
);
89
context.ReadDefault(suppresion, 0.0);
90
context.ReadDefault(shotsFired, 0.0);
91
context.ReadDefault(injury, 0.0);
92
context.ReadDefault(endangered, 0.0);
93
context.EndObject();
94
95
utility.m_ThreatSystem.SetThreatValues(suppresion, shotsFired, injury, endangered);
96
// m_fThreatTotal is updated through system update with current behavior on load
97
}
98
99
const
WorldTimestamp
timestamp =
GetGame
().GetWorld().GetTimestamp();
100
array<ref SCR_PersistentThreatSector> threatSectors();
101
context.Read(threatSectors);
102
foreach
(
auto
threatSector : threatSectors)
103
{
104
SCR_AIThreatSector sector = utility.m_SectorThreatFilter.GetSector(threatSector.idx);
105
if
(!sector)
106
continue
;
107
108
sector.m_vEstimatedPos = threatSector.estimatedPos;
109
sector.m_fMaxDangerBumpSinceLastUpdate = threatSector.danger;
110
sector.m_eFlags = threatSector.flags;
111
sector.m_iState = SCR_AIThreatSector.SECTOR_STATE_ACTIVE;
112
sector.m_fTimestampLastUpdateWithEvents = timestamp;
113
sector.m_fTimestampStart = timestamp;
114
}
115
116
return
true
;
117
}
118
}
GetTargetType
class SCR_PersistentThreatSector GetTargetType()
Definition
AIControlComponentSerializer.c:12
GetGame
ArmaReforgerScripted GetGame()
Definition
game.c:1398
SCR_EAIThreatSectorFlags
SCR_EAIThreatSectorFlags
Definition
SCR_AISectorThreatFilter.c:2
GenericComponent
Definition
GenericComponent.c:13
IEntity
Definition
IEntity.c:13
LoadContext
Definition
LoadContext.c:17
SCR_AIUtils
Definition
SCR_AIUtils.c:667
SCR_ChimeraAIAgent
Definition
SCR_ChimeraAIAgent.c:6
SCR_PersistentThreatSector
Definition
AIControlComponentSerializer.c:2
SaveContext
Definition
SaveContext.c:17
ScriptedComponentSerializer
Definition
ScriptedComponentSerializer.c:13
ScriptedComponentSerializer::Serialize
ESerializeResult Serialize(notnull IEntity owner, notnull GenericComponent component, notnull SaveContext context)
Definition
ScriptedComponentSerializer.c:34
ScriptedComponentSerializer::Deserialize
bool Deserialize(notnull IEntity owner, notnull GenericComponent component, notnull LoadContext context)
Definition
ScriptedComponentSerializer.c:39
WorldTimestamp
Definition
WorldTimestamp.c:26
vector
Definition
vector.c:13
ESerializeResult
ESerializeResult
Definition
ESerializeResult.c:13
scripts
Game
Plugins
Persistence
System
Serializers
Components
AI
AIControlComponentSerializer.c
Generated by
1.17.0