3 [
Attribute(
"{35BD6541CBB8AC08}Prefabs/AI/Waypoints/AIWaypoint_Cycle.et", UIWidgets.ResourceNamePicker,
"Cycle waypoint to be used for waypoints in hierarchy.",
"et")]
4 protected ResourceName m_sCycleWaypointPrefab;
6 [
Attribute(
"{93291E72AC23930F}Prefabs/AI/Waypoints/AIWaypoint_Defend.et", UIWidgets.ResourceNamePicker,
"Waypoint to be used if no waypoints are found in hierarchy.",
"et")]
7 protected ResourceName m_sDefaultWaypointPrefab;
11 ResourceName GetCycleWaypointPrefab()
18 ResourceName GetDefaultWaypointPrefab()
32 [
Attribute(
"0", UIWidgets.EditBox,
"How often will the group respawn. (seconds, 0 = no respawn)",
"0 inf 1")]
35 [
Attribute(
"0.95",
desc:
"If (CurrentAIs / AILimit) > this value, the group will not be spawned.",
params:
"0 0.95 0.01")]
165 float highestProbability;
166 array<ResourceName> prefabs = {};
167 array<int> eligiblePrefabIds = {};
168 array<float> probabilities = {};
173 for (
int i = 0, count =
data.Count(); i < count; i++)
175 int catalogIndex =
data[i].GetCatalogIndex();
176 catalogEntry = entityCatalog.GetCatalogEntry(catalogIndex);
186 probability = patrolData.GetProbabilityOfPresence();
188 prefabs.Insert(catalogEntry.GetPrefab());
189 probabilities.Insert(probability);
191 if (probability > highestProbability)
192 highestProbability = probability
195 if (prefabs.IsEmpty())
196 return ResourceName.Empty;
199 float rand = Math.RandomFloat(0, highestProbability);
201 for (
int i = 0, count = probabilities.Count(); i < count; i++)
203 if (probabilities[i] >= rand)
204 eligiblePrefabIds.Insert(i);
207 if (eligiblePrefabIds.IsEmpty())
208 return ResourceName.Empty;
210 return prefabs[eligiblePrefabIds.GetRandomElement()];
229 array<SCR_EntityCatalogEntry>
data = {};
241 for (
int i = 0, count =
data.Count(); i < count; i++)
243 int catalogIndex =
data[i].GetCatalogIndex();
244 catalogEntry = entityCatalog.GetCatalogEntry(catalogIndex);
254 if (patrolData.GetGroupType() != m_eGroupType)
265 array<AIWaypoint> waypoints = {};
266 array<IEntity> queue = {
GetOwner()};
268 IEntity processedEntity;
269 IEntity nextInHierarchy;
271 while (!queue.IsEmpty())
273 processedEntity = queue[0];
276 waypoint = AIWaypoint.Cast(processedEntity);
279 waypoints.Insert(waypoint);
281 nextInHierarchy = processedEntity.GetChildren();
283 while (nextInHierarchy)
285 queue.Insert(nextInHierarchy);
286 nextInHierarchy = nextInHierarchy.GetSibling();
290 if (waypoints.IsEmpty())
293 if (waypoints.Count() == 1)
304 Resource waypointResource = Resource.Load(componentData.GetCycleWaypointPrefab());
306 if (!waypointResource || !waypointResource.IsValid())
309 AIWaypointCycle wp = AIWaypointCycle.Cast(
GetGame().SpawnEntityPrefab(waypointResource,
null,
params));
313 Print(
"SCR_AmbientPatrolSpawnPointComponent: AIWaypointCycle cast of m_sCycleWaypointPrefab has failed!", LogLevel.ERROR);
317 wp.SetWaypoints(waypoints);
326 EntitySpawnParams
params = EntitySpawnParams();
327 params.TransformMode = ETransformMode.WORLD;
332 if (predefinedWaypoint)
347 Resource waypointResource = Resource.Load(componentData.GetDefaultWaypointPrefab());
349 if (!waypointResource || !waypointResource.IsValid())
352 AIWaypoint wp = AIWaypoint.Cast(
GetGame().SpawnEntityPrefab(waypointResource,
null,
params));
372 faction =
SCR_Faction.Cast(comp.GetDefaultAffiliatedFaction());
383 Resource prefab = Resource.Load(
m_sPrefab);
385 if (!prefab || !prefab.IsValid())
388 EntitySpawnParams
params = EntitySpawnParams();
389 params.TransformMode = ETransformMode.WORLD;
395 AIWaypointCycle cycleWP = AIWaypointCycle.Cast(
m_Waypoint);
399 array<AIWaypoint> waypoints = {};
400 cycleWP.GetWaypoints(waypoints);
401 params.Transform[3] = waypoints.GetRandomElement().GetOrigin();
410 if (!
m_Group.GetSpawnImmediately())
437 array<AIAgent> units = {};
439 int count =
m_Group.GetAgentsCount();
441 RplComponent.DeleteRplEntity(
m_Group,
false);
461 m_Group.DeactivateAllMembers();
493 if (!factionComponent)
495 Print(
"SCR_AmbientPatrolSpawnPointComponent: SCR_FactionAffiliationComponent not found on owner entity. Patrol spawning will not be available.", LogLevel.WARNING);
499 SetEventMask(owner, EntityEvent.INIT);
510 manager.RegisterPatrol(
this);
522 manager.UnregisterPatrol(
this);