Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_AreaGeneratorBaseEntity.c
Go to the documentation of this file.
4
8class SCR_AreaGeneratorBaseEntity : SCR_GeneratorBaseEntity
9{
10 /*
11 Obstacles
12 */
13
14 [Attribute(defvalue: "0", desc: "[COSTY] Avoid objects - the trace check is a 10cm cylinder (for trees mostly)", category: "Obstacles")]
15 protected bool m_bAvoidObjects;
16
17 [Attribute(defvalue: "0", desc: "Avoid roads, respecting their clearance setting", category: "Obstacles")]
18 protected bool m_bAvoidRoads;
19
20 [Attribute(defvalue: "0", desc: "Avoid rivers, respecting their clearance setting", category: "Obstacles")]
21 protected bool m_bAvoidRivers;
22
23 [Attribute(defvalue: "0", desc: "Avoid power lines, respecting their clearance setting", category: "Obstacles")]
24 protected bool m_bAvoidPowerLines;
25
26 [Attribute(defvalue: "0", desc: "Avoid tracks, respecting their clearance setting", category: "Obstacles")]
27 protected bool m_bAvoidTracks;
28
29 [Attribute(defvalue: "0", desc: "Avoid lakes", category: "Obstacles")]
30 protected bool m_bAvoidLakes;
31
32 [Attribute(defvalue: "0", desc: "Avoid above or below ocean level", category: "Obstacles", uiwidget: UIWidgets.ComboBox, enums: SCR_ParamEnumArray.FromString("None;Avoid land;Avoid ocean"))]
33 protected int m_iAvoidLandOrOcean;
34
35// [Attribute(defvalue: "0", desc: "Land/Ocean separation offset", category: "Obstacles")]
36// protected float m_fAvoidLandOceanOffset;
37
38 [Attribute(defvalue: "0", category: "Obstacles", desc: "Entirely regenerates if a shape obstacle (listed and checked above) is added/(re)moved in the area")]
39 protected bool m_bRegenerateByObstacleChanges;
40
41#ifdef WORKBENCH
42
43 protected static ref SCR_ObstacleDetector s_ObstacleDetector;
44
45 protected static const float BBOX_CHECK_HEIGHT = 100.0;
46 protected static const float AVOID_OBJECTS_CHECK_RADIUS = 0.1;
47
48 //------------------------------------------------------------------------------------------------
49 protected void RefreshObstacles()
50 {
51 if (!m_ParentShapeSource)
52 return;
53
54 array<vector> vectorPoints = GetAnchorPoints(m_ParentShapeSource);
55 SCR_AABB bbox = new SCR_AABB(vectorPoints);
56 bbox.m_vMin[1] = BBOX_CHECK_HEIGHT * -0.5;
57 bbox.m_vMax[1] = BBOX_CHECK_HEIGHT * 0.5;
58
59 SetAvoidOptions();
60 s_ObstacleDetector.RefreshObstaclesByAABB(CoordToParent(bbox.m_vMin), CoordToParent(bbox.m_vMax));
61 }
62
63 //------------------------------------------------------------------------------------------------
64 // overridable for each generator to have their own options (e.g Forest Generator to not have an "Avoid Forests" option)
65 protected void SetAvoidOptions()
66 {
67 s_ObstacleDetector.SetAvoidObjects(m_bAvoidObjects);
68 s_ObstacleDetector.SetAvoidObjectsDetectionRadius(AVOID_OBJECTS_CHECK_RADIUS);
69 s_ObstacleDetector.SetAvoidObjectsDetectionHeight(BBOX_CHECK_HEIGHT);
70 s_ObstacleDetector.SetAvoidRoads(m_bAvoidRoads);
71 s_ObstacleDetector.SetAvoidRivers(m_bAvoidRivers);
72 s_ObstacleDetector.SetAvoidPowerLines(m_bAvoidPowerLines);
73 s_ObstacleDetector.SetAvoidTracks(m_bAvoidTracks);
74 s_ObstacleDetector.SetAvoidLakes(m_bAvoidLakes);
75 s_ObstacleDetector.SetAvoidLand(m_iAvoidLandOrOcean == 1);
76 s_ObstacleDetector.SetAvoidOcean(m_iAvoidLandOrOcean == 2);
77// s_ObstacleDetector.SetAvoidLandOceanOffset(m_fAvoidLandOceanOffset);
78 }
79
80 //------------------------------------------------------------------------------------------------
81 protected bool HasObstacle(vector worldPos, array<IEntity> exclusionList = null)
82 {
83 if (!s_ObstacleDetector)
84 {
85 Print("HasObstacle() method requires obstacles info through RefreshObstacle() method first", LogLevel.ERROR);
86 return true; // prevent placement by default
87 }
88
89 return s_ObstacleDetector.HasObstacle(worldPos, exclusionList);
90 }
91
92 //------------------------------------------------------------------------------------------------
93 protected bool HasObstaclesList()
94 {
95 if (!s_ObstacleDetector)
96 {
97 Print("HasObstacle() method requires obstacles info through RefreshObstacle() method first", LogLevel.ERROR);
98 return true; // prevent placement by default
99 }
100
101 return s_ObstacleDetector.HasObstaclesList();
102 }
103
104 //------------------------------------------------------------------------------------------------
105 protected void ClearObstacles()
106 {
107 if (s_ObstacleDetector)
108 s_ObstacleDetector.ClearObstacles();
109 }
110
111 //------------------------------------------------------------------------------------------------
115 protected float GetShapeArea(bool forcePolyLine = false)
116 {
117 if (!m_ParentShapeSource)
118 return 0;
119
120 bool isShapeClosed;
121 m_ParentShapeSource.Get("IsClosed", isShapeClosed);
122
123 array<vector> tesselatedPoints;
124 if (forcePolyLine)
125 tesselatedPoints = GetAnchorPoints(m_ParentShapeSource, isShapeClosed: isShapeClosed);
126 else
127 tesselatedPoints = GetTesselatedShapePoints(m_ParentShapeSource, isShapeClosed: isShapeClosed);
128
129 array<float> tesselatedPoints2D = {};
130 tesselatedPoints2D.Reserve(tesselatedPoints.Count() * 2);
131 foreach (vector point : tesselatedPoints)
132 {
133 tesselatedPoints2D.Insert(point[0]);
134 tesselatedPoints2D.Insert(point[2]);
135 }
136
137 return SCR_Math2D.GetPolygonArea(tesselatedPoints2D);
138 }
139
140 //------------------------------------------------------------------------------------------------
141 protected override void OnIntersectingShapeChangedXZInternal(IEntitySource shapeEntitySrc, IEntitySource other, array<vector> mins, array<vector> maxes)
142 {
143 super.OnIntersectingShapeChangedXZInternal(shapeEntitySrc, other, mins, maxes);
144
145 if (!m_bRegenerateByObstacleChanges || !shapeEntitySrc || !other)
146 return;
147
148 WorldEditorAPI worldEditorAPI = _WB_GetEditorAPI();
149 if (!worldEditorAPI)
150 return;
151
152 IEntitySource childEntitySource;
153 GeneratorBaseEntity generator;
154 for (int i, childrenCount = other.GetNumChildren(); i < childrenCount; i++)
155 {
156 childEntitySource = other.GetChild(i);
157 generator = GeneratorBaseEntity.Cast(worldEditorAPI.SourceToEntity(childEntitySource));
158 if (!generator)
159 continue;
160
161 if ((m_bAvoidRoads && generator.IsInherited(RoadGeneratorEntity)) ||
162 (m_bAvoidRivers && generator.IsInherited(RiverEntity)) ||
163 (m_bAvoidPowerLines && generator.IsInherited(SCR_PowerlineGeneratorEntity)) ||
164 (m_bAvoidTracks && generator.IsInherited(SCR_TrackGeneratorEntity)) ||
165 // (m_bAvoidPrefabGenerators && generator.IsInherited(PrefabGeneratorEntity)) || // no clearance... yet
166 (m_bAvoidLakes && generator.IsInherited(LakeGeneratorEntity)))
167 {
168 OnRegenerate();
169 break;
170 }
171 }
172 }
173
174 //------------------------------------------------------------------------------------------------
175 // to be overridden for now
176 protected void OnRegenerate();
177
178 //------------------------------------------------------------------------------------------------
179 // constructor
180 protected void SCR_AreaGeneratorBaseEntity(IEntitySource src, IEntity parent)
181 {
182 if (!_WB_GetEditorAPI()) // thumbnail generation
183 return;
184
185 if (!s_ObstacleDetector)
186 s_ObstacleDetector = new SCR_ObstacleDetector();
187 }
188#endif
189}
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
enum EVehicleType IEntity
static ParamEnumArray FromString(string input)
proto void Print(void var, LogLevel level=LogLevel.NORMAL)
Prints content of variable to console/log.
LogLevel
Enum with severity of the logging message.
Definition LogLevel.c:14
SCR_FieldOfViewSettings Attribute
void OnIntersectingShapeChangedXZInternal(IEntitySource shapeEntitySrc, IEntitySource other, array< vector > mins, array< vector > maxes)