Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
DebrisBuildingEntity.c
Go to the documentation of this file.
1[EntityEditorProps(category: "GameScripted/Debris", description: "Entity used to represent a large piece of debris from a collapsing building.", dynamicBox: true)]
2class SCR_DebrisBuildingEntityClass: GenericEntityClass
3{
4};
5
6//------------------------------------------------------------------------------------------------
8{
9 const static float RANDOM_INITIAL_LINEAR_VELOCITY_XZ = 0.5;
10 const static float RANDOM_INITIAL_LINEAR_VELOCITY_Y = 1;
11 const static float RANDOM_INITIAL_ANGULAR_VELOCITY = 3;
12 const static float RANDOM_BUMP_DELAY_MIN = 0.5;
13 const static float RANDOM_BUMP_DELAY_MAX = 2;
14 const static float RANDOM_BUMP_HEIGHT_MAX = 15;
15 const static float ANGULAR_VELOCITY_MAX = 30;
16
18 protected int m_iBuildingRegion = 0;
21 protected vector m_vCenter = vector.Zero;
22 protected float m_fImpactPosY = 0;
23 protected float m_fDebrisPosY = 0;
24 protected float m_fDelayDeleteTime = 0;
25 protected float m_fRandomBumpDelay = 0;
26 protected bool m_bSpawnedDebris = false;
27
28 //------------------------------------------------------------------------------------------------
29 static SCR_DebrisBuildingEntity SpawnBuildingDebris(vector mat[4], SCR_BuildingSetup buildingSetup, int buildingRegion, IEntity ignoreEnt, string remap = "")
30 {
31 if (!buildingSetup)
32 return null;
33
34 ResourceName model = buildingSetup.GetDamagedRegionModel(buildingRegion);
35
36 // Check if model is valid
37 if (model == string.Empty)
38 return null;
39
40 Resource resource = Resource.Load(model);
41
42 // Check if resource is valid
43 if (!resource.IsValid())
44 return null;
45
47 if (!entity)
48 return null;
49
50 entity.SetParentBuilding(buildingSetup);
51 entity.SetTransform(mat);
52 VObject obj = resource.GetResource().ToVObject();
53 entity.SetObject(obj, remap);
54 entity.m_vLinearVelocity = Vector(Math.RandomFloat(-RANDOM_INITIAL_LINEAR_VELOCITY_XZ, RANDOM_INITIAL_LINEAR_VELOCITY_XZ), Math.RandomFloat(-RANDOM_INITIAL_LINEAR_VELOCITY_Y, RANDOM_INITIAL_LINEAR_VELOCITY_Y), Math.RandomFloat(-RANDOM_INITIAL_LINEAR_VELOCITY_XZ, RANDOM_INITIAL_LINEAR_VELOCITY_XZ));
55 entity.m_vAngularVelocity = Vector(Math.RandomFloat(-1, 1), Math.RandomFloat(-1, 1), Math.RandomFloat(-1, 1)) * RANDOM_INITIAL_ANGULAR_VELOCITY;
56 entity.SetBuildingRegion(buildingRegion);
57
58 vector mins, maxs;
59 entity.GetBounds(mins, maxs);
60
61 float regionVerticalSize = 3;
62
63 entity.m_vCenter = (maxs - mins) * 0.5 + mins;
64 regionVerticalSize = maxs[1] - mins[1];
65
66 // Trace downward and find the impact pos
67 vector center = entity.CoordToParent(entity.m_vCenter);
68 autoptr TraceParam param = new TraceParam;
69 param.Exclude = ignoreEnt;
70 param.Start = center;
71 param.End = param.Start - Vector(0, buildingSetup.m_fLargeDebrisDropMax, 0);
72 param.Flags = TraceFlags.ENTS | TraceFlags.WORLD;
73 entity.m_fImpactPosY = param.End[1] - regionVerticalSize;
74 entity.m_fDebrisPosY = entity.m_fImpactPosY;
75
76 float traced = entity.GetWorld().TraceMove(param, null);
77 if (traced < 1)
78 {
79 entity.m_fDebrisPosY = (param.End[1] - param.Start[1]) * traced + param.Start[1];
80 entity.m_fImpactPosY = entity.m_fDebrisPosY - regionVerticalSize;
81 }
82
83 return entity;
84 }
85
86 //------------------------------------------------------------------------------------------------
88 {
89 m_ParentBuildingSetup = buildingSetup;
90 }
91
92 //------------------------------------------------------------------------------------------------
97
98 //------------------------------------------------------------------------------------------------
100 {
101 return m_vAngularVelocity;
102 }
103
104 //------------------------------------------------------------------------------------------------
106 {
107 m_vLinearVelocity = vel;
108 }
109
110 //------------------------------------------------------------------------------------------------
112 {
113 m_vAngularVelocity = vel;
114 }
115
116 //------------------------------------------------------------------------------------------------
117 protected void SetBuildingRegion(int buildingRegion)
118 {
119 m_iBuildingRegion = buildingRegion;
120 }
121
122 //------------------------------------------------------------------------------------------------
123 override protected void EOnFrame(IEntity owner, float timeSlice) //EntityEvent.FRAME
124 {
125 #ifdef BUILDING_DESTRUCTION_DEBUG
126 if (Debug.KeyState(KeyCode.KC_SUBTRACT))
127 timeSlice *= 0.1;
128 #endif
129
130 vector curMat[4];
131 GetTransform(curMat);
132
133 vector rotMat[3];
134 Math3D.AnglesToMatrix(m_vAngularVelocity * timeSlice, rotMat);
135
136 vector newMat[4];
137 Math3D.MatrixMultiply3(curMat, rotMat, newMat);
138 newMat[3] = curMat[3] + m_vLinearVelocity * timeSlice;
139
140 SetTransform(newMat);
142
143 float height = center[1];
144 float heightAboveImpact = height - m_fImpactPosY;
145
146 float gravityMult = 1;
147 if (heightAboveImpact < RANDOM_BUMP_HEIGHT_MAX)
148 gravityMult = 0.5;
149
150 // Add gravity to fall
151 m_vLinearVelocity += PhysicsWorld.GetGravity(GetGame().GetWorldEntity()) * timeSlice * gravityMult;
152
153 // Add angular velocity, but don't increase if at maximum
154 if (m_vAngularVelocity.LengthSq() < Math.Pow(ANGULAR_VELOCITY_MAX, 2))
156
157 // Handle random "bumping", so simulate bouncing off surroundings
158 m_fRandomBumpDelay -= timeSlice;
159 if (m_fRandomBumpDelay <= 0 && heightAboveImpact > RANDOM_BUMP_HEIGHT_MAX)
160 {
161 m_fRandomBumpDelay = Math.RandomFloat(RANDOM_BUMP_DELAY_MIN, RANDOM_BUMP_DELAY_MAX);
162 const float rndPosXZ = 1;
163 const float rndPosYPctMin = 0.3;
164 const float rndPosYPctMax = 0.9;
165 const float rndAng = 2;
166 m_vLinearVelocity += Vector(Math.RandomFloat(-rndPosXZ, rndPosXZ), Math.RandomFloat(rndPosYPctMin, rndPosYPctMax) * -m_vLinearVelocity[1], Math.RandomFloat(-rndPosXZ, rndPosXZ));
167 m_vAngularVelocity += Vector(Math.RandomFloat(-rndAng, rndAng), Math.RandomFloat(-rndAng, rndAng), Math.RandomFloat(-rndAng, rndAng));
168 }
169
170 if (!m_bSpawnedDebris && height < m_fDebrisPosY)
171 {
172 m_bSpawnedDebris = true;
175 }
176
177 if (height > m_fImpactPosY)
178 return;
179
180 delete this;
181 }
182
183 //------------------------------------------------------------------------------------------------
185 {
187 SetFlags(EntityFlags.ACTIVE, true);
188
189 m_fRandomBumpDelay = Math.RandomFloat(RANDOM_BUMP_DELAY_MIN, RANDOM_BUMP_DELAY_MAX);
190 }
191
192 //------------------------------------------------------------------------------------------------
194 {
195 IEntity child = GetChildren();
196 while (child)
197 {
198 delete child;
199 child = GetChildren();
200 }
201 }
202};
ArmaReforgerScripted GetGame()
Definition game.c:1398
IEntity SpawnEntity(ResourceName entityResourceName, notnull IEntity slotOwner)
enum SCR_ECompassType EntityEditorProps(category:"GameScripted/Gadgets", description:"Compass", color:"0 0 255 255")
Prefab data class for compass component.
Definition Debug.c:13
void IEntity(IEntitySource src, IEntity parent)
protected script Constructor
proto external EntityEvent SetEventMask(EntityEvent e)
proto external IEntity GetChildren()
proto external bool SetTransform(vector mat[4])
proto external EntityFlags SetFlags(EntityFlags flags, bool recursively=false)
proto external void GetTransform(out vector mat[])
proto external vector CoordToParent(vector coord)
Definition Math.c:13
Object holding reference to resource. In destructor release the resource.
Definition Resource.c:25
SCR_BuildingSetup m_ParentBuildingSetup
void EOnFrame(IEntity owner, float timeSlice)
void SetBuildingRegion(int buildingRegion)
static SCR_DebrisBuildingEntity SpawnBuildingDebris(vector mat[4], SCR_BuildingSetup buildingSetup, int buildingRegion, IEntity ignoreEnt, string remap="")
void SetParentBuilding(SCR_BuildingSetup buildingSetup)
void SCR_DebrisBuildingEntity(IEntitySource src, IEntity parent)
Visual object.
Definition VObject.c:14
EntityEvent
Various entity events.
Definition EntityEvent.c:14
EntityFlags
Various entity flags.
Definition EntityFlags.c:14
KeyCode
Definition KeyCode.c:13
proto native vector Vector(float x, float y, float z)
TraceFlags
Definition TraceFlags.c:13