Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_WallGroupContainer.c
Go to the documentation of this file.
1#ifdef WORKBENCH
3class SCR_WallGroupContainer
4{
5 bool m_bGenerated;
6 float m_fMiddleObjectLength;
7 float m_fSmallestWall = float.MAX;
8
9 // for quick access, wallgroup lengths are in a seperate array (indices corresponding with those in wallgroup array)
10 protected ref array<float> m_aLengths = {};
11
12 protected ref array<ref SCR_WallGroup> m_aWallGroups = {}; // sorted by ascending length
13
14 //------------------------------------------------------------------------------------------------
16 bool IsEmpty()
17 {
18 return m_aWallGroups.IsEmpty();
19 }
20
21 //------------------------------------------------------------------------------------------------
24 SCR_WallPair GetRandomWall(float biggestSmallerThan, float value01)
25 {
26 for (int i = m_aLengths.Count() - 1; i >= 0; --i) // find the longest wall which is smaller than given amount
27 {
28 if (m_aLengths[i] < biggestSmallerThan)
29 return m_aWallGroups[i].GetRandomWall(value01);
30 }
31
32 return null;
33 }
34
35 //------------------------------------------------------------------------------------------------
40 void PrepareWallGroups(notnull array<ref WallLengthGroup> groups, bool forward, string middleObj)
41 {
42 m_aWallGroups.Clear();
43
44 array<ref SCR_WallGroup> wallGroupsTmp = {};
45
46 int forwardAxis;
47 if (!forward)
48 forwardAxis = 2;
49
50 if (!middleObj.IsEmpty())
51 m_fMiddleObjectLength = WallGeneratorEntity.MeasureEntity(middleObj, forwardAxis);
52
53 SCR_WallGroup wallGroup;
54 SCR_WallPair wallPair;
55 float wallLength;
56 foreach (WallLengthGroup group : groups)
57 {
58 wallGroup = new SCR_WallGroup();
59
60 foreach (WallWeightPair pair : group.m_aWallPrefabs)
61 {
62 wallPair = new SCR_WallPair();
63
64 wallPair.m_sWallAsset = pair.m_sWallAsset;
65 wallPair.m_fPostPadding = pair.m_fPostPadding;
66 wallPair.m_fPrePadding = pair.m_fPrePadding;
67 wallGroup.m_aWeights.Insert(pair.m_fWeight);
68
69 wallLength = WallGeneratorEntity.MeasureEntity(wallPair.m_sWallAsset, forwardAxis);
70 // wallLength += wallPair.m_fPostPadding;
71 wallPair.m_fWallLength = wallLength;
72
73 if (wallLength > wallGroup.m_fWallLength)
74 wallGroup.m_fWallLength = wallLength; // biggest length is the one being used for the whole group
75
76 if (!wallPair.m_sWallAsset.IsEmpty())
77 wallGroup.m_aWallPairs.Insert(wallPair);
78 }
79
80 if (!wallGroup.m_aWallPairs.IsEmpty())
81 {
82 wallGroupsTmp.Insert(wallGroup);
83 m_bGenerated = true;
84 }
85 }
86
87 // order groups by length
88 while (!wallGroupsTmp.IsEmpty())
89 {
90 float smallestSize = float.MAX;
91 float smallestIndex;
92 foreach (int i, SCR_WallGroup groupTmp : wallGroupsTmp)
93 {
94 if (groupTmp.m_fWallLength < smallestSize)
95 {
96 smallestSize = groupTmp.m_fWallLength;
97 if (smallestSize < m_fSmallestWall)
98 m_fSmallestWall = smallestSize;
99
100 smallestIndex = i;
101 }
102 }
103
104 m_aWallGroups.Insert(wallGroupsTmp[smallestIndex]);
105 m_aLengths.Insert(wallGroupsTmp[smallestIndex].m_fWallLength);
106 wallGroupsTmp.Remove(smallestIndex);
107 }
108 }
109
110 //------------------------------------------------------------------------------------------------
111 // constructor
112 void SCR_WallGroupContainer(notnull array<ref WallLengthGroup> items, bool forward, string middleObj)
113 {
114 PrepareWallGroups(items, forward, middleObj);
115 }
116}
117#endif // WORKBENCH
proto native bool IsEmpty()