Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
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)]
5
9class SCR_DummyTargetEntity : SCR_GenericBoxEntity
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;
137 }
138};
string path
AddonBuildInfoTool id
enum SCR_ECompassType EntityEditorProps(category:"GameScripted/Gadgets", description:"Compass", color:"0 0 255 255")
Prefab data class for compass component.
Get all prefabs that have the spawner data
void IEntity(IEntitySource src, IEntity parent)
protected script Constructor
proto external EntityEvent SetEventMask(EntityEvent e)
proto external void SetOrigin(vector orig)
proto external vector GetOrigin()
proto external IEntity GetChildren()
proto external BaseWorld GetWorld()
void EOnFrame(IEntity owner, float timeSlice)
void EOnInit(IEntity owner)
SCR_FieldOfViewSettings Attribute
EntityEvent
Various entity events.
Definition EntityEvent.c:14