9 ResourceName m_sObjectToSpawn;
14 [
Attribute(
desc:
"This won't spawn new object, but it will rather use the object already existing in the world",
category:
"Asset")]
15 bool m_bUseExistingWorldAsset;
17 [
Attribute(
desc:
"Overrides display name of the spawned object for task purposes",
category:
"Asset")]
18 string m_sOverrideObjectDisplayName;
21 bool m_bCanBeGarbageCollected;
23 [
Attribute(
desc:
"Randomize spawned asset(s) per Faction Attribute which needs to be filled as well. Will override Object To Spawn Attribute.",
category:
"Randomization")]
24 bool m_bRandomizePerFaction;
29 [
Attribute(
"0", UIWidgets.SearchComboBox,
"Select Entity Labels which you want to optionally include to random spawn. If you want to spawn everything, you can leave it out empty and also leave Include Only Selected Labels attribute to false.",
"", ParamEnumArray.FromEnum(
EEditableEntityLabel),
category:
"Randomization")]
32 [
Attribute(
"0", UIWidgets.SearchComboBox,
"Select Entity Labels which you want to exclude from random spawn",
"", ParamEnumArray.FromEnum(
EEditableEntityLabel),
category:
"Randomization")]
35 [
Attribute(
desc:
"If true, it will spawn only the entities that are from Included Editable Entity Labels and also do not contain Label to be Excluded.",
category:
"Randomization")]
36 bool m_bIncludeOnlySelectedLabels;
38 [
Attribute(defvalue:
"0",
category:
"Composition",
desc:
"When disabled orientation to terrain will be skipped for the next composition")]
39 bool m_bIgnoreOrientChildrenToTerrain;
42 ref EntitySpawnParams
m_SpawnParams =
new EntitySpawnParams();
44 ResourceName m_sRandomlySpawnedObject;
48 bool m_bShowDebugShapesInWorkbench;
56 protected void QueryObjectsInRange(
float fRange = 2.5)
58 BaseWorld pWorld =
GetGame().GetWorld();
72 SCR_DamageManagerComponent objectDmgManager = SCR_DamageManagerComponent.Cast(
m_Entity.FindComponent(SCR_DamageManagerComponent));
105 void OnCompartmentEntered(IEntity vehicle, BaseCompartmentManagerComponent mgr, IEntity occupant,
int managerId,
int slotID)
115 return m_sOverrideObjectDisplayName;
123 m_sOverrideObjectDisplayName = name;
133 if (!m_sOverrideObjectDisplayName.IsEmpty())
134 return m_sOverrideObjectDisplayName;
137 if (!editableEntityComp)
140 return editableEntityComp.GetDisplayName();
148 EntityPrefabData prefabData = pParent.GetPrefabData();
152 ResourceName resource = prefabData.GetPrefabName();
153 if (resource.IsEmpty())
155 resource = prefabData.GetPrefab().GetAncestor().GetName();
156 if (resource.IsEmpty())
158 if (!m_sID.IsEmpty())
160 if (entity.GetName() != m_sID)
170 if (m_sObjectToSpawn.IsEmpty())
173 TStringArray strs =
new TStringArray();
174 resource.Split(
"/", strs,
true);
175 string resourceName = strs[strs.Count() - 1];
177 TStringArray strsObject =
new TStringArray();
178 m_sObjectToSpawn.Split(
"/", strsObject,
true);
179 string resourceObject = strsObject[strsObject.Count() - 1];
181 if (resourceName == resourceObject)
194 if (resource != m_sObjectToSpawn)
207 IEntity entity =
GetOwner().GetParent();
214 entity = entity.GetParent();
231 return m_sObjectToSpawn;
238 return m_sRandomlySpawnedObject;
245 m_sRandomlySpawnedObject = name;
250 override void RestoreToDefault(
bool includeChildren =
false,
bool reinitAfterRestoration =
false)
252 m_sRandomlySpawnedObject =
string.Empty;
255 super.RestoreToDefault(includeChildren, reinitAfterRestoration);
294 override void Init(
SCR_ScenarioFrameworkArea area =
null, SCR_ScenarioFrameworkEActivationType activation = SCR_ScenarioFrameworkEActivationType.SAME_AS_PARENT)
309 IEntity entity =
GetOwner().GetParent();
316 Print(
string.Format(
"ScenarioFramework: Slot %1 has no parent layer linked - whole parent hierarchy won't be properly working!",
GetName()), LogLevel.ERROR);
332 if (!activationCondition.Init(
GetOwner()))
341 Print(
string.Format(
"ScenarioFramework: Object %1 already exists and won't be spawned for %2, exiting...",
m_Entity,
GetName()), LogLevel.ERROR);
350 if (!m_bUseExistingWorldAsset)
356 QueryObjectsInRange();
367 if (!m_sID.IsEmpty())
370 SCR_DamageManagerComponent objectDmgManager = SCR_DamageManagerComponent.Cast(
m_Entity.FindComponent(SCR_DamageManagerComponent));
371 if (objectDmgManager)
372 objectDmgManager.GetOnDamageStateChanged().Insert(
OnObjectDamage);
376 EventHandlerManagerComponent ehManager = EventHandlerManagerComponent.Cast(
m_Entity.FindComponent(EventHandlerManagerComponent));
385 if (!m_bCanBeGarbageCollected)
389 garbageSystem.UpdateBlacklist(
m_Entity,
true);
394 SCR_GameModeSFManager gameModeComp = SCR_GameModeSFManager.Cast(
GetGame().
GetGameMode().FindComponent(SCR_GameModeSFManager));
396 area = gameModeComp.GetParentArea(
GetOwner());
428 BaseGameMode gameMode =
GetGame().GetGameMode();
432 SCR_GameModeSFManager pGameModeMgr = SCR_GameModeSFManager.Cast(gameMode.FindComponent(SCR_GameModeSFManager));
436 return pGameModeMgr.GetOnAllAreasInitiated();
452 SCR_EntityCatalogManagerComponent catalogManager = SCR_EntityCatalogManagerComponent.GetInstance();
459 entityCatalog = catalogManager.GetFactionEntityCatalogOfType(m_eEntityCatalogType,
m_sFactionKey);
462 entityCatalog = catalogManager.GetEntityCatalogOfType(m_eEntityCatalogType);
469 Print(
"ScenarioFramework Randomized Spawn: No catalog manager found and faction key is empty!", LogLevel.ERROR);
473 FactionManager factionManager =
GetGame().GetFactionManager();
476 Print(
"ScenarioFramework Randomized Spawn: Faction manager not found.", LogLevel.ERROR);
483 Print(
string.Format(
"ScenarioFramework Randomized Spawn: Selected faction not found for %1.",
GetOwner().
GetName()), LogLevel.ERROR);
488 entityCatalog = faction.GetFactionEntityCatalogOfType(m_eEntityCatalogType);
492 Print(
string.Format(
"ScenarioFramework Randomized Spawn: Faction Entity Catalog (type: %1) not found for %2.",
typename.EnumToString(
EEntityCatalogType, m_eEntityCatalogType),
GetOwner().
GetName()), LogLevel.ERROR);
501 Print(
string.Format(
"ScenarioFramework Randomized Spawn: Faction Entity Catalog for faction %1 (type %2) not found for %3.",
m_sFactionKey,
typename.EnumToString(
EEntityCatalogType, m_eEntityCatalogType),
GetOwner().
GetName()), LogLevel.ERROR);
503 Print(
string.Format(
"ScenarioFramework Randomized Spawn: Non-Faction Entity Catalog (Type: %1) not found for %2.",
typename.EnumToString(
EEntityCatalogType, m_eEntityCatalogType),
GetOwner().
GetName()), LogLevel.ERROR);
508 array<SCR_EntityCatalogEntry> entityEntries = {};
510 if (entityEntries.IsEmpty())
512 Print(
string.Format(
"ScenarioFramework Randomized Spawn: Applied labels resulted in no viable prefabs to be randomly selected for %1.",
GetOwner().
GetName()), LogLevel.ERROR);
517 prefab = entityEntries.GetRandomElement().GetPrefab();
518 m_sRandomlySpawnedObject = prefab;
529 if (m_bRandomizePerFaction)
531 ResourceName randomAsset;
536 m_sObjectToSpawn = randomAsset;
544 Resource resource = Resource.Load(m_sObjectToSpawn);
551 vector angles = Math3D.MatrixToAngles(
m_SpawnParams.Transform);
555 BaseResourceObject resourceObject = resource.GetResource();
559 if (m_bIgnoreOrientChildrenToTerrain)
562 if (slotCompositionComponent)
571 aiWorld.RequestNavmeshRebuildEntity(entity);
586 override void _WB_AfterWorldUpdate(IEntity owner,
float timeSlice)
592 override void _WB_SetTransform(IEntity owner, inout vector mat[4], IEntitySource src)
599 baseGameEntity.Teleport(mat);
608 void SpawnEntityPreview(IEntity owner, Resource resource)
610 EntitySpawnParams spawnParams =
new EntitySpawnParams();
611 spawnParams.TransformMode = ETransformMode.WORLD;
612 owner.GetWorldTransform(spawnParams.Transform);
618 override void _WB_OnInit(IEntity owner, inout vector mat[4], IEntitySource src)
622 Resource resource = Resource.Load(m_sObjectToSpawn);
626 SpawnEntityPreview(owner, resource);
630 override bool _WB_OnKeyChanged(IEntity owner, BaseContainer src,
string key, BaseContainerList ownerContainers, IEntity parent)
632 if (key ==
"m_bShowDebugShapesInWorkbench")
639 Resource resource = Resource.Load(m_sObjectToSpawn);
643 SpawnEntityPreview(owner, resource);
646 else if (key ==
"m_sObjectToSpawn")
683 bool Init(IEntity entity);
689 [
Attribute(defvalue:
"1",
desc:
"If true, this can be activated only during the day. If false, only during the night.",
category:
"Time")]
690 protected bool m_bOnlyDuringDay;
693 override bool Init(IEntity entity)
699 TimeAndWeatherManagerEntity manager = world.GetTimeAndWeatherManager();
703 TimeContainer timeContainer = manager.GetTime();
704 int currentHour = timeContainer.m_iHours;
706 if (m_bOnlyDuringDay)
707 return manager.IsDayHour(currentHour);
709 return manager.IsNightHour(currentHour);
717 protected int m_iMinHour;
720 protected int m_iMaxHour;
723 override bool Init(IEntity entity)
729 TimeAndWeatherManagerEntity manager = world.GetTimeAndWeatherManager();
733 TimeContainer timeContainer = manager.GetTime();
734 int currentHour = timeContainer.m_iHours;
736 if (currentHour < m_iMinHour || currentHour > m_iMaxHour)
747 protected float m_fMinWindSpeed;
749 [
Attribute(defvalue:
"20",
desc:
"Maximal wind speed in meters per second",
params:
"0 100 0.001", precision: 3,
category:
"Wind")]
750 protected float m_fMaxWindSpeed;
753 protected float m_fMinRainIntensity;
756 protected float m_fMaxRainIntensity;
759 override bool Init(IEntity entity)
765 TimeAndWeatherManagerEntity manager = world.GetTimeAndWeatherManager();
769 float currentWindSpeed = manager.GetWindSpeed();
770 if (currentWindSpeed < m_fMinWindSpeed || currentWindSpeed > m_fMaxWindSpeed)
773 float currentRainIntensity = manager.GetRainIntensity();
774 if (currentRainIntensity < m_fMinRainIntensity || currentRainIntensity > m_fMaxRainIntensity)