Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_DummyTargetEntity.c
Go to the documentation of this file.
1 [EntityEditorProps(category: "GameScripted/Shapes", description: "Procedural box", color: "255 0 0 255", style: "box", dynamicBox: true)]
3 {
4 };
5 
10 {
11  [Attribute("10", UIWidgets.Slider, "", "0 100 0.1")]
12  private float m_fDefaultTimeBetweenPoints;
13 
14  private BaseWorld m_World;
15  private IEntitySource m_Source;
16 
17  private ref array<vector> m_aPathPoints = {};
18  private ref array<float> m_aPathSpeedValues = {};
19 
20  private vector m_vCurrentPathPoint;
21  private vector m_vNextPathPoint;
22  private vector m_targetWorldPosition;
23 
24  private int m_iCurrentPathPointIndex;
25  private int m_iNextPathPointIndex = m_iCurrentPathPointIndex+1;
26 
27  private ref SimplePreload m_Preload;
28 
29  override protected void EOnInit(IEntity owner)
30  {
31  m_World = GetWorld();
32 
33  if (GetChildren())
34  {
35  PolylineShapeEntity polyline = PolylineShapeEntity.Cast(GetChildren());
36  GetPathFromPolyline(polyline, m_aPathPoints);
37 
38  int num = m_Source.GetNumChildren();
39  IEntitySource pnt = m_Source.GetChild(0);
40  BaseContainerList points = pnt.GetObjectArray("Points");
41 
42  if (points != null)
43  {
44  for (int i = 0; i < points.Count(); ++i)
45  {
46  BaseContainer point = points.Get(i);
47  BaseContainerList data_array = point.GetObjectArray("Data");
48 
49  for (int j = 0; j < data_array.Count(); ++j)
50  {
51  BaseContainer data = data_array.Get(j);
52  bool hasPointData = false;
53  if (data.GetClassName() == "SCR_DummyTargetEntity")
54  {
55  float travel_time;
56  data.Get("m_fTimeToTravel", travel_time);
57  m_aPathSpeedValues.Insert(travel_time);
58  }
59  }
60  }
61  }
62 
63  m_vCurrentPathPoint = m_aPathPoints[m_iCurrentPathPointIndex];
64  m_vNextPathPoint = m_aPathPoints[m_iNextPathPointIndex];
65  owner.SetOrigin(m_vCurrentPathPoint);
66  }
67  }
68 
69  override protected void EOnFrame(IEntity owner, float timeSlice)
70  {
71  vector target_position = owner.GetOrigin();
72 
73  if (VectorEqualApprox(target_position, m_vNextPathPoint, 1))
74  {
75  m_iCurrentPathPointIndex++;
76  if (m_iCurrentPathPointIndex == m_aPathPoints.Count())
77  m_iCurrentPathPointIndex = 0;
78 
79  m_iNextPathPointIndex++;
80  if (m_iNextPathPointIndex == m_aPathPoints.Count())
81  m_iNextPathPointIndex = 0;
82 
83  m_vCurrentPathPoint = m_aPathPoints[m_iCurrentPathPointIndex];
84  m_vNextPathPoint = m_aPathPoints[m_iNextPathPointIndex];
85 
86  }
87 
88  // get the speed values
89  float cur_time_to_travel = m_fDefaultTimeBetweenPoints;
90  if (m_aPathSpeedValues.Count() > 0)
91  {
92  int id = m_iCurrentPathPointIndex;
93  if (id >= m_aPathSpeedValues.Count())
94  {
95  id = m_aPathSpeedValues.Count()-1;
96  }
97  cur_time_to_travel = m_aPathSpeedValues[id];
98  }
99 
100  // calculate the target speed
101  float dist = vector.Distance(m_vCurrentPathPoint, m_vNextPathPoint);
102  float velocity = dist / cur_time_to_travel;
103  float cur_camera_speed = velocity * timeSlice;
104 
105  vector movement_dir = vector.Direction(m_vCurrentPathPoint, m_vNextPathPoint).Normalized();
106  // resulting camera movement:
107  target_position = target_position + movement_dir * cur_camera_speed;
108 
109  this.SetOrigin(target_position);
110  }
111 
112 
113  private void GetPathFromPolyline(PolylineShapeEntity polyline, out array <vector> path)
114  {
115  vector offset = polyline.GetOrigin();
116  array <vector> temp_path = {};
117  polyline.GetPointsPositions(temp_path);
118 
119  for (int i = 0; i < temp_path.Count(); ++i)
120  {
121  temp_path[i] = temp_path[i] + offset;
122  }
123  path = temp_path;
124  }
125 
126  private bool VectorEqualApprox(vector v1, vector v2, float epsilon = 1)
127  {
128  return (Math.AbsFloat(v1[0] - v2[0]) < epsilon)
129  && (Math.AbsFloat(v1[1] - v2[1]) < epsilon)
130  && (Math.AbsFloat(v1[2] - v2[2]) < epsilon);
131  }
132 
133  void SCR_DummyTargetEntity(IEntitySource src, IEntity parent)
134  {
135  m_Source = src;
136  SetEventMask(EntityEvent.FRAME | EntityEvent.INIT);
137  }
138 };
EntityEditorProps
enum EQueryType EntityEditorProps(category:"GameScripted/Sound", description:"THIS IS THE SCRIPT DESCRIPTION.", color:"0 0 255 255")
Definition: SCR_AmbientSoundsComponent.c:12
SCR_DummyTargetEntity
Definition: SCR_DummyTargetEntity.c:9
Attribute
typedef Attribute
Post-process effect of scripted camera.
SimplePreload
Definition: SimplePreload.c:1
m_World
protected BaseWorld m_World
Definition: SCR_PreviewEntityEditorUIComponent.c:46
m_Source
protected IEntitySource m_Source
Definition: SCR_PowerPole.c:14
SCR_GenericBoxEntityClass
Definition: SCR_GenericBoxEntity.c:2
SCR_GenericBoxEntity
Definition: SCR_GenericBoxEntity.c:9
GetChildren
void GetChildren(out array< SCR_ScenarioFrameworkLayerBase > children)
Definition: SCR_ScenarioFrameworkLayerBase.c:359
data
Get all prefabs that have the spawner data
Definition: SCR_EntityCatalogManagerComponent.c:305
SCR_DummyTargetEntityClass
Definition: SCR_DummyTargetEntity.c:2
category
params category
Definition: SCR_VehicleDamageManagerComponent.c:180