Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_AreaGeneratorBaseEntity.c
Go to the documentation of this file.
2 {
3 }
4 
7 class SCR_AreaGeneratorBaseEntity : SCR_GeneratorBaseEntity
8 {
9  /*
10  Obstacles
11  */
12 
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;
15 
16  [Attribute(defvalue: "0", desc: "Avoid roads, respecting their clearance setting", category: "Obstacles")]
17  protected bool m_bAvoidRoads;
18 
19  [Attribute(defvalue: "0", desc: "Avoid rivers, respecting their clearance setting", category: "Obstacles")]
20  protected bool m_bAvoidRivers;
21 
22  [Attribute(defvalue: "0", desc: "Avoid power lines, respecting their clearance setting", category: "Obstacles")]
23  protected bool m_bAvoidPowerLines;
24 
25  [Attribute(defvalue: "0", desc: "Avoid tracks, respecting their clearance setting", category: "Obstacles")]
26  protected bool m_bAvoidTracks;
27 
28  [Attribute(defvalue: "0", desc: "Avoid lakes", category: "Obstacles")]
29  protected bool m_bAvoidLakes;
30 
31 // [Attribute(defvalue: "0", desc: "Avoid land", category: "Obstacles")]
32 // protected bool m_bAvoidLand;
33 
34 // [Attribute(defvalue: "0", desc: "Avoid ocean", category: "Obstacles")]
35 // protected bool m_bAvoidOcean;
36 
37 // [Attribute(defvalue: "0", desc: "Land/Ocean separation offset", category: "Obstacles")]
38 // protected float m_fAvoidLandOceanOffset;
39 
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;
42 
43 #ifdef WORKBENCH
44 
45  protected static ref SCR_ObstacleDetector s_ObstacleDetector;
46 
47  protected static const float BBOX_CHECK_HEIGHT = 100.0;
48  protected static const float AVOID_OBJECTS_CHECK_RADIUS = 0.1;
49 
50  //------------------------------------------------------------------------------------------------
51  protected void RefreshObstacles()
52  {
53  if (!m_ParentShapeSource)
54  return;
55 
56  array<vector> vectorPoints = GetPoints(m_ParentShapeSource);
57  SCR_AABB bbox = new SCR_AABB(vectorPoints);
58  bbox.m_vMin[1] = BBOX_CHECK_HEIGHT * -0.5;
59  bbox.m_vMax[1] = BBOX_CHECK_HEIGHT * 0.5;
60 
61  SetAvoidOptions();
62  s_ObstacleDetector.RefreshObstaclesByAABB(CoordToParent(bbox.m_vMin), CoordToParent(bbox.m_vMax));
63  }
64 
65  //------------------------------------------------------------------------------------------------
66  // overridable for each generator to have their own options (e.g Forest Generator to not have an "Avoid Forests" option)
67  protected void SetAvoidOptions()
68  {
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);
77 // s_ObstacleDetector.SetAvoidLand(m_bAvoidLand);
78 // s_ObstacleDetector.SetAvoidOcean(m_bAvoidOcean);
79 // s_ObstacleDetector.SetAvoidLandOceanOffset(m_fAvoidLandOceanOffset);
80  }
81 
82  //------------------------------------------------------------------------------------------------
83  protected bool HasObstacle(vector worldPos, array<IEntity> exclusionList = null)
84  {
85  if (!s_ObstacleDetector)
86  {
87  Print("HasObstacle() method requires obstacles info through RefreshObstacle() method first", LogLevel.ERROR);
88  return true; // prevent placement by default
89  }
90 
91  return s_ObstacleDetector.HasObstacle(worldPos, exclusionList);
92  }
93 
94  //------------------------------------------------------------------------------------------------
95  protected bool HasObstaclesList()
96  {
97  if (!s_ObstacleDetector)
98  {
99  Print("HasObstacle() method requires obstacles info through RefreshObstacle() method first", LogLevel.ERROR);
100  return true; // prevent placement by default
101  }
102 
103  return s_ObstacleDetector.HasObstaclesList();
104  }
105 
106  //------------------------------------------------------------------------------------------------
107  protected void ClearObstacles()
108  {
109  if (s_ObstacleDetector)
110  s_ObstacleDetector.ClearObstacles();
111  }
112 
113  //------------------------------------------------------------------------------------------------
114  protected override void OnIntersectingShapeChangedXZInternal(IEntitySource shapeEntitySrc, IEntitySource other, array<vector> mins, array<vector> maxes)
115  {
116  super.OnIntersectingShapeChangedXZInternal(shapeEntitySrc, other, mins, maxes);
117 
118  if (!m_bRegenerateByObstacleChanges || !shapeEntitySrc || !other)
119  return;
120 
121  WorldEditorAPI worldEditorAPI = _WB_GetEditorAPI();
122  if (!worldEditorAPI)
123  return;
124 
125  m_ParentShapeSource = shapeEntitySrc;
126 
127  IEntitySource childEntitySource;
128  GeneratorBaseEntity generator;
129  for (int i, childrenCount = other.GetNumChildren(); i < childrenCount; i++)
130  {
131  childEntitySource = other.GetChild(i);
132  generator = GeneratorBaseEntity.Cast(worldEditorAPI.SourceToEntity(childEntitySource));
133  if (!generator)
134  continue;
135 
136  if ((m_bAvoidRoads && generator.IsInherited(RoadGeneratorEntity)) ||
137  (m_bAvoidRivers && generator.IsInherited(RiverEntity)) ||
138  (m_bAvoidPowerLines && generator.IsInherited(SCR_PowerlineGeneratorEntity)) ||
139  (m_bAvoidTracks && generator.IsInherited(SCR_TrackGeneratorEntity)) ||
140  // (m_bAvoidPrefabGenerators && generator.IsInherited(PrefabGeneratorEntity)) || // no clearance... yet
141  (m_bAvoidLakes && generator.IsInherited(LakeGeneratorEntity)))
142  {
143  OnRegenerate();
144  break;
145  }
146  }
147  }
148 
149  //------------------------------------------------------------------------------------------------
150  // to be overridden for now
151  protected void OnRegenerate();
152 
153 #endif // WORKBENCH
154 
155  //------------------------------------------------------------------------------------------------
156  void SCR_AreaGeneratorBaseEntity(IEntitySource src, IEntity parent)
157  {
158 #ifdef WORKBENCH
159  if (!_WB_GetEditorAPI()) // thumbnail generation
160  return;
161 
162  if (!s_ObstacleDetector || !s_ObstacleDetector.IsValid())
163  s_ObstacleDetector = new SCR_ObstacleDetector(_WB_GetEditorAPI());
164 #endif
165  }
166 }
SCR_GeneratorBaseEntity
SCR_GeneratorBaseEntityClass GeneratorBaseEntityClass SCR_GeneratorBaseEntity(IEntitySource src, IEntity parent)
Definition: SCR_GeneratorBaseEntity.c:335
SCR_AreaGeneratorBaseEntityClass
Definition: SCR_AreaGeneratorBaseEntity.c:1
Attribute
SCR_AreaGeneratorBaseEntityClass SCR_GeneratorBaseEntityClass Attribute(defvalue:"0", desc:" Avoid objects - the trace check is a 10cm cylinder (for trees mostly)"[COSTY], category:"Obstacles")
Definition: SCR_AreaGeneratorBaseEntity.c:13
SCR_AABB
Definition: SCR_AABB.c:3
SCR_PowerlineGeneratorEntity
void SCR_PowerlineGeneratorEntity(IEntitySource src, IEntity parent)
Definition: SCR_PowerlineGeneratorEntity.c:980
desc
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
Definition: SCR_RespawnBriefingComponent.c:17
SCR_TrackGeneratorEntity
void SCR_TrackGeneratorEntity(IEntitySource src, IEntity parent)
Definition: SCR_TrackGeneratorEntity.c:12
SCR_GeneratorBaseEntityClass
Definition: SCR_GeneratorBaseEntity.c:1
category
params category
Definition: SCR_VehicleDamageManagerComponent.c:180