Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
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)]
5
6//------------------------------------------------------------------------------------------------
7class 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
63 m_RegionIntersectDebris.Find(otherRegionIndex, debris);
64
65 if (debris)
66 delete debris;
67 }
68
69 //------------------------------------------------------------------------------------------------
71 void CreateIntersectDebris(int otherRegionIndex)
72 {
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};
ArmaReforgerScripted GetGame()
Definition game.c:1398
IEntity SpawnEntity(ResourceName entityResourceName, notnull IEntity slotOwner)
SCR_CharacterBloodHitZone OnDamage
Resilience - incapacitation or death, depending on game mode settings.
enum SCR_ECompassType EntityEditorProps(category:"GameScripted/Gadgets", description:"Compass", color:"0 0 255 255")
Prefab data class for compass component.
EDamageType type
void Cleanup()
Cleanup component.
Object holding reference to resource. In destructor release the resource.
Definition Resource.c:25
Visual object.
Definition VObject.c:14
Definition Types.c:486
EPhysicsLayerPresets
Enum is filled by C++ by data in project config PhysicsSettings.LayerPresets.
Definition gameLib.c:19
EAddChildFlags
EntityFlags
Various entity flags.
Definition EntityFlags.c:14
EDamageType
Definition EDamageType.c:13