Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_CompositionValidationEntity.c
Go to the documentation of this file.
1 //#define DEBUG_SHAPE
2 [EntityEditorProps(category: "GameScripted/Editor", description: "Core Editor manager", color: "251 91 0 255", dynamicBox: true)]
4 {
5 };
6 
8 {
9  [Attribute(category: "Slot")]
10  private vector m_vSlotSize;
11 
12  [Attribute(category: "Slot")]
13  private bool m_bIsRectangle;
14 
15  [Attribute(defvalue: "0.1")]
16  private float m_fRefreshRate;
17 
18 #ifdef WORKBENCH
19  private bool m_bCompositionSearched;
20  private WorldEditorAPI m_API;
21  private IEntitySource m_CompositionSource;
22  private float m_fTime;
23  private ref DebugTextScreenSpace m_Title;
24  private ref DebugTextScreenSpace m_Text;
25 #ifdef DEBUG_SHAPE
26  private ref Shape m_Shape;
27 #endif
28 
29  protected bool InArea(vector pos)
30  {
31  pos = CoordToLocal(pos);
32  float sizeX = m_vSlotSize[0];
33  float sizeY = m_vSlotSize[1];
34  float sizeZ = m_vSlotSize[2];
35 
36  if (m_bIsRectangle)
37  {
38  return (pos[0] > -sizeX && pos[0] < sizeX) && (pos[2] > -sizeZ && pos[2] < sizeZ);
39  }
40  else
41  {
42  return Vector(pos[0], 0, pos[2]).Length() < sizeX;
43  }
44  }
45 
46  protected bool FindComposition()
47  {
48  if (m_bCompositionSearched)
49  {
50  if (m_CompositionSource)
51  return true;
52  else
53  return false;
54  }
55 
56  m_bCompositionSearched = true;
57 
58  WorldEditor worldEditor = Workbench.GetModule(WorldEditor);
59  if (!worldEditor) return false;
60 
61  m_API = worldEditor.GetApi();
62  if (!m_API) return false;
63 
64  for (int i = 0, containersCount = worldEditor.GetNumContainers(); i < containersCount; i++)
65  {
66  IEntitySource entitySource = IEntitySource.Cast(worldEditor.GetContainer(i));
67  if (!entitySource || entitySource.GetSubScene() != m_API.GetCurrentSubScene() || entitySource.GetLayerID() != m_API.GetCurrentEntityLayerId()) continue;
68 
69  //--- Get composition prefab
70  m_CompositionSource = entitySource;
71  break;
72  }
73  if (!m_CompositionSource)
74  {
75  Print("Cannot find the composition, no entities are present in the current layer.", LogLevel.WARNING);
76  return false;
77  }
78  m_Title.SetText(m_CompositionSource.GetResourceName());
79  return true;
80  }
81 
82  protected void ProcessEntities(IEntitySource entitySource, out int count)
83  {
84  IEntitySource childSource;
85  IEntity child;
86  vector boundMin, boundMax;
87  vector boundPoints[8];
88  bool inArea;
89  for (int i = 0, countChildren = entitySource.GetNumChildren(); i < countChildren; i++)
90  {
91  childSource = entitySource.GetChild(i);
92  child = m_API.SourceToEntity(childSource);
93  if (!child) continue;
94 
95  //--- Check if it's inside slot area
96  child.GetBounds(boundMin, boundMax);
97  if (!InArea(child.CoordToParent(Vector(boundMin[0], boundMin[1], boundMin[2])))
98  || !InArea(child.CoordToParent(Vector(boundMax[0], boundMin[1], boundMin[2])))
99  || !InArea(child.CoordToParent(Vector(boundMin[0], boundMax[1], boundMin[2])))
100  || !InArea(child.CoordToParent(Vector(boundMax[0], boundMax[1], boundMin[2])))
101  || !InArea(child.CoordToParent(Vector(boundMin[0], boundMin[1], boundMax[2])))
102  || !InArea(child.CoordToParent(Vector(boundMax[0], boundMin[1], boundMax[2])))
103  || !InArea(child.CoordToParent(Vector(boundMin[0], boundMax[1], boundMax[2])))
104  || !InArea(child.CoordToParent(Vector(boundMax[0], boundMax[1], boundMax[2])))
105  )
106  {
107  vector pos = child.GetOrigin();
108  DebugTextWorldSpace.Create(GetWorld(), "!", DebugTextFlags.FACE_CAMERA | DebugTextFlags.CENTER | DebugTextFlags.ONCE, pos[0], pos[1], pos[2], 30, Color.WHITE, Color.RED);
109  }
110 
111 
112  //--- Check if it has replication component
113  /*if (child.FindComponent(RplComponent))
114  {
115  vector pos = child.GetOrigin();
116  DebugTextWorldSpace.Create(GetWorld(), "Rpl", DebugTextFlags.FACE_CAMERA | DebugTextFlags.CENTER | DebugTextFlags.ONCE, pos[0], pos[1], pos[2], 10, Color.WHITE, Color.ORANGE);
117  }*/
118 
119  //--- Increase counter and go deeper
120  count += 1;
121  ProcessEntities(childSource, count);
122  }
123  }
124 
125  override void _WB_AfterWorldUpdate(float timeSlice)
126  {
127  if (!FindComposition()) return;
128 
129  //--- Save performance by not refreshing every frame
130  if (m_fTime < m_fRefreshRate)
131  {
132  m_fTime += timeSlice;
133  return;
134  }
135 
136  //Print(m_API.GetSelectedEntity(0));
137 
138  int count = 1;
139  ProcessEntities(m_CompositionSource, count);
140  m_Text.SetText(string.Format("Entities: %1", count));
141  }
142  void SCR_CompositionValidationEntity(IEntitySource src, IEntity parent)
143  {
144  m_Title = DebugTextScreenSpace.Create(GetWorld(), "", DebugTextFlags.FACE_CAMERA, 10, 10, 20, ARGBF(1, 1, 1, 1), ARGBF(1, 0, 0, 0));
145  m_Text = DebugTextScreenSpace.Create(GetWorld(), "", DebugTextFlags.FACE_CAMERA, 10, 33, 14, ARGBF(1, 1, 1, 1), ARGBF(1, 0, 0, 0));
146 
147 #ifdef DEBUG_SHAPE
148  if (m_bIsRectangle)
149  m_Shape = Shape.Create(ShapeType.BBOX, ARGBF(0.1, 1, 1, 1), ShapeFlags.VISIBLE | ShapeFlags.TRANSP | ShapeFlags.NOOUTLINE | ShapeFlags.ADDITIVE | ShapeFlags.DOUBLESIDE, GetOrigin() - m_vSlotSize, GetOrigin() + m_vSlotSize);
150  else
151  m_Shape = Shape.CreateCylinder(ARGBF(0.1, 1, 1, 1), ShapeFlags.VISIBLE | ShapeFlags.TRANSP | ShapeFlags.NOOUTLINE | ShapeFlags.ADDITIVE | ShapeFlags.DOUBLESIDE, GetOrigin(), m_vSlotSize[0], m_vSlotSize[2]);
152 #endif
153  }
155  {
156 #ifdef DEBUG_SHAPE
157  delete m_Shape;
158 #endif
159  }
160 #endif
161 };
EntityEditorProps
enum EQueryType EntityEditorProps(category:"GameScripted/Sound", description:"THIS IS THE SCRIPT DESCRIPTION.", color:"0 0 255 255")
Definition: SCR_AmbientSoundsComponent.c:12
GetOrigin
vector GetOrigin()
Definition: SCR_AIUtilityComponent.c:279
Attribute
typedef Attribute
Post-process effect of scripted camera.
m_fTime
float m_fTime
Definition: SCR_CharacterCommandSwim.c:221
SCR_CompositionValidationEntity
Definition: SCR_CompositionValidationEntity.c:7
SCR_GenericBoxEntityClass
Definition: SCR_GenericBoxEntity.c:2
SCR_CompositionValidationEntityClass
Definition: SCR_CompositionValidationEntity.c:3
m_Shape
private ref Shape m_Shape
Definition: UnitDisplayComponent.c:11
SCR_GenericBoxEntity
Definition: SCR_GenericBoxEntity.c:9
category
params category
Definition: SCR_VehicleDamageManagerComponent.c:180