Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_ScenarioFrameworkTaskDestroyObject.c
Go to the documentation of this file.
1 //------------------------------------------------------------------------------------------------
3 {
4 };
5 
6 //------------------------------------------------------------------------------------------------
8 {
9 
10  //------------------------------------------------------------------------------------------------
11  void OnObjectDamage(EDamageState state)
12  {
13  if (state != EDamageState.DESTROYED || !m_Asset || !m_SupportEntity)
14  return;
15 
16  SCR_DamageManagerComponent objectDmgManager = SCR_DamageManagerComponent.Cast(SCR_DamageManagerComponent.GetDamageManager(m_Asset));
17  if (objectDmgManager)
18  {
19  objectDmgManager.GetOnDamageStateChanged().Remove(OnObjectDamage);
20  GetGame().GetCallqueue().Remove(CheckEngineDrowned);
21 
22  VehicleControllerComponent_SA vehicleController = VehicleControllerComponent_SA.Cast(m_Asset.FindComponent(VehicleControllerComponent_SA));
23  if (vehicleController)
24  vehicleController.GetOnEngineStop().Remove(CheckEngineDrowned);
25  }
26 
27  m_SupportEntity.FinishTask(this);
28  }
29 
30  //------------------------------------------------------------------------------------------------
31  void CheckEngineDrowned()
32  {
33  if (!m_Asset || !m_SupportEntity)
34  return;
35 
36  VehicleControllerComponent_SA vehicleController = VehicleControllerComponent_SA.Cast(m_Asset.FindComponent(VehicleControllerComponent_SA));
37  if (vehicleController && vehicleController.GetEngineDrowned())
38  {
39  vehicleController.GetOnEngineStop().Remove(CheckEngineDrowned);
40  GetGame().GetCallqueue().Remove(CheckEngineDrowned);
41 
42  SCR_DamageManagerComponent objectDmgManager = SCR_DamageManagerComponent.Cast(SCR_DamageManagerComponent.GetDamageManager(m_Asset));
43  if (objectDmgManager)
44  objectDmgManager.GetOnDamageStateChanged().Remove(OnObjectDamage);
45 
46  m_SupportEntity.FinishTask(this);
47  }
48  }
49 
50  //------------------------------------------------------------------------------------------------
51  override void RehookTaskAsset(IEntity object)
52  {
53  if (!object)
54  return;
55 
56  m_Asset = object;
57 
58  SCR_DamageManagerComponent objectDmgManager = SCR_DamageManagerComponent.Cast(SCR_DamageManagerComponent.GetDamageManager(m_Asset));
59  if (objectDmgManager)
60  objectDmgManager.GetOnDamageStateChanged().Insert(OnObjectDamage);
61 
62  if (Vehicle.Cast(m_Asset))
63  {
64  VehicleControllerComponent_SA vehicleController = VehicleControllerComponent_SA.Cast(m_Asset.FindComponent(VehicleControllerComponent_SA));
65  if (vehicleController)
66  vehicleController.GetOnEngineStop().Insert(CheckEngineDrowned);
67 
68  // Since there is no invoker and no reliable way how to tackle drowned vehicles, in order to make it reliable,
69  // We cannot solely rely on GetOnEngineStop because vehicle could have been pushed/moved into the water without started engine.
70  GetGame().GetCallqueue().CallLater(CheckEngineDrowned, 5000, true);
71  }
72  }
73 
74  //------------------------------------------------------------------------------------------------
75  override bool SetSupportEntity()
76  {
78 
79  if (!m_SupportEntity)
80  {
81  Print("ScenarioFramework: Task Destroy support entity not found in the world, task won't be created!", LogLevel.ERROR);
82  return false;
83  }
84 
85  return true;
86  }
87 
88  //------------------------------------------------------------------------------------------------
89  override void Init()
90  {
91  super.Init();
92 
93  if (!m_Asset)
94  return;
95 
96  SCR_DamageManagerComponent objectDmgManager = SCR_DamageManagerComponent.Cast(SCR_DamageManagerComponent.GetDamageManager(m_Asset));
97  if (objectDmgManager)
98  objectDmgManager.GetOnDamageStateChanged().Insert(OnObjectDamage);
99 
100  if (Vehicle.Cast(m_Asset))
101  {
102  VehicleControllerComponent_SA vehicleController = VehicleControllerComponent_SA.Cast(m_Asset.FindComponent(VehicleControllerComponent_SA));
103  if (vehicleController)
104  vehicleController.GetOnEngineStop().Insert(CheckEngineDrowned);
105 
106  // Since there is no invoker and no reliable way how to tackle drowned vehicles, in order to make it reliable,
107  // We cannot solely rely on GetOnEngineStop because vehicle could have been pushed/moved into the water without started engine.
108  GetGame().GetCallqueue().CallLater(CheckEngineDrowned, 5000, true);
109  }
110  }
111 }
SCR_TaskDestroyObjectClass
Definition: SCR_ScenarioFrameworkTaskDestroyObject.c:2
SCR_ScenarioFrameworkTaskDestroySupportEntity
Definition: SCR_ScenarioFrameworkTaskDestroySupportEntity.c:8
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
EDamageState
EDamageState
Definition: EDamageState.c:12
GetTaskManager
SCR_BaseTaskManager GetTaskManager()
Definition: SCR_BaseTaskManager.c:7
SCR_TaskDestroyObject
Definition: SCR_ScenarioFrameworkTaskDestroyObject.c:7
SCR_ScenarioFrameworkTask
Definition: SCR_ScenarioFrameworkTask.c:7
SCR_ScenarioFrameworkTaskClass
Definition: SCR_ScenarioFrameworkTask.c:2