Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_UnflipVehicleAction.c
Go to the documentation of this file.
2{
3 [Attribute(defvalue: "1", desc: "Factor that will multiply number of suggested required players to better indicate difficulty of flipping this vehicle\nDue to the fact that some vehicles are very boxy they are inherently harder to flip back on wheels", params: "0.01 inf")]
5
6 protected ref array<IEntity> m_aUsers = {};
7 protected SCR_RepairSupportStationComponent m_HelpingStation;
8 protected bool m_bSelected;
9
11 protected const float SUPPORT_STATION_SEARCH_RADIUS_SQ = 100;
12
13 //------------------------------------------------------------------------------------------------
15 override bool CanBeShownScript(IEntity user)
16 {
17 if (!super.CanBeShownScript(user))
18 return false;
19
21 if (float.AlmostEqual(0, angles[0], 45) && float.AlmostEqual(0, angles[2], 45))
22 return false;
23
24 return true;
25 }
26
27 //------------------------------------------------------------------------------------------------
29 override void PerformContinuousAction(IEntity pOwnerEntity, IEntity pUserEntity, float timeSlice)
30 {
31 // Offset force target slightly above the center of mass to provide better leverage
32 // Slightly unrealistic, but it should be good for gameplay.
33 vector mins, maxs;
34 IEntity rootEntity = pOwnerEntity.GetRootParent();
35 rootEntity.GetWorldBounds(mins, maxs);
36 vector forceLeverage = vector.Up * (maxs[1] - mins[1]) * 0.3;
37 ApplyForce(rootEntity, pUserEntity, timeSlice, forceLeverage);
38 }
39
40 //------------------------------------------------------------------------------------------------
43 override void OnActionStart(IEntity pUserEntity)
44 {
45 super.OnActionStart(pUserEntity);
46
47 if (!m_aUsers.Contains(pUserEntity))
48 m_aUsers.Insert(pUserEntity);
49 }
50
51 //------------------------------------------------------------------------------------------------
54 override void OnActionCanceled(IEntity pOwnerEntity, IEntity pUserEntity)
55 {
56 super.OnActionCanceled(pOwnerEntity, pUserEntity);
57
58 m_aUsers.RemoveItem(pUserEntity);
59 }
60
61 //------------------------------------------------------------------------------------------------
64 override bool GetActionNameScript(out string outName)
65 {
66 UIInfo info = GetUIInfo();
67 if (!info)
68 return false;
69
70 Physics physics = GetOwner().GetPhysics();
71 if (!physics)
72 return false;
73
74 float mass = physics.GetMass();
75 float forcePerUser = Math.Min(m_fMassToForce * mass, m_fForceLimit);
76 if (forcePerUser == 0)
77 return false;
78
79 float assistedForce;
80 if (m_bSelected) // only check this when this action is selected
81 assistedForce = GetAdditionalForce();
82
83 int suggestedUsers = Math.Max(1, Math.Ceil(((mass - assistedForce) / forcePerUser) * m_fSuggestedUsersMultiplier));
84
85 // Manually translate instead of using BaseUserAction.ActionNameParams, as SCR_ActionMenuInteractionDisplay.CompareNewDateWithOld() will not see the change in ActionNameParams
86 // In this case it wont cause the problems, as it is being refreshed every other frame or so, thus even after language change string will regenerate
87 outName = WidgetManager.Translate(info.GetName(), m_aUsers.Count(), suggestedUsers);
88 if (assistedForce > 0)
89 outName = WidgetManager.Translate(info.GetDescription(), outName);
90
91 return true;
92 }
93
94 //------------------------------------------------------------------------------------------------
96 override float GetActionProgressScript(float fProgress, float timeSlice)
97 {
98 Physics physics = GetOwner().GetPhysics();
99 if (!physics)
100 return 1;
101
102 float mass = physics.GetMass();
103 float forcePerUser = Math.Min(m_fMassToForce * mass, m_fForceLimit);
104 if (forcePerUser == 0)
105 return 1;
106
107 float assistedForce;
109 assistedForce = m_HelpingStation.GetUnflippingPower();
110
111 int suggestedUsers = Math.Max(1, Math.Ceil(((mass - assistedForce) / forcePerUser) * m_fSuggestedUsersMultiplier));
112
113 return m_aUsers.Count() / suggestedUsers;
114 }
115
116 //------------------------------------------------------------------------------------------------
117 override protected float GetAdditionalForce()
118 {
119 if (!m_HelpingStation)
120 {
122 if (!m_HelpingStation)
123 return 0;
124 }
125 else if (vector.DistanceSq(GetOwner().GetOrigin(), m_HelpingStation.GetOwner().GetOrigin()) > SUPPORT_STATION_SEARCH_RADIUS_SQ)
126 {
127 m_HelpingStation = null;
129 if (!m_HelpingStation)
130 return 0;
131 }
132
133 return m_HelpingStation.GetUnflippingPower();
134 }
135
136 //------------------------------------------------------------------------------------------------
137 override protected float GetMaxForceToMassFactor()
138 {
140 return 1;
141
142 float mass = GetOwner().GetPhysics().GetMass();
143 float forcePerUser = Math.Min(m_fMassToForce * mass, m_fForceLimit);
144 return forcePerUser * Math.Ceil((mass / forcePerUser) * m_fSuggestedUsersMultiplier + 1) / mass;
145 }
146
147 //------------------------------------------------------------------------------------------------
150 {
151 IEntity owner = GetOwner();
152
153 owner.GetWorld().QueryEntitiesBySphere(owner.GetOrigin(), Math.Sqrt(SUPPORT_STATION_SEARCH_RADIUS_SQ), EvaluateFoundEntity, QueryFilter);
154 }
155
156 //------------------------------------------------------------------------------------------------
160 protected bool QueryFilter(IEntity ent)
161 {
162 if (!ent)
163 return false;
164
165 IEntity owner = GetOwner();
166 if (ent == owner)
167 return false; // skip itself
168
169 IEntity parent = ent.GetParent();
170 if (parent && (parent == owner || ChimeraCharacter.Cast(parent)))
171 return false; // check if slotted repair station is no the child of this action owner or some character
172
173 if (!ent.GetPrefabData())
174 return false; // f.e. particles dont have prefab data
175
176 if (ChimeraCharacter.Cast(ent))
177 return false; // character are not support stations
178
179 if (DestructibleEntity.Cast(ent))
180 return false; // dont check buildings and trees
181
182 if (vector.DistanceSq(owner.GetOrigin(), ent.GetOrigin()) > SUPPORT_STATION_SEARCH_RADIUS_SQ)
183 return false; // BBOX of an object can be large, and we will later use origin for easy validation if it is in range
184
185 return true;
186 }
187
188 //------------------------------------------------------------------------------------------------
192 protected bool EvaluateFoundEntity(IEntity ent)
193 {
194 SCR_RepairSupportStationComponent foundStation = SCR_RepairSupportStationComponent.Cast(ent.FindComponent(SCR_RepairSupportStationComponent));
195 if (!foundStation)
196 return true;
197
198 float flippingPower = foundStation.GetUnflippingPower();
199 if (flippingPower <= 0)
200 return true;
201
202 if (m_HelpingStation == foundStation)
203 return false; // stop searching as we still have the old station
204
205 if (m_HelpingStation && m_HelpingStation.GetUnflippingPower() >= flippingPower)
206 return true;
207
208 m_HelpingStation = foundStation;
209 return true; // maybe we will find a better station
210 }
211
212 //------------------------------------------------------------------------------------------------
213 override protected event void OnActionSelected()
214 {
215 m_bSelected = true;
217 }
218
219 //------------------------------------------------------------------------------------------------
220 override protected event void OnActionDeselected()
221 {
222 m_bSelected = false;
223 }
224
225 //------------------------------------------------------------------------------------------------
227 override bool CanBroadcastScript()
228 {
229 return true;
230 }
231}
ref array< string > angles
vector GetOrigin()
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
proto external Managed FindComponent(typename typeName)
proto external vector GetAngles()
Same as GetYawPitchRoll(), but returns rotation vector around X, Y and Z axis.
proto external vector GetOrigin()
proto external Physics GetPhysics()
proto external BaseWorld GetWorld()
proto external void GetWorldBounds(out vector mins, out vector maxs)
proto external EntityPrefabData GetPrefabData()
proto external IEntity GetParent()
proto external IEntity GetRootParent()
Definition Math.c:13
void ApplyForce(IEntity rootEntity, IEntity pUserEntity, float timeSlice, vector forceOffset=vector.Zero)
override void OnActionCanceled(IEntity pOwnerEntity, IEntity pUserEntity)
SCR_RepairSupportStationComponent m_HelpingStation
override void PerformContinuousAction(IEntity pOwnerEntity, IEntity pUserEntity, float timeSlice)
Called when someone tries to perform the continuous action, user entity is typically character.
override float GetActionProgressScript(float fProgress, float timeSlice)
Returns the progress of this action in seconds.
override bool CanBeShownScript(IEntity user)
Can this action be shown in the UI to the provided user entity?
override void OnActionStart(IEntity pUserEntity)
override bool CanBroadcastScript()
If HasLocalEffectOnly() is false this method tells if the server is supposed to broadcast this action...
const float SUPPORT_STATION_SEARCH_RADIUS_SQ
squared radius in meters
ref array< IEntity > m_aUsers
void FindNearbySupportStation()
Queries the area around the owner of this action, in order to search for support station,...
override bool GetActionNameScript(out string outName)
UIInfo - allows to define UI elements.
Definition UIInfo.c:14
IEntity GetOwner()
Owner entity of the fuel tank.
SCR_FieldOfViewSettings Attribute