Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_BuildingRegionEntity.c
Go to the documentation of this file.
1 [EntityEditorProps(category: "GameScripted/Buildings", description: "Entity used to represent each region of a building when in the damaged state.", dynamicBox: true)]
3 {
4 };
5 
6 //------------------------------------------------------------------------------------------------
7 class SCR_BuildingRegionEntity : BaseBuilding
8 {
9  #ifdef ENABLE_BUILDING_DESTRUCTION
10  private SCR_DestructibleBuildingEntity m_OwnerBuilding = null;
11  private int m_RegionNumber = -1;
12 
13  ref map<int, SCR_RegionIntersectDebrisEntity> m_RegionIntersectDebris = null;
14 
15  //------------------------------------------------------------------------------------------------
17  protected void Cleanup()
18  {
19  if (!m_RegionIntersectDebris)
20  return;
21 
22  for (int i = m_RegionIntersectDebris.Count() - 1; i >= 0; i--)
23  {
24  SCR_RegionIntersectDebrisEntity debris = m_RegionIntersectDebris.GetElement(i);
25  if (debris)
26  delete debris;
27  }
28  }
29 
30  //------------------------------------------------------------------------------------------------
32  VObject LoadIntersectDebrisModel(int otherRegionIndex)
33  {
34  if (!m_OwnerBuilding)
35  return null;
36 
37  if (!m_OwnerBuilding.m_BuildingSetup)
38  return null;
39 
40  ResourceName assetPath = m_OwnerBuilding.m_BuildingSetup.GetRegionIntersectDebrisModel(m_RegionNumber, otherRegionIndex);
41  if (!FileIO.FileExist(assetPath.GetPath()))
42  return null;
43 
44  Resource resource = Resource.Load(assetPath);
45  if (!resource)
46  return null;
47 
48  BaseResourceObject baseObj = resource.GetResource();
49  if (!baseObj)
50  return null;
51 
52  return baseObj.ToVObject();
53  }
54 
55  //------------------------------------------------------------------------------------------------
57  void DeleteIntersectDebris(int otherRegionIndex)
58  {
59  if (!m_RegionIntersectDebris)
60  return;
61 
62  SCR_RegionIntersectDebrisEntity debris = null;
63  m_RegionIntersectDebris.Find(otherRegionIndex, debris);
64 
65  if (debris)
66  delete debris;
67  }
68 
69  //------------------------------------------------------------------------------------------------
71  void CreateIntersectDebris(int otherRegionIndex)
72  {
73  SCR_RegionIntersectDebrisEntity debris = null;
74 
75  if (!m_RegionIntersectDebris)
76  m_RegionIntersectDebris = new map<int, SCR_RegionIntersectDebrisEntity>();
77 
78  // Already created, ignore
79  if (m_RegionIntersectDebris.Find(otherRegionIndex, debris))
80  return;
81 
82  // Load the debris model (if exists)
83  VObject debrisVObj = LoadIntersectDebrisModel(otherRegionIndex);
84  if (!debrisVObj)
85  return;
86 
88 
89  AddChild(debris, -1, EAddChildFlags.AUTO_TRANSFORM);
90 
91  debris.SetObject(debrisVObj, "");
92  debris.Update();
93 
94  m_RegionIntersectDebris.Insert(otherRegionIndex, debris);
95  }
96 
97  //------------------------------------------------------------------------------------------------
99  bool LoadRegionModel()
100  {
101  if (!m_OwnerBuilding)
102  return false;
103 
104  if (!m_OwnerBuilding.m_BuildingSetup)
105  return false;
106 
107  Resource resource = Resource.Load(m_OwnerBuilding.m_BuildingSetup.GetDamagedRegionModel(m_RegionNumber));
108  if (!resource)
109  return false;
110 
111  BaseResourceObject baseObj = resource.GetResource();
112  if (!baseObj)
113  return false;
114 
115  VObject obj = baseObj.ToVObject();
116  if (!obj)
117  return false;
118 
119  SetObject(obj, "");
120  Physics phys = Physics.CreateStatic(this, -1);
121 
122  phys.SetInteractionLayer(EPhysicsLayerPresets.BuildingFireView);
123 
124  //Update();
125  SetFlags(EntityFlags.ACTIVE);
126 
127  return true;
128  }
129 
130  //------------------------------------------------------------------------------------------------
131  SCR_DestructibleBuildingEntity GetBuildingOwner()
132  {
133  return m_OwnerBuilding;
134  }
135 
136  //------------------------------------------------------------------------------------------------
137  int GetRegionNumber()
138  {
139  return m_RegionNumber;
140  }
141 
142  //------------------------------------------------------------------------------------------------
143  void SetBuildingAndIndex(SCR_DestructibleBuildingEntity building, int regionNumber)
144  {
145  m_OwnerBuilding = building;
146  m_RegionNumber = regionNumber;
147  }
148 
149  //------------------------------------------------------------------------------------------------
150  override void OnDamage(float damage, EDamageType type, IEntity pHitEntity, inout vector outMat[3], IEntity damageSource, notnull Instigator instigator, int colliderID, float speed)
151  {
152  if (!m_OwnerBuilding)
153  return;
154 
155  damage = SCR_Global.GetScaledStructuralDamage(damage, type);
156  if (damage <= 0)
157  return;
158 
159  m_OwnerBuilding.AddRegionDamage(m_RegionNumber, damage);
160  }
161 
162  //------------------------------------------------------------------------------------------------
164  {
165  Cleanup();
166  }
167  #endif
168 };
SpawnEntity
protected IEntity SpawnEntity(ResourceName entityResourceName, notnull IEntity slotOwner)
Definition: SCR_CatalogEntitySpawnerComponent.c:1008
SCR_DestructibleBuildingEntity
Definition: SCR_DestructibleBuildingEntity.c:47
EntityEditorProps
enum EQueryType EntityEditorProps(category:"GameScripted/Sound", description:"THIS IS THE SCRIPT DESCRIPTION.", color:"0 0 255 255")
Definition: SCR_AmbientSoundsComponent.c:12
OnDamage
override protected void OnDamage(notnull BaseDamageContext damageContext)
Definition: SCR_ArmorDamageManagerComponent.c:11
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
Cleanup
protected void Cleanup()
Cleanup component.
Definition: SCR_VONController.c:807
SCR_BuildingRegionEntityClass
Definition: SCR_BuildingRegionEntity.c:2
Instigator
Definition: Instigator.c:6
BaseBuildingClass
Definition: BaseBuilding.c:12
SCR_RegionIntersectDebrisEntity
Definition: SCR_RegionIntersectDebrisEntity.c:7
SCR_Global
Definition: Functions.c:6
type
EDamageType type
Definition: SCR_DestructibleTreeV2.c:32
EDamageType
EDamageType
Definition: EDamageType.c:12
SCR_BuildingRegionEntity
Definition: SCR_BuildingRegionEntity.c:7
category
params category
Definition: SCR_VehicleDamageManagerComponent.c:180