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