Arma Reforger Explorer
1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Toggle main menu visibility
Loading...
Searching...
No Matches
SCR_CacheManagerComponent.c
Go to the documentation of this file.
1
[
ComponentEditorProps
(
category
:
"GameScripted/GameMode/Components"
, description:
"Manager that spawns caches and provides hints"
)]
2
class
SCR_CacheManagerComponentClass
:
SCR_BaseGameModeComponentClass
{}
3
4
class
SCR_CacheManagerComponent :
SCR_BaseGameModeComponent
5
{
6
[
Attribute
(uiwidget:
UIWidgets
.ResourcePickerThumbnail,
category
:
"Cache Config"
,
desc
:
"Prefab to spawn at cache locations (e.g. AmmoBox)"
,
params
:
"et"
)]
7
protected
ResourceName
m_sCachePrefab;
8
9
[
Attribute
(
"3"
,
params
:
"0 inf"
, uiwidget:
UIWidgets
.EditBox,
category
:
"Cache Config"
,
desc
:
"Amount of caches to spawn"
)]
10
int
m_iAmount
;
11
12
[
Attribute
(
category
:
"Cache Config"
,
desc
:
"Cache coordinates config"
,
params
:
"conf"
)]
13
protected
ResourceName
m_sTerrainConfig
;
14
15
protected
ref array<ref SCR_CacheLocationData>
m_aCachePool
= {};
16
protected
ref
SCR_CacheTerrainConfig
m_TerrainConfig
;
17
protected
static
SCR_CacheManagerComponent s_Instance;
18
protected
ref array<string>
m_aActiveCacheHints
= {};
19
20
//------------------------------------------------------------------------------------------------
23
static
SCR_CacheManagerComponent GetInstance()
24
{
25
return
s_Instance
;
26
}
27
28
//------------------------------------------------------------------------------------------------
29
override
void
OnPostInit
(
IEntity
owner)
30
{
31
super.OnPostInit(owner);
32
s_Instance =
this
;
33
}
34
35
//------------------------------------------------------------------------------------------------
36
override
void
OnGameModeStart
()
37
{
38
if
(!
Replication
.IsServer())
39
return
;
40
41
SCR_GameModeCampaign
campaign =
SCR_GameModeCampaign
.GetInstance();
42
if
(!campaign || !campaign.GetSpawnRandomCaches())
43
return
;
44
45
m_TerrainConfig
=
SCR_CacheTerrainConfig
.Cast(
SCR_BaseContainerTools
.CreateInstanceFromPrefab(
m_sTerrainConfig
,
true
));
46
if
(
m_TerrainConfig
&&
m_TerrainConfig
.m_aCachePool)
47
m_aCachePool
=
m_TerrainConfig
.m_aCachePool;
48
49
if
(
m_iAmount
>
m_aCachePool
.Count())
50
m_iAmount
=
m_aCachePool
.Count();
51
52
SpawnRandomCaches
(
m_iAmount
);
53
}
54
55
//------------------------------------------------------------------------------------------------
56
protected
void
SpawnRandomCaches
(
int
count)
57
{
58
if
(
m_aCachePool
.IsEmpty() || m_sCachePrefab.IsEmpty())
59
return
;
60
61
const
string
padding =
"0"
;
62
const
string
coordsFormat =
"%1 %2"
;
63
const
float
startPosOffset = 0.5;
64
const
float
endPosOffset = -1;
65
int
gridX, gridZ;
66
string
output;
67
array<ref SCR_CacheLocationData> tempPool = {};
68
foreach
(
SCR_CacheLocationData
data
:
m_aCachePool
)
69
{
70
tempPool.Insert(
data
);
71
}
72
73
EntitySpawnParams
params
=
new
EntitySpawnParams
();
74
params
.TransformMode = ETransformMode.WORLD;
75
ArmaReforgerScripted
game
=
GetGame
();
76
if
(!
game
)
77
return
;
78
79
BaseWorld
world =
game
.GetWorld();
80
if
(!world)
81
return
;
82
83
vector
startPos;
84
vector
endPos;
85
TraceParam
trace =
new
TraceParam
();
86
trace.Flags =
TraceFlags
.ENTS |
TraceFlags
.WORLD;
87
trace.LayerMask = EPhysicsLayerDefs.Projectile;
88
Resource
cacheResource =
Resource
.Load(m_sCachePrefab);
89
vector
snapPosition;
90
vector
normal;
91
for
(
int
i = 0; i < count; i++)
92
{
93
if
(tempPool.IsEmpty())
94
break
;
95
96
int
idx
=
Math
.RandomInt(0, tempPool.Count());
97
SCR_CacheLocationData
chosen = tempPool[
idx
];
98
startPos = chosen.m_vPosition;
99
startPos[1] = startPos[1] + startPosOffset;
100
endPos = chosen.m_vPosition;
101
endPos[1] = endPos[1] + endPosOffset;
102
trace.Start = startPos;
103
trace.End = endPos;
104
// Tracing the surface under the cache to set correct angles for the spawn. If check goes too far - snapping to the terrain
105
float
hitFraction = world.TraceMove(trace, null);
106
if
(hitFraction < 1.0)
107
{
108
snapPosition = startPos + ((endPos - startPos) * hitFraction);
109
normal = trace.TraceNorm;
110
}
111
else
112
{
113
SCR_TerrainHelper
.
SnapToGeometry
(snapPosition, chosen.m_vPosition, null, world, surfaceNormal: normal);
114
}
115
116
Math3D
.MatrixIdentity4(
params
.Transform);
117
if
(normal !=
vector
.Zero)
118
{
119
Math3D
.MatrixFromUpVec(normal,
params
.Transform);
120
}
121
122
params
.Transform[3] = snapPosition;
123
IEntity
spawnedEntity =
game
.SpawnEntityPrefab(cacheResource, world,
params
);
124
if
(spawnedEntity)
125
{
126
gridX = 0;
127
gridZ = 0;
128
SCR_MapEntity
.
GetGridPos
(
params
.Transform[3], gridX, gridZ);
129
output =
string
.Format(coordsFormat,
SCR_StringHelper
.
PadLeft
(gridX.ToString(), 3, padding),
SCR_StringHelper
.
PadLeft
(gridZ.ToString(), 3, padding));
130
m_aActiveCacheHints
.Insert(output);
131
}
132
133
tempPool.Remove(
idx
);
134
}
135
}
136
137
//------------------------------------------------------------------------------------------------
140
void
GetRandomCacheData
(out notnull array<string> outLines)
141
{
142
outLines.Copy(
m_aActiveCacheHints
);
143
}
144
}
idx
int idx
Definition
AIControlComponentSerializer.c:13
game
ref DSGameConfig game
Definition
DSConfig.c:81
GetGame
ArmaReforgerScripted GetGame()
Definition
game.c:1398
ComponentEditorProps
enum EAIGroupCombatMode ComponentEditorProps(category:"GameScripted/AI", description:"Component for utility AI system for groups")
Definition
SCR_AIGroupUtilityComponent.c:12
SCR_BaseGameModeComponent
void SCR_BaseGameModeComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
Definition
SCR_BaseGameModeComponent.c:171
m_iAmount
int m_iAmount
Definition
SCR_CacheManagerComponent.c:10
OnGameModeStart
override void OnGameModeStart()
Definition
SCR_CacheManagerComponent.c:36
m_TerrainConfig
ref SCR_CacheTerrainConfig m_TerrainConfig
Definition
SCR_CacheManagerComponent.c:16
m_sTerrainConfig
ResourceName m_sTerrainConfig
Definition
SCR_CacheManagerComponent.c:13
SpawnRandomCaches
void SpawnRandomCaches(int count)
Definition
SCR_CacheManagerComponent.c:56
m_aCachePool
ref array< ref SCR_CacheLocationData > m_aCachePool
Definition
SCR_CacheManagerComponent.c:15
m_aActiveCacheHints
ref array< string > m_aActiveCacheHints
Definition
SCR_CacheManagerComponent.c:18
GetRandomCacheData
void GetRandomCacheData(out notnull array< string > outLines)
Definition
SCR_CacheManagerComponent.c:140
data
Get all prefabs that have the spawner data
Definition
SCR_EntityCatalogManagerComponent.c:320
SCR_GameModeCampaign
void SCR_GameModeCampaign(IEntitySource src, IEntity parent)
Definition
SCR_GameModeCampaign.c:1812
desc
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
Definition
SCR_RespawnBriefingComponent.c:17
s_Instance
SCR_SpawnerSlotManagerClass s_Instance
Class used for managing changes and removals of slots present in world.
params
category params
Definition
SCR_SpherePointGeneratorPreviewComponent.c:21
category
params category
Definition
SCR_VehicleDamageManagerComponent.c:302
BaseWorld
Definition
BaseWorld.c:13
IEntity
Definition
IEntity.c:13
Math3D
Definition
Math3D.c:13
Math
Definition
Math.c:13
Replication
Main replication API.
Definition
Replication.c:14
Resource
Object holding reference to resource. In destructor release the resource.
Definition
Resource.c:25
ResourceName
Definition
ResourceName.c:13
SCR_BaseContainerTools
Definition
SCR_BaseContainerTools.c:4
SCR_BaseGameModeComponentClass
Definition
SCR_BaseGameModeComponent.c:3
SCR_CacheLocationData
Definition
SCR_CacheLocationData.c:3
SCR_CacheManagerComponentClass
Definition
SCR_CacheManagerComponent.c:2
SCR_CacheTerrainConfig
Definition
SCR_CacheManagerConfig.c:3
SCR_MapEntity
Definition
SCR_MapEntity.c:18
SCR_MapEntity::GetGridPos
static void GetGridPos(vector pos, out int gridX, out int gridZ, int resMin=2, int resMax=4)
Definition
SCR_MapEntity.c:987
SCR_StringHelper
Definition
SCR_StringHelper.c:2
SCR_StringHelper::PadLeft
static string PadLeft(string input, int length, string padding=SPACE)
Definition
SCR_StringHelper.c:928
SCR_TerrainHelper
Definition
SCR_TerrainHelper.c:2
SCR_TerrainHelper::SnapToGeometry
static void SnapToGeometry(out vector newPosition, vector currentPosition, array< IEntity > excludedEntities, BaseWorld world=null, TraceParam traceParam=null, out vector surfaceNormal=vector.Zero)
Definition
SCR_TerrainHelper.c:160
TraceParam
Definition
TraceParam.c:16
UIWidgets
Definition
attributes.c:40
vector
Definition
vector.c:13
EntitySpawnParams
void EntitySpawnParams()
Definition
gameLib.c:130
Attribute
SCR_FieldOfViewSettings Attribute
Definition
SendGoalMessage.c:170
OnPostInit
@ OnPostInit
Definition
SndComponentCallbacks.c:15
TraceFlags
TraceFlags
Definition
TraceFlags.c:13
scripts
Game
Caches
SCR_CacheManagerComponent.c
Generated by
1.17.0