1 [
EntityEditorProps(
category:
"GameScripted/Destruction", description:
"Building destruction manager, stores data for destroyed buildings.")]
6 class SCR_BuildingDestructionData
27 ref SCR_BuildingDestructionCameraShakeProgress
m_CameraShake =
new SCR_BuildingDestructionCameraShakeProgress();
54 m_CameraShake =
new SCR_BuildingDestructionCameraShakeProgress();
65 private int m_iFirstFreeData = -1;
66 private ref array<ref SCR_BuildingDestructionData> m_aBuildingDestructionData = {};
68 protected ref array<SCR_DestructibleBuildingComponent> m_aDestroyedBuildings = {};
69 protected static int s_iHighestId;
70 protected static ref map<int, SCR_DestructibleBuildingComponent> s_mBuildingIds =
new map<int, SCR_DestructibleBuildingComponent>();
75 notnull SCR_BuildingDestructionData GetData(inout
int index)
78 index = AllocateData();
80 return m_aBuildingDestructionData[
index];
86 private int AllocateData()
88 if (m_iFirstFreeData == -1)
89 return m_aBuildingDestructionData.Insert(
new SCR_BuildingDestructionData());
91 int returnIndex = m_iFirstFreeData;
92 SCR_BuildingDestructionData
data = m_aBuildingDestructionData[returnIndex];
93 m_iFirstFreeData =
data.m_iNextFreeIndex;
94 data.m_iNextFreeIndex = -1;
101 void FreeData(
int index)
105 m_aBuildingDestructionData[
index].Reset();
106 m_aBuildingDestructionData[
index].m_iNextFreeIndex = m_iFirstFreeData;
107 m_iFirstFreeData =
index;
112 array<string> GetExcludedQueryTypes()
114 array<string> outArray = {};
115 if (!m_BuildingDestructionConfig)
118 outArray.Copy(m_BuildingDestructionConfig.m_aExcludedEntityQueryTypes);
127 static bool IsIdTaken(
int id, SCR_DestructibleBuildingComponent building)
129 SCR_DestructibleBuildingComponent idBuilding = s_mBuildingIds.Get(
id);
130 return idBuilding && building != idBuilding;
135 static int GetNewId()
144 static SCR_DestructibleBuildingComponent GetDestructibleBuilding(
int id)
146 return s_mBuildingIds.Get(
id);
152 static void UnregisterBuildingId(notnull SCR_DestructibleBuildingComponent component)
154 int id = s_mBuildingIds.GetKeyByValue(component);
155 if (id <= 0 || id > s_iHighestId)
158 s_mBuildingIds.Remove(
id);
160 if (
id == s_iHighestId)
162 while (!s_mBuildingIds.Contains(s_iHighestId) && s_iHighestId > 0)
173 static void RegisterBuildingId(notnull SCR_DestructibleBuildingComponent component,
int id)
175 if (s_mBuildingIds.Contains(
id))
177 Print(
"Id taken!", LogLevel.WARNING);
181 if (
id >= s_iHighestId)
184 s_mBuildingIds.Insert(
id, component);
190 int GetDestroyedBuildings(notnull array<SCR_DestructibleBuildingComponent> destroyedBuildings)
192 return destroyedBuildings.Copy(m_aDestroyedBuildings);
198 void RegisterDestroyedBuilding(SCR_DestructibleBuildingComponent building)
200 if (m_aDestroyedBuildings.Contains(building))
203 m_aDestroyedBuildings.Insert(building);
213 GetGame().RegisterBuildingDestructionManager(
this);
220 GetGame().UnregisterBuildingDestructionManager(
this);