9 protected bool m_bPrintTreeDamage;
11 #ifdef ENABLE_DESTRUCTION
17 private ref array<ref SCR_DestroyedTreesData> m_aDestroyedTreesData =
new array<ref SCR_DestroyedTreesData>();
18 private ref array<ref SCR_ActiveTreeData> m_aActiveTreesData =
new array<ref SCR_ActiveTreeData>();
27 SCR_ActiveTreeData GetActiveTreeData(
int index)
29 if (!m_aActiveTreesData || m_aActiveTreesData.Count() <=
index)
32 return m_aActiveTreesData[
index];
38 if (!m_aActiveTreesData)
41 return m_aActiveTreesData.Insert(
new SCR_ActiveTreeData());
45 void SynchronizeTreePartTransform(
int treePartIdx,
float quat[4], vector
position, vector velocity, vector angularVelocity,
EntityID treeID)
47 if (RplSession.Mode() == RplMode.Client)
50 int treeIdx = FindTreeIndex(treeID);
53 int treePartArrayIdx = FindTreePartIndex(treeIdx, treePartIdx);
54 if (treePartArrayIdx != -1)
56 m_aDestroyedTreesData[treeIdx].m_aRotations[treePartArrayIdx*4] = quat[0];
57 m_aDestroyedTreesData[treeIdx].m_aRotations[treePartArrayIdx*4 + 1] = quat[1];
58 m_aDestroyedTreesData[treeIdx].m_aRotations[treePartArrayIdx*4 + 2] = quat[2];
59 m_aDestroyedTreesData[treeIdx].m_aRotations[treePartArrayIdx*4 + 3] = quat[3];
60 m_aDestroyedTreesData[treeIdx].m_aPositions[treePartArrayIdx] =
position;
65 data.m_iTreePartIndex = treePartIdx;
66 Math3D.QuatCopy(quat,
data.m_fQuaternion);
68 data.m_vVelocity = velocity;
69 data.m_vAngularVelocity = angularVelocity;
70 data.m_TreeID = treeID;
72 Rpc(RPC_SynchronizeTreePart,
data);
76 void SynchronizeSetToBreak(
int treePartIdx, vector positionVector, vector impulseVector,
EDamageType damageType,
EntityID treeID)
78 if (RplSession.Mode() == RplMode.Client)
86 int treeIdx = FindTreeIndex(treeID);
89 int treePartArrayIdx = FindTreePartIndex(treeIdx, treePartIdx);
90 if (treePartArrayIdx == -1)
92 m_aDestroyedTreesData[treeIdx].m_aDestroyedPartsIndexes.Insert(treePartIdx);
93 m_aDestroyedTreesData[treeIdx].m_aPositions.Insert(
"0 0 0");
94 m_aDestroyedTreesData[treeIdx].m_aRotations.Insert(0);
95 m_aDestroyedTreesData[treeIdx].m_aRotations.Insert(0);
96 m_aDestroyedTreesData[treeIdx].m_aRotations.Insert(0);
97 m_aDestroyedTreesData[treeIdx].m_aRotations.Insert(0);
98 m_aDestroyedTreesData[treeIdx].m_aIsTreePartDynamic.Insert(
false);
99 m_aDestroyedTreesData[treeIdx].m_aIsParented.Insert(
true);
104 Rpc(RPC_SetToBreak, treePartIdx, treeID);
108 void SynchronizeRemoveFromParent(
int treePartIdx,
EntityID treeID)
110 if (RplSession.Mode() == RplMode.Client)
113 int treeIdx = FindTreeIndex(treeID);
116 int treePartArrayIdx = FindTreePartIndex(treeIdx, treePartIdx);
117 if (treePartArrayIdx != -1)
119 m_aDestroyedTreesData[treeIdx].m_aIsParented[treePartArrayIdx] =
false;
123 Rpc(RPC_RemoveFromParent, treePartIdx, treeID);
127 void SynchronizeSetToDestroy(
EntityID treeID)
129 if (RplSession.Mode() == RplMode.Client)
137 int treeIdx = FindTreeIndex(treeID);
141 data.treeID = treeID;
142 m_aDestroyedTreesData.Insert(
data);
145 Rpc(RPC_SendSetToDestroy, treeID);
149 void SynchronizeSwitchTreePartToStatic(
int treePartIdx,
EntityID treeID)
154 int treeIdx = FindTreeIndex(treeID);
157 int treePartArrayIdx = FindTreePartIndex(treeIdx, treePartIdx);
158 if (treePartArrayIdx != -1)
160 m_aDestroyedTreesData[treeIdx].m_aIsTreePartDynamic[treePartArrayIdx] =
false;
164 Rpc(RPC_SendSwitchTreePartToStatic, treePartIdx, treeID);
168 void SynchronizeStaticPosition(
int treePartIdx, vector
position,
EntityID treeID)
170 if (RplSession.Mode() == RplMode.Client)
173 int treeIdx = FindTreeIndex(treeID);
176 int treePartArrayIdx = FindTreePartIndex(treeIdx, treePartIdx);
177 if (treePartArrayIdx != -1)
179 m_aDestroyedTreesData[treeIdx].m_aPositions[treePartArrayIdx] =
position;
183 Rpc(RPC_SendStaticPosition, treePartIdx,
position , treeID);
187 void SynchronizeStaticRotation(
int treePartIdx,
float quat[4],
EntityID treeID)
189 if (RplSession.Mode() == RplMode.Client)
192 int treeIdx = FindTreeIndex(treeID);
195 int treePartArrayIdx = FindTreePartIndex(treeIdx, treePartIdx);
196 if (treePartArrayIdx != -1)
198 m_aDestroyedTreesData[treeIdx].m_aRotations[treePartArrayIdx*4] = quat[0];
199 m_aDestroyedTreesData[treeIdx].m_aRotations[treePartArrayIdx*4 + 1] = quat[1];
200 m_aDestroyedTreesData[treeIdx].m_aRotations[treePartArrayIdx*4 + 2] = quat[2];
201 m_aDestroyedTreesData[treeIdx].m_aRotations[treePartArrayIdx*4 + 3] = quat[3];
205 Rpc(RPC_SendStaticRotation, treePartIdx, quat[0], quat[1], quat[2], quat[3], treeID);
211 IEntity treeEnt =
m_OwnerEntity.GetWorld().FindEntityByID(treeID);
229 int count = m_aDestroyedTreesData.Count();
230 for (
int i = 0; i < count; i++)
232 if (m_aDestroyedTreesData[i].treeID == treeID)
240 int FindTreePartIndex(
int treeIdx,
int treePartIdx)
242 int count = m_aDestroyedTreesData[treeIdx].m_aDestroyedPartsIndexes.Count();
244 for (
int i = 0; i < count; i++)
246 if (m_aDestroyedTreesData[treeIdx].m_aDestroyedPartsIndexes[i] == treePartIdx)
254 BaseSoundComponent GetSoundComponent()
271 [
RplRpc(RplChannel.Reliable, RplRcver.Broadcast)]
272 protected void RPC_RemoveFromParent(
int treePartIndex,
EntityID treeID)
279 tree.RemoveTreePartFromParent(treePartIndex);
283 [
RplRpc(RplChannel.Reliable, RplRcver.Broadcast)]
291 tree.UpdateTransformOfTreePart(
data.m_iTreePartIndex,
data.m_vPosition,
data.m_fQuaternion,
data.m_vVelocity,
data.m_vAngularVelocity);
295 [
RplRpc(RplChannel.Reliable, RplRcver.Broadcast)]
296 private void RPC_SetToBreak(
int treePartIdx,
EntityID treeID)
303 tree.SetToBreak(treePartIdx);
307 [
RplRpc(RplChannel.Reliable, RplRcver.Broadcast)]
308 private void RPC_SendSetToDestroy(
EntityID treeID)
324 [
RplRpc(RplChannel.Reliable, RplRcver.Broadcast)]
325 void RPC_SendSwitchTreePartToStatic(
int treePartIdx,
EntityID treeID)
332 tree.ClientSwitchTreePartToStatic(treePartIdx);
336 [
RplRpc(RplChannel.Reliable, RplRcver.Broadcast)]
337 void RPC_SendStaticPosition(
int treePartIdx, vector
position,
EntityID treeID)
344 tree.SetPositionOfTreePart(treePartIdx,
position);
348 [
RplRpc(RplChannel.Reliable, RplRcver.Broadcast)]
349 void RPC_SendStaticRotation(
int treePartIdx,
float q0,
float q1,
float q2,
float q3,
EntityID treeID)
362 tree.SetRotationOfTreePart(treePartIdx, quat);
370 override bool RplLoad(ScriptBitReader reader)
373 reader.ReadInt(count);
376 for (
int i = 0; i < count; i++)
379 reader.ReadEntityId(treeID);
384 reader.ReadInt(treePartsCount);
386 if (treePartsCount == 0)
393 for (
int x = 0; x < treePartsCount; x++)
396 reader.ReadInt(treePartIdx);
408 reader.ReadBool(isDynamic);
412 reader.ReadBool(isParented);
415 tree.CacheDestroyedTreePart(treePartIdx,
position,
rotation, isDynamic, isParented);
423 override bool RplSave(ScriptBitWriter writer)
425 int count = m_aDestroyedTreesData.Count();
426 writer.WriteInt(count);
429 for (
int i = 0; i < count; i++)
431 writer.WriteEntityId(m_aDestroyedTreesData[i].treeID);
434 int treePartsCount = m_aDestroyedTreesData[i].m_aDestroyedPartsIndexes.Count();
435 writer.WriteInt(treePartsCount);
438 for (
int x = 0; x < treePartsCount; x++)
440 writer.WriteInt(m_aDestroyedTreesData[i].m_aDestroyedPartsIndexes[x]);
443 writer.WriteVector(m_aDestroyedTreesData[i].m_aPositions[x]);
448 writer.WriteQuaternion(m_aDestroyedTreesData[i].m_aRotations[x*4]);
454 writer.WriteBool(m_aDestroyedTreesData[i].m_aIsTreePartDynamic[x]);
457 writer.WriteBool(m_aDestroyedTreesData[i].m_aIsParented[x]);
468 super.OnPostInit(owner);
469 SetEventMask(owner, EntityEvent.INIT);
473 override void EOnInit(IEntity owner)
478 m_RplComponent = RplComponent.Cast(owner.FindComponent(RplComponent));
491 m_SoundComponent = BaseSoundComponent.Cast(owner.FindComponent(BaseSoundComponent));
506 m_aDestroyedTreesData.Clear();
507 m_aDestroyedTreesData =
null;