Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_MineAwarenessComponent.c
Go to the documentation of this file.
1 [EntityEditorProps(category: "GameScripted/ScriptWizard", description: "")]
2 class SCR_MineAwarenessComponentClass : ScriptComponentClass
3 {
4 }
5 
6 class SCR_MineDetectionData
7 {
8  WorldTimestamp m_fLastTime;
10 }
11 
13 {
14  protected ref set<RplId> m_aDetectedMines;
15  protected ref map<RplId, ref SCR_MineDetectionData> m_mMineDetection = new map<RplId, ref SCR_MineDetectionData>();
16 
17  //------------------------------------------------------------------------------------------------
19  static SCR_MineAwarenessComponent GetLocalInstance()
20  {
21  PlayerController playerController = GetGame().GetPlayerController();
22  if (!playerController)
23  return null;
24 
25  return SCR_MineAwarenessComponent.Cast(playerController.FindComponent(SCR_MineAwarenessComponent));
26  }
27 
28  //------------------------------------------------------------------------------------------------
32  void Detect(RplId id, bool instant = false)
33  {
34  if (instant)
35  {
36  m_aDetectedMines.Insert(id);
37  return;
38  }
39 
40  // Only called for mines which are not in m_aDetectedMines
41  if (!m_mMineDetection.Contains(id))
42  m_mMineDetection.Insert(id, new SCR_MineDetectionData);
43 
44  // Check if there is some start time
45  ChimeraWorld world = GetOwner().GetWorld();
46  WorldTimestamp currentTime = world.GetServerTimestamp();
47  SCR_MineDetectionData data = m_mMineDetection.Get(id);
48  if (data.m_fLastTime == 0)
49  data.m_fLastTime = currentTime;
50 
51  float sinceLastTime = currentTime.DiffMilliseconds(data.m_fLastTime);
52  if (sinceLastTime < 1000)
53  data.m_fTimeElapsed += sinceLastTime;
54 
55  data.m_fLastTime = currentTime;
56 
57  if (data.m_fTimeElapsed > 2000)
58  {
59  m_aDetectedMines.Insert(id);
60  m_mMineDetection.Remove(id);
61  }
62  }
63 
64  //------------------------------------------------------------------------------------------------
68  bool IsDetected(IEntity entity)
69  {
70  RplComponent rplComponent = RplComponent.Cast(entity.FindComponent(RplComponent));
71  if (!rplComponent)
72  return true; // visible by default when entity doesn't have any rpl component
73 
74  RplId id = rplComponent.Id();
75  bool isDetected = m_aDetectedMines.Contains(id);
76 
77  if (!isDetected)
78  Detect(id);
79 
80  return isDetected;
81  }
82 
83  //------------------------------------------------------------------------------------------------
84  override event protected void EOnInit(IEntity owner)
85  {
86  m_aDetectedMines = new set<RplId>();
87  }
88 
89  //------------------------------------------------------------------------------------------------
90  override event protected void OnPostInit(IEntity owner)
91  {
92  SetEventMask(GetOwner(), EntityEvent.INIT);
93  }
94 }
ChimeraWorld
Definition: ChimeraWorld.c:12
EntityEditorProps
enum EQueryType EntityEditorProps(category:"GameScripted/Sound", description:"THIS IS THE SCRIPT DESCRIPTION.", color:"0 0 255 255")
Definition: SCR_AmbientSoundsComponent.c:12
ScriptComponent
SCR_SiteSlotEntityClass ScriptComponent
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
SCR_MineAwarenessComponentClass
Definition: SCR_MineAwarenessComponent.c:2
GetOwner
IEntity GetOwner()
Owner entity of the fuel tank.
Definition: SCR_FuelNode.c:128
m_fLastTime
SCR_MineAwarenessComponentClass m_fLastTime
SCR_MineAwarenessComponent
Definition: SCR_MineAwarenessComponent.c:12
data
Get all prefabs that have the spawner data
Definition: SCR_EntityCatalogManagerComponent.c:305
m_fTimeElapsed
float m_fTimeElapsed
Definition: SCR_MineAwarenessComponent.c:9
category
params category
Definition: SCR_VehicleDamageManagerComponent.c:180