8class SCR_AreaGeneratorBaseEntity : SCR_GeneratorBaseEntity
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;
17 [
Attribute(defvalue:
"0",
desc:
"Avoid roads, respecting their clearance setting",
category:
"Obstacles")]
18 protected bool m_bAvoidRoads;
20 [
Attribute(defvalue:
"0",
desc:
"Avoid rivers, respecting their clearance setting",
category:
"Obstacles")]
21 protected bool m_bAvoidRivers;
23 [
Attribute(defvalue:
"0",
desc:
"Avoid power lines, respecting their clearance setting",
category:
"Obstacles")]
24 protected bool m_bAvoidPowerLines;
26 [
Attribute(defvalue:
"0",
desc:
"Avoid tracks, respecting their clearance setting",
category:
"Obstacles")]
27 protected bool m_bAvoidTracks;
30 protected bool m_bAvoidLakes;
33 protected int m_iAvoidLandOrOcean;
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;
43 protected static ref SCR_ObstacleDetector s_ObstacleDetector;
45 protected static const float BBOX_CHECK_HEIGHT = 100.0;
46 protected static const float AVOID_OBJECTS_CHECK_RADIUS = 0.1;
49 protected void RefreshObstacles()
51 if (!m_ParentShapeSource)
54 array<vector> vectorPoints = GetAnchorPoints(m_ParentShapeSource);
56 bbox.m_vMin[1] = BBOX_CHECK_HEIGHT * -0.5;
57 bbox.m_vMax[1] = BBOX_CHECK_HEIGHT * 0.5;
60 s_ObstacleDetector.RefreshObstaclesByAABB(CoordToParent(bbox.m_vMin), CoordToParent(bbox.m_vMax));
65 protected void SetAvoidOptions()
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);
81 protected bool HasObstacle(vector worldPos, array<IEntity> exclusionList = null)
83 if (!s_ObstacleDetector)
85 Print(
"HasObstacle() method requires obstacles info through RefreshObstacle() method first",
LogLevel.ERROR);
89 return s_ObstacleDetector.HasObstacle(worldPos, exclusionList);
93 protected bool HasObstaclesList()
95 if (!s_ObstacleDetector)
97 Print(
"HasObstacle() method requires obstacles info through RefreshObstacle() method first",
LogLevel.ERROR);
101 return s_ObstacleDetector.HasObstaclesList();
105 protected void ClearObstacles()
107 if (s_ObstacleDetector)
108 s_ObstacleDetector.ClearObstacles();
115 protected float GetShapeArea(
bool forcePolyLine =
false)
117 if (!m_ParentShapeSource)
121 m_ParentShapeSource.Get(
"IsClosed", isShapeClosed);
123 array<vector> tesselatedPoints;
125 tesselatedPoints = GetAnchorPoints(m_ParentShapeSource, isShapeClosed: isShapeClosed);
127 tesselatedPoints = GetTesselatedShapePoints(m_ParentShapeSource, isShapeClosed: isShapeClosed);
129 array<float> tesselatedPoints2D = {};
130 tesselatedPoints2D.Reserve(tesselatedPoints.Count() * 2);
131 foreach (vector point : tesselatedPoints)
133 tesselatedPoints2D.Insert(point[0]);
134 tesselatedPoints2D.Insert(point[2]);
137 return SCR_Math2D.GetPolygonArea(tesselatedPoints2D);
143 super.OnIntersectingShapeChangedXZInternal(shapeEntitySrc, other, mins, maxes);
145 if (!m_bRegenerateByObstacleChanges || !shapeEntitySrc || !other)
148 WorldEditorAPI worldEditorAPI = _WB_GetEditorAPI();
152 IEntitySource childEntitySource;
153 GeneratorBaseEntity generator;
154 for (
int i, childrenCount = other.GetNumChildren(); i < childrenCount; i++)
156 childEntitySource = other.GetChild(i);
157 generator = GeneratorBaseEntity.Cast(worldEditorAPI.SourceToEntity(childEntitySource));
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)) ||
166 (m_bAvoidLakes && generator.IsInherited(LakeGeneratorEntity)))
176 protected void OnRegenerate();
180 protected void SCR_AreaGeneratorBaseEntity(IEntitySource src,
IEntity parent)
182 if (!_WB_GetEditorAPI())
185 if (!s_ObstacleDetector)
186 s_ObstacleDetector =
new SCR_ObstacleDetector();
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.
SCR_FieldOfViewSettings Attribute
void OnIntersectingShapeChangedXZInternal(IEntitySource shapeEntitySrc, IEntitySource other, array< vector > mins, array< vector > maxes)