Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
actionpushcar.c
Go to the documentation of this file.
1 class ActionPushCarDataReceiveData : ActionReciveData
2 {
3  CarScript m_Car;
4 }
5 
6 class ActionPushCarData : ActionData
7 {
8  int m_PushDirection = -1;
9  int m_EndType = 0;
10 
13 
14  vector m_Origin = "0 0 0";
15 
18 }
19 
21 {
22  void CAContinuousRepeatPushCar(float time_to_complete_action)
23  {
24  m_DefaultTimeToComplete = time_to_complete_action;
25  }
26 
27  override int Execute(ActionData action_data)
28  {
29  if (!action_data.m_Player)
30  return UA_ERROR;
31 
32  if (m_TimeElpased < m_TimeToComplete)
33  {
34  m_TimeElpased += action_data.m_Player.GetDeltaT();
35  m_TotalTimeElpased += action_data.m_Player.GetDeltaT();
36  return UA_PROCESSING;
37  }
38  else
39  {
40  m_SpentUnits.param1 = m_TimeElpased;
41  SetACData(m_SpentUnits);
42  m_TimeElpased = m_TimeToComplete - m_TimeElpased;
43  OnCompletePogress(action_data);
44 
45  return UA_CANCEL;
46  }
47 
48  return UA_FINISHED;
49  }
50 }
51 
52 class ActionPushCarCB : ActionContinuousBaseCB
53 {
54  private static float PUSH_FORCE_IMPULSE_INCREMENT = 200.0;
55  private ActionPushCarData m_ActionDataPushCar;
56 
57  override void CreateActionComponent()
58  {
59  m_ActionData.m_ActionComponent = new CAContinuousRepeatPushCar(10.0);
60  }
61 
62  override void ProgressActionComponent()
63  {
64  super.ProgressActionComponent();
65 
66  ActionPushCarData data = ActionPushCarData.Cast(m_ActionData);
67  ApplyForce(data);
68  }
69 
70  override void EndActionComponent()
71  {
72  m_ActionDataPushCar = ActionPushCarData.Cast(m_ActionData);
73 
75  {
76  super.EndActionComponent();
77  return;
78  }
79 
80  if (m_ActionDataPushCar.m_State == UA_FINISHED)
81  {
82  if (m_ActionDataPushCar.m_EndType == 1)
83  SetCommand(DayZPlayerConstants.CMD_ACTIONINT_FINISH);
84  else if (m_ActionDataPushCar.m_EndType == 0)
85  SetCommand(DayZPlayerConstants.CMD_ACTIONINT_END);
86  }
87  else if (m_ActionDataPushCar.m_State == UA_CANCEL)
88  {
90  if (action.HasAlternativeInterrupt())
91  SetCommand(DayZPlayerConstants.CMD_ACTIONINT_FINISH);
92  else
93  SetCommand(DayZPlayerConstants.CMD_ACTIONINT_END);
94 
95  return;
96  }
97 
99  }
100 
101  protected void ApplyForce(ActionPushCarData actionData)
102  {
103  CarScript car = actionData.m_Car;
104 
105  actionData.m_HorizontalDirectionRandom = Math.RandomFloat(1.0, 3.5);
106  actionData.m_VerticalDirectionRandom = Math.RandomFloat(-0.5, 0.5);
107 
108  float bodyMass = dBodyGetMass(car);
109  float invBodyMass = 1.0 / bodyMass;
110  float force = dBodyGetMass(car) * PUSH_FORCE_IMPULSE_INCREMENT * car.GetPushForceCoefficientMultiplier();
111 
112  float easedProgress = Easing.EaseInOutSine(actionData.m_ActionComponent.GetProgress());
113 
114  vector impulse = car.GetDirection() * force * (float)actionData.m_PushDirection;
115  impulse = impulse * invBodyMass;
116  impulse[0] = impulse[0] * actionData.m_HorizontalDirectionRandom;
117  impulse[1] = impulse[1] * actionData.m_VerticalDirectionRandom;
118  impulse = impulse * easedProgress;
119 
120  actionData.m_Player.DepleteStamina(EStaminaModifiers.PUSH_CAR);
121 
122  dBodyApplyImpulseAt(car, impulse, car.ModelToWorld(car.GetEnginePos()));
123  }
124 }
125 
127 {
128  void ActionPushCar()
129  {
130  m_CallbackClass = ActionPushCarCB;
131  m_CommandUID = DayZPlayerConstants.CMD_ACTIONFB_VEHICLE_PUSH;
132  m_FullBody = true;
133  m_StanceMask = DayZPlayerConstants.STANCEMASK_ERECT;
134 
135  m_Text = "#push_car";
136  }
137 
138  override typename GetInputType()
139  {
141  }
142 
143  override void CreateConditionComponents()
144  {
147  }
148 
149  override bool HasAlternativeInterrupt()
150  {
151  return true;
152  }
153 
154  override ActionData CreateActionData()
155  {
156  ActionPushCarData data = new ActionPushCarData();
157  return data;
158  }
159 
160  override bool ActionCondition(PlayerBase player, ActionTarget target, ItemBase item)
161  {
162  if (!player.IsPlayerInStance(DayZPlayerConstants.STANCEMASK_ERECT|DayZPlayerConstants.STANCEMASK_CROUCH))
163  return false;
164 
165  if (!player.GetSurfaceType())
166  return false;
167 
168  if (!IsInReach(player, target, UAMaxDistances.SMALL))
169  return false;
170 
171  if (!player.CanConsumeStamina(EStaminaConsumers.PUSH))
172  return false;
173 
174  CarScript car = GetCar(target);
175  if (car)
176  {
177  if (car.GetGear() != CarGear.NEUTRAL)
178  return false;
179 
180  if (Math.AbsFloat(GetDirectionDot(car, player)) < 0.85)
181  return false;
182 
183  return true;
184  }
185 
186  return false;
187  }
188 
189  override void OnUpdate(ActionData action_data)
190  {
191  super.OnUpdate(action_data);
192 
193  ActionPushCarData data = ActionPushCarData.Cast(action_data);
194  if (data.m_NeedUpdate)
195  {
196  if (!data.m_Player.CanConsumeStamina(EStaminaConsumers.PUSH))
197  {
198  data.m_State = UA_CANCEL;
199  data.m_NeedUpdate = false;
200 
201  return;
202  }
203 
204  if (vector.Distance(data.m_Car.GetPosition(), data.m_Origin) > 0.5)
205  {
206  data.m_State = UA_FINISHED;
207  data.m_EndType = 0;
208  data.m_NeedUpdate = false;
209  }
210  }
211  }
212 
213  override void OnStart(ActionData action_data)
214  {
215  super.OnStart(action_data);
216 
217  ActionPushCarData data = ActionPushCarData.Cast(action_data);
218  data.m_Car = GetCar(action_data.m_Target);
219  data.m_Origin = data.m_Car.GetPosition();
220  data.m_NeedUpdate = true;
221  }
222 
223  override void OnStartServer(ActionData action_data)
224  {
225  super.OnStartServer(action_data);
226 
227  ActionPushCarData data = ActionPushCarData.Cast(action_data);
228 
229  if (data.m_Car)
230  {
231  data.m_Car.SetBrake(0.0);
232  data.m_Car.SetHandbrake(0.0);
233  data.m_Car.SetBrakesActivateWithoutDriver(false);
234  }
235 
236  data.m_PushDirection = -1;
237  if (GetDirectionDot(data.m_Car, data.m_Player) > 0)
238  data.m_PushDirection = 1;
239 
240  }
241 
242  override void OnEndServer(ActionData action_data)
243  {
244  super.OnEndServer(action_data);
245 
246  ActionPushCarData data = ActionPushCarData.Cast(action_data);
247  if (data.m_Car)
248  data.m_Car.SetBrakesActivateWithoutDriver(true);
249  }
250 
251  override void OnEndInput(ActionData action_data)
252  {
253  super.OnEndInput(action_data);
254 
255  ActionPushCarData data = ActionPushCarData.Cast(action_data);
256  data.m_State = UA_CANCEL;
257  data.m_EndType = 1;
258  data.m_NeedUpdate = false;
259  }
260 
261  override void WriteToContext(ParamsWriteContext ctx, ActionData action_data)
262  {
263  super.WriteToContext(ctx, action_data);
264 
265  ActionPushCarData data = ActionPushCarData.Cast(action_data);
266 
267  ctx.Write(data.m_Car);
268  }
269 
270  override bool ReadFromContext(ParamsReadContext ctx, out ActionReciveData action_recive_data)
271  {
272  if (!action_recive_data)
273  action_recive_data = new ActionPushCarDataReceiveData();
274 
275  super.ReadFromContext(ctx, action_recive_data);
276 
277  CarScript car;
278  if (!ctx.Read(car))
279  return false;
280 
281  ActionPushCarDataReceiveData receiveData = ActionPushCarDataReceiveData.Cast(action_recive_data);
282  receiveData.m_Car = car;
283 
284  return true;
285  }
286 
287  override void HandleReciveData(ActionReciveData action_recive_data, ActionData action_data)
288  {
289  super.HandleReciveData(action_recive_data, action_data);
290 
291  ActionPushCarDataReceiveData receiveData = ActionPushCarDataReceiveData.Cast(action_recive_data);
292  receiveData.m_Car = receiveData.m_Car;
293  }
294 
295  private float GetDirectionDot(Object target, EntityAI player)
296  {
297  return vector.Dot(target.GetDirection(), player.GetDirection());
298  }
299 
300  private CarScript GetCar(ActionTarget target)
301  {
302  if (target.IsProxy())
303  return CarScript.Cast(target.GetParent());
304 
305  return CarScript.Cast(target.GetObject());
306  }
307 }
ItemBase
Definition: inventoryitem.c:730
UA_ERROR
const int UA_ERROR
Definition: constants.c:455
CAContinuousRepeat
Definition: cacontinuousrepeat.c:1
CCINotPresent
Definition: ccinotpresent.c:1
m_ActionDataPushCar
private ActionPushCarData m_ActionDataPushCar
Definition: actionpushcar.c:55
ContinuousInteractActionInput
Definition: actioninput.c:521
EStaminaModifiers
EStaminaModifiers
Definition: estaminamodifiers.c:1
ProgressActionComponent
override void ProgressActionComponent()
Definition: actionpushcar.c:62
ApplyForce
protected void ApplyForce(ActionPushCarData actionData)
Definition: actionpushcar.c:101
dBodyGetMass
proto native float dBodyGetMass(notnull IEntity ent)
CarScript
Definition: civiliansedan.c:1
dBodyApplyImpulseAt
proto void dBodyApplyImpulseAt(notnull IEntity body, vector impulse, vector pos)
Applies impuls on a pos position in world coordinates.
Easing
Input value between 0 and 1, returns value adjusted by easing, no automatic clamping of input(do your...
Definition: easing.c:2
m_Car
CarScript m_Car
Definition: actionpushcar.c:17
UAMaxDistances
Definition: actionconstants.c:104
UA_CANCEL
const int UA_CANCEL
Definition: constants.c:437
Serializer
Serialization general interface. Serializer API works with:
Definition: serializer.c:55
CCTCursorNoRuinCheck
Definition: cctcursornoruincheck.c:1
m_FullBody
protected bool m_FullBody
Definition: actionbase.c:52
m_EndType
int m_EndType
Definition: actionpushcar.c:9
PlayerBase
Definition: playerbaseclient.c:1
vector
Definition: enconvert.c:105
UA_FINISHED
const int UA_FINISHED
Definition: constants.c:436
m_NeedUpdate
bool m_NeedUpdate
Definition: actionpushcar.c:16
EStaminaConsumers
EStaminaConsumers
Definition: estaminaconsumers.c:1
CAContinuousRepeatPushCar
Definition: actionpushcar.c:20
ActionTarget
class ActionTargets ActionTarget
ActionData
Definition: actionbase.c:20
DayZPlayerConstants
DayZPlayerConstants
defined in C++
Definition: dayzplayer.c:601
PUSH_FORCE_IMPULSE_INCREMENT
CAContinuousRepeatPushCar PUSH_FORCE_IMPULSE_INCREMENT
Object
Definition: objecttyped.c:1
ActionPushCarDataReceiveData
Definition: actionpushcar.c:1
EndActionComponent
override void EndActionComponent()
Definition: actionpushcar.c:70
ActionContinuousBaseCB
Definition: actioncontinuousbase.c:1
IsInReach
protected bool IsInReach(PlayerBase player, ActionTarget target, float maxDistance=1.0)
Definition: actionbase.c:928
m_Origin
vector m_Origin
Definition: actionpushcar.c:14
m_Text
protected string m_Text
Definition: actionbase.c:49
m_ConditionItem
ref CCIBase m_ConditionItem
Definition: actionbase.c:55
ActionPushCar
Definition: actionpushcar.c:126
UA_PROCESSING
const int UA_PROCESSING
Definition: constants.c:434
m_PushDirection
ActionPushCarDataReceiveData m_PushDirection
ActionContinuousBase
Definition: actioncontinuousbase.c:132
Math
Definition: enmath.c:6
CreateActionComponent
override void CreateActionComponent()
Definition: actionpushcar.c:57
m_ConditionTarget
ref CCTBase m_ConditionTarget
Definition: actionbase.c:56
m_StanceMask
protected int m_StanceMask
Definition: actionbase.c:53
EntityAI
Definition: building.c:5
m_VerticalDirectionRandom
float m_VerticalDirectionRandom
Definition: actionpushcar.c:12
float
Definition: enconvert.c:96
m_HorizontalDirectionRandom
float m_HorizontalDirectionRandom
Definition: actionpushcar.c:11