Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
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")]
3
4class 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")]
11
12 [Attribute(category: "Cache Config", desc: "Cache coordinates config", params: "conf")]
14
15 protected ref array<ref SCR_CacheLocationData> m_aCachePool = {};
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
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
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 = {};
69 {
70 tempPool.Insert(data);
71 }
72
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}
ref DSGameConfig game
Definition DSConfig.c:81
ArmaReforgerScripted GetGame()
Definition game.c:1398
enum EAIGroupCombatMode ComponentEditorProps(category:"GameScripted/AI", description:"Component for utility AI system for groups")
void SCR_BaseGameModeComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
override void OnGameModeStart()
ref SCR_CacheTerrainConfig m_TerrainConfig
ResourceName m_sTerrainConfig
void SpawnRandomCaches(int count)
ref array< ref SCR_CacheLocationData > m_aCachePool
ref array< string > m_aActiveCacheHints
void GetRandomCacheData(out notnull array< string > outLines)
Get all prefabs that have the spawner data
void SCR_GameModeCampaign(IEntitySource src, IEntity parent)
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
SCR_SpawnerSlotManagerClass s_Instance
Class used for managing changes and removals of slots present in world.
Definition Math.c:13
Main replication API.
Definition Replication.c:14
Object holding reference to resource. In destructor release the resource.
Definition Resource.c:25
static void GetGridPos(vector pos, out int gridX, out int gridZ, int resMin=2, int resMax=4)
static string PadLeft(string input, int length, string padding=SPACE)
static void SnapToGeometry(out vector newPosition, vector currentPosition, array< IEntity > excludedEntities, BaseWorld world=null, TraceParam traceParam=null, out vector surfaceNormal=vector.Zero)
void EntitySpawnParams()
Definition gameLib.c:130
SCR_FieldOfViewSettings Attribute
TraceFlags
Definition TraceFlags.c:13