13 [
Attribute(defvalue:
"0",
desc:
"[COSTY] Avoid objects - the trace check is a 10cm cylinder (for trees mostly)",
category:
"Obstacles")]
14 protected bool m_bAvoidObjects;
16 [
Attribute(defvalue:
"0",
desc:
"Avoid roads, respecting their clearance setting",
category:
"Obstacles")]
17 protected bool m_bAvoidRoads;
19 [
Attribute(defvalue:
"0",
desc:
"Avoid rivers, respecting their clearance setting",
category:
"Obstacles")]
20 protected bool m_bAvoidRivers;
22 [
Attribute(defvalue:
"0",
desc:
"Avoid power lines, respecting their clearance setting",
category:
"Obstacles")]
23 protected bool m_bAvoidPowerLines;
25 [
Attribute(defvalue:
"0",
desc:
"Avoid tracks, respecting their clearance setting",
category:
"Obstacles")]
26 protected bool m_bAvoidTracks;
29 protected bool m_bAvoidLakes;
40 [
Attribute(defvalue:
"0",
category:
"Obstacles",
desc:
"Entirely regenerates if a shape obstacle (listed and checked above) is added/(re)moved in the area")]
41 protected bool m_bRegenerateByObstacleChanges;
45 protected static ref SCR_ObstacleDetector s_ObstacleDetector;
47 protected static const float BBOX_CHECK_HEIGHT = 100.0;
48 protected static const float AVOID_OBJECTS_CHECK_RADIUS = 0.1;
51 protected void RefreshObstacles()
53 if (!m_ParentShapeSource)
56 array<vector> vectorPoints = GetPoints(m_ParentShapeSource);
58 bbox.m_vMin[1] = BBOX_CHECK_HEIGHT * -0.5;
59 bbox.m_vMax[1] = BBOX_CHECK_HEIGHT * 0.5;
62 s_ObstacleDetector.RefreshObstaclesByAABB(CoordToParent(bbox.m_vMin), CoordToParent(bbox.m_vMax));
67 protected void SetAvoidOptions()
69 s_ObstacleDetector.SetAvoidObjects(m_bAvoidObjects);
70 s_ObstacleDetector.SetAvoidObjectsDetectionRadius(AVOID_OBJECTS_CHECK_RADIUS);
71 s_ObstacleDetector.SetAvoidObjectsDetectionHeight(BBOX_CHECK_HEIGHT);
72 s_ObstacleDetector.SetAvoidRoads(m_bAvoidRoads);
73 s_ObstacleDetector.SetAvoidRivers(m_bAvoidRivers);
74 s_ObstacleDetector.SetAvoidPowerLines(m_bAvoidPowerLines);
75 s_ObstacleDetector.SetAvoidTracks(m_bAvoidTracks);
76 s_ObstacleDetector.SetAvoidLakes(m_bAvoidLakes);
83 protected bool HasObstacle(vector worldPos, array<IEntity> exclusionList =
null)
85 if (!s_ObstacleDetector)
87 Print(
"HasObstacle() method requires obstacles info through RefreshObstacle() method first", LogLevel.ERROR);
91 return s_ObstacleDetector.HasObstacle(worldPos, exclusionList);
95 protected bool HasObstaclesList()
97 if (!s_ObstacleDetector)
99 Print(
"HasObstacle() method requires obstacles info through RefreshObstacle() method first", LogLevel.ERROR);
103 return s_ObstacleDetector.HasObstaclesList();
107 protected void ClearObstacles()
109 if (s_ObstacleDetector)
110 s_ObstacleDetector.ClearObstacles();
114 protected override void OnIntersectingShapeChangedXZInternal(IEntitySource shapeEntitySrc, IEntitySource other, array<vector> mins, array<vector> maxes)
116 super.OnIntersectingShapeChangedXZInternal(shapeEntitySrc, other, mins, maxes);
118 if (!m_bRegenerateByObstacleChanges || !shapeEntitySrc || !other)
121 WorldEditorAPI worldEditorAPI = _WB_GetEditorAPI();
125 m_ParentShapeSource = shapeEntitySrc;
127 IEntitySource childEntitySource;
128 GeneratorBaseEntity generator;
129 for (
int i, childrenCount = other.GetNumChildren(); i < childrenCount; i++)
131 childEntitySource = other.GetChild(i);
132 generator = GeneratorBaseEntity.Cast(worldEditorAPI.SourceToEntity(childEntitySource));
136 if ((m_bAvoidRoads && generator.IsInherited(RoadGeneratorEntity)) ||
137 (m_bAvoidRivers && generator.IsInherited(RiverEntity)) ||
141 (m_bAvoidLakes && generator.IsInherited(LakeGeneratorEntity)))
151 protected void OnRegenerate();
156 void SCR_AreaGeneratorBaseEntity(IEntitySource src, IEntity parent)
159 if (!_WB_GetEditorAPI())
162 if (!s_ObstacleDetector || !s_ObstacleDetector.IsValid())
163 s_ObstacleDetector =
new SCR_ObstacleDetector(_WB_GetEditorAPI());